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
This commit is contained in:
Jonas Ådahl 2016-09-21 17:28:51 +08:00
parent 7ae4b28bda
commit 6cc8450f8e

View File

@ -447,17 +447,10 @@ is_within_constraint_region (MetaWaylandPointerConstraint *constraint,
return is_within; return is_within;
} }
static void static gboolean
meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *constraint) should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint)
{ {
MetaWindow *window; 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; window = constraint->surface->window;
if (!window) if (!window)
@ -467,11 +460,14 @@ meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *cons
* associate the X11 Window with the wl_surface. * associate the X11 Window with the wl_surface.
*/ */
g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface)); g_warn_if_fail (meta_xwayland_is_xwayland_surface (constraint->surface));
return; return FALSE;
} }
if (window->unmanaging) if (window->unmanaging)
return; return FALSE;
if (constraint->seat->pointer->focus_surface != constraint->surface)
return FALSE;
if (meta_xwayland_is_xwayland_surface (constraint->surface)) if (meta_xwayland_is_xwayland_surface (constraint->surface))
{ {
@ -493,14 +489,30 @@ meta_wayland_pointer_constraint_maybe_enable (MetaWaylandPointerConstraint *cons
if (display->focus_window && if (display->focus_window &&
display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11) display->focus_window->client_type != META_WINDOW_CLIENT_TYPE_X11)
return; return FALSE;
} }
else else
{ {
MetaWindow *window = constraint->surface->window;
if (!meta_window_appears_focused (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, meta_wayland_pointer_get_relative_coordinates (constraint->seat->pointer,
constraint->surface, constraint->surface,
&sx, &sy); &sx, &sy);
@ -550,11 +562,7 @@ meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
constraint = wl_container_of (pointer->grab, constraint, grab); constraint = wl_container_of (pointer->grab, constraint, grab);
if (constraint->surface != window->surface) if (should_constraint_be_enabled (constraint))
return;
if (meta_window_appears_focused (window) &&
pointer->focus_surface == window->surface)
return; return;
meta_wayland_pointer_constraint_deactivate (constraint); meta_wayland_pointer_constraint_deactivate (constraint);