From 1b737190cc66e09137222361e903812590c34510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 7 Sep 2022 11:34:35 +0200 Subject: [PATCH] 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: --- src/x11/events.c | 3 ++- src/x11/meta-x11-display.c | 40 +++++++++++++++++++++++------------- src/x11/meta-x11-selection.c | 16 ++++++++------- src/x11/window-x11.c | 18 ++++++++-------- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/x11/events.c b/src/x11/events.c index e32781d89..e83f25dcf 100644 --- a/src/x11/events.c +++ b/src/x11/events.c @@ -944,7 +944,8 @@ handle_input_xevent (MetaX11Display *x11_display, MetaWindow *window; MetaDisplay *display = x11_display->display; 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)); if (input_event == NULL) diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index f5e606dad..3d6cb04f9 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -95,6 +95,15 @@ static void prefs_changed_callback (MetaPreference pref, 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 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; 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); num_monitors = meta_monitor_manager_get_num_logical_monitors (monitor_manager); @@ -1178,6 +1188,9 @@ meta_x11_display_new (MetaDisplay *display, GError **error) { 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; Display *xdisplay; Screen *xscreen; @@ -1192,9 +1205,6 @@ meta_x11_display_new (MetaDisplay *display, Window restart_helper_window = None; gboolean is_restart = FALSE; 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. */ const char *atom_names[] = { @@ -1643,23 +1653,24 @@ meta_x11_display_reload_cursor (MetaX11Display *x11_display) } 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); int scale; scale = meta_settings_get_ui_scaling_factor (settings); 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 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); if (META_IS_BACKEND_X11 (backend)) @@ -1667,7 +1678,7 @@ update_cursor_theme (MetaX11Display *x11_display) MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend); 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); } } @@ -1794,7 +1805,8 @@ create_guard_window (MetaX11Display *x11_display) { 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); unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; @@ -2081,7 +2093,7 @@ ensure_x11_display_logical_monitor_data (MetaLogicalMonitor *logical_monitor) static void 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 = meta_backend_get_monitor_manager (backend); GList *logical_monitors, *l; @@ -2149,7 +2161,7 @@ MetaLogicalMonitor * meta_x11_display_xinerama_index_to_logical_monitor (MetaX11Display *x11_display, int xinerama_index) { - MetaBackend *backend = meta_get_backend (); + MetaBackend *backend = backend_from_x11_display (x11_display); MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); GList *logical_monitors, *l; @@ -2363,7 +2375,7 @@ meta_x11_display_set_stage_input_region (MetaX11Display *x11_display, XserverRegion region) { 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)); Window stage_xwindow; diff --git a/src/x11/meta-x11-selection.c b/src/x11/meta-x11-selection.c index cf50e635d..aa5e23a1e 100644 --- a/src/x11/meta-x11-selection.c +++ b/src/x11/meta-x11-selection.c @@ -221,6 +221,7 @@ static gboolean meta_x11_selection_handle_selection_request (MetaX11Display *x11_display, XEvent *xevent) { + MetaDisplay *display = meta_x11_display_get_display (x11_display); XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent; MetaSelectionType selection_type; MetaSelection *selection; @@ -232,7 +233,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display, if (x11_display->selection.xwindow != event->owner) 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")) { @@ -343,11 +344,11 @@ source_new_cb (GObject *object, } 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); - MetaX11Display *x11_display = meta_display_get_x11_display (display); meta_selection_unset_owner (selection, 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, XEvent *xevent) { + MetaDisplay *display = meta_x11_display_get_display (x11_display); XFixesSelectionNotifyEvent *event = (XFixesSelectionNotifyEvent *) xevent; Display *xdisplay = x11_display->xdisplay; 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)) return FALSE; - selection = meta_display_get_selection (meta_get_display ()); + selection = meta_display_get_selection (display); if (selection_type == META_SELECTION_CLIPBOARD) 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. */ x11_display->selection.timeout_id = g_timeout_add (10, unset_clipboard_owner, - NULL); + x11_display); } else { @@ -477,8 +479,8 @@ notify_selection_owner (MetaX11Display *x11_display, void meta_x11_selection_init (MetaX11Display *x11_display) { + MetaDisplay *display = meta_x11_display_get_display (x11_display); XSetWindowAttributes attributes = { 0 }; - MetaDisplay *display = meta_get_display (); MetaSelection *selection; guint mask, i; diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 637f7a3dc..93cacb882 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -3624,6 +3624,10 @@ is_our_xwindow (MetaX11Display *x11_display, Window xwindow, XWindowAttributes *attrs) { + MetaDisplay *display; + MetaContext *context; + MetaBackend *backend; + if (xwindow == x11_display->no_focus_window) return TRUE; @@ -3639,15 +3643,13 @@ is_our_xwindow (MetaX11Display *x11_display, if (xwindow == x11_display->composite_overlay_window) return TRUE; - { - MetaBackend *backend = meta_get_backend (); + display = meta_x11_display_get_display (x11_display); + context = meta_display_get_context (display); + backend = meta_context_get_backend (context); - if (META_IS_BACKEND_X11 (backend)) - { - if (xwindow == meta_backend_x11_get_xwindow (META_BACKEND_X11 (backend))) - return TRUE; - } - } + if (META_IS_BACKEND_X11 (backend) && + xwindow == meta_backend_x11_get_xwindow (META_BACKEND_X11 (backend))) + return TRUE; /* Any windows created via meta_create_offscreen_window */ if (attrs->override_redirect &&