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
This commit is contained in:
Jonas Ådahl 2016-09-21 14:33:47 +08:00
parent 5306d36522
commit 6e7057426e
2 changed files with 16 additions and 0 deletions

View File

@ -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)
{

View File

@ -46,6 +46,7 @@ struct _MetaWaylandPointerGrabInterface
const ClutterEvent *event);
void (*button) (MetaWaylandPointerGrab *grab,
const ClutterEvent *event);
void (*cancel) (MetaWaylandPointerGrab *grab);
};
struct _MetaWaylandPointerGrab