[Xfce4-commits] <xfce4-settings:bluesabre/display-settings> Simplify position handling with enums and structs

Nick Schermer noreply at xfce.org
Mon Dec 9 12:57:00 CET 2013


Updating branch refs/heads/bluesabre/display-settings
         to 9e5481cb8a2d00f2c77e12b7e15f1f0a586a3927 (commit)
       from b6139161381874dff079765a2e1f2abae5061ac5 (commit)

commit 9e5481cb8a2d00f2c77e12b7e15f1f0a586a3927
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date:   Mon Oct 15 18:15:02 2012 +0200

    Simplify position handling with enums and structs
    
    This matches what's done for Rotations and Reflections.
    
    Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>

 dialogs/display-settings/main.c       |   50 ++++++++++++++-------------------
 dialogs/display-settings/xfce-randr.h |   22 +++++++++++----
 2 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 0fcc825..560a37c 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -77,6 +77,18 @@ typedef struct {
 
 
 
+/* Xrandr relation name conversion */
+static const XfceRelation relation_names[] =
+{
+    { XFCE_RANDR_PLACEMENT_MIRROR,   N_("Same as") },
+    { XFCE_RANDR_PLACEMENT_UP, N_("Above") },
+    { XFCE_RANDR_PLACEMENT_DOWN, N_("Below") },
+    { XFCE_RANDR_PLACEMENT_RIGHT, N_("Right of") },
+    { XFCE_RANDR_PLACEMENT_LEFT,  N_("Left of") }
+};
+
+
+
 /* Xrandr rotation name conversion */
 static const XfceRotation rotation_names[] =
 {
@@ -413,6 +425,7 @@ display_setting_positions_populate (GtkBuilder *builder)
     GtkTreeModel *model;
     GObject      *combobox;
     GtkTreeIter   iter;
+    guint         n;
 
     /* Get the positions combo box store and clear it */
     combobox = gtk_builder_get_object (builder, "randr-position");
@@ -433,35 +446,14 @@ display_setting_positions_populate (GtkBuilder *builder)
                          display_setting_positions_changed,
                          builder, NULL);
     
-    /* Insert mirror */
-    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                        COLUMN_COMBO_NAME, _("Mirror"),
-                        COLUMN_COMBO_VALUE, XFCE_RANDR_PLACEMENT_MIRROR, -1);
-    
-    /* Insert left-of */
-    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                        COLUMN_COMBO_NAME, _("Left of"),
-                        COLUMN_COMBO_VALUE, XFCE_RANDR_PLACEMENT_LEFT, -1);
-
-    /* Insert right-of */
-    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                        COLUMN_COMBO_NAME, _("Right of"),
-                        COLUMN_COMBO_VALUE, XFCE_RANDR_PLACEMENT_RIGHT, -1);
-                        
-    /* Insert above */
-    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                        COLUMN_COMBO_NAME, _("Above"),
-                        COLUMN_COMBO_VALUE, XFCE_RANDR_PLACEMENT_UP, -1);
-                        
-    /* Insert below */
-    gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                        COLUMN_COMBO_NAME, _("Below"),
-                        COLUMN_COMBO_VALUE, XFCE_RANDR_PLACEMENT_DOWN, -1);
+    /* Try to insert the relations */
+    for (n = 0; n < G_N_ELEMENTS (relation_names); n++)
+    {
+        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                            COLUMN_COMBO_NAME, _(relation_names[n].name),
+                            COLUMN_COMBO_VALUE, relation_names[n].relation, -1);
+    }
     
     /* Reconnect the signal */
     g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_positions_changed), builder);
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 78a0e7e..f6997ad 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -34,11 +34,6 @@
 #define XFCE_RANDR_POS_Y(randr)           (randr->position[randr->active_output].y)
 #define XFCE_RANDR_ROTATIONS_MASK         (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270)
 #define XFCE_RANDR_REFLECTIONS_MASK       (RR_Reflect_X|RR_Reflect_Y)
-#define XFCE_RANDR_PLACEMENT_UP           0
-#define XFCE_RANDR_PLACEMENT_RIGHT        1
-#define XFCE_RANDR_PLACEMENT_DOWN         2
-#define XFCE_RANDR_PLACEMENT_LEFT         3
-#define XFCE_RANDR_PLACEMENT_MIRROR       4
 
 /* check for randr 1.3 or better */
 #if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
@@ -50,8 +45,10 @@
 typedef struct _XfceRandr          XfceRandr;
 typedef struct _XfceOutputPosition XfceOutputPosition;
 typedef struct _XfceRRMode         XfceRRMode;
+typedef struct _XfceRelation       XfceRelation;
 typedef struct _XfceRotation       XfceRotation;
 typedef enum   _XfceOutputStatus   XfceOutputStatus;
+typedef enum   _XfceOutputRelation XfceOutputRelation;
 
 enum _XfceOutputStatus
 {
@@ -59,6 +56,15 @@ enum _XfceOutputStatus
     XFCE_OUTPUT_STATUS_SECONDARY
 };
 
+enum _XfceOutputRelation
+{
+    XFCE_RANDR_PLACEMENT_MIRROR,
+    XFCE_RANDR_PLACEMENT_UP,
+    XFCE_RANDR_PLACEMENT_DOWN,
+    XFCE_RANDR_PLACEMENT_RIGHT,
+    XFCE_RANDR_PLACEMENT_LEFT
+};
+
 struct _XfceOutputPosition
 {
     gint x;
@@ -73,6 +79,12 @@ struct _XfceRRMode
     gdouble rate;
 };
 
+struct _XfceRelation
+{
+    XfceOutputRelation  relation;
+    const gchar        *name;
+};
+
 struct _XfceRotation
 {
     Rotation     rotation;


More information about the Xfce4-commits mailing list