From 6cc8450f8e5a04f58c39024dffc4a6a8fa9adbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 21 Sep 2016 17:28:51 +0800 Subject: [PATCH] wayland/pointer-constraints: Unify requirements for enablement Put the conditions for enabling a pointer constraint in a helper function, and use that in both maybe_enable() and maybe_remove(). The constraint region checking is still only done in maybe_enable() however. This changes the conditions for maybe disabling the constraint on focus change and other trigger points, namely it makes constraints by Xwayland not disable when they shouldn't due to the constraining window being an override-redirect window. https://bugzilla.gnome.org/show_bug.cgi?id=771859 --- .../meta-wayland-pointer-constraints.c | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c index 8e7d5af1f..68395b540 100644 --- a/src/wayland/meta-wayland-pointer-constraints.c +++ b/src/wayland/meta-wayland-pointer-constraints.c @@ -447,17 +447,10 @@ is_within_constraint_region (MetaWaylandPointerConstraint *constraint, return is_within; } -static void -meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *constraint) +static gboolean +should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) { MetaWindow *window; - wl_fixed_t sx, sy; - - if (constraint->is_enabled) - return; - - if (constraint->seat->pointer->focus_surface != constraint->surface) - return; window = constraint->surface->window; if (!window) @@ -467,11 +460,14 @@ meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *cons * associate the X11 Window with the wl_surface. */ g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface)); - return; + return FALSE; } if (window->unmanaging) - return; + return FALSE; + + if (constraint->seat->pointer->focus_surface != constraint->surface) + return FALSE; if (meta_xwayland_is_xwayland_surface (constraint->surface)) { @@ -493,14 +489,30 @@ meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *cons if (display->focus_window && display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11) - return; + return FALSE; } else { + MetaWindow *window = constraint->surface->window; + if (!meta_window_appears_focused (window)) - return; + return FALSE; } + return TRUE; +} + +static void +meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *constraint) +{ + wl_fixed_t sx, sy; + + if (constraint->is_enabled) + return; + + if (!should_constraint_be_enabled (constraint)) + return; + meta_wayland_pointer_get_relative_coordinates (constraint->seat->pointer, constraint->surface, &sx, &sy); @@ -550,11 +562,7 @@ meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat, constraint = wl_container_of (pointer->grab, constraint, grab); - if (constraint->surface != window->surface) - return; - - if (meta_window_appears_focused (window) && - pointer->focus_surface == window->surface) + if (should_constraint_be_enabled (constraint)) return; meta_wayland_pointer_constraint_deactivate (constraint);