Move xinerama management to MetaX11Display

https://bugzilla.gnome.org/show_bug.cgi?id=759538
This commit is contained in:
Armin Krezović 2017-08-26 21:28:04 +02:00 committed by Jonas Ådahl
parent e1c67a1824
commit 82307dd694
5 changed files with 158 additions and 157 deletions

View File

@ -51,8 +51,6 @@ struct _MetaScreen
GList *workspaces; GList *workspaces;
gboolean has_xinerama_indices;
int rows_of_workspaces; int rows_of_workspaces;
int columns_of_workspaces; int columns_of_workspaces;
MetaScreenCorner starting_corner; MetaScreenCorner starting_corner;
@ -118,12 +116,6 @@ void meta_screen_workspace_switched (MetaScreen *screen,
void meta_screen_set_active_workspace_hint (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); void meta_screen_on_monitors_changed (MetaScreen *screen);
#endif #endif

View File

@ -87,13 +87,6 @@ static guint screen_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (MetaScreen, meta_screen, G_TYPE_OBJECT); 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 static void
meta_screen_set_property (GObject *object, meta_screen_set_property (GObject *object,
guint prop_id, guint prop_id,
@ -188,9 +181,6 @@ meta_screen_class_init (MetaScreenClass *klass)
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_N_WORKSPACES, PROP_N_WORKSPACES,
pspec); pspec);
quark_screen_x11_logical_monitor_data =
g_quark_from_static_string ("-meta-screen-logical-monitor-x11-data");
} }
static void 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 static void
reload_logical_monitors (MetaScreen *screen) reload_logical_monitors (MetaScreen *screen)
{ {
@ -329,8 +198,6 @@ reload_logical_monitors (MetaScreen *screen)
MetaWorkspace *space = l->data; MetaWorkspace *space = l->data;
meta_workspace_invalidate_work_area (space); meta_workspace_invalidate_work_area (space);
} }
screen->has_xinerama_indices = FALSE;
} }
MetaScreen* MetaScreen*

View File

@ -28,6 +28,7 @@
#include <glib.h> #include <glib.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include "backends/meta-monitor-manager-private.h"
#include "core/display-private.h" #include "core/display-private.h"
#include "meta/common.h" #include "meta/common.h"
#include "meta/types.h" #include "meta/types.h"
@ -95,6 +96,8 @@ struct _MetaX11Display
GHashTable *xids; GHashTable *xids;
gboolean has_xinerama_indices;
/* Managed by group.c */ /* Managed by group.c */
GHashTable *groups_by_leader; GHashTable *groups_by_leader;
@ -188,5 +191,10 @@ void meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display,
Window window, Window window,
guint32 timestamp); 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 */ #endif /* META_X11_DISPLAY_PRIVATE_H */

View File

@ -46,8 +46,10 @@
#include <X11/extensions/Xcomposite.h> #include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h> #include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h> #include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xinerama.h>
#include "backends/meta-backend-private.h" #include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/x11/meta-backend-x11.h" #include "backends/x11/meta-backend-x11.h"
#include "core/frame.h" #include "core/frame.h"
#include "core/util-private.h" #include "core/util-private.h"
@ -65,6 +67,13 @@
G_DEFINE_TYPE (MetaX11Display, meta_x11_display, G_TYPE_OBJECT) 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 *gnome_wm_keybindings = "Mutter";
static const char *net_wm_name = "Mutter"; static const char *net_wm_name = "Mutter";
@ -198,6 +207,8 @@ meta_x11_display_class_init (MetaX11DisplayClass *klass)
static void static void
meta_x11_display_init (MetaX11Display *x11_display) 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 static void
@ -1227,6 +1238,8 @@ on_monitors_changed (MetaDisplay *display,
CWX | CWY | CWWidth | CWHeight, CWX | CWY | CWWidth | CWHeight,
&changes); &changes);
} }
x11_display->has_xinerama_indices = FALSE;
} }
void void
@ -1414,3 +1427,124 @@ meta_x11_display_focus_the_no_focus_window (MetaX11Display *x11_display,
x11_display->no_focus_window, x11_display->no_focus_window,
timestamp); 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;
}

View File

@ -1689,17 +1689,17 @@ meta_window_x11_set_net_wm_state (MetaWindow *window)
if (meta_window_has_fullscreen_monitors (window)) if (meta_window_has_fullscreen_monitors (window))
{ {
data[0] = data[0] =
meta_screen_logical_monitor_to_xinerama_index (window->screen, meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display,
window->fullscreen_monitors.top); window->fullscreen_monitors.top);
data[1] = data[1] =
meta_screen_logical_monitor_to_xinerama_index (window->screen, meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display,
window->fullscreen_monitors.bottom); window->fullscreen_monitors.bottom);
data[2] = data[2] =
meta_screen_logical_monitor_to_xinerama_index (window->screen, meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display,
window->fullscreen_monitors.left); window->fullscreen_monitors.left);
data[3] = data[3] =
meta_screen_logical_monitor_to_xinerama_index (window->screen, meta_x11_display_logical_monitor_to_xinerama_index (window->display->x11_display,
window->fullscreen_monitors.right); window->fullscreen_monitors.right);
meta_verbose ("Setting _NET_WM_FULLSCREEN_MONITORS\n"); meta_verbose ("Setting _NET_WM_FULLSCREEN_MONITORS\n");
meta_error_trap_push (x11_display); meta_error_trap_push (x11_display);
@ -2814,17 +2814,17 @@ meta_window_x11_client_message (MetaWindow *window,
window->desc); window->desc);
top = top =
meta_screen_xinerama_index_to_logical_monitor (window->screen, meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display,
event->xclient.data.l[0]); event->xclient.data.l[0]);
bottom = bottom =
meta_screen_xinerama_index_to_logical_monitor (window->screen, meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display,
event->xclient.data.l[1]); event->xclient.data.l[1]);
left = left =
meta_screen_xinerama_index_to_logical_monitor (window->screen, meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display,
event->xclient.data.l[2]); event->xclient.data.l[2]);
right = right =
meta_screen_xinerama_index_to_logical_monitor (window->screen, meta_x11_display_xinerama_index_to_logical_monitor (window->display->x11_display,
event->xclient.data.l[3]); event->xclient.data.l[3]);
/* source_indication = event->xclient.data.l[4]; */ /* source_indication = event->xclient.data.l[4]; */
meta_window_update_fullscreen_monitors (window, top, bottom, left, right); meta_window_update_fullscreen_monitors (window, top, bottom, left, right);