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
This commit is contained in:
Alexander Larsson 2011-02-25 14:07:48 +01:00
parent de8eb1f8ee
commit f9b5cdfeb1
3 changed files with 30 additions and 0 deletions

View File

@ -99,6 +99,7 @@ struct _MetaScreen
guint32 wm_sn_timestamp; guint32 wm_sn_timestamp;
MetaMonitorInfo *monitor_infos; MetaMonitorInfo *monitor_infos;
int primary_monitor_index;
int n_monitor_infos; int n_monitor_infos;
/* Cache the current monitor */ /* Cache the current monitor */

View File

@ -352,6 +352,18 @@ reload_monitor_infos (MetaScreen *screen)
screen->n_monitor_infos = 0; screen->n_monitor_infos = 0;
screen->last_monitor_index = 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; screen->display->monitor_cache_invalidated = TRUE;
if (g_getenv ("MUTTER_DEBUG_XINERAMA")) if (g_getenv ("MUTTER_DEBUG_XINERAMA"))
@ -2140,6 +2152,22 @@ meta_screen_get_n_monitors (MetaScreen *screen)
return screen->n_monitor_infos; return screen->n_monitor_infos;
} }
/**
* 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: * meta_screen_get_monitor_geometry:
* @screen: a #MetaScreen * @screen: a #MetaScreen

View File

@ -76,6 +76,7 @@ int meta_screen_get_active_workspace_index (MetaScreen *screen);
MetaWorkspace * meta_screen_get_active_workspace (MetaScreen *screen); MetaWorkspace * meta_screen_get_active_workspace (MetaScreen *screen);
int meta_screen_get_n_monitors (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, void meta_screen_get_monitor_geometry (MetaScreen *screen,
int monitor, int monitor,
MetaRectangle *geometry); MetaRectangle *geometry);