[Xfce4-commits] [xfce/xfce4-settings] 02/05: Fix the mirror state machine by visualizing all three states
noreply at xfce.org
noreply at xfce.org
Sun Mar 11 13:09:06 CET 2018
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h x f c e - 4 . 1 2
in repository xfce/xfce4-settings.
commit 52d69f9e9509039cd76b4d231c7172438f5c3cf0
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Fri Mar 2 23:09:07 2018 +0100
Fix the mirror state machine by visualizing all three states
The three states are:
0: not cloned
1: cloned (same x/y, same resolution)
2: mirrored (same x/y, different resolution)
In the case of 2 I added some precautions to make both overlapping
displays visible, so the user knows what the current state is.
TODO: Make sure the resolution combobox is updated correctly when the
mirror checkbox is clicked (currently it remains unaltered, even if the
resolution would change through enabling mirror mode).
---
dialogs/display-settings/main.c | 117 ++++++++++++++++++++++++++++------------
1 file changed, 82 insertions(+), 35 deletions(-)
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 6fdd015..b8d0694 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -166,6 +166,8 @@ static void display_settings_minimal_only_display2_toggled (GtkToggleButton *b
static void display_setting_primary_toggled (GtkToggleButton *button,
GtkBuilder *builder);
+static void display_setting_mirror_displays_populate (GtkBuilder *builder);
+
static void
display_settings_changed (void)
{
@@ -482,8 +484,12 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
/* Set new mode */
xfce_randr->mode[active_output] = value;
+ /* In any case, check if we're now in mirror mode */
+ display_setting_mirror_displays_populate (builder);
+
/* Apply the changes */
display_settings_changed ();
+ foo_scroll_area_invalidate (FOO_SCROLL_AREA (randr_gui_area));
}
static void
@@ -549,6 +555,9 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
if (gtk_combo_box_get_active (GTK_COMBO_BOX (combobox)) == -1)
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+ /* In any case, check if we're now in mirror mode */
+ display_setting_mirror_displays_populate (builder);
+
/* Unblock the signal */
g_signal_handlers_unblock_by_func (combobox, display_setting_refresh_rates_changed,
builder);
@@ -877,6 +886,10 @@ display_setting_mirror_displays_toggled (GtkToggleButton *togglebutton,
if (!xfce_randr)
return;
+ /* reset the inconsistent state, since the mirror checkbutton is being toggled */
+ if (gtk_toggle_button_get_inconsistent(togglebutton))
+ gtk_toggle_button_set_inconsistent (togglebutton, FALSE);
+
if (gtk_toggle_button_get_active (togglebutton))
{
/* Activate mirror-mode with a single mode for all of them */
@@ -980,9 +993,15 @@ display_setting_mirror_displays_populate (GtkBuilder *builder)
/* if two displays are 'mirrored', i.e. their x and y positions are the same
we set the checkbutton to the inconsistent state */
if (mirrored == TRUE && cloned == FALSE)
+ {
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (check), 1);
+ }
else
+ {
+ if (gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (check)))
+ gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (check), 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), cloned);
+ }
/* Unblock the signal */
@@ -1562,12 +1581,19 @@ screen_on_event (GdkXEvent *xevent,
}
/* Xfce RANDR GUI **TODO** Place these functions in a sensible location */
-static gboolean
+/* This function checks the status quo of more than one display with respect to
+ cloning and mirroring and returns:
+ 0: not cloned
+ 1: cloned (same x/y, same resolution)
+ 2: mirrored (same x/y, different resolution)
+*/
+static gint
get_mirrored_configuration (void)
{
- gboolean cloned = FALSE;
+ gboolean cloned = TRUE;
RRMode mode = None;
guint n;
+ gint mirrored;
if (!xfce_randr)
return FALSE;
@@ -1580,7 +1606,7 @@ get_mirrored_configuration (void)
mode = xfce_randr_clonable_mode (xfce_randr);
if (mode == None)
- return FALSE;
+ return 0;
/* Check if mirror settings are on */
for (n = 0; n < xfce_randr->noutput; n++)
@@ -1588,13 +1614,18 @@ get_mirrored_configuration (void)
if (xfce_randr->mode[n] == None)
continue;
- cloned = xfce_randr->mirrored[n];
+ cloned &= (xfce_randr->mode[n] == mode &&
+ xfce_randr->mirrored[n]);
+ mirrored = xfce_randr->mirrored[n];
if (!cloned)
break;
}
- return cloned;
+ if (mirrored == TRUE && cloned == FALSE)
+ return 2;
+ else
+ return cloned;
}
static XfceOutputInfo *convert_xfce_output_info (gint output_id)
@@ -2232,14 +2263,16 @@ on_output_event (FooScrollArea *area,
gpointer data)
{
XfceOutputInfo *output = data;
+ gint mirrored;
//App *app = g_object_get_data (G_OBJECT (area), "app");
+ mirrored = get_mirrored_configuration();
/* If the mouse is inside the outputs, set the cursor to "you can move me". See
* on_canvas_event() for where we reset the cursor to the default if it
* exits the outputs' area.
*/
- if (!get_mirrored_configuration() && get_n_connected() > 1)
+ if (!mirrored == 1 && get_n_connected() > 1)
set_cursor (GTK_WIDGET (area), GDK_FLEUR);
if (event->type == FOO_BUTTON_PRESS)
@@ -2248,7 +2281,7 @@ on_output_event (FooScrollArea *area,
gtk_combo_box_set_active (GTK_COMBO_BOX(randr_outputs_combobox), output->id);
- if (!get_mirrored_configuration() && get_n_connected() > 1)
+ if (!mirrored == 1 && get_n_connected() > 1)
{
foo_scroll_area_begin_grab (area, on_output_event, data);
@@ -2352,29 +2385,6 @@ on_canvas_event (FooScrollArea *area,
set_cursor (GTK_WIDGET (area), GDK_BLANK_CURSOR);
}
-static PangoLayout *
-get_display_name (XfceOutputInfo *output)
-{
- const char *text;
-
- if (get_mirrored_configuration())
- {
- /* Translators: this is the feature where what you see on your laptop's
- * screen is the same as your external monitor. Here, "Mirror" is being
- * used as an adjective, not as a verb. For example, the Spanish
- * translation could be "Pantallas en Espejo", *not* "Espejar Pantallas".
- */
- text = _("Mirror Screens");
- }
- else
- {
- text = output->display_name;
- }
-
- return gtk_widget_create_pango_layout (
- GTK_WIDGET (randr_gui_area), text);
-}
-
static void
paint_background (FooScrollArea *area,
cairo_t *cr)
@@ -2418,13 +2428,17 @@ paint_output (cairo_t *cr, int i, double *snap_x, double *snap_y)
gint total_w, total_h;
GList *connected_outputs = list_connected_outputs (&total_w, &total_h);
XfceOutputInfo *output = g_list_nth (connected_outputs, i)->data;
- PangoLayout *layout = get_display_name (output);
+ PangoLayout *layout;
PangoRectangle ink_extent, log_extent;
GdkRectangle viewport;
cairo_pattern_t *pat_lin = NULL, *pat_radial = NULL;
double alpha = 1.0;
double available_w;
double factor = 1.0;
+ const char *text;
+ gint mirrored;
+
+ mirrored = get_mirrored_configuration();
cairo_save (cr);
@@ -2477,7 +2491,17 @@ paint_output (cairo_t *cr, int i, double *snap_x, double *snap_y)
cairo_set_line_width (cr, 1.0);
- if (output->id != active_output)
+ /* Make overlapping displays ('mirrored') more transparent so both displays can
+ be recognized more easily */
+ if (output->id != active_output && mirrored == 2)
+ alpha = 0.3;
+ /* When displays are mirrored it makes no sense to make them semi-transparent
+ because they overlay each other completely */
+ else if (mirrored == 1)
+ alpha = 1.0;
+ /* the inactive display should be more transparent and the overlapping one as
+ well */
+ else if (output->id != active_output || mirrored == 2)
alpha = 0.8;
if (output->on)
@@ -2529,6 +2553,20 @@ paint_output (cairo_t *cr, int i, double *snap_x, double *snap_y)
cairo_fill (cr);
/* Display name label*/
+ if (mirrored == 1)
+ {
+ /* Translators: this is the feature where what you see on your laptop's
+ * screen is the same as your external monitor. Here, "Mirror" is being
+ * used as an adjective, not as a verb. For example, the Spanish
+ * translation could be "Pantallas en Espejo", *not* "Espejar Pantallas".
+ */
+ text = _("Mirror Screens");
+ }
+ else
+ {
+ text = output->display_name;
+ }
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (randr_gui_area), text);
layout_set_font (layout, "Sans Bold 12");
pango_layout_get_pixel_extents (layout, &ink_extent, &log_extent);
@@ -2546,7 +2584,11 @@ paint_output (cairo_t *cr, int i, double *snap_x, double *snap_y)
cairo_move_to (cr,
x + ((w * scale + 0.5) - factor * log_extent.width) / 2,
y + ((h * scale + 0.5) - factor * log_extent.height) / 2 - 1);
- cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, alpha - 0.6);
+ /* Try to make the text as readable as possible for overlapping displays */
+ if (output->id == active_output && mirrored == 2)
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, alpha);
+ else
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, alpha - 0.6);
pango_cairo_show_layout (cr, layout);
@@ -2554,7 +2596,12 @@ paint_output (cairo_t *cr, int i, double *snap_x, double *snap_y)
x + ((w * scale + 0.5) - factor * log_extent.width) / 2,
y + ((h * scale + 0.5) - factor * log_extent.height) / 2);
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha);
+ /* Try to make the text as readable as possible for overlapping displays - the
+ currently selected one could be painted below the other display*/
+ if (output->id == active_output && mirrored == 2)
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
+ else
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha);
pango_cairo_show_layout (cr, layout);
@@ -2608,7 +2655,7 @@ on_area_paint (FooScrollArea *area,
{
paint_output (cr, g_list_position (connected_outputs, list), &x, &y);
- if (get_mirrored_configuration())
+ if (get_mirrored_configuration() == 1)
break;
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list