[mutter] Add api to get the primary monitor of the screen



commit f9b5cdfeb1a3dbe2c39551d086f2290082f3d789
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Feb 25 14:07:48 2011 +0100

    Add api to get the primary monitor of the screen
    
    We don't actually use the full xrandr to get the primary monitor, we
    just rely on the xrandr xinerama compat code to return the primary
    monitor first. This lets us avoid adding unnecessary xrandr code and
    avoids issues with _NET_WM_FULLSCREEN_MONITORS monitor indexes being
    defined wrt xinerama monitor index order.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=609258

 src/core/screen-private.h |    1 +
 src/core/screen.c         |   28 ++++++++++++++++++++++++++++
 src/meta/screen.h         |    1 +
 3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index 1d98a18..acb826a 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -99,6 +99,7 @@ struct _MetaScreen
   guint32 wm_sn_timestamp;
   
   MetaMonitorInfo *monitor_infos;
+  int primary_monitor_index;
   int n_monitor_infos;
 
   /* Cache the current monitor */
diff --git a/src/core/screen.c b/src/core/screen.c
index b6abbe3..252c3e3 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -352,6 +352,18 @@ reload_monitor_infos (MetaScreen *screen)
   screen->n_monitor_infos = 0;
   screen->last_monitor_index = 0;
 
+  /* Xinerama doesn't have a concept of primary monitor, however XRandR
+   * does. However, the XRandR xinerama compat code always sorts the
+   * primary output first, so we rely on that here. We could use the
+   * native XRandR calls instead of xinerama, but that would be
+   * slightly problematic for _NET_WM_FULLSCREEN_MONITORS support, as
+   * that is defined in terms of xinerama monitor indexes.
+   * So, since we don't need anything in xrandr except the primary
+   * we can keep using xinerama and use the first monitor as the
+   * primary.
+   */
+  screen->primary_monitor_index = 0;
+
   screen->display->monitor_cache_invalidated = TRUE;
 
   if (g_getenv ("MUTTER_DEBUG_XINERAMA"))
@@ -2141,6 +2153,22 @@ meta_screen_get_n_monitors (MetaScreen *screen)
 }
 
 /**
+ * meta_screen_get_primary_monitor:
+ * @screen: a #MetaScreen
+ *
+ * Gets the index of the primary monitor on this @screen.
+ *
+ * Return value: a monitor index
+ */
+int
+meta_screen_get_primary_monitor (MetaScreen *screen)
+{
+  g_return_val_if_fail (META_IS_SCREEN (screen), 0);
+
+  return screen->primary_monitor_index;
+}
+
+/**
  * meta_screen_get_monitor_geometry:
  * @screen: a #MetaScreen
  * @monitor: the monitor number
diff --git a/src/meta/screen.h b/src/meta/screen.h
index ddb29a9..06297cc 100644
--- a/src/meta/screen.h
+++ b/src/meta/screen.h
@@ -76,6 +76,7 @@ int meta_screen_get_active_workspace_index (MetaScreen *screen);
 MetaWorkspace * meta_screen_get_active_workspace (MetaScreen *screen);
 
 int  meta_screen_get_n_monitors       (MetaScreen    *screen);
+int  meta_screen_get_primary_monitor  (MetaScreen    *screen);
 void meta_screen_get_monitor_geometry (MetaScreen    *screen,
                                        int            monitor,
                                        MetaRectangle *geometry);



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