[gnome-shell] Rework shell_global_get_primary_monitor



commit ca13cec01c44f65f4d17863aa78741cbe14a156b
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Sun Apr 4 18:03:08 2010 +0200

    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 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index b3a87b8..92855c5 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);
 }
 



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