From 20efdfcb41e096586505bd9c2494d8780a5fdafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 21 Sep 2016 14:33:47 +0800 Subject: [PATCH] wayland/pointer: Add way to cancel current grab Previously a grab could suddenly end without the grabber knowing anything about it. Some grabs assume they won't suddenly end without notice, and can use then new 'cancel' vfunc to be notified. Currently a grab is cancelled when a new one is started (i.e. in meta_wayland_pointer_grab_start()), when a non-popup compositor wide event route is initiated, and when the seat looses the pointer capability. https://bugzilla.gnome.org/show_bug.cgi?id=771858 --- src/wayland/meta-wayland-pointer.c | 15 +++++++++++++++ src/wayland/meta-wayland-pointer.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index 55fcb068b..7122d098f 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -89,6 +89,9 @@ G_DEFINE_TYPE (MetaWaylandPointer, meta_wayland_pointer, static void meta_wayland_pointer_reset_grab (MetaWaylandPointer *pointer); +static void +meta_wayland_pointer_cancel_grab (MetaWaylandPointer *pointer); + static MetaWaylandPointerClient * meta_wayland_pointer_client_new (void) { @@ -226,6 +229,8 @@ sync_focus_surface (MetaWaylandPointer *pointer) case META_EVENT_ROUTE_COMPOSITOR_GRAB: case META_EVENT_ROUTE_FRAME_BUTTON: /* The compositor has a grab, so remove our focus... */ + meta_wayland_pointer_cancel_grab (pointer); + meta_wayland_pointer_reset_grab (pointer); meta_wayland_pointer_set_focus (pointer, NULL); break; @@ -498,6 +503,7 @@ meta_wayland_pointer_disable (MetaWaylandPointer *pointer) pointer->cursor_surface_destroy_id); } + meta_wayland_pointer_cancel_grab (pointer); meta_wayland_pointer_reset_grab (pointer); meta_wayland_pointer_set_focus (pointer, NULL); @@ -862,6 +868,8 @@ meta_wayland_pointer_start_grab (MetaWaylandPointer *pointer, { const MetaWaylandPointerGrabInterface *interface; + meta_wayland_pointer_cancel_grab (pointer); + pointer->grab = grab; interface = pointer->grab->interface; grab->pointer = pointer; @@ -887,6 +895,13 @@ meta_wayland_pointer_end_grab (MetaWaylandPointer *pointer) meta_wayland_pointer_update_cursor_surface (pointer); } +static void +meta_wayland_pointer_cancel_grab (MetaWaylandPointer *pointer) +{ + if (pointer->grab->interface->cancel) + pointer->grab->interface->cancel (pointer->grab); +} + void meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer) { diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h index 10765929f..547cd5610 100644 --- a/src/wayland/meta-wayland-pointer.h +++ b/src/wayland/meta-wayland-pointer.h @@ -46,6 +46,7 @@ struct _MetaWaylandPointerGrabInterface const ClutterEvent *event); void (*button) (MetaWaylandPointerGrab *grab, const ClutterEvent *event); + void (*cancel) (MetaWaylandPointerGrab *grab); }; struct _MetaWaylandPointerGrab