[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Add initial support for extended mode

Jérôme Guelfucci noreply at xfce.org
Thu Jun 10 11:28:07 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to 032591e71c96d333aec0a13de307ac0c2105a053 (commit)
       from 17cc24fa6771064481a9019d20b8f509e46c3e37 (commit)

commit 032591e71c96d333aec0a13de307ac0c2105a053
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Tue Jun 8 22:50:50 2010 +0200

    Add initial support for extended mode
    
    It adds the ability to detect the outputs' relative positions and store them in
    xfconf. It's probably not that beautiful, but at least it works with two
    outputs, and well, it's a start.

 dialogs/display-settings/xfce-randr.c |   83 ++++++++++++++++++++++++++-------
 dialogs/display-settings/xfce-randr.h |   41 +++++++++++------
 2 files changed, 93 insertions(+), 31 deletions(-)

diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index 0fb2f3f..d123a73 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -35,6 +35,45 @@
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
 
+static void
+xfce_randr_compute_position (XfceRandr *randr,
+                             gint      *pos_x,
+                             gint      *pos_y)
+{
+    gint m, n;
+
+    for (n = 0; n < randr->resources->noutput; ++n)
+    {
+        randr->position[n].output = -1;
+
+        if (randr->status[n] == XFCE_OUTPUT_STATUS_NONE || randr->mode[n] == None)
+            continue;
+
+        for (m = 0; m < randr->resources->noutput; ++m)
+        {
+            if (randr->status[m] == XFCE_OUTPUT_STATUS_NONE || m == n
+                || randr->mode[m] == None)
+                continue;
+
+            randr->position[n].output = m;
+            if (pos_x[n] < pos_x[m])
+                randr->position[n].option = XFCE_OUTPUT_POSITION_LEFT_OF;
+            else if (pos_x[n] > pos_x[m])
+                randr->position[n].option = XFCE_OUTPUT_POSITION_RIGHT_OF;
+            else if (pos_y[n] < pos_y[m])
+                randr->position[n].option = XFCE_OUTPUT_POSITION_ABOVE;
+            else if (pos_y[n] > pos_y[m])
+                randr->position[n].option = XFCE_OUTPUT_POSITION_BELOW;
+            else
+                randr->position[n].option = XFCE_OUTPUT_POSITION_SAME_AS;
+
+            break;
+        }
+    }
+}
+
+
+
 XfceRandr *
 xfce_randr_new (GdkDisplay  *display,
                 GError     **error)
@@ -47,6 +86,7 @@ xfce_randr_new (GdkDisplay  *display,
     XRRCrtcInfo            *crtc_info;
     gint                    n;
     gint                    major, minor;
+    gint                   *pos_x, *pos_y;
 
     g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
     g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -95,7 +135,11 @@ xfce_randr_new (GdkDisplay  *display,
     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);
-    
+
+    /* keep track of the positions */
+    pos_x = g_new0 (gint, randr->resources->noutput);
+    pos_y = g_new0 (gint, randr->resources->noutput);
+
     /* walk the outputs */
     for (n = 0; n < randr->resources->noutput; n++)
     {
@@ -152,6 +196,8 @@ xfce_randr_new (GdkDisplay  *display,
                 randr->rotation[n] = crtc_info->rotation;
                 randr->rotations[n] = crtc_info->rotations;
                 XRRFreeCrtcInfo (crtc_info);
+                pos_x[n] = crtc_info->x;
+                pos_y[n] = crtc_info->y;
                 continue;
             }
         }
@@ -162,6 +208,10 @@ xfce_randr_new (GdkDisplay  *display,
         randr->rotations[n] = XRRConfigRotations (screen_config, &randr->rotation[n]);
         XRRFreeScreenConfigInfo (screen_config);
     }
+
+    /* compute the relative positions of outputs */
+    xfce_randr_compute_position (randr, pos_x, pos_y);
+
     return randr;
 }
 
@@ -238,7 +288,7 @@ xfce_randr_save_device (XfceRandr     *randr,
     const gchar *resolution_name = NULL;
     gdouble      refresh_rate = 0.00;
     XRRModeInfo *mode;
-    const gchar *position_name;
+    const gchar *position_option;
     gint         n;
     gint         degrees;
 
@@ -303,27 +353,26 @@ xfce_randr_save_device (XfceRandr     *randr,
         xfconf_channel_reset_property (channel, property, FALSE);
 #endif
 
-    /* save the position */
+    /* first, remove any existing position */
     g_snprintf (property, sizeof (property), "/%s/%s/Position", scheme, distinct);
-    if (randr->layout == XFCE_DISPLAY_LAYOUT_EXTEND
-        && randr->status[output] == XFCE_OUTPUT_STATUS_SECONDARY)
+    xfconf_channel_reset_property (channel, property, TRUE);
+    /* then save the new one */
+    if (G_LIKELY (resolution_name != NULL)
+        && randr->position[output].output >= 0
+        && randr->position[output].output < randr->resources->noutput)
     {
         /* convert the position into a string */
-        switch (randr->position[output])
+        switch (randr->position[output].option)
         {
-            case XFCE_OUTPUT_POSITION_LEFT:  position_name = "Left";   break;
-            case XFCE_OUTPUT_POSITION_RIGHT: position_name = "Right";  break;
-            case XFCE_OUTPUT_POSITION_TOP:   position_name = "Top";    break;
-            default:                         position_name = "Bottom"; break;
+            case XFCE_OUTPUT_POSITION_LEFT_OF:  position_option = "LeftOf";  break;
+            case XFCE_OUTPUT_POSITION_RIGHT_OF: position_option = "RightOf"; break;
+            case XFCE_OUTPUT_POSITION_ABOVE:    position_option = "Above";   break;
+            case XFCE_OUTPUT_POSITION_BELOW:    position_option = "Below";   break;
+            default:                            position_option = "SameAs";  break;
         }
-
+        g_snprintf (property, sizeof (property), "/%s/%s/Position/%s", scheme, distinct, position_option);
         /* save the position */
-        xfconf_channel_set_string (channel, property, position_name);
-    }
-    else
-    {
-        /* remove an existing postion */
-        xfconf_channel_reset_property (channel, property, FALSE);
+        xfconf_channel_set_string (channel, property, randr->output_info[randr->position[output].output]->name);
     }
 }
 
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 840e2b5..37bfb77 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -24,11 +24,13 @@
 #ifndef __XFCE_RANDR_H__
 #define __XFCE_RANDR_H__
 
-#define XFCE_RANDR_MODE(randr)           (randr->mode[randr->active_output])
-#define XFCE_RANDR_PREFERRED_MODE(randr) (randr->preferred_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])
+#define XFCE_RANDR_MODE(randr)            (randr->mode[randr->active_output])
+#define XFCE_RANDR_PREFERRED_MODE(randr)  (randr->preferred_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])
+#define XFCE_RANDR_POSITION_OPTION(randr) (randr->position[randr->active_output].option)
+#define XFCE_RANDR_POSITION_OUTPUT(randr) (randr->position[randr->active_output].output)
 
 /* check for randr 1.2 or better */
 #if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 2)
@@ -43,10 +45,11 @@
 #endif
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
-typedef struct _XfceRandr          XfceRandr;
-typedef enum   _XfceDisplayLayout  XfceDisplayLayout;
-typedef enum   _XfceOutputPosition XfceOutputPosition;
-typedef enum   _XfceOutputStatus   XfceOutputStatus;
+typedef struct _XfceRandr                XfceRandr;
+typedef struct _XfceOutputPosition       XfceOutputPosition;
+typedef enum   _XfceDisplayLayout        XfceDisplayLayout;
+typedef enum   _XfceOutputPositionOption XfceOutputPositionOption;
+typedef enum   _XfceOutputStatus         XfceOutputStatus;
 
 enum _XfceDisplayLayout
 {
@@ -55,12 +58,13 @@ enum _XfceDisplayLayout
     XFCE_DISPLAY_LAYOUT_EXTEND
 };
 
-enum _XfceOutputPosition
+enum _XfceOutputPositionOption
 {
-    XFCE_OUTPUT_POSITION_LEFT,
-    XFCE_OUTPUT_POSITION_RIGHT,
-    XFCE_OUTPUT_POSITION_TOP,
-    XFCE_OUTPUT_POSITION_BOTTOM
+    XFCE_OUTPUT_POSITION_LEFT_OF,
+    XFCE_OUTPUT_POSITION_RIGHT_OF,
+    XFCE_OUTPUT_POSITION_ABOVE,
+    XFCE_OUTPUT_POSITION_BELOW,
+    XFCE_OUTPUT_POSITION_SAME_AS
 };
 
 enum _XfceOutputStatus
@@ -70,6 +74,15 @@ enum _XfceOutputStatus
     XFCE_OUTPUT_STATUS_SECONDARY
 };
 
+struct _XfceOutputPosition
+{
+    /* option... */
+    XfceOutputPositionOption option;
+
+    /* ... relative to the position of */
+    gint                     output;
+};
+
 struct _XfceRandr
 {
     /* xrandr 1.3 capable */



More information about the Xfce4-commits mailing list