x11: Setup and user ownership chains

On the path towards clear ownership chains and always using them to find
other components, do the same for X11 client support paths too.

x11-display: Don't get backend from signleton

x11/selection: Don't get display from singleton

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
This commit is contained in:
Jonas Ådahl 2022-09-07 11:34:35 +02:00 committed by Robert Mader
parent e5908f5752
commit 1b737190cc
4 changed files with 47 additions and 30 deletions

View File

@ -944,7 +944,8 @@ handle_input_xevent (MetaX11Display *x11_display,
MetaWindow *window; MetaWindow *window;
MetaDisplay *display = x11_display->display; MetaDisplay *display = x11_display->display;
MetaWorkspaceManager *workspace_manager = display->workspace_manager; MetaWorkspaceManager *workspace_manager = display->workspace_manager;
MetaBackend *backend = meta_get_backend (); MetaContext *context = meta_display_get_context (display);
MetaBackend *backend = meta_context_get_backend (context);
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend)); ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
if (input_event == NULL) if (input_event == NULL)

View File

@ -95,6 +95,15 @@ static void prefs_changed_callback (MetaPreference pref,
static void meta_x11_display_init_frames_client (MetaX11Display *x11_display); static void meta_x11_display_init_frames_client (MetaX11Display *x11_display);
static MetaBackend *
backend_from_x11_display (MetaX11Display *x11_display)
{
MetaDisplay *display = meta_x11_display_get_display (x11_display);
MetaContext *context = meta_display_get_context (display);
return meta_context_get_backend (context);
}
static void static void
meta_x11_display_unmanage_windows (MetaX11Display *x11_display) meta_x11_display_unmanage_windows (MetaX11Display *x11_display)
{ {
@ -919,7 +928,8 @@ set_workspace_work_area_hint (MetaWorkspace *workspace,
g_autofree char *workarea_name = NULL; g_autofree char *workarea_name = NULL;
Atom workarea_atom; Atom workarea_atom;
monitor_manager = meta_backend_get_monitor_manager (meta_get_backend ()); monitor_manager =
meta_backend_get_monitor_manager (backend_from_x11_display (x11_display));
logical_monitors = meta_monitor_manager_get_logical_monitors (monitor_manager); logical_monitors = meta_monitor_manager_get_logical_monitors (monitor_manager);
num_monitors = meta_monitor_manager_get_num_logical_monitors (monitor_manager); num_monitors = meta_monitor_manager_get_num_logical_monitors (monitor_manager);
@ -1178,6 +1188,9 @@ meta_x11_display_new (MetaDisplay *display,
GError **error) GError **error)
{ {
MetaContext *context = meta_display_get_context (display); MetaContext *context = meta_display_get_context (display);
MetaBackend *backend = meta_context_get_backend (context);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
g_autoptr (MetaX11Display) x11_display = NULL; g_autoptr (MetaX11Display) x11_display = NULL;
Display *xdisplay; Display *xdisplay;
Screen *xscreen; Screen *xscreen;
@ -1192,9 +1205,6 @@ meta_x11_display_new (MetaDisplay *display,
Window restart_helper_window = None; Window restart_helper_window = None;
gboolean is_restart = FALSE; gboolean is_restart = FALSE;
GdkDisplay *gdk_display; GdkDisplay *gdk_display;
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
/* A list of all atom names, so that we can intern them in one go. */ /* A list of all atom names, so that we can intern them in one go. */
const char *atom_names[] = { const char *atom_names[] = {
@ -1643,23 +1653,24 @@ meta_x11_display_reload_cursor (MetaX11Display *x11_display)
} }
static void static void
set_cursor_theme (Display *xdisplay) set_cursor_theme (Display *xdisplay,
MetaBackend *backend)
{ {
MetaBackend *backend = meta_get_backend ();
MetaSettings *settings = meta_backend_get_settings (backend); MetaSettings *settings = meta_backend_get_settings (backend);
int scale; int scale;
scale = meta_settings_get_ui_scaling_factor (settings); scale = meta_settings_get_ui_scaling_factor (settings);
XcursorSetTheme (xdisplay, meta_prefs_get_cursor_theme ()); XcursorSetTheme (xdisplay, meta_prefs_get_cursor_theme ());
XcursorSetDefaultSize (xdisplay, meta_prefs_get_cursor_size () * scale); XcursorSetDefaultSize (xdisplay,
meta_prefs_get_cursor_size () * scale);
} }
static void static void
update_cursor_theme (MetaX11Display *x11_display) update_cursor_theme (MetaX11Display *x11_display)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = backend_from_x11_display (x11_display);
set_cursor_theme (x11_display->xdisplay); set_cursor_theme (x11_display->xdisplay, backend);
meta_x11_display_reload_cursor (x11_display); meta_x11_display_reload_cursor (x11_display);
if (META_IS_BACKEND_X11 (backend)) if (META_IS_BACKEND_X11 (backend))
@ -1667,7 +1678,7 @@ update_cursor_theme (MetaX11Display *x11_display)
MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend); MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11); Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
set_cursor_theme (xdisplay); set_cursor_theme (xdisplay, backend);
meta_backend_x11_reload_cursor (backend_x11); meta_backend_x11_reload_cursor (backend_x11);
} }
} }
@ -1794,7 +1805,8 @@ create_guard_window (MetaX11Display *x11_display)
{ {
if (!meta_is_wayland_compositor ()) if (!meta_is_wayland_compositor ())
{ {
MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ()); MetaBackendX11 *backend =
META_BACKEND_X11 (backend_from_x11_display (x11_display));
Display *backend_xdisplay = meta_backend_x11_get_xdisplay (backend); Display *backend_xdisplay = meta_backend_x11_get_xdisplay (backend);
unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
@ -2081,7 +2093,7 @@ ensure_x11_display_logical_monitor_data (MetaLogicalMonitor *logical_monitor)
static void static void
meta_x11_display_ensure_xinerama_indices (MetaX11Display *x11_display) meta_x11_display_ensure_xinerama_indices (MetaX11Display *x11_display)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = backend_from_x11_display (x11_display);
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);
GList *logical_monitors, *l; GList *logical_monitors, *l;
@ -2149,7 +2161,7 @@ MetaLogicalMonitor *
meta_x11_display_xinerama_index_to_logical_monitor (MetaX11Display *x11_display, meta_x11_display_xinerama_index_to_logical_monitor (MetaX11Display *x11_display,
int xinerama_index) int xinerama_index)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = backend_from_x11_display (x11_display);
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);
GList *logical_monitors, *l; GList *logical_monitors, *l;
@ -2363,7 +2375,7 @@ meta_x11_display_set_stage_input_region (MetaX11Display *x11_display,
XserverRegion region) XserverRegion region)
{ {
Display *xdisplay = x11_display->xdisplay; Display *xdisplay = x11_display->xdisplay;
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = backend_from_x11_display (x11_display);
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend)); ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
Window stage_xwindow; Window stage_xwindow;

View File

@ -221,6 +221,7 @@ static gboolean
meta_x11_selection_handle_selection_request (MetaX11Display *x11_display, meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
XEvent *xevent) XEvent *xevent)
{ {
MetaDisplay *display = meta_x11_display_get_display (x11_display);
XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent; XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent;
MetaSelectionType selection_type; MetaSelectionType selection_type;
MetaSelection *selection; MetaSelection *selection;
@ -232,7 +233,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
if (x11_display->selection.xwindow != event->owner) if (x11_display->selection.xwindow != event->owner)
return FALSE; return FALSE;
selection = meta_display_get_selection (meta_get_display ()); selection = meta_display_get_selection (display);
if (event->target == gdk_x11_get_xatom_by_name ("TARGETS")) if (event->target == gdk_x11_get_xatom_by_name ("TARGETS"))
{ {
@ -343,11 +344,11 @@ source_new_cb (GObject *object,
} }
static gboolean static gboolean
unset_clipboard_owner (gpointer data) unset_clipboard_owner (gpointer user_data)
{ {
MetaDisplay *display = meta_get_display (); MetaX11Display *x11_display = user_data;
MetaDisplay *display = meta_x11_display_get_display (x11_display);
MetaSelection *selection = meta_display_get_selection (display); MetaSelection *selection = meta_display_get_selection (display);
MetaX11Display *x11_display = meta_display_get_x11_display (display);
meta_selection_unset_owner (selection, META_SELECTION_CLIPBOARD, meta_selection_unset_owner (selection, META_SELECTION_CLIPBOARD,
x11_display->selection.owners[META_SELECTION_CLIPBOARD]); x11_display->selection.owners[META_SELECTION_CLIPBOARD]);
@ -362,6 +363,7 @@ static gboolean
meta_x11_selection_handle_xfixes_selection_notify (MetaX11Display *x11_display, meta_x11_selection_handle_xfixes_selection_notify (MetaX11Display *x11_display,
XEvent *xevent) XEvent *xevent)
{ {
MetaDisplay *display = meta_x11_display_get_display (x11_display);
XFixesSelectionNotifyEvent *event = (XFixesSelectionNotifyEvent *) xevent; XFixesSelectionNotifyEvent *event = (XFixesSelectionNotifyEvent *) xevent;
Display *xdisplay = x11_display->xdisplay; Display *xdisplay = x11_display->xdisplay;
MetaSelectionType selection_type; MetaSelectionType selection_type;
@ -370,7 +372,7 @@ meta_x11_selection_handle_xfixes_selection_notify (MetaX11Display *x11_display,
if (!atom_to_selection_type (xdisplay, event->selection, &selection_type)) if (!atom_to_selection_type (xdisplay, event->selection, &selection_type))
return FALSE; return FALSE;
selection = meta_display_get_selection (meta_get_display ()); selection = meta_display_get_selection (display);
if (selection_type == META_SELECTION_CLIPBOARD) if (selection_type == META_SELECTION_CLIPBOARD)
g_clear_handle_id (&x11_display->selection.timeout_id, g_source_remove); g_clear_handle_id (&x11_display->selection.timeout_id, g_source_remove);
@ -406,7 +408,7 @@ meta_x11_selection_handle_xfixes_selection_notify (MetaX11Display *x11_display,
* arrives. */ * arrives. */
x11_display->selection.timeout_id = g_timeout_add (10, x11_display->selection.timeout_id = g_timeout_add (10,
unset_clipboard_owner, unset_clipboard_owner,
NULL); x11_display);
} }
else else
{ {
@ -477,8 +479,8 @@ notify_selection_owner (MetaX11Display *x11_display,
void void
meta_x11_selection_init (MetaX11Display *x11_display) meta_x11_selection_init (MetaX11Display *x11_display)
{ {
MetaDisplay *display = meta_x11_display_get_display (x11_display);
XSetWindowAttributes attributes = { 0 }; XSetWindowAttributes attributes = { 0 };
MetaDisplay *display = meta_get_display ();
MetaSelection *selection; MetaSelection *selection;
guint mask, i; guint mask, i;

View File

@ -3624,6 +3624,10 @@ is_our_xwindow (MetaX11Display *x11_display,
Window xwindow, Window xwindow,
XWindowAttributes *attrs) XWindowAttributes *attrs)
{ {
MetaDisplay *display;
MetaContext *context;
MetaBackend *backend;
if (xwindow == x11_display->no_focus_window) if (xwindow == x11_display->no_focus_window)
return TRUE; return TRUE;
@ -3639,15 +3643,13 @@ is_our_xwindow (MetaX11Display *x11_display,
if (xwindow == x11_display->composite_overlay_window) if (xwindow == x11_display->composite_overlay_window)
return TRUE; return TRUE;
{ display = meta_x11_display_get_display (x11_display);
MetaBackend *backend = meta_get_backend (); context = meta_display_get_context (display);
backend = meta_context_get_backend (context);
if (META_IS_BACKEND_X11 (backend)) if (META_IS_BACKEND_X11 (backend) &&
{ xwindow == meta_backend_x11_get_xwindow (META_BACKEND_X11 (backend)))
if (xwindow == meta_backend_x11_get_xwindow (META_BACKEND_X11 (backend))) return TRUE;
return TRUE;
}
}
/* Any windows created via meta_create_offscreen_window */ /* Any windows created via meta_create_offscreen_window */
if (attrs->override_redirect && if (attrs->override_redirect &&