From 02a436d607481492a37ad15fcc401abf6385eeff Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 1 Jun 2022 10:45:20 +0200 Subject: [PATCH] wayland: Move surface check to MetaWaylandSurface Allows dropping various HAVE_XWAYLAND ifdef as the function would always return false if Mutter is built without XWayland Part-of: --- src/wayland/meta-wayland-cursor-surface.c | 4 +--- src/wayland/meta-wayland-pointer-constraints.c | 12 ++++-------- src/wayland/meta-wayland-surface.c | 14 ++++++++++++++ src/wayland/meta-wayland-surface.h | 1 + src/wayland/meta-xwayland-dnd.c | 2 +- src/wayland/meta-xwayland.c | 10 ---------- src/wayland/meta-xwayland.h | 3 --- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c index c75fe0ee3..10f632eb3 100644 --- a/src/wayland/meta-wayland-cursor-surface.c +++ b/src/wayland/meta-wayland-cursor-surface.c @@ -92,8 +92,7 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite, MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role); -#ifdef HAVE_XWAYLAND - if (!meta_xwayland_is_xwayland_surface (surface)) + if (!meta_wayland_surface_is_xwayland (surface)) { MetaWaylandSurfaceRole *surface_role = META_WAYLAND_SURFACE_ROLE (cursor_surface); @@ -123,7 +122,6 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite, surface->buffer_transform); } } -#endif meta_wayland_surface_update_outputs (surface); } diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c index 9389dd6f8..01e9d855c 100644 --- a/src/wayland/meta-wayland-pointer-constraints.c +++ b/src/wayland/meta-wayland-pointer-constraints.c @@ -193,7 +193,7 @@ surface_constraint_data_new (MetaWaylandSurface *surface) connect_window (data, window); } #ifdef HAVE_XWAYLAND - else if (meta_xwayland_is_xwayland_surface (surface)) + else if (meta_wayland_surface_is_xwayland (surface)) { data->window_associated_handler_id = g_signal_connect (surface->role, "window-associated", @@ -475,7 +475,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) * For subsurfaces the window of the ancestor might be gone already. */ #ifdef HAVE_XWAYLAND - g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface) || + g_warn_if_fail (meta_wayland_surface_is_xwayland (constraint->surface) || META_IS_WAYLAND_SUBSURFACE (constraint->surface->role)); #endif return FALSE; @@ -488,8 +488,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) if (constraint->seat->pointer->focus_surface != constraint->surface) return FALSE; -#ifdef HAVE_XWAYLAND - if (meta_xwayland_is_xwayland_surface (constraint->surface)) + if (meta_wayland_surface_is_xwayland (constraint->surface)) { MetaDisplay *display = meta_window_get_display (window); @@ -511,7 +510,6 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11) return FALSE; } -#endif if (!meta_window_appears_focused (window)) return FALSE; @@ -632,9 +630,7 @@ meta_wayland_pointer_constraint_calculate_effective_region (MetaWaylandPointerCo MetaFrame *frame = window->frame; int actual_width, actual_height; -#ifdef HAVE_XWAYLAND - g_assert (meta_xwayland_is_xwayland_surface (constraint->surface)); -#endif + g_assert (meta_wayland_surface_is_xwayland (constraint->surface)); actual_width = window->buffer_rect.width - (frame->child_x + frame->right_width); diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index abd5dae15..7e8a78d21 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -2396,3 +2396,17 @@ meta_wayland_surface_get_compositor (MetaWaylandSurface *surface) { return surface->compositor; } + +gboolean +meta_wayland_surface_is_xwayland (MetaWaylandSurface *surface) +{ +#ifdef HAVE_XWAYLAND + MetaWaylandCompositor *compositor = surface->compositor; + MetaXWaylandManager *manager = &compositor->xwayland_manager; + + return surface->resource != NULL && + wl_resource_get_client (surface->resource) == manager->client; +#else + return FALSE; +#endif +} diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index 91cc64c0b..63f160894 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -419,6 +419,7 @@ meta_wayland_surface_state_new (void) { return g_object_new (META_TYPE_WAYLAND_SURFACE_STATE, NULL); } +gboolean meta_wayland_surface_is_xwayland (MetaWaylandSurface *surface); static inline GNode * meta_get_next_subsurface_sibling (GNode *n) diff --git a/src/wayland/meta-xwayland-dnd.c b/src/wayland/meta-xwayland-dnd.c index 314880cdb..b4a679162 100644 --- a/src/wayland/meta-xwayland-dnd.c +++ b/src/wayland/meta-xwayland-dnd.c @@ -1033,7 +1033,7 @@ meta_xwayland_dnd_handle_xfixes_selection_notify (MetaWaylandCompositor *composi focus = compositor->seat->pointer->focus_surface; if (event->owner != None && event->owner != x11_display->selection.xwindow && - focus && meta_xwayland_is_xwayland_surface (focus)) + focus && meta_wayland_surface_is_xwayland (focus)) { dnd->source = meta_wayland_data_source_xwayland_new (dnd, compositor); meta_wayland_data_device_set_dnd_source (&compositor->seat->data_device, diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c index 8a50b93f3..12d2b1702 100644 --- a/src/wayland/meta-xwayland.c +++ b/src/wayland/meta-xwayland.c @@ -146,16 +146,6 @@ meta_xwayland_handle_wl_surface_id (MetaWindow *window, } } -gboolean -meta_xwayland_is_xwayland_surface (MetaWaylandSurface *surface) -{ - MetaWaylandCompositor *compositor = surface->compositor; - MetaXWaylandManager *manager = &compositor->xwayland_manager; - - return surface->resource != NULL && - wl_resource_get_client (surface->resource) == manager->client; -} - static gboolean try_display (int display, char **filename_out, diff --git a/src/wayland/meta-xwayland.h b/src/wayland/meta-xwayland.h index cbe27b183..06f68ea2d 100644 --- a/src/wayland/meta-xwayland.h +++ b/src/wayland/meta-xwayland.h @@ -39,9 +39,6 @@ void meta_xwayland_handle_wl_surface_id (MetaWindow *window, guint32 surface_id); -gboolean -meta_xwayland_is_xwayland_surface (MetaWaylandSurface *surface); - void meta_xwayland_handle_xwayland_grab (MetaWindow *window, gboolean allow);