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
This commit is contained in:
Adel Gadllah 2010-04-04 18:03:08 +02:00
parent f2af295867
commit ca13cec01c

View File

@ -1103,16 +1103,29 @@ shell_global_get_monitors (ShellGlobal *global)
GdkRectangle * GdkRectangle *
shell_global_get_primary_monitor (ShellGlobal *global) shell_global_get_primary_monitor (ShellGlobal *global)
{ {
MetaScreen *screen = shell_global_get_screen (global); GdkScreen *screen = gdk_screen_get_default ();
MetaRectangle rect; GdkRectangle rect;
gint i, primary = 0;
gchar *output_name = NULL;
g_assert (sizeof (MetaRectangle) == sizeof (GdkRectangle) && for (i = 0; i < gdk_screen_get_n_monitors (screen); i++)
G_STRUCT_OFFSET (MetaRectangle, x) == G_STRUCT_OFFSET (GdkRectangle, x) && {
G_STRUCT_OFFSET (MetaRectangle, y) == G_STRUCT_OFFSET (GdkRectangle, y) && /* Prefer the laptop's internal screen if present */
G_STRUCT_OFFSET (MetaRectangle, width) == G_STRUCT_OFFSET (GdkRectangle, width) && output_name = gdk_screen_get_monitor_plug_name (screen, i);
G_STRUCT_OFFSET (MetaRectangle, height) == G_STRUCT_OFFSET (GdkRectangle, height)); 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); return g_boxed_copy (GDK_TYPE_RECTANGLE, &rect);
} }