Add cancel function to grab interfaces
A grab can potentially allocate memory and would normally end the grab
itself, freeing the allocated memory in the process. However at in some
situations the compositor may want to abort a grab. The grab owner still
needs to free some memory and abort the grab properly. To do this a new
function 'cancel' is introduced in all the grab interfaces instructing
the grabs owner to abort the grab.
This patch also hooks up grab cancelling to seat device releasing and
when the compositor looses focus, which would potentially leak memory
before.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
diff --git a/src/input.c b/src/input.c
index ffb7b35..e265efd 100644
--- a/src/input.c
+++ b/src/input.c
@@ -162,11 +162,17 @@
}
}
+static void
+default_grab_pointer_cancel(struct weston_pointer_grab *grab)
+{
+}
+
static const struct weston_pointer_grab_interface
default_pointer_grab_interface = {
default_grab_focus,
default_grab_motion,
- default_grab_button
+ default_grab_button,
+ default_grab_pointer_cancel,
};
static void
@@ -225,10 +231,16 @@
}
}
+static void
+default_grab_touch_cancel(struct weston_touch_grab *grab)
+{
+}
+
static const struct weston_touch_grab_interface default_touch_grab_interface = {
default_grab_touch_down,
default_grab_touch_up,
- default_grab_touch_motion
+ default_grab_touch_motion,
+ default_grab_touch_cancel,
};
static void
@@ -329,10 +341,16 @@
}
}
+static void
+default_grab_keyboard_cancel(struct weston_keyboard_grab *grab)
+{
+}
+
static const struct weston_keyboard_grab_interface
default_keyboard_grab_interface = {
default_grab_key,
default_grab_modifiers,
+ default_grab_keyboard_cancel,
};
static void
@@ -601,6 +619,12 @@
keyboard->grab = &keyboard->default_grab;
}
+static void
+weston_keyboard_cancel_grab(struct weston_keyboard *keyboard)
+{
+ keyboard->grab->interface->cancel(keyboard->grab);
+}
+
WL_EXPORT void
weston_pointer_start_grab(struct weston_pointer *pointer,
struct weston_pointer_grab *grab)
@@ -617,6 +641,12 @@
pointer->grab->interface->focus(pointer->grab);
}
+static void
+weston_pointer_cancel_grab(struct weston_pointer *pointer)
+{
+ pointer->grab->interface->cancel(pointer->grab);
+}
+
WL_EXPORT void
weston_touch_start_grab(struct weston_touch *touch, struct weston_touch_grab *grab)
{
@@ -630,6 +660,12 @@
touch->grab = &touch->default_grab;
}
+static void
+weston_touch_cancel_grab(struct weston_touch *touch)
+{
+ touch->grab->interface->cancel(touch->grab);
+}
+
WL_EXPORT void
weston_pointer_clamp(struct weston_pointer *pointer, wl_fixed_t *fx, wl_fixed_t *fy)
{
@@ -1139,10 +1175,7 @@
}
weston_keyboard_set_focus(keyboard, NULL);
- /* FIXME: We really need keyboard grab cancel here to
- * let the grab shut down properly. As it is we leak
- * the grab data. */
- weston_keyboard_end_grab(keyboard);
+ weston_keyboard_cancel_grab(keyboard);
}
WL_EXPORT void
@@ -1798,6 +1831,7 @@
seat->keyboard_device_count--;
if (seat->keyboard_device_count == 0) {
weston_keyboard_set_focus(seat->keyboard, NULL);
+ weston_keyboard_cancel_grab(seat->keyboard);
seat_send_updated_caps(seat);
}
}
@@ -1835,6 +1869,7 @@
weston_pointer_set_focus(pointer, NULL,
wl_fixed_from_int(0),
wl_fixed_from_int(0));
+ weston_pointer_cancel_grab(pointer);
if (pointer->sprite)
pointer_unmap_sprite(pointer);
@@ -1872,6 +1907,7 @@
seat->touch_device_count--;
if (seat->touch_device_count == 0) {
weston_touch_set_focus(seat, NULL);
+ weston_touch_cancel_grab(seat->touch);
seat_send_updated_caps(seat);
}
}