[Xfce4-commits] <xfce4-settings:master> Initial work of Lionel Le Folgoc.

Nick Schermer noreply at xfce.org
Sat Aug 28 23:02:01 CEST 2010


Updating branch refs/heads/master
         to 5e60d8cf9307749d1f609d6c0c3dac2fc92108e9 (commit)
       from 07d166afddce6e4874a10bff58083be8ea1528ab (commit)

commit 5e60d8cf9307749d1f609d6c0c3dac2fc92108e9
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Thu May 27 17:37:19 2010 +0200

    Initial work of Lionel Le Folgoc.

 dialogs/display-settings/main.c       |  128 ++++++++++++++++++++------------
 dialogs/display-settings/xfce-randr.c |  100 +++++++++++++++++---------
 dialogs/display-settings/xfce-randr.h |    7 ++
 3 files changed, 154 insertions(+), 81 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 5ff49fb..dac6737 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -43,9 +43,6 @@
 #include "xfce-randr-legacy.h"
 #include "display-dialog_ui.h"
 
-/* not available yet */
-#undef HAS_RANDR_ONE_POINT_TWO
-
 enum
 {
     COLUMN_OUTPUT_NAME,
@@ -114,6 +111,26 @@ display_setting_combo_box_get_value (GtkComboBox *combobox,
 
 
 
+static gboolean
+display_setting_combo_box_get_name (GtkComboBox *combobox,
+                                    gchar       **name)
+{
+    GtkTreeModel *model;
+    GtkTreeIter   iter;
+
+    if (gtk_combo_box_get_active_iter (combobox, &iter))
+    {
+        model = gtk_combo_box_get_model (combobox);
+        gtk_tree_model_get (model, &iter, COLUMN_COMBO_NAME, name, -1);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+
+
 static void
 display_setting_rotations_changed (GtkComboBox *combobox,
                                    GtkBuilder  *builder)
@@ -152,7 +169,9 @@ display_setting_rotations_populate (GtkBuilder *builder)
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
     {
-        rotations = active_rotation = RR_Rotate_0;
+        /* load only supported rotations */
+        rotations = XFCE_RANDR_ROTATIONS (xfce_randr);
+        active_rotation = XFCE_RANDR_ROTATION (xfce_randr);
     }
     else
 #endif
@@ -174,8 +193,13 @@ display_setting_rotations_populate (GtkBuilder *builder)
                                 COLUMN_COMBO_VALUE, rotation_names[n].rotation, -1);
 
             /* select active rotation */
-            if (rotation_names[n].rotation == active_rotation)
-                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+#ifdef HAS_RANDR_ONE_POINT_TWO
+            if (xfce_randr && XFCE_RANDR_MODE (xfce_randr) != None)
+#endif
+            {
+                if (rotation_names[n].rotation == active_rotation)
+                    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+            }
         }
     }
 }
@@ -191,7 +215,7 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
     if (!display_setting_combo_box_get_value (combobox, &value))
         return;
 
-    /* set new rotation */
+    /* set new rate */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
         XFCE_RANDR_MODE (xfce_randr) = value;
@@ -211,7 +235,7 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
     gint          nrates;
     GtkTreeIter   iter;
     gchar        *name = NULL;
-    gint          n, active = -1;
+    gint          n, m, active = -1;
     gshort        diff, active_diff = G_MAXSHORT;
 #ifdef HAS_RANDR_ONE_POINT_TWO
     GObject      *rescombo;
@@ -229,49 +253,44 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
 #ifdef HAS_RANDR_ONE_POINT_TWO
     /* get the selected resolution mode */
     rescombo = gtk_builder_get_object (builder, "randr-resolution");
-    if (!display_setting_combo_box_get_value (GTK_COMBO_BOX (rescombo), (gint *) &active_mode))
-        active_mode = 0;
+    if (!display_setting_combo_box_get_value (GTK_COMBO_BOX (rescombo), (gint *) &active_mode)
+        || !display_setting_combo_box_get_name (GTK_COMBO_BOX (rescombo), (gchar **) &mode_name))
+        active_mode = None;
 
     if (xfce_randr)
     {
-        /* find the selected resolution name */
-        for (n = 0; n < xfce_randr->resources->nmode; n++)
+        /* walk all supported modes */
+        for (m = 0; m < XFCE_RANDR_OUTPUT_INFO (xfce_randr)->nmode; ++m)
         {
-            if (xfce_randr->resources->modes[n].id == active_mode)
+            /* walk the modes to get the mode info for the mode with a matching resolution */
+            for (n = 0; n < xfce_randr->resources->nmode; ++n)
             {
-                /* set the mode (resolution) name */
-                mode_name = xfce_randr->resources->modes[n].name;
+                mode_info = &xfce_randr->resources->modes[n];
 
-                /* walk the modes again to add the resolutions that match the name */
-                for (n = 0; n < xfce_randr->resources->nmode; n++)
+                /* check if this mode is supported by the output */
+                if (XFCE_RANDR_OUTPUT_INFO (xfce_randr)->modes[m] == mode_info->id)
                 {
-                    mode_info = &xfce_randr->resources->modes[n];
-
-                    if (strcmp (mode_name, mode_info->name) != 0)
-                        continue;
+                    if (g_strcmp0 (xfce_randr->resources->modes[n].name, mode_name) == 0)
+                    {
+                        /* calculate the refresh rate */
+                        rate = (gfloat) mode_info->dotClock / ((gfloat) mode_info->hTotal * (gfloat) mode_info->vTotal);
 
-                    /* calculate the refresh rate */
-                    rate = (gfloat) mode_info->dotClock / ((gfloat) mode_info->hTotal * (gfloat) mode_info->vTotal);
+                        /* insert in the combo box */
+                        name = g_strdup_printf (_("%.1f Hz"), rate);
+                        gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
+                        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                                            COLUMN_COMBO_NAME, name,
+                                            COLUMN_COMBO_VALUE, mode_info->id, -1);
+                        g_free (name);
 
-                    /* insert in the combo box */
-                    name = g_strdup_printf (_("%d Hz"), (gint) rate);
-                    gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
-                    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                                        COLUMN_COMBO_NAME, name,
-                                        COLUMN_COMBO_VALUE, mode_info->id, -1);
-                    g_free (name);
+                        /* select the active mode */
+                        if (mode_info->id == XFCE_RANDR_MODE (xfce_randr))
+                            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+                    }
 
-                    /* select the active mode */
-                    if (mode_info->id == XFCE_RANDR_MODE (xfce_randr))
-                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+                    /* finished */
+                    break;
                 }
-
-                /* select the first item if there is no active */
-                if (gtk_combo_box_get_active (GTK_COMBO_BOX (combobox)) == -1)
-                    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
-
-                /* finished */
-                break;
             }
         }
     }
@@ -320,12 +339,19 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
     if (!display_setting_combo_box_get_value (combobox, &value))
         return;
 
-    /* set new rotation */
+    /* set new resolution */
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    if (xfce_randr)
+        XFCE_RANDR_MODE (xfce_randr) = value;
+    else
+#endif
+    /* set new resolution */
     if (xfce_randr_legacy)
         XFCE_RANDR_LEGACY_RESOLUTION (xfce_randr_legacy) = value;
 
     /* update refresh rates */
     display_setting_refresh_rates_populate (builder);
+    display_setting_rotations_populate (builder);
 }
 
 
@@ -352,15 +378,16 @@ display_setting_resolutions_populate (GtkBuilder *builder)
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
     {
-        /* walk all the modes */
-        for (n = 0; n < xfce_randr->resources->nmode; n++)
+        /* walk all supported modes */
+        for (m = 0; m < XFCE_RANDR_OUTPUT_INFO (xfce_randr)->nmode; ++m)
         {
-            /* get the mode */
-            mode = &xfce_randr->resources->modes[n];
-
-            /* check if this mode is supported by the output */
-            for (m = 0; m < XFCE_RANDR_OUTPUT_INFO (xfce_randr)->nmode; m++)
+            /* walk all the modes */
+            for (n = 0; n < xfce_randr->resources->nmode; ++n)
             {
+                /* get the mode */
+                mode = &xfce_randr->resources->modes[n];
+
+                /* check if this mode is supported by the output */
                 if (XFCE_RANDR_OUTPUT_INFO (xfce_randr)->modes[m] == mode->id)
                 {
                     /* avoid dupplicates */
@@ -372,6 +399,10 @@ display_setting_resolutions_populate (GtkBuilder *builder)
                                             COLUMN_COMBO_NAME, mode->name,
                                             COLUMN_COMBO_VALUE, mode->id, -1);
 
+                        /* select the active mode */
+                        if (mode->id == XFCE_RANDR_MODE (xfce_randr))
+                            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+
                         /* set the previous mode */
                         prev = mode;
                     }
@@ -432,6 +463,7 @@ display_settings_treeview_selection_changed (GtkTreeSelection *selection,
 
         /* update the combo boxes */
         display_setting_resolutions_populate (builder);
+        display_setting_refresh_rates_populate (builder);
         display_setting_rotations_populate (builder);
     }
 }
diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index c30047f..e1eb585 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -37,11 +37,16 @@ XfceRandr *
 xfce_randr_new (GdkDisplay  *display,
                 GError     **error)
 {
-    XfceRandr    *randr;
-    Display      *xdisplay;
-    GdkWindow    *root_window;
-    gint          n;
-    gint          major, minor;
+    XfceRandr              *randr;
+    Display                *xdisplay;
+    GdkWindow              *root_window;
+    XRRScreenConfiguration *screen_config;
+    XRRCrtcInfo            *crtc_info;
+#ifdef HAS_RANDR_ONE_POINT_THREE
+    gint                    has_1_3 = FALSE;
+#endif
+    gint                    n;
+    gint                    major, minor;
 
     g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
     g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -64,6 +69,10 @@ xfce_randr_new (GdkDisplay  *display,
                                     "version 1.1 is required at least"), major, minor); 
         return NULL;
     }
+#ifdef HAS_RANDR_ONE_POINT_THREE
+    else if (major == 1 && minor >= 3)
+        has_1_3 = TRUE;
+#endif
 
     /* allocate the structure */
     randr = g_slice_new0 (XfceRandr);
@@ -83,6 +92,7 @@ xfce_randr_new (GdkDisplay  *display,
     /* allocate space for the settings */
     randr->mode = g_new0 (RRMode, randr->resources->noutput);
     randr->rotation = g_new0 (Rotation, randr->resources->noutput);
+    randr->rotations = g_new0 (Rotation, randr->resources->noutput);
     randr->position = g_new0 (XfceOutputPosition, randr->resources->noutput);
     randr->status = g_new0 (XfceOutputStatus, randr->resources->noutput);
     randr->output_info = g_new0 (XRROutputInfo *, randr->resources->noutput);
@@ -110,10 +120,44 @@ xfce_randr_new (GdkDisplay  *display,
             return NULL;
         }
 
-        /* TODO: load defaults */
-        randr->mode[n] = 0;
-        randr->rotation[n] = 0;
-        randr->status[n] = XFCE_OUTPUT_STATUS_NONE;
+        /* load defaults */
+        if (randr->output_info[n]->crtc != None)
+        {
+            crtc_info = XRRGetCrtcInfo (xdisplay, randr->resources, randr->output_info[n]->crtc);
+            randr->mode[n] = crtc_info->mode;
+            randr->rotation[n] = crtc_info->rotation;
+            randr->rotations[n] = crtc_info->rotations;
+            XRRFreeCrtcInfo (crtc_info);
+        }
+        else
+        {
+            randr->mode[n] = None;
+            screen_config = XRRGetScreenInfo (xdisplay, GDK_WINDOW_XID (root_window));
+            randr->rotations[n] = XRRConfigRotations (screen_config, &randr->rotation[n]);
+            XRRFreeScreenConfigInfo (screen_config);
+        }
+
+        if (randr->output_info[n]->connection == RR_Connected)
+        {
+#ifdef HAS_RANDR_ONE_POINT_THREE
+            if (has_1_3 && XRRGetOutputPrimary (xdisplay, GDK_WINDOW_XID (root_window)) == randr->resources->outputs[n])
+            {
+                randr->status[n] = XFCE_OUTPUT_STATUS_PRIMARY;
+                continue;
+            }
+            else
+#endif
+            {
+                /* for randr 1.2, no XRRGetOutputPrimary(), so use the first one */
+                if (G_UNLIKELY (n == 0))
+                {
+                    randr->status[n] = XFCE_OUTPUT_STATUS_PRIMARY;
+                    continue;
+                }
+            }
+
+            randr->status[n] = XFCE_OUTPUT_STATUS_SECONDARY;
+        }
     }
 
     return randr;
@@ -137,6 +181,7 @@ xfce_randr_free (XfceRandr *randr)
     /* free the settings */
     g_free (randr->mode);
     g_free (randr->rotation);
+    g_free (randr->rotations);
     g_free (randr->status);
     g_free (randr->position);
     g_free (randr->output_info);
@@ -242,7 +287,11 @@ xfce_randr_save_device (XfceRandr     *randr,
 
     /* save the rotation in degrees */
     g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme, distinct);
-    xfconf_channel_set_int (channel, property, degrees);
+    /* 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);
 
     /* save the position */
     g_snprintf (property, sizeof (property), "/%s/%s/Position", scheme, distinct);
@@ -338,34 +387,19 @@ xfce_randr_friendly_name (const gchar *name)
 
     /* try to find a translated user friendly name
      * for the output name */
-    if (strcmp (name, "LVDS") == 0
+    if (g_str_has_prefix (name, "LVDS")
         || strcmp (name, "PANEL") == 0)
         return _("Laptop");
-    else if (strcmp (name, "VGA") == 0
-             || strcmp (name, "VGA0") == 0
-             || strcmp (name, "Analog-0") == 0)
+    else if (g_str_has_prefix (name, "VGA")
+             || g_str_has_prefix (name, "Analog"))
         return _("Monitor");
-    else if (strcmp (name, "TV") == 0
-             || strcmp (name, "S-video") == 0
-             || strcmp (name, "TV_7PIN_DIN") == 0)
+    else if (g_str_has_prefix (name, "TV")
+             || strcmp (name, "S-video") == 0)
         return _("Television");
-    else if (strcmp (name, "TMDS-1") == 0
-             || strcmp (name, "DVI-0") == 0
-             || strncmp (name, "DVI-I_1", 7) == 0
-             || strcmp (name, "DVI0") == 0
-             || strcmp (name, "DVI") == 0
-             || strcmp (name, "Digital-0") == 0)
+    else if (g_str_has_prefix (name, "TMDS")
+             || g_str_has_prefix (name, "DVI")
+             || g_str_has_prefix (name, "Digital"))
         return _("Digital display");
-    else if (strcmp (name, "VGA_1") == 0
-             || strcmp (name, "VGA1") == 0
-             || strcmp (name, "Analog-1") == 0)
-        return _("Second monitor");
-    else if (strcmp (name, "TMDS-2") == 0
-             || strcmp (name, "DVI-1") == 0
-             || strncmp (name, "DVI-I_2", 7) == 0
-             || strcmp (name, "DVI1") == 0
-             || strcmp (name, "Digital-1") == 0)
-        return _("Second digital display");
 
     return name;
 }
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 8254433..825f2ef 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -26,13 +26,19 @@
 
 #define XFCE_RANDR_MODE(randr)        (randr->mode[randr->active_output])
 #define XFCE_RANDR_ROTATION(randr)    (randr->rotation[randr->active_output])
+#define XFCE_RANDR_ROTATIONS(randr)   (randr->rotations[randr->active_output])
 #define XFCE_RANDR_OUTPUT_INFO(randr) (randr->output_info[randr->active_output])
 
 /* check for randr 1.2 or better */
 #if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 2)
 #define HAS_RANDR_ONE_POINT_TWO
+/* check for randr 1.3 or better */
+#if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
+#define HAS_RANDR_ONE_POINT_THREE
+#endif
 #else
 #undef HAS_RANDR_ONE_POINT_TWO
+#undef HAS_RANDR_ONE_POINT_THREE
 #endif
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
@@ -83,6 +89,7 @@ struct _XfceRandr
     /* selected settings for all outputs */
     RRMode              *mode;
     Rotation            *rotation;
+    Rotation            *rotations;
     XfceOutputPosition  *position;
     XfceOutputStatus    *status;
 };



More information about the Xfce4-commits mailing list