From 82307dd69468d44a10027f8c3eb7bff7e8f62c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20Krezovi=C4=87?= Date: Sat, 26 Aug 2017 21:28:04 +0200 Subject: [PATCH] Move xinerama management to MetaX11Display https://bugzilla.gnome.org/show_bug.cgi?id=759538 --- src/core/screen-private.h | 8 -- src/core/screen.c | 133 ---------------------------- src/x11/meta-x11-display-private.h | 8 ++ src/x11/meta-x11-display.c | 134 +++++++++++++++++++++++++++++ src/x11/window-x11.c | 32 +++---- 5 files changed, 158 insertions(+), 157 deletions(-) diff --git a/src/core/screen-private.h b/src/core/screen-private.h index 486bdcd41..548271c6a 100644 --- a/src/core/screen-private.h +++ b/src/core/screen-private.h @@ -51,8 +51,6 @@ struct _MetaScreen GList *workspaces; - gboolean has_xinerama_indices; - int rows_of_workspaces; int columns_of_workspaces; MetaScreenCorner starting_corner; @@ -118,12 +116,6 @@ void meta_screen_workspace_switched (MetaScreen *screen, void meta_screen_set_active_workspace_hint (MetaScreen *screen); -MetaLogicalMonitor * meta_screen_xinerama_index_to_logical_monitor (MetaScreen *screen, - int index); - -int meta_screen_logical_monitor_to_xinerama_index (MetaScreen *screen, - MetaLogicalMonitor *logical_monitor); - void meta_screen_on_monitors_changed (MetaScreen *screen); #endif diff --git a/src/core/screen.c b/src/core/screen.c index eb9f2f5d8..7099e2379 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -87,13 +87,6 @@ static guint screen_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (MetaScreen, meta_screen, G_TYPE_OBJECT); -static GQuark quark_screen_x11_logical_monitor_data = 0; - -typedef struct _MetaScreenX11LogicalMonitorData -{ - int xinerama_index; -} MetaScreenX11LogicalMonitorData; - static void meta_screen_set_property (GObject *object, guint prop_id, @@ -188,9 +181,6 @@ meta_screen_class_init (MetaScreenClass *klass) g_object_class_install_property (object_class, PROP_N_WORKSPACES, pspec); - - quark_screen_x11_logical_monitor_data = - g_quark_from_static_string ("-meta-screen-logical-monitor-x11-data"); } static void @@ -198,127 +188,6 @@ meta_screen_init (MetaScreen *screen) { } -static MetaScreenX11LogicalMonitorData * -get_screen_x11_logical_monitor_data (MetaLogicalMonitor *logical_monitor) -{ - return g_object_get_qdata (G_OBJECT (logical_monitor), - quark_screen_x11_logical_monitor_data); -} - -static MetaScreenX11LogicalMonitorData * -ensure_screen_x11_logical_monitor_data (MetaLogicalMonitor *logical_monitor) -{ - MetaScreenX11LogicalMonitorData *data; - - data = get_screen_x11_logical_monitor_data (logical_monitor); - if (data) - return data; - - data = g_new0 (MetaScreenX11LogicalMonitorData, 1); - g_object_set_qdata_full (G_OBJECT (logical_monitor), - quark_screen_x11_logical_monitor_data, - data, - g_free); - - return data; -} - -static void -meta_screen_ensure_xinerama_indices (MetaScreen *screen) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - GList *logical_monitors, *l; - XineramaScreenInfo *infos; - int n_infos, j; - - if (screen->has_xinerama_indices) - return; - - screen->has_xinerama_indices = TRUE; - - if (!XineramaIsActive (screen->display->x11_display->xdisplay)) - return; - - infos = XineramaQueryScreens (screen->display->x11_display->xdisplay, - &n_infos); - if (n_infos <= 0 || infos == NULL) - { - meta_XFree (infos); - return; - } - - logical_monitors = - meta_monitor_manager_get_logical_monitors (monitor_manager); - - for (l = logical_monitors; l; l = l->next) - { - MetaLogicalMonitor *logical_monitor = l->data; - - for (j = 0; j < n_infos; ++j) - { - if (logical_monitor->rect.x == infos[j].x_org && - logical_monitor->rect.y == infos[j].y_org && - logical_monitor->rect.width == infos[j].width && - logical_monitor->rect.height == infos[j].height) - { - MetaScreenX11LogicalMonitorData *logical_monitor_data; - - logical_monitor_data = - ensure_screen_x11_logical_monitor_data (logical_monitor); - logical_monitor_data->xinerama_index = j; - } - } - } - - meta_XFree (infos); -} - -int -meta_screen_logical_monitor_to_xinerama_index (MetaScreen *screen, - MetaLogicalMonitor *logical_monitor) -{ - MetaScreenX11LogicalMonitorData *logical_monitor_data; - - g_return_val_if_fail (logical_monitor, -1); - - meta_screen_ensure_xinerama_indices (screen); - - logical_monitor_data = get_screen_x11_logical_monitor_data (logical_monitor); - - return logical_monitor_data->xinerama_index; -} - -MetaLogicalMonitor * -meta_screen_xinerama_index_to_logical_monitor (MetaScreen *screen, - int xinerama_index) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - GList *logical_monitors, *l; - - meta_screen_ensure_xinerama_indices (screen); - - logical_monitors = - meta_monitor_manager_get_logical_monitors (monitor_manager); - - for (l = logical_monitors; l; l = l->next) - { - MetaLogicalMonitor *logical_monitor = l->data; - MetaScreenX11LogicalMonitorData *logical_monitor_data; - - logical_monitor_data = - ensure_screen_x11_logical_monitor_data (logical_monitor); - - if (logical_monitor_data->xinerama_index == xinerama_index) - return logical_monitor; - } - - return NULL; -} - static void reload_logical_monitors (MetaScreen *screen) { @@ -329,8 +198,6 @@ reload_logical_monitors (MetaScreen *screen) MetaWorkspace *space = l->data; meta_workspace_invalidate_work_area (space); } - - screen->has_xinerama_indices = FALSE; } MetaScreen* diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index f2f6cb57b..a0bdbac78 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -28,6 +28,7 @@ #include #include +#include "backends/meta-monitor-manager-private.h" #include "core/display-private.h" #include "meta/common.h" #include "meta/types.h" @@ -95,6 +96,8 @@ struct _MetaX11Display GHashTable *xids; + gboolean has_xinerama_indices; + /* Managed by group.c */ GHashTable *groups_by_leader; @@ -188,5 +191,10 @@ void meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display, Window window, guint32 timestamp); +int meta_x11_display_logical_monitor_to_xinerama_index (MetaX11Display *x11_display, + MetaLogicalMonitor *logical_monitor); + +MetaLogicalMonitor *meta_x11_display_xinerama_index_to_logical_monitor (MetaX11Display *x11_display, + int xinerama_index); #endif /* META_X11_DISPLAY_PRIVATE_H */ diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index c454a562a..ecaf816ff 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -46,8 +46,10 @@ #include #include #include +#include #include "backends/meta-backend-private.h" +#include "backends/meta-logical-monitor.h" #include "backends/x11/meta-backend-x11.h" #include "core/frame.h" #include "core/util-private.h" @@ -65,6 +67,13 @@ G_DEFINE_TYPE (MetaX11Display, meta_x11_display, G_TYPE_OBJECT) +static GQuark quark_x11_display_logical_monitor_data = 0; + +typedef struct _MetaX11DisplayLogicalMonitorData +{ + int xinerama_index; +} MetaX11DisplayLogicalMonitorData; + static const char *gnome_wm_keybindings = "Mutter"; static const char *net_wm_name = "Mutter"; @@ -198,6 +207,8 @@ meta_x11_display_class_init (MetaX11DisplayClass *klass) static void meta_x11_display_init (MetaX11Display *x11_display) { + quark_x11_display_logical_monitor_data = + g_quark_from_static_string ("-meta-x11-display-logical-monitor-data"); } static void @@ -1227,6 +1238,8 @@ on_monitors_changed (MetaDisplay *display, CWX | CWY | CWWidth | CWHeight, &changes); } + + x11_display->has_xinerama_indices = FALSE; } void @@ -1414,3 +1427,124 @@ meta_x11_display_focus_the_no_focus_window (MetaX11Display *x11_display, x11_display->no_focus_window, timestamp); } + +static MetaX11DisplayLogicalMonitorData * +get_x11_display_logical_monitor_data (MetaLogicalMonitor *logical_monitor) +{ + return g_object_get_qdata (G_OBJECT (logical_monitor), + quark_x11_display_logical_monitor_data); +} + +static MetaX11DisplayLogicalMonitorData * +ensure_x11_display_logical_monitor_data (MetaLogicalMonitor *logical_monitor) +{ + MetaX11DisplayLogicalMonitorData *data; + + data = get_x11_display_logical_monitor_data (logical_monitor); + if (data) + return data; + + data = g_new0 (MetaX11DisplayLogicalMonitorData, 1); + g_object_set_qdata_full (G_OBJECT (logical_monitor), + quark_x11_display_logical_monitor_data, + data, + g_free); + + return data; +} + +static void +meta_x11_display_ensure_xinerama_indices (MetaX11Display *x11_display) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + GList *logical_monitors, *l; + XineramaScreenInfo *infos; + int n_infos, j; + + if (x11_display->has_xinerama_indices) + return; + + x11_display->has_xinerama_indices = TRUE; + + if (!XineramaIsActive (x11_display->xdisplay)) + return; + + infos = XineramaQueryScreens (x11_display->xdisplay, + &n_infos); + if (n_infos <= 0 || infos == NULL) + { + meta_XFree (infos); + return; + } + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + + for (l = logical_monitors; l; l = l->next) + { + MetaLogicalMonitor *logical_monitor = l->data; + + for (j = 0; j < n_infos; ++j) + { + if (logical_monitor->rect.x == infos[j].x_org && + logical_monitor->rect.y == infos[j].y_org && + logical_monitor->rect.width == infos[j].width && + logical_monitor->rect.height == infos[j].height) + { + MetaX11DisplayLogicalMonitorData *logical_monitor_data; + + logical_monitor_data = + ensure_x11_display_logical_monitor_data (logical_monitor); + logical_monitor_data->xinerama_index = j; + } + } + } + + meta_XFree (infos); +} + +int +meta_x11_display_logical_monitor_to_xinerama_index (MetaX11Display *x11_display, + MetaLogicalMonitor *logical_monitor) +{ + MetaX11DisplayLogicalMonitorData *logical_monitor_data; + + g_return_val_if_fail (logical_monitor, -1); + + meta_x11_display_ensure_xinerama_indices (x11_display); + + logical_monitor_data = get_x11_display_logical_monitor_data (logical_monitor); + + return logical_monitor_data->xinerama_index; +} + +MetaLogicalMonitor * +meta_x11_display_xinerama_index_to_logical_monitor (MetaX11Display *x11_display, + int xinerama_index) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + GList *logical_monitors, *l; + + meta_x11_display_ensure_xinerama_indices (x11_display); + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + + for (l = logical_monitors; l; l = l->next) + { + MetaLogicalMonitor *logical_monitor = l->data; + MetaX11DisplayLogicalMonitorData *logical_monitor_data; + + logical_monitor_data = + ensure_x11_display_logical_monitor_data (logical_monitor); + + if (logical_monitor_data->xinerama_index == xinerama_index) + return logical_monitor; + } + + return NULL; +} diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index a5ab68236..d297b554d 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -1689,17 +1689,17 @@ meta_window_x11_set_net_wm_state (MetaWindow *window) if (meta_window_has_fullscreen_monitors (window)) { data[0] = - meta_screen_logical_monitor_to_xinerama_index (window->screen, - window->fullscreen_monitors.top); + meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display, + window->fullscreen_monitors.top); data[1] = - meta_screen_logical_monitor_to_xinerama_index (window->screen, - window->fullscreen_monitors.bottom); + meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display, + window->fullscreen_monitors.bottom); data[2] = - meta_screen_logical_monitor_to_xinerama_index (window->screen, - window->fullscreen_monitors.left); + meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display, + window->fullscreen_monitors.left); data[3] = - meta_screen_logical_monitor_to_xinerama_index (window->screen, - window->fullscreen_monitors.right); + meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display, + window->fullscreen_monitors.right); meta_verbose ("Setting _NET_WM_FULLSCREEN_MONITORS\n"); meta_error_trap_push (x11_display); @@ -2814,17 +2814,17 @@ meta_window_x11_client_message (MetaWindow *window, window->desc); top = - meta_screen_xinerama_index_to_logical_monitor (window->screen, - event->xclient.data.l[0]); + meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display, + event->xclient.data.l[0]); bottom = - meta_screen_xinerama_index_to_logical_monitor (window->screen, - event->xclient.data.l[1]); + meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display, + event->xclient.data.l[1]); left = - meta_screen_xinerama_index_to_logical_monitor (window->screen, - event->xclient.data.l[2]); + meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display, + event->xclient.data.l[2]); right = - meta_screen_xinerama_index_to_logical_monitor (window->screen, - event->xclient.data.l[3]); + meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display, + event->xclient.data.l[3]); /* source_indication = event->xclient.data.l[4]; */ meta_window_update_fullscreen_monitors (window, top, bottom, left, right);