gnome-control-center r9238 - trunk/capplets/display



Author: federico
Date: Wed Feb  4 22:59:50 2009
New Revision: 9238
URL: http://svn.gnome.org/viewvc/gnome-control-center?rev=9238&view=rev

Log:
bnc434729 (RANDR) - Realign the outputs after changing the resolution of one of them
2009-02-04  Federico Mena Quintero  <federico novell com>

	https://bugzilla.novell.com/show_bug.cgi?id=434729 - Realign the
	outputs when changing the resolution of one of them, so one
	doesn't get overlapping monitors (when the resolution becomes
	bigger) or disjoint monitors (when the resolution becomes smaller).

	* xrandr-capplet.c (on_resolution_changed): Align the monitors.
	(realign_outputs_after_resolution_change): New function.  The
	algorithm here could certainly be improved...

Signed-off-by: Federico Mena Quintero <federico novell com>

Modified:
   trunk/capplets/display/ChangeLog
   trunk/capplets/display/xrandr-capplet.c

Modified: trunk/capplets/display/xrandr-capplet.c
==============================================================================
--- trunk/capplets/display/xrandr-capplet.c	(original)
+++ trunk/capplets/display/xrandr-capplet.c	Wed Feb  4 22:59:50 2009
@@ -69,6 +69,7 @@
 static gboolean output_overlaps (GnomeOutputInfo *output, GnomeRRConfig *config);
 static void select_current_output_from_dialog_position (App *app);
 static void monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data);
+static void get_geometry (GnomeOutputInfo *output, int *w, int *h);
 
 static void
 error_message (App *app, const char *primary_text, const char *secondary_text)
@@ -689,15 +690,63 @@
 }
 
 static void
+realign_outputs_after_resolution_change (App *app, GnomeOutputInfo *output_that_changed, int old_width, int old_height)
+{
+    /* We find the outputs that were below or to the right of the output that
+     * changed, and realign them; we also do that for outputs that shared the
+     * right/bottom edges with the output that changed.  The outputs that are
+     * above or to the left of that output don't need to change.
+     */
+
+    int i;
+    int old_right_edge, old_bottom_edge;
+    int dx, dy;
+
+    g_assert (app->current_configuration != NULL);
+
+    old_right_edge = output_that_changed->x + old_width;
+    old_bottom_edge = output_that_changed->y + old_height;
+
+    dx = output_that_changed->width - old_width;
+    dy = output_that_changed->height - old_height;
+
+    for (i = 0; app->current_configuration->outputs[i] != NULL; i++) {
+	GnomeOutputInfo *output;
+	int output_width, output_height;
+
+	output = app->current_configuration->outputs[i];
+
+	if (output == output_that_changed || !output->connected)
+	    continue;
+
+	get_geometry (output, &output_width, &output_height);
+
+	if (output->x >= old_right_edge)
+	    output->x += dx;
+	else if (output->x + output_width == old_right_edge)
+	    output->x = output_that_changed->x + output_that_changed->width - output_width;
+
+	if (output->y >= old_bottom_edge)
+	    output->y += dy;
+	else if (output->y + output_height == old_bottom_edge)
+	    output->y = output_that_changed->y + output_that_changed->height - output_height;
+    }
+}
+
+static void
 on_resolution_changed (GtkComboBox *box, gpointer data)
 {
     App *app = data;
+    int old_width, old_height;
     int width;
     int height;
 
     if (!app->current_output)
 	return;
 
+    old_width = app->current_output->width;
+    old_height = app->current_output->height;
+
     if (get_mode (app->resolution_combo, &width, &height, NULL, NULL))
     {
 	app->current_output->width = width;
@@ -709,23 +758,7 @@
 	    app->current_output->on = TRUE;
     }
 
-#if 0
-    if (app->current_configuration)
-    {
-	x = 0;
-	for (i = 0; app->current_configuration->outputs[i] != NULL; ++i)
-	{
-	    GnomeOutputInfo *output = app->current_configuration->outputs[i];
-
-	    if (output->connected)
-	    {
-		output->x = x;
-
-		x += output->width;
-	    }
-	}
-    }
-#endif
+    realign_outputs_after_resolution_change (app, app->current_output, old_width, old_height);
 
     rebuild_rate_combo (app);
     rebuild_rotation_combo (app);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]