[Xfce4-commits] [xfce/xfce4-settings] 08/18: display: Refactor profile-loading in xfsettingsd

noreply at xfce.org noreply at xfce.org
Thu Apr 4 23:03:06 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-settings.

commit b18649e313d9751d6f1641d0d695a7aef5fbfcd0
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Sat Mar 30 11:37:41 2019 +0100

    display: Refactor profile-loading in xfsettingsd
---
 xfsettingsd/displays.c | 114 ++++++++++++++++++++++---------------------------
 1 file changed, 52 insertions(+), 62 deletions(-)

diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c
index 5589a18..c17a040 100644
--- a/xfsettingsd/displays.c
+++ b/xfsettingsd/displays.c
@@ -81,6 +81,7 @@ typedef struct _XfceRROutput XfceRROutput;
 static void             xfce_displays_helper_dispose                        (GObject                 *object);
 static void             xfce_displays_helper_finalize                       (GObject                 *object);
 static void             xfce_displays_helper_reload                         (XfceDisplaysHelper      *helper);
+static gchar           *xfce_displays_helper_get_matching_profile           (XfceDisplaysHelper      *helper);
 static GdkFilterReturn  xfce_displays_helper_screen_on_event                (GdkXEvent               *xevent,
                                                                              GdkEvent                *event,
                                                                              gpointer                 data);
@@ -216,13 +217,6 @@ xfce_displays_helper_init (XfceDisplaysHelper *helper)
 {
     gint major = 0, minor = 0;
     gint error_base, err;
-    GList              *profiles = NULL;
-    GdkDisplay         *display;
-    GError             *error = NULL;
-    gpointer           *profile;
-    XfceRandr          *xfce_randr;
-    gchar              *profile_name;
-    gchar              *property;
 
 #ifdef HAVE_UPOWERGLIB
     helper->power = NULL;
@@ -301,32 +295,12 @@ xfce_displays_helper_init (XfceDisplaysHelper *helper)
             /*  check if we can auto-enable a profile */
             if (xfconf_channel_get_bool (helper->channel, AUTO_ENABLE_PROFILES, TRUE))
             {
-                display = gdk_display_get_default ();
-                xfce_randr = xfce_randr_new (display, &error);
-                if (xfce_randr)
-                {
-                    profiles = display_settings_get_profiles (xfce_randr, helper->channel);
-                    xfce_randr_free (xfce_randr);
-                }
+                gchar *matching_profile = NULL;
 
-                if (profiles == NULL)
-                {
-                    xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "No matching display profiles found.");
-                }
-                else if (g_list_length (profiles) == 1)
-                {
-                    profile = g_list_nth_data (profiles, 0);
-                    xfce_displays_helper_channel_apply (helper, (gchar *)profile);
-                    property = g_strdup_printf ("/%s", (gchar *) profile);
-                    profile_name = xfconf_channel_get_string (helper->channel, property, NULL);
-                    xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Applied the only matching display profile: %s", profile_name);
-                    xfconf_channel_set_string (helper->channel, ACTIVE_PROFILE, (gchar *) profile);
-                    g_free (profile_name);
-                    g_free (property);
-                }
-                else
+                matching_profile = xfce_displays_helper_get_matching_profile (helper);
+                if (matching_profile)
                 {
-                    xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Found %d matching display profiles.", g_list_length (profiles));
+                    xfce_displays_helper_channel_apply (helper, matching_profile);
                 }
             }
             /* restore the default scheme */
@@ -456,6 +430,49 @@ xfce_displays_helper_reload (XfceDisplaysHelper *helper)
 
 
 
+static gchar *
+xfce_displays_helper_get_matching_profile (XfceDisplaysHelper *helper)
+{
+    GList              *profiles = NULL;
+    GdkDisplay         *display;
+    GError             *error = NULL;
+    gpointer           *profile;
+    XfceRandr          *xfce_randr;
+    gchar              *profile_name;
+    gchar              *property;
+
+    display = gdk_display_get_default ();
+    xfce_randr = xfce_randr_new (display, &error);
+    if (xfce_randr)
+    {
+        profiles = display_settings_get_profiles (xfce_randr, helper->channel);
+        xfce_randr_free (xfce_randr);
+    }
+
+    if (profiles == NULL)
+    {
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "No matching display profiles found.");
+    }
+    else if (g_list_length (profiles) == 1)
+    {
+        profile = g_list_nth_data (profiles, 0);
+        property = g_strdup_printf ("/%s", (gchar *) profile);
+        profile_name = xfconf_channel_get_string (helper->channel, property, NULL);
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Applied the only matching display profile: %s", profile_name);
+        xfconf_channel_set_string (helper->channel, ACTIVE_PROFILE, (gchar *) profile);
+        g_free (profile_name);
+        g_free (property);
+        return (gchar *)profile;
+    }
+    else
+    {
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Found %d matching display profiles.", g_list_length (profiles));
+    }
+    return NULL;
+}
+
+
+
 static GdkFilterReturn
 xfce_displays_helper_screen_on_event (GdkXEvent *xevent,
                                       GdkEvent  *event,
@@ -470,13 +487,6 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent,
     gint                j;
     guint               n, m, nactive = 0;
     gboolean            found = FALSE, changed = FALSE;
-    GList              *profiles = NULL;
-    GdkDisplay         *display;
-    GError             *error = NULL;
-    gpointer           *profile;
-    XfceRandr          *xfce_randr;
-    gchar              *profile_name;
-    gchar              *property;
 
     if (!e)
         return GDK_FILTER_CONTINUE;
@@ -496,34 +506,14 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent,
         /* Check if we have a matching profile and apply it if there's only one */
         if (xfconf_channel_get_bool (helper->channel, AUTO_ENABLE_PROFILES, TRUE))
         {
-            display = gdk_display_get_default ();
-            xfce_randr = xfce_randr_new (display, &error);
-            if (xfce_randr)
-            {
-                profiles = display_settings_get_profiles (xfce_randr, helper->channel);
-                xfce_randr_free (xfce_randr);
-            }
+            gchar *matching_profile = NULL;
 
-            if (profiles == NULL)
-            {
-                xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "No matching display profiles found.");
-            }
-            else if (g_list_length (profiles) == 1)
+            matching_profile = xfce_displays_helper_get_matching_profile (helper);
+            if (matching_profile)
             {
-                profile = g_list_nth_data (profiles, 0);
-                xfce_displays_helper_channel_apply (helper, (gchar *)profile);
-                property = g_strdup_printf ("/%s", (gchar *) profile);
-                profile_name = xfconf_channel_get_string (helper->channel, property, NULL);
-                xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Applied the only matching display profile: %s", profile_name);
-                xfconf_channel_set_string (helper->channel, ACTIVE_PROFILE, (gchar *) profile);
-                g_free (profile_name);
-                g_free (property);
+                xfce_displays_helper_channel_apply (helper, matching_profile);
                 return GDK_FILTER_CONTINUE;
             }
-            else
-            {
-                xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Found %d matching display profiles.", g_list_length (profiles));
-            }
         }
         xfconf_channel_set_string (helper->channel, ACTIVE_PROFILE, "Default");
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list