From ca13cec01c44f65f4d17863aa78741cbe14a156b Mon Sep 17 00:00:00 2001 From: Adel Gadllah Date: Sun, 4 Apr 2010 18:03:08 +0200 Subject: [PATCH] Rework shell_global_get_primary_monitor Currently shell_global_get_primary_monitor just returns the first screen, in the list as primary. This is not always correct as the first screen reported by mutter isn't always, the first one listed by RANDR. Use gdk_screen_* to query the monitor information and add a heuristic to prefer LVDS displays (similar like in done for gnome-panel) to prefer the laptop's internal screen over external displays. https://bugzilla.gnome.org/show_bug.cgi?id=608647 --- src/shell-global.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/shell-global.c b/src/shell-global.c index b3a87b857..92855c5c3 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -1103,16 +1103,29 @@ shell_global_get_monitors (ShellGlobal *global) GdkRectangle * shell_global_get_primary_monitor (ShellGlobal *global) { - MetaScreen *screen = shell_global_get_screen (global); - MetaRectangle rect; + GdkScreen *screen = gdk_screen_get_default (); + GdkRectangle rect; + gint i, primary = 0; + gchar *output_name = NULL; - g_assert (sizeof (MetaRectangle) == sizeof (GdkRectangle) && - G_STRUCT_OFFSET (MetaRectangle, x) == G_STRUCT_OFFSET (GdkRectangle, x) && - G_STRUCT_OFFSET (MetaRectangle, y) == G_STRUCT_OFFSET (GdkRectangle, y) && - G_STRUCT_OFFSET (MetaRectangle, width) == G_STRUCT_OFFSET (GdkRectangle, width) && - G_STRUCT_OFFSET (MetaRectangle, height) == G_STRUCT_OFFSET (GdkRectangle, height)); + for (i = 0; i < gdk_screen_get_n_monitors (screen); i++) + { + /* Prefer the laptop's internal screen if present */ + output_name = gdk_screen_get_monitor_plug_name (screen, i); + if (output_name && g_ascii_strncasecmp (output_name, "LVDS", 4) == 0) + { + primary = i; + break; + } + if (output_name) + g_free (output_name); + } + + if (output_name) + g_free (output_name); + + gdk_screen_get_monitor_geometry (screen, primary, &rect); - meta_screen_get_monitor_geometry (screen, 0, &rect); return g_boxed_copy (GDK_TYPE_RECTANGLE, &rect); }