[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Clarify the properties stored in xfconf

Jérôme Guelfucci noreply at xfce.org
Mon Jun 28 22:38:01 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to 5fae5c118cea888a5f0b29e31678637f2db1b28b (commit)
       from 015d29d5fc8b310cff555bab3313112a3d313a9f (commit)

commit 5fae5c118cea888a5f0b29e31678637f2db1b28b
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Mon Jun 28 21:22:24 2010 +0200

    Clarify the properties stored in xfconf
    
    In xfce4-display-settings, instead of storing dubious properties like:
     /Default/Output0                      VGA1
     /Default/Output0/Resolution           1280x1024
    , store:
     /Default/VGA1                         ViewSonic Corporation 17"
     /Default/VGA1/Resolution              1280x1024
    .
    This is more obvious, easier to understand and to edit manually.
    
    Adapt xfce4-settings-helper to this change: instead of parsing each property of
    the channel and trying to find a match in the currently connected outputs, get
    a hash table of all xfconf properties, and for each currently connected output,
    lookup for its (possibly) stored properties in the hash table.
    
    (If you are currently testing the branch, you should reset the channel, as
    properties from the old scheme "/Default/Output%d" won't be deleted:
    "xfconf-query -c displays -p / -r -R".)

 dialogs/display-settings/xfce-randr.c |   38 ++-------
 xfce4-settings-helper/displays.c      |  149 +++++++++++++++++++++------------
 2 files changed, 104 insertions(+), 83 deletions(-)

diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index 25416ad..89230de 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -379,7 +379,7 @@ xfce_randr_save_device (XfceRandr     *randr,
                         const gchar   *distinct)
 {
     gchar        property[512];
-    gchar       *resolution_name = NULL;
+    gchar       *friendly_name, *resolution_name = NULL;
     const gchar *reflection_name = NULL;
     XfceRRMode  *mode;
     gint         degrees;
@@ -390,8 +390,11 @@ xfce_randr_save_device (XfceRandr     *randr,
         resolution_name = g_strdup_printf ("%dx%d", mode->width, mode->height);
 
     /* save the device name */
+    friendly_name = xfce_randr_friendly_name (randr, randr->resources->outputs[output],
+                                              randr->output_info[output]->name);
     g_snprintf (property, sizeof (property), "/%s/%s", scheme, distinct);
-    xfconf_channel_set_string (channel, property, randr->output_info[output]->name);
+    xfconf_channel_set_string (channel, property, friendly_name);
+    g_free (friendly_name);
 
     /* save (or remove) the resolution */
     g_snprintf (property, sizeof (property), "/%s/%s/Resolution", scheme, distinct);
@@ -475,7 +478,7 @@ xfce_randr_save (XfceRandr     *randr,
                  XfconfChannel *channel)
 {
     gchar        property[512];
-    guint        n, nsaved;
+    guint        n;
 
     g_return_if_fail (XFCONF_IS_CHANNEL (channel));
 
@@ -483,32 +486,9 @@ xfce_randr_save (XfceRandr     *randr,
     g_snprintf (property, sizeof (property), "/%s/Layout", scheme);
     xfconf_channel_set_string (channel, property, "Outputs");
 
-    /* first pass: save connected and active outputs */
-    nsaved = 0;
+    /* save connected outputs */
     for (n = 0; n < randr->noutput; ++n)
-    {
-        if (randr->mode[n] == None)
-            continue;
-
-        g_snprintf (property, sizeof (property), "Output%u", nsaved++);
-        xfce_randr_save_device (randr, scheme, channel, n, property);
-    }
-
-    /* second pass: save connected and disabled outputs */
-    for (n = 0; n < randr->noutput; ++n)
-    {
-        if (randr->mode[n] != None)
-            continue;
-
-        g_snprintf (property, sizeof (property), "Output%u", nsaved++);
-        xfce_randr_save_device (randr, scheme, channel, n, property);
-    }
-
-    g_assert_cmpuint (nsaved, ==, randr->noutput);
-
-    /* store the number of outputs saved */
-    g_snprintf (property, sizeof (property), "/%s/NumOutputs", scheme);
-    xfconf_channel_set_int (channel, property, randr->noutput);
+        xfce_randr_save_device (randr, scheme, channel, n, randr->output_info[n]->name);
 
     /* tell the helper to apply this theme */
     xfconf_channel_set_string (channel, "/Schemes/Apply", scheme);
@@ -568,7 +548,7 @@ xfce_randr_friendly_name (XfceRandr   *randr,
     guint8      *edid_data;
     gchar       *friendly_name = NULL;
 
-    g_return_val_if_fail (randr != NULL && output != None && name != NULL, "<null>");
+    g_return_val_if_fail (randr != NULL && output != None && name != NULL, g_strdup ("<null>"));
 
     /* special case, a laptop */
     if (g_str_has_prefix (name, "LVDS")
diff --git a/xfce4-settings-helper/displays.c b/xfce4-settings-helper/displays.c
index 3e4bde8..bf95a6b 100644
--- a/xfce4-settings-helper/displays.c
+++ b/xfce4-settings-helper/displays.c
@@ -293,12 +293,12 @@ xfce_displays_helper_free_output (XfceRROutput *output)
 
 
 
-static GHashTable *
+static GPtrArray *
 xfce_displays_helper_list_outputs (Display            *xdisplay,
                                    XRRScreenResources *resources,
                                    gint               *nactive)
 {
-    GHashTable    *outputs;
+    GPtrArray     *outputs;
     XRROutputInfo *info;
     XfceRROutput  *output;
     gint           n;
@@ -308,9 +308,8 @@ xfce_displays_helper_list_outputs (Display            *xdisplay,
     g_return_val_if_fail (resources->noutput > 0, NULL);
     g_return_val_if_fail (nactive != NULL, NULL);
 
-    /* keys (info->name) are owned by X, do not free them */
-    outputs = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
-                                     (GDestroyNotify) xfce_displays_helper_free_output);
+    outputs = g_ptr_array_new_with_free_func (
+        (GDestroyNotify) xfce_displays_helper_free_output);
 
     /* get all connected outputs */
     *nactive = 0;
@@ -330,8 +329,8 @@ xfce_displays_helper_list_outputs (Display            *xdisplay,
         /* this will contain the settings to apply (filled in later) */
         output->pending = NULL;
 
-        /* enable quick lookup by name */
-        g_hash_table_insert (outputs, info->name, output);
+        /* cache it */
+        g_ptr_array_add (outputs, output);
 
         /* return the number of active outputs */
         if (info->crtc != None)
@@ -561,14 +560,17 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
     gchar               property[512];
     gint                min_width, min_height, max_width, max_height;
     gint                mm_width, mm_height, width, height;
-    gint                l, m, n, num_outputs, output_rot, nactive;
+    gint                l, m, output_rot, nactive;
+    guint               n;
 #ifdef HAS_RANDR_ONE_POINT_THREE
     gint                is_primary;
 #endif
-    gchar              *value;
+    GValue             *value;
+    const gchar        *str_value;
     gdouble             output_rate, rate;
     XRRModeInfo        *mode_info;
-    GHashTable         *connected_outputs;
+    GPtrArray          *connected_outputs;
+    GHashTable         *saved_outputs;
     XfceRROutput       *output;
 
     /* flush x and trap errors */
@@ -601,28 +603,31 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
     /* then all connected outputs */
     connected_outputs = xfce_displays_helper_list_outputs (xdisplay, resources, &nactive);
 
-    /* get the number of saved outputs */
-    g_snprintf (property, sizeof (property), "/%s/NumOutputs", scheme);
-    num_outputs = xfconf_channel_get_int (helper->channel, property, 0);
+    /* finally the list of saved outputs from xfconf */
+    g_snprintf (property, sizeof (property), "/%s", scheme);
+    saved_outputs = xfconf_channel_get_properties (helper->channel, property);
 
-    for (n = 0; n < num_outputs; ++n)
+    for (n = 0; n < connected_outputs->len; ++n)
     {
-        /* get the output name */
-        g_snprintf (property, sizeof (property), "/%s/Output%d", scheme, n);
-        value = xfconf_channel_get_string (helper->channel, property, NULL);
+        output = g_ptr_array_index (connected_outputs, n);
 
-        /* does this output exist? */
-        output = g_hash_table_lookup (connected_outputs, value);
-        g_free (value);
+        /* does this output exist in xfconf? */
+        g_snprintf (property, sizeof (property), "/%s/%s", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
 
-        if (output == NULL)
+        if (value == NULL || !G_VALUE_HOLDS_STRING (value))
             continue;
+        else
+            str_value = g_value_get_string (value);
 
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Resolution", scheme, n);
-        value = xfconf_channel_get_string (helper->channel, property, NULL);
+        /* resolution */
+        g_snprintf (property, sizeof (property), "/%s/%s/Resolution",
+                    scheme, output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
 
         /* outputs that have to be disabled are stored without resolution */
-        if (value == NULL)
+        if (value == NULL || !G_VALUE_HOLDS_STRING (value))
         {
             /* output already disabled */
             if (output->info->crtc == None)
@@ -633,7 +638,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
                 xfce_dialog_show_warning (NULL,
                                           _("The last active screen must not be disabled, the system would"
                                             " be unusable."),
-                                          _("%s was not disabled"), output->info->name);
+                                          _("%s (%s) was not disabled"), str_value, output->info->name);
                 continue;
             }
             crtc = xfce_displays_helper_find_crtc_by_id (resources, crtcs,
@@ -645,9 +650,17 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
 
             continue;
         }
-
-        g_snprintf (property, sizeof (property), "/%s/Output%d/RefreshRate", scheme, n);
-        output_rate = xfconf_channel_get_double (helper->channel, property, 0.0);
+        else
+            str_value = g_value_get_string (value);
+
+        /* refresh rate */
+        g_snprintf (property, sizeof (property), "/%s/%s/RefreshRate", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_DOUBLE (value))
+            output_rate = g_value_get_double (value);
+        else
+            output_rate = 0.0;
 
         /* prepare pending settings */
         pending = g_new0 (XfceRRCrtc, 1);
@@ -671,32 +684,34 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
 
                 /* find the mode corresponding to the saved values */
                 if (((int) rate == (int) output_rate)
-                    && (g_strcmp0 (mode_info->name, value) == 0))
+                    && (g_strcmp0 (mode_info->name, str_value) == 0))
                 {
                     pending->mode = mode_info->id;
                     break;
                 }
             }
-
             /* found it */
             if (pending->mode != None)
                 break;
         }
-
         /* unsupported mode, abort for this output */
         if (pending->mode == None)
         {
             g_warning ("Unknown mode '%s @ %.1f' for output %s.\n",
-                       value, output_rate, output->info->name);
+                       str_value, output_rate, output->info->name);
             g_free (pending);
-            g_free (value);
-
             continue;
         }
-        g_free (value);
 
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Rotation", scheme, n);
-        output_rot = xfconf_channel_get_int (helper->channel, property, 0);
+        /* rotation */
+        g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_INT (value))
+            output_rot = g_value_get_int (value);
+        else
+            output_rot = 0;
+
         /* convert to a Rotation */
         switch (output_rot)
         {
@@ -706,30 +721,53 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
             default:  pending->rotation = RR_Rotate_0;   break;
         }
 
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Reflection", scheme, n);
-        value = xfconf_channel_get_string (helper->channel, property, "0");
+        /* reflection */
+        g_snprintf (property, sizeof (property), "/%s/%s/Reflection", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_STRING (value))
+            str_value = g_value_get_string (value);
+        else
+            str_value = "0";
+
         /* convert to a Rotation */
-        if (g_strcmp0 (value, "X") == 0)
+        if (g_strcmp0 (str_value, "X") == 0)
             pending->rotation |= RR_Reflect_X;
-        else if (g_strcmp0 (value, "Y") == 0)
+        else if (g_strcmp0 (str_value, "Y") == 0)
             pending->rotation |= RR_Reflect_Y;
-        else if (g_strcmp0 (value, "XY") == 0)
+        else if (g_strcmp0 (str_value, "XY") == 0)
             pending->rotation |= (RR_Reflect_X|RR_Reflect_Y);
 
-        g_free (value);
-
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Position/X", scheme, n);
-        pending->x = xfconf_channel_get_int (helper->channel, property, 0);
-
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Position/Y", scheme, n);
-        pending->y = xfconf_channel_get_int (helper->channel, property, 0);
+        /* position, x */
+        g_snprintf (property, sizeof (property), "/%s/%s/Position/X", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_INT (value))
+            pending->x = g_value_get_int (value);
+        else
+            pending->x = 0;
+
+        /* position, y */
+        g_snprintf (property, sizeof (property), "/%s/%s/Position/Y", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_INT (value))
+            pending->y = g_value_get_int (value);
+        else
+            pending->y = 0;
 
         /* done */
         output->pending = pending;
 
 #ifdef HAS_RANDR_ONE_POINT_THREE
-        g_snprintf (property, sizeof (property), "/%s/Output%d/Primary", scheme, n);
-        is_primary = xfconf_channel_get_bool (helper->channel, property, FALSE);
+        /* is it the primary output? */
+        g_snprintf (property, sizeof (property), "/%s/%s/Primary", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_BOOLEAN (value))
+            is_primary = g_value_get_boolean (value);
+        else
+            is_primary = FALSE;
 #endif
 
         /* first, search for a possible clone */
@@ -803,13 +841,16 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         XRRSetScreenSize (xdisplay, GDK_WINDOW_XID (root_window),
                           width, height, mm_width, mm_height);
 
+    /* Free the xfconf properties */
+    g_hash_table_destroy (saved_outputs);
+
     /* Free our output cache */
-    g_hash_table_unref (connected_outputs);
+    g_ptr_array_unref (connected_outputs);
 
     /* cleanup our CRTC cache */
-    for (n = 0; n < resources->ncrtc; ++n)
+    for (m = 0; m < resources->ncrtc; ++m)
     {
-        xfce_displays_helper_cleanup_crtc (&crtcs[n]);
+        xfce_displays_helper_cleanup_crtc (&crtcs[m]);
     }
     g_free (crtcs);
 



More information about the Xfce4-commits mailing list