[Xfce4-commits] <xfce4-settings:master> Allow per-output config save

Nick Schermer noreply at xfce.org
Sat Aug 28 23:05:04 CEST 2010


Updating branch refs/heads/master
         to ccdee7af034e2ecfb4e89d5cb3deb950381dd226 (commit)
       from 4c480c95388ef695cb7485815f1de800d9efa438 (commit)

commit ccdee7af034e2ecfb4e89d5cb3deb950381dd226
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Sat Jul 3 18:52:31 2010 +0200

    Allow per-output config save
    
    People already using this git branch should remove any '/%s/Layout' property,
    it is not used anymore with randr 1.2 (still with randr 1.1).

 dialogs/display-settings/main.c       |   54 +++++++++---
 dialogs/display-settings/xfce-randr.c |  147 ++++++++++++++++-----------------
 dialogs/display-settings/xfce-randr.h |   11 ++-
 xfce4-settings-helper/displays.c      |   38 +++++----
 4 files changed, 147 insertions(+), 103 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 95f6fd4..3b92454 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -252,13 +252,17 @@ display_setting_reflections_changed (GtkComboBox *combobox,
         /* set the new one */
         XFCE_RANDR_ROTATION (xfce_randr) |= value;
         /* Apply the changes */
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
 
         /* Ask user confirmation */
         if (!display_setting_timed_confirmation (builder))
         {
             XFCE_RANDR_ROTATION (xfce_randr) = old_rotation;
-            xfce_randr_save (xfce_randr, "Default", display_channel);
+            xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                    xfce_randr->active_output);
+            xfce_randr_apply (xfce_randr, "Default", display_channel);
         }
     }
 }
@@ -356,7 +360,11 @@ display_setting_rotations_changed (GtkComboBox *combobox,
     /* Apply the changes */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+    {
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
+    }
     else
 #endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
@@ -368,7 +376,9 @@ display_setting_rotations_changed (GtkComboBox *combobox,
         if (xfce_randr)
         {
           XFCE_RANDR_ROTATION (xfce_randr) = old_rotation;
-          xfce_randr_save (xfce_randr, "Default", display_channel);
+          xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                  xfce_randr->active_output);
+          xfce_randr_apply (xfce_randr, "Default", display_channel);
         }
         else
 #endif
@@ -488,7 +498,11 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
     /* Apply the changes */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+    {
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
+    }
     else
 #endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
@@ -500,7 +514,9 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
         if (xfce_randr)
         {
             XFCE_RANDR_MODE (xfce_randr) = old_mode;
-            xfce_randr_save (xfce_randr, "Default", display_channel);
+            xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                    xfce_randr->active_output);
+            xfce_randr_apply (xfce_randr, "Default", display_channel);
         }
         else
 #endif
@@ -663,7 +679,11 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
     /* Apply the changes */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+    {
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
+    }
     else
 #endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
@@ -675,7 +695,9 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
         if (xfce_randr)
         {
             XFCE_RANDR_MODE (xfce_randr) = old_mode;
-            xfce_randr_save (xfce_randr, "Default", display_channel);
+            xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                    xfce_randr->active_output);
+            xfce_randr_apply (xfce_randr, "Default", display_channel);
         }
         else
 #endif
@@ -804,14 +826,18 @@ display_setting_output_toggled (GtkToggleButton *togglebutton,
         XFCE_RANDR_MODE (xfce_randr) =
             xfce_randr_preferred_mode (xfce_randr, xfce_randr->active_output);
         /* Apply the changes */
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
     }
     else if (!is_active && XFCE_RANDR_MODE (xfce_randr) != None)
     {
         XFCE_RANDR_MODE (xfce_randr) = None;
         disabling = TRUE;
         /* Apply the changes */
-        xfce_randr_save (xfce_randr, "Default", display_channel);
+        xfce_randr_save_output (xfce_randr, "Default", display_channel,
+                                xfce_randr->active_output);
+        xfce_randr_apply (xfce_randr, "Default", display_channel);
     }
 
     /* if the user attempted to disable an output, forcefully reload the view.
@@ -1209,8 +1235,12 @@ display_settings_minimal_dialog_response (GtkDialog  *dialog,
                 }
             }
         }
-
-        xfce_randr_save (xfce_randr, "MinimalAutoConfig", display_channel);
+        /* save the two outputs and apply */
+        xfce_randr_save_output (xfce_randr, "MinimalAutoConfig", display_channel,
+                                first);
+        xfce_randr_save_output (xfce_randr, "MinimalAutoConfig", display_channel,
+                                second);
+        xfce_randr_apply (xfce_randr, "MinimalAutoConfig", display_channel);
     }
 
     gtk_main_quit ();
diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index 89230de..600aaad 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -371,44 +371,51 @@ xfce_randr_reload (XfceRandr *randr)
 
 
 
-static void
-xfce_randr_save_device (XfceRandr     *randr,
+void
+xfce_randr_save_output (XfceRandr     *randr,
                         const gchar   *scheme,
                         XfconfChannel *channel,
-                        guint          output,
-                        const gchar   *distinct)
+                        guint          output)
 {
-    gchar        property[512];
-    gchar       *friendly_name, *resolution_name = NULL;
-    const gchar *reflection_name = NULL;
-    XfceRRMode  *mode;
-    gint         degrees;
+    gchar             property[512];
+    gchar            *str_value;
+    const XfceRRMode *mode;
+    gint              degrees;
+
+    g_return_if_fail (randr != NULL && scheme != NULL);
+    g_return_if_fail (XFCONF_IS_CHANNEL (channel));
+    g_return_if_fail (output < randr->noutput);
+
+    /* save the device name */
+    str_value = xfce_randr_friendly_name (randr, randr->resources->outputs[output],
+                                          randr->output_info[output]->name);
+    g_snprintf (property, sizeof (property), "/%s/%s", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_string (channel, property, str_value);
+    g_free (str_value);
 
     /* find the resolution and refresh rate */
     mode = xfce_randr_find_mode_by_id (randr, output, randr->mode[output]);
-    if (mode)
-        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, friendly_name);
-    g_free (friendly_name);
-
-    /* save (or remove) the resolution */
-    g_snprintf (property, sizeof (property), "/%s/%s/Resolution", scheme, distinct);
-    if (G_LIKELY (resolution_name != NULL))
-        xfconf_channel_set_string (channel, property, resolution_name);
-    else
-        xfconf_channel_reset_property (channel, property, FALSE);
+    /* if no resolution was found, mark it as inactive and stop */
+    g_snprintf (property, sizeof (property), "/%s/%s/Active", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_bool (channel, property, mode != NULL);
+
+    if (mode == NULL)
+        return;
+
+    /* save the resolution */
+    str_value = g_strdup_printf ("%dx%d", mode->width, mode->height);
+    g_snprintf (property, sizeof (property), "/%s/%s/Resolution", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_string (channel, property, str_value);
+    g_free (str_value);
 
     /* save the refresh rate */
-    g_snprintf (property, sizeof (property), "/%s/%s/RefreshRate", scheme, distinct);
-    if (G_LIKELY (resolution_name != NULL))
-        xfconf_channel_set_double (channel, property, mode->rate);
-    else
-        xfconf_channel_reset_property (channel, property, FALSE);
+    g_snprintf (property, sizeof (property), "/%s/%s/RefreshRate", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_double (channel, property, mode->rate);
 
     /* convert the rotation into degrees */
     switch (randr->rotation[output] & XFCE_RANDR_ROTATIONS_MASK)
@@ -420,75 +427,67 @@ xfce_randr_save_device (XfceRandr     *randr,
     }
 
     /* save the rotation in degrees */
-    g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme, distinct);
-    /* resolution name NULL means output disabled */
-    if (G_LIKELY (resolution_name != NULL))
-        xfconf_channel_set_int (channel, property, degrees);
-    else
-        xfconf_channel_reset_property (channel, property, FALSE);
+    g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_int (channel, property, degrees);
 
     /* convert the reflection into a string */
     switch (randr->rotation[output] & XFCE_RANDR_REFLECTIONS_MASK)
     {
-        case RR_Reflect_X:              reflection_name = "X";  break;
-        case RR_Reflect_Y:              reflection_name = "Y";  break;
-        case RR_Reflect_X|RR_Reflect_Y: reflection_name = "XY"; break;
-        default:                        reflection_name = "0";  break;
+        case RR_Reflect_X:              str_value = "X";  break;
+        case RR_Reflect_Y:              str_value = "Y";  break;
+        case RR_Reflect_X|RR_Reflect_Y: str_value = "XY"; break;
+        default:                        str_value = "0";  break;
     }
 
     /* save the reflection string */
-    g_snprintf (property, sizeof (property), "/%s/%s/Reflection", scheme, distinct);
-    /* resolution name NULL means output disabled */
-    if (G_LIKELY (resolution_name != NULL))
-        xfconf_channel_set_string (channel, property, reflection_name);
-    else
-        xfconf_channel_reset_property (channel, property, FALSE);
+    g_snprintf (property, sizeof (property), "/%s/%s/Reflection", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_string (channel, property, str_value);
 
 #ifdef HAS_RANDR_ONE_POINT_THREE
     /* is it the primary output? */
-    g_snprintf (property, sizeof (property), "/%s/%s/Primary", scheme, distinct);
-    if (randr->status[output] == XFCE_OUTPUT_STATUS_PRIMARY)
-        xfconf_channel_set_bool (channel, property, TRUE);
-    else
-        xfconf_channel_reset_property (channel, property, FALSE);
+    g_snprintf (property, sizeof (property), "/%s/%s/Primary", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_bool (channel, property,
+                             randr->status[output] == XFCE_OUTPUT_STATUS_PRIMARY);
 #endif
 
-    /* first, remove any existing position */
-    g_snprintf (property, sizeof (property), "/%s/%s/Position", scheme, distinct);
-    xfconf_channel_reset_property (channel, property, TRUE);
-    /* then save the new one */
-    if (G_LIKELY (resolution_name != NULL)
-        && randr->position[output].x >= 0
-        && randr->position[output].y >= 0)
-    {
-        g_snprintf (property, sizeof (property), "/%s/%s/Position/X", scheme, distinct);
-        xfconf_channel_set_int (channel, property, randr->position[output].x);
-        g_snprintf (property, sizeof (property), "/%s/%s/Position/Y", scheme, distinct);
-        xfconf_channel_set_int (channel, property, randr->position[output].y);
-    }
-
-    g_free (resolution_name);
+    /* save the position */
+    g_snprintf (property, sizeof (property), "/%s/%s/Position/X", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_int (channel, property, MAX (randr->position[output].x, 0));
+    g_snprintf (property, sizeof (property), "/%s/%s/Position/Y", scheme,
+                randr->output_info[output]->name);
+    xfconf_channel_set_int (channel, property, MAX (randr->position[output].y, 0));
 }
 
 
 
 void
-xfce_randr_save (XfceRandr     *randr,
-                 const gchar   *scheme,
-                 XfconfChannel *channel)
+xfce_randr_save_all (XfceRandr     *randr,
+                     const gchar   *scheme,
+                     XfconfChannel *channel)
 {
-    gchar        property[512];
     guint        n;
 
+    g_return_if_fail (randr != NULL && scheme != NULL);
     g_return_if_fail (XFCONF_IS_CHANNEL (channel));
 
-    /* store the layout type */
-    g_snprintf (property, sizeof (property), "/%s/Layout", scheme);
-    xfconf_channel_set_string (channel, property, "Outputs");
-
     /* save connected outputs */
     for (n = 0; n < randr->noutput; ++n)
-        xfce_randr_save_device (randr, scheme, channel, n, randr->output_info[n]->name);
+        xfce_randr_save_output (randr, scheme, channel, n);
+}
+
+
+
+void
+xfce_randr_apply (XfceRandr     *randr,
+                  const gchar   *scheme,
+                  XfconfChannel *channel)
+{
+    g_return_if_fail (randr != NULL && scheme != NULL);
+    g_return_if_fail (XFCONF_IS_CHANNEL (channel));
 
     /* tell the helper to apply this theme */
     xfconf_channel_set_string (channel, "/Schemes/Apply", scheme);
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 400192d..02aeb25 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -117,7 +117,16 @@ void        xfce_randr_free            (XfceRandr     *randr);
 
 void        xfce_randr_reload          (XfceRandr     *randr);
 
-void        xfce_randr_save            (XfceRandr     *randr,
+void        xfce_randr_save_output     (XfceRandr     *randr,
+                                        const gchar   *scheme,
+                                        XfconfChannel *channel,
+                                        guint          output);
+
+void        xfce_randr_save_all        (XfceRandr     *randr,
+                                        const gchar   *scheme,
+                                        XfconfChannel *channel);
+
+void        xfce_randr_apply           (XfceRandr     *randr,
                                         const gchar   *scheme,
                                         XfconfChannel *channel);
 
diff --git a/xfce4-settings-helper/displays.c b/xfce4-settings-helper/displays.c
index bf95a6b..34a929e 100644
--- a/xfce4-settings-helper/displays.c
+++ b/xfce4-settings-helper/displays.c
@@ -621,13 +621,14 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         else
             str_value = g_value_get_string (value);
 
-        /* resolution */
-        g_snprintf (property, sizeof (property), "/%s/%s/Resolution",
-                    scheme, output->info->name);
+        /* status */
+        g_snprintf (property, sizeof (property), "/%s/%s/Active", 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 || !G_VALUE_HOLDS_STRING (value))
+        /* disable inactive outputs  */
+        if (value == NULL || !G_VALUE_HOLDS_BOOLEAN (value)
+            || !g_value_get_boolean (value))
         {
             /* output already disabled */
             if (output->info->crtc == None)
@@ -650,6 +651,13 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
 
             continue;
         }
+
+        /* resolution */
+        g_snprintf (property, sizeof (property), "/%s/%s/Resolution",
+                    scheme, output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (value == NULL || !G_VALUE_HOLDS_STRING (value))
+            continue;
         else
             str_value = g_value_get_string (value);
 
@@ -997,23 +1005,21 @@ xfce_displays_helper_channel_property_changed (XfconfChannel      *channel,
         layout_name = xfconf_channel_get_string (channel, property, NULL);
         g_free (property);
 
-        if (G_LIKELY (layout_name))
+        /* if there is a layout name, this is the old randr 1.1 scheme */
+        if (layout_name)
         {
-#ifdef HAS_RANDR_ONE_POINT_TWO
-            if (strcmp (layout_name, "Outputs") == 0)
-                xfce_displays_helper_channel_apply (helper, g_value_get_string (value));
+            if (strcmp (layout_name, "Screens") == 0)
+                xfce_displays_helper_channel_apply_legacy (helper, g_value_get_string (value));
             else
-#endif
-            {
-                if (strcmp (layout_name, "Screens") == 0)
-                    xfce_displays_helper_channel_apply_legacy (helper, g_value_get_string (value));
-                else
-                    g_warning ("Unknown layout: %s\n", layout_name);
-            }
+                g_warning ("Unknown layout: %s\n", layout_name);
 
             /* cleanup */
             g_free (layout_name);
         }
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        else
+            xfce_displays_helper_channel_apply (helper, g_value_get_string (value));
+#endif
 
         /* remove the apply property */
         xfconf_channel_reset_property (channel, "/Schemes/Apply", FALSE);



More information about the Xfce4-commits mailing list