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

Jérôme Guelfucci noreply at xfce.org
Thu May 27 17:38:01 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to e82ee0d6dfddbbc835f353d44180a8a8e17115aa (commit)
       from 57be4629d45a1ac5d76edf79291c0c8543705ad5 (commit)

commit e82ee0d6dfddbbc835f353d44180a8a8e17115aa
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Thu May 27 17:27:44 2010 +0200

    Initial work of Lionel Le Folgoc.

 dialogs/display-settings/main.c       |   51 +++++++++++++--------
 dialogs/display-settings/xfce-randr.c |   78 ++++++++++++++++++++++++++++----
 dialogs/display-settings/xfce-randr.h |    7 +++
 3 files changed, 106 insertions(+), 30 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 5ff49fb..861e335 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,
@@ -152,7 +149,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 +173,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 +195,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;
@@ -230,7 +234,7 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
     /* 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;
+        active_mode = None;
 
     if (xfce_randr)
     {
@@ -254,7 +258,7 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
                     rate = (gfloat) mode_info->dotClock / ((gfloat) mode_info->hTotal * (gfloat) mode_info->vTotal);
 
                     /* insert in the combo box */
-                    name = g_strdup_printf (_("%d Hz"), (gint) rate);
+                    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,
@@ -266,10 +270,6 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
                         gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
                 }
 
-                /* 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;
             }
@@ -321,6 +321,12 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
         return;
 
     /* set new rotation */
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    if (xfce_randr)
+        XFCE_RANDR_MODE (xfce_randr) = value;
+    else
+#endif
+    /* set new rotation */
     if (xfce_randr_legacy)
         XFCE_RANDR_LEGACY_RESOLUTION (xfce_randr_legacy) = value;
 
@@ -352,15 +358,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 +379,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;
                     }
diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index c30047f..dd197c5 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);
@@ -75,7 +84,17 @@ xfce_randr_new (GdkDisplay  *display,
     root_window = gdk_get_default_root_window ();
 
     /* get the screen resource */
-    randr->resources = XRRGetScreenResources (xdisplay, GDK_WINDOW_XID (root_window));
+#ifdef HAS_RANDR_ONE_POINT_THREE
+    if (has_1_3)
+    {
+        /*XXX: faster, doesn't probe the hw, only returns the current config. Remove after debug? */
+        randr->resources = XRRGetScreenResourcesCurrent (xdisplay, GDK_WINDOW_XID (root_window));
+    }
+    else
+#endif
+    {
+        randr->resources = XRRGetScreenResources (xdisplay, GDK_WINDOW_XID (root_window));
+    }
 
     /* set some layout */
     randr->layout = XFCE_DISPLAY_LAYOUT_SINGLE;
@@ -83,6 +102,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 +130,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->resources && 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 +191,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);
@@ -338,7 +393,10 @@ xfce_randr_friendly_name (const gchar *name)
 
     /* try to find a translated user friendly name
      * for the output name */
+    /*XXX: read EDID instead? */
     if (strcmp (name, "LVDS") == 0
+        || strcmp (name, "LVDS0") == 0
+        || strcmp (name, "LVDS1") == 0
         || strcmp (name, "PANEL") == 0)
         return _("Laptop");
     else if (strcmp (name, "VGA") == 0
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