From 4c3e307ec829f103920e8d25306b11357e51f4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Mon, 12 Jul 2021 19:51:40 +0200 Subject: [PATCH] cursor: emit hold gesture events Recevie the hold gesture events from the libinput or Wayland backends, abstracted as pointer signals, and re-emit them from the cursor interface. --- include/wlr/types/wlr_cursor.h | 2 ++ types/wlr_cursor.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index f5a016f4..739549c3 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -58,6 +58,8 @@ struct wlr_cursor { struct wl_signal pinch_begin; struct wl_signal pinch_update; struct wl_signal pinch_end; + struct wl_signal hold_begin; + struct wl_signal hold_end; struct wl_signal touch_up; struct wl_signal touch_down; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 3d75505b..7ae9c46c 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -32,6 +32,8 @@ struct wlr_cursor_device { struct wl_listener pinch_begin; struct wl_listener pinch_update; struct wl_listener pinch_end; + struct wl_listener hold_begin; + struct wl_listener hold_end; struct wl_listener touch_down; struct wl_listener touch_up; @@ -100,6 +102,8 @@ struct wlr_cursor *wlr_cursor_create(void) { wl_signal_init(&cur->events.pinch_begin); wl_signal_init(&cur->events.pinch_update); wl_signal_init(&cur->events.pinch_end); + wl_signal_init(&cur->events.hold_begin); + wl_signal_init(&cur->events.hold_end); // touch signals wl_signal_init(&cur->events.touch_up); @@ -160,6 +164,8 @@ static void cursor_device_destroy(struct wlr_cursor_device *c_device) { wl_list_remove(&c_device->pinch_begin.link); wl_list_remove(&c_device->pinch_update.link); wl_list_remove(&c_device->pinch_end.link); + wl_list_remove(&c_device->hold_begin.link); + wl_list_remove(&c_device->hold_end.link); } else if (dev->type == WLR_INPUT_DEVICE_TOUCH) { wl_list_remove(&c_device->touch_down.link); wl_list_remove(&c_device->touch_up.link); @@ -488,6 +494,18 @@ static void handle_pointer_pinch_end(struct wl_listener *listener, void *data) { wlr_signal_emit_safe(&device->cursor->events.pinch_end, event); } +static void handle_pointer_hold_begin(struct wl_listener *listener, void *data) { + struct wlr_event_pointer_hold_begin *event = data; + struct wlr_cursor_device *device = wl_container_of(listener, device, hold_begin); + wlr_signal_emit_safe(&device->cursor->events.hold_begin, event); +} + +static void handle_pointer_hold_end(struct wl_listener *listener, void *data) { + struct wlr_event_pointer_hold_end *event = data; + struct wlr_cursor_device *device = wl_container_of(listener, device, hold_end); + wlr_signal_emit_safe(&device->cursor->events.hold_end, event); +} + static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_event_touch_up *event = data; struct wlr_cursor_device *device; @@ -660,6 +678,12 @@ static struct wlr_cursor_device *cursor_device_create( wl_signal_add(&device->pointer->events.pinch_end, &c_device->pinch_end); c_device->pinch_end.notify = handle_pointer_pinch_end; + + wl_signal_add(&device->pointer->events.hold_begin, &c_device->hold_begin); + c_device->hold_begin.notify = handle_pointer_hold_begin; + + wl_signal_add(&device->pointer->events.hold_end, &c_device->hold_end); + c_device->hold_end.notify = handle_pointer_hold_end; } else if (device->type == WLR_INPUT_DEVICE_TOUCH) { wl_signal_add(&device->touch->events.motion, &c_device->touch_motion); c_device->touch_motion.notify = handle_touch_motion;