[Xfce4-commits] [xfce/xfce4-settings] 01/01: display: Fix settings retention (Bug #15437)

noreply at xfce.org noreply at xfce.org
Thu Aug 8 01:53:56 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 09bdf5d1118b9ba8ce48fb8cf4528f024b218be2
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Aug 5 09:37:41 2019 +0200

    display: Fix settings retention (Bug #15437)
    
    While this is a rather big commit, at the core it's simply replacing a
    misguided call to xfce_randr_new. This led to xfsettingsd asking X for
    the default/preferred mode etc. of the connected displays, essentially
    resetting all saved settings (i.e. the "Default" profile in xfconf).
    The correct approach is to get all necessary display_infos from the xfce
    display helper (aka displays.c).
    
    Other, unrelated, changes are the replacement of the completely
    unnecessary "buf" variable and correctly freeing the GList
    "channel_contents".
---
 common/display-profiles.c       | 43 ++++++++++++++++++++---------------------
 common/display-profiles.h       |  8 ++++----
 common/xfce-randr.c             |  2 +-
 common/xfce-randr.h             |  3 +++
 dialogs/display-settings/main.c | 27 ++++++++++++++++++++++----
 xfsettingsd/displays.c          | 42 +++++++++++++++++++++++++++++++---------
 6 files changed, 85 insertions(+), 40 deletions(-)

diff --git a/common/display-profiles.c b/common/display-profiles.c
index 0274bc4..2265a22 100644
--- a/common/display-profiles.c
+++ b/common/display-profiles.c
@@ -66,27 +66,24 @@ display_settings_profile_name_exists (XfconfChannel *channel, const gchar *new_p
 
         current = g_list_next (current);
     }
+    g_list_free (channel_contents);
     g_hash_table_destroy (properties);
     return TRUE;
 }
 
 GList*
-display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
+display_settings_get_profiles (gchar **display_infos, XfconfChannel *channel)
 {
     GHashTable *properties;
-    GList *channel_contents, *profiles = NULL, *current;
-    guint                     m;
-    gchar                   **display_infos;
+    GList      *channel_contents;
+    GList      *profiles = NULL;
+    GList      *current;
+    guint       m;
+    guint       noutput;
 
     properties = xfconf_channel_get_properties (channel, NULL);
     channel_contents = g_hash_table_get_keys (properties);
-    display_infos = g_new0 (gchar *, xfce_randr->noutput);
-
-    /* get all display edids, to only query randr once */
-    for (m = 0; m < xfce_randr->noutput; ++m)
-    {
-        display_infos[m] = g_strdup_printf ("%s", xfce_randr_get_edid (xfce_randr, m));
-    }
+    noutput = g_strv_length (display_infos);
 
     /* get all profiles */
     current = g_list_first (channel_contents);
@@ -98,8 +95,8 @@ display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
         gpointer        key, value;
         guint           profile_match = 0;
         guint           monitors = 0;
-        gchar          *buf;
         gchar         **current_elements = g_strsplit (current->data, "/", -1);
+        gchar          *profile_name;
 
         /* Only process the profiles and skip all other xfconf properties */
         /* If xfconf ever supports just getting the first-level children of a property
@@ -110,11 +107,12 @@ display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
             current = g_list_next (current);
             continue;
         }
+
+        profile_name = g_strdup_printf ("%s", *(current_elements+1));
         g_strfreev (current_elements);
-        buf = strtok (current->data, "/");
 
         /* Walk through the profile and check if every EDID referenced there is also currently available */
-        property_profile = g_strdup_printf ("/%s", buf);
+        property_profile = g_strdup_printf ("/%s", profile_name);
         props = xfconf_channel_get_properties (channel, property_profile);
         g_hash_table_iter_init (&iter, props);
 
@@ -132,7 +130,7 @@ display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
 
                 if (current_edid) {
 
-                    for (m = 0; m < xfce_randr->noutput; ++m)
+                    for (m = 0; m < noutput; ++m)
                     {
                         if (g_strcmp0 (display_infos[m], current_edid) == 0)
                         {
@@ -150,20 +148,21 @@ display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
         g_hash_table_destroy (props);
 
         /* filter the content of the combobox to only matching profiles and exclude "Notify", "Default" and "Schemes" */
-        if (!g_list_find_custom (profiles, (char*) buf, (GCompareFunc) strcmp) &&
-            strcmp (buf, "Notify") &&
-            strcmp (buf, "Default") &&
-            strcmp (buf, "Schemes") &&
+        if (!g_list_find_custom (profiles, profile_name, (GCompareFunc) strcmp) &&
+            strcmp (profile_name, "Notify") &&
+            strcmp (profile_name, "Default") &&
+            strcmp (profile_name, "Schemes") &&
             profile_match == monitors &&
-            xfce_randr->noutput == profile_match)
+            noutput == profile_match)
         {
-            profiles = g_list_prepend (profiles, g_strdup (buf));
+            profiles = g_list_prepend (profiles, g_strdup (profile_name));
         }
         /* else don't add the profile to the list */
         current = g_list_next (current);
+        g_free (profile_name);
     }
 
-    for (m = 0; m < xfce_randr->noutput; ++m)
+    for (m = 0; m < noutput; ++m)
     {
         g_free (display_infos[m]);
     }
diff --git a/common/display-profiles.h b/common/display-profiles.h
index 0299964..910a27c 100644
--- a/common/display-profiles.h
+++ b/common/display-profiles.h
@@ -22,7 +22,7 @@
 #include "xfce-randr.h"
 
 
-gboolean display_settings_profile_name_exists   (XfconfChannel *channel,
-                                                 const gchar   *new_profile_name);
-GList*   display_settings_get_profiles          (XfceRandr     *xfce_randr,
-                                                 XfconfChannel *channel);
+gboolean display_settings_profile_name_exists   (XfconfChannel  *channel,
+                                                 const gchar    *new_profile_name);
+GList*   display_settings_get_profiles          (gchar         **display_infos,
+                                                 XfconfChannel  *channel);
diff --git a/common/xfce-randr.c b/common/xfce-randr.c
index 0c7c5d4..11f94db 100644
--- a/common/xfce-randr.c
+++ b/common/xfce-randr.c
@@ -515,7 +515,7 @@ xfce_randr_load (XfceRandr     *randr,
 
 
 
-static guint8 *
+guint8 *
 xfce_randr_read_edid_data (Display  *xdisplay,
                            RROutput  output)
 {
diff --git a/common/xfce-randr.h b/common/xfce-randr.h
index 53eb882..cf7fb73 100644
--- a/common/xfce-randr.h
+++ b/common/xfce-randr.h
@@ -128,6 +128,9 @@ void              xfce_randr_load            (XfceRandr        *randr,
                                               const gchar      *scheme,
                                               XfconfChannel    *channel);
 
+guint8 *          xfce_randr_read_edid_data  (Display          *xdisplay,
+                                              RROutput          output);
+
 const XfceRRMode *xfce_randr_find_mode_by_id (XfceRandr        *randr,
                                               guint             output,
                                               RRMode            id);
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index ab9aad8..bbabfaa 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -1258,17 +1258,34 @@ display_settings_combobox_selection_changed (GtkComboBox *combobox,
     }
 }
 
+static gchar **
+display_settings_get_display_infos (void)
+{
+    gchar   **display_infos;
+    guint     m;
+
+    display_infos = g_new0 (gchar *, xfce_randr->noutput);
+    /* get all display edids, to only query randr once */
+    for (m = 0; m < xfce_randr->noutput; ++m)
+    {
+        display_infos[m] = g_strdup_printf ("%s", xfce_randr_get_edid (xfce_randr, m));
+    }
+    return display_infos;
+}
+
 static void
 display_settings_minimal_profile_populate (GtkBuilder *builder)
 {
     GObject  *profile_box, *profile_display1;
     GList    *profiles = NULL;
     GList    *current;
+    gchar   **display_infos;
 
     profile_box  = gtk_builder_get_object (builder, "profile-box");
     profile_display1  = gtk_builder_get_object (builder, "display1");
 
-    profiles = display_settings_get_profiles (xfce_randr, display_channel);
+    display_infos = display_settings_get_display_infos ();
+    profiles = display_settings_get_profiles (display_infos, display_channel);
 
     current = g_list_first (profiles);
     while (current)
@@ -1353,8 +1370,9 @@ display_settings_profile_list_populate (GtkBuilder *builder)
     GtkListStore     *store;
     GObject          *treeview;
     GtkTreeIter       iter;
-    GList *profiles = NULL;
-    GList *current;
+    GList            *profiles = NULL;
+    GList            *current;
+    gchar           **display_infos;
 
     /* create a new list store */
     store = gtk_list_store_new (N_COLUMNS,
@@ -1366,7 +1384,8 @@ display_settings_profile_list_populate (GtkBuilder *builder)
     treeview = gtk_builder_get_object (builder, "randr-profile");
     gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
 
-    profiles = display_settings_get_profiles (xfce_randr, display_channel);
+    display_infos = display_settings_get_display_infos ();
+    profiles = display_settings_get_profiles (display_infos, display_channel);
 
     /* Populate treeview */
     current = g_list_first (profiles);
diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c
index 80a147a..4933ca4 100644
--- a/xfsettingsd/displays.c
+++ b/xfsettingsd/displays.c
@@ -303,6 +303,9 @@ xfce_displays_helper_init (XfceDisplaysHelper *helper)
                 {
                     xfce_displays_helper_channel_apply (helper, matching_profile);
                 }
+                else {
+                    xfce_displays_helper_channel_apply (helper, DEFAULT_SCHEME_NAME);
+                }
             }
             /* restore the default scheme */
             else {
@@ -432,23 +435,44 @@ xfce_displays_helper_reload (XfceDisplaysHelper *helper)
 
 
 
+static gchar **
+xfce_displays_helper_get_display_infos (gint      noutput,
+                                        Display  *xdisplay,
+                                        RROutput *outputs)
+{
+    gchar    **display_infos;
+    gint       m;
+    guint8    *edid_data;
+
+    display_infos = g_new0 (gchar *, noutput);
+    /* get all display edids, to only query randr once */
+    for (m = 0; m < noutput; ++m)
+    {
+        edid_data = xfce_randr_read_edid_data (xdisplay, outputs[m]);
+
+        if (edid_data)
+            display_infos[m] = g_compute_checksum_for_data (G_CHECKSUM_SHA1 , edid_data, 128);
+    }
+    return display_infos;
+}
+
+
+
 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;
+    gchar             **display_infos;
 
-    display = gdk_display_get_default ();
-    xfce_randr = xfce_randr_new (display, &error);
-    if (xfce_randr)
+    display_infos = xfce_displays_helper_get_display_infos (helper->resources->noutput,
+                                                            helper->xdisplay,
+                                                            helper->resources->outputs);
+    if (display_infos)
     {
-        profiles = display_settings_get_profiles (xfce_randr, helper->channel);
-        xfce_randr_free (xfce_randr);
+        profiles = display_settings_get_profiles (display_infos, helper->channel);
     }
 
     if (profiles == NULL)
@@ -469,6 +493,7 @@ xfce_displays_helper_get_matching_profile (XfceDisplaysHelper *helper)
     {
         xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Found %d matching display profiles.", g_list_length (profiles));
     }
+
     return NULL;
 }
 
@@ -806,7 +831,6 @@ xfce_displays_helper_load_from_xfconf (XfceDisplaysHelper *helper,
     else
         str_value = g_value_get_string (value);
 
-
     /* refresh rate */
     g_snprintf (property, sizeof (property), RRATE_PROP, scheme, output->info->name);
     value = g_hash_table_lookup (saved_outputs, property);

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


More information about the Xfce4-commits mailing list