[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Support reflections
Jérôme Guelfucci
noreply at xfce.org
Sat Jun 12 09:58:08 CEST 2010
Updating branch refs/heads/xrandr-display-settings
to 0688bf31194298e975b794176d155dca85e85cb7 (commit)
from 87b69fa729c299efbad3d8da49bf921114efb188 (commit)
commit 0688bf31194298e975b794176d155dca85e85cb7
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date: Fri Jun 11 21:48:17 2010 +0200
Support reflections
.../display-dialog-xrandr1.2.glade | 29 ++++++-
dialogs/display-settings/main.c | 98 +++++++++++++++++++-
dialogs/display-settings/xfce-randr.c | 20 ++++-
dialogs/display-settings/xfce-randr.h | 2 +
xfce4-settings-helper/displays.c | 32 ++++---
5 files changed, 160 insertions(+), 21 deletions(-)
diff --git a/dialogs/display-settings/display-dialog-xrandr1.2.glade b/dialogs/display-settings/display-dialog-xrandr1.2.glade
index d7f65c6..e18f465 100644
--- a/dialogs/display-settings/display-dialog-xrandr1.2.glade
+++ b/dialogs/display-settings/display-dialog-xrandr1.2.glade
@@ -47,11 +47,26 @@
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
- <property name="n_rows">2</property>
+ <property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Re_flection:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">randr-reflection</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
@@ -80,6 +95,18 @@
</packing>
</child>
<child>
+ <object class="GtkComboBox" id="randr-reflection">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkComboBox" id="randr-rotation">
<property name="visible">True</property>
</object>
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index a3083f2..b3e6908 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -75,6 +75,19 @@ static const XfceRotation rotation_names[] =
+#ifdef HAS_RANDR_ONE_POINT_TWO
+/* xrandr reflection name conversion */
+static const XfceRotation reflection_names[] =
+{
+ { 0, N_("None") },
+ { RR_Reflect_X, N_("Horizontal") },
+ { RR_Reflect_Y, N_("Vertical") },
+ { RR_Reflect_X|RR_Reflect_Y, N_("Both") }
+};
+#endif
+
+
+
/* option entries */
static gboolean opt_version = FALSE;
static GOptionEntry option_entries[] =
@@ -114,6 +127,72 @@ display_setting_combo_box_get_value (GtkComboBox *combobox,
+#ifdef HAS_RANDR_ONE_POINT_TWO
+static void
+display_setting_reflections_changed (GtkComboBox *combobox,
+ GtkBuilder *builder)
+{
+ gint value;
+
+ if (!display_setting_combo_box_get_value (combobox, &value))
+ return;
+
+ if (xfce_randr)
+ {
+ /* remove existing reflection */
+ XFCE_RANDR_ROTATION (xfce_randr) &= ~XFCE_RANDR_REFLECTIONS_MASK;
+ /* set the new one */
+ XFCE_RANDR_ROTATION (xfce_randr) |= value;
+ }
+}
+
+
+static void
+display_setting_reflections_populate (GtkBuilder *builder)
+{
+ GtkTreeModel *model;
+ GObject *combobox;
+ Rotation reflections;
+ Rotation active_reflection;
+ guint n;
+ GtkTreeIter iter;
+
+ /* get the combo box store and clear it */
+ combobox = gtk_builder_get_object (builder, "randr-reflection");
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ if (xfce_randr)
+ {
+ /* load only supported reflections */
+ reflections = XFCE_RANDR_ROTATIONS (xfce_randr) & XFCE_RANDR_REFLECTIONS_MASK;
+ active_reflection = XFCE_RANDR_ROTATION (xfce_randr) & XFCE_RANDR_REFLECTIONS_MASK;
+ }
+
+ /* try to insert the reflections */
+ for (n = 0; n < G_N_ELEMENTS (reflection_names); n++)
+ {
+ if ((reflections & reflection_names[n].rotation) == reflection_names[n].rotation)
+ {
+ /* insert */
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ COLUMN_COMBO_NAME, _(reflection_names[n].name),
+ COLUMN_COMBO_VALUE, reflection_names[n].rotation, -1);
+
+ /* select active reflection */
+ if (xfce_randr && XFCE_RANDR_MODE (xfce_randr) != None)
+ {
+ if ((reflection_names[n].rotation & active_reflection) == reflection_names[n].rotation)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+ }
+ }
+ }
+}
+#endif
+
+
+
static void
display_setting_rotations_changed (GtkComboBox *combobox,
GtkBuilder *builder)
@@ -126,7 +205,10 @@ display_setting_rotations_changed (GtkComboBox *combobox,
/* set new rotation */
#ifdef HAS_RANDR_ONE_POINT_TWO
if (xfce_randr)
- XFCE_RANDR_ROTATION (xfce_randr) = value;
+ {
+ XFCE_RANDR_ROTATION (xfce_randr) &= ~XFCE_RANDR_ROTATIONS_MASK;
+ XFCE_RANDR_ROTATION (xfce_randr) |= value;
+ }
else
#endif
XFCE_RANDR_LEGACY_ROTATION (xfce_randr_legacy) = value;
@@ -153,8 +235,8 @@ display_setting_rotations_populate (GtkBuilder *builder)
if (xfce_randr)
{
/* load only supported rotations */
- rotations = XFCE_RANDR_ROTATIONS (xfce_randr);
- active_rotation = XFCE_RANDR_ROTATION (xfce_randr);
+ rotations = XFCE_RANDR_ROTATIONS (xfce_randr) & XFCE_RANDR_ROTATIONS_MASK;
+ active_rotation = XFCE_RANDR_ROTATION (xfce_randr) & XFCE_RANDR_ROTATIONS_MASK;
}
else
#endif
@@ -167,7 +249,7 @@ display_setting_rotations_populate (GtkBuilder *builder)
/* try to insert the rotations */
for (n = 0; n < G_N_ELEMENTS (rotation_names); n++)
{
- if ((rotations & rotation_names[n].rotation) != 0)
+ if ((rotations & rotation_names[n].rotation) == rotation_names[n].rotation)
{
/* insert */
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
@@ -180,7 +262,7 @@ display_setting_rotations_populate (GtkBuilder *builder)
if (xfce_randr && XFCE_RANDR_MODE (xfce_randr) != None)
#endif
{
- if (rotation_names[n].rotation == active_rotation)
+ if ((rotation_names[n].rotation & active_rotation) == rotation_names[n].rotation)
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
}
}
@@ -331,6 +413,7 @@ display_setting_modes_changed (GtkComboBox *combobox,
display_setting_refresh_rates_populate (builder);
display_setting_rotations_populate (builder);
+ display_setting_reflections_populate (builder);
}
@@ -432,6 +515,7 @@ display_settings_treeview_selection_changed (GtkTreeSelection *selection,
/* update the combo boxes */
#ifdef HAS_RANDR_ONE_POINT_TWO
display_setting_modes_populate (builder);
+ display_setting_reflections_populate (builder);
#else
display_setting_resolutions_populate (builder);
display_setting_refresh_rates_populate (builder);
@@ -611,6 +695,10 @@ display_settings_dialog_new (GtkBuilder *builder)
combobox = gtk_builder_get_object (builder, "randr-mode");
display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_modes_changed), builder);
+
+ combobox = gtk_builder_get_object (builder, "randr-reflection");
+ display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
+ g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_reflections_changed), builder);
}
else
#endif
diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index d50c7a1..5d898ca 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -239,6 +239,7 @@ xfce_randr_save_device (XfceRandr *randr,
{
gchar property[512];
const gchar *resolution_name = NULL;
+ const gchar *reflection_name = NULL;
gdouble refresh_rate = 0.00;
XRRModeInfo *mode;
gint n;
@@ -280,7 +281,7 @@ xfce_randr_save_device (XfceRandr *randr,
xfconf_channel_reset_property (channel, property, FALSE);
/* convert the rotation into degrees */
- switch (randr->rotation[output])
+ switch (randr->rotation[output] & XFCE_RANDR_ROTATIONS_MASK)
{
case RR_Rotate_90: degrees = 90; break;
case RR_Rotate_180: degrees = 180; break;
@@ -296,6 +297,23 @@ xfce_randr_save_device (XfceRandr *randr,
else
xfconf_channel_reset_property (channel, property, FALSE);
+ /* 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;
+ }
+
+ /* 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);
+
#ifdef HAS_RANDR_ONE_POINT_THREE
/* is it the primary output? */
g_snprintf (property, sizeof (property), "/%s/%s/Primary", scheme, distinct);
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index 214a49c..e687394 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -31,6 +31,8 @@
#define XFCE_RANDR_OUTPUT_INFO(randr) (randr->output_info[randr->active_output])
#define XFCE_RANDR_POS_X(randr) (randr->position[randr->active_output].x)
#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)
/* check for randr 1.2 or better */
#if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 2)
diff --git a/xfce4-settings-helper/displays.c b/xfce4-settings-helper/displays.c
index 6a24bad..66a7f04 100644
--- a/xfce4-settings-helper/displays.c
+++ b/xfce4-settings-helper/displays.c
@@ -291,7 +291,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
gint is_primary;
#endif
gint pos_x, pos_y;
- gchar *output_name, *output_res;
+ gchar *output_name, *output_res, *output_ref;
gdouble output_rate;
XRROutputInfo *output_info;
XRRCrtcInfo *crtc_info;
@@ -352,20 +352,24 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
/* convert to a Rotation */
switch (output_rot)
{
- case 90:
- rot = RR_Rotate_90;
- break;
- case 180:
- rot = RR_Rotate_180;
- break;
- case 270:
- rot = RR_Rotate_270;
- break;
- default:
- rot = RR_Rotate_0;
- break;
+ case 90: rot = RR_Rotate_90; break;
+ case 180: rot = RR_Rotate_180; break;
+ case 270: rot = RR_Rotate_270; break;
+ default: rot = RR_Rotate_0; break;
}
+ g_snprintf (property, sizeof (property), "/%s/Output%d/Reflection", scheme, n);
+ output_ref = xfconf_channel_get_string (helper->channel, property, "0");
+ /* convert to a Rotation */
+ if (g_strcmp0 (output_ref, "X") == 0)
+ rot |= RR_Reflect_X;
+ else if (g_strcmp0 (output_ref, "Y") == 0)
+ rot |= RR_Reflect_Y;
+ else if (g_strcmp0 (output_ref, "XY") == 0)
+ rot |= (RR_Reflect_X|RR_Reflect_Y);
+
+ g_free (output_ref);
+
#ifdef HAS_RANDR_ONE_POINT_THREE
g_snprintf (property, sizeof (property), "/%s/Output%d/Primary", scheme, n);
is_primary = xfconf_channel_get_bool (helper->channel, property, FALSE);
@@ -466,7 +470,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
}
/* get the sizes of the mode to enforce */
- if (rot == RR_Rotate_90 || rot == RR_Rotate_270)
+ if ((rot & (RR_Rotate_90|RR_Rotate_270)) != 0)
xfce_displays_helper_process_screen_size (xdisplay, resources->modes[j].height,
resources->modes[j].width, pos_x, pos_y,
&width, &height, &mm_width, &mm_height);
More information about the Xfce4-commits
mailing list