diff -up gtk+-2.15.4/gdk/x11/gdkscreen-x11.c.monitor-sizes gtk+-2.15.4/gdk/x11/gdkscreen-x11.c --- gtk+-2.15.4/gdk/x11/gdkscreen-x11.c.monitor-sizes 2009-02-23 17:46:34.738078794 -0500 +++ gtk+-2.15.4/gdk/x11/gdkscreen-x11.c 2009-02-23 17:47:01.228887089 -0500 @@ -663,6 +663,31 @@ init_fake_xinerama (GdkScreen *screen) return FALSE; } +static int +monitor_compare_function (GdkX11Monitor *monitor1, + GdkX11Monitor *monitor2) +{ + /* Sort the leftmost/topmost monitors first. + * For "cloned" monitors, sort the bigger ones first + * (giving preference to taller monitors over wider + * monitors) + */ + + if (monitor1->geometry.x != monitor2->geometry.x) + return monitor1->geometry.x - monitor2->geometry.x; + + if (monitor1->geometry.y != monitor2->geometry.y) + return monitor1->geometry.y - monitor2->geometry.y; + + if (monitor1->geometry.height != monitor2->geometry.height) + return - (monitor1->geometry.height - monitor2->geometry.height); + + if (monitor1->geometry.width != monitor2->geometry.width) + return - (monitor1->geometry.width - monitor2->geometry.width); + + return 0; +} + static gboolean init_randr13 (GdkScreen *screen) { @@ -732,10 +757,12 @@ init_randr13 (GdkScreen *screen) return FALSE; } + g_array_sort (monitors, + (GCompareFunc) monitor_compare_function); screen_x11->n_monitors = monitors->len; screen_x11->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE); - return TRUE; + return screen_x11->n_monitors > 0; #endif return FALSE;