diff options
author | Greg V <greg@unrelenting.technology> | 2019-06-21 01:48:19 +0300 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-21 14:43:28 -0400 |
commit | d80acadfd814ce022f3b2c5ad570551e622e1f66 (patch) | |
tree | a6b042f5de7e4ea6152464f010c7b5222c193a2b /backend | |
parent | 5027b23dc2223a803086f9ae6caab4f2a829cc45 (diff) |
Support pointer-gestures on Wayland backend
Diffstat (limited to 'backend')
-rw-r--r-- | backend/wayland/backend.c | 7 | ||||
-rw-r--r-- | backend/wayland/wl_seat.c | 111 |
2 files changed, 118 insertions, 0 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 1abc3e8b..25feb6fb 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -17,6 +17,7 @@ #include "backend/wayland.h" #include "util/signal.h" #include "xdg-decoration-unstable-v1-client-protocol.h" +#include "pointer-gestures-unstable-v1-client-protocol.h" #include "xdg-shell-client-protocol.h" struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) { @@ -77,6 +78,9 @@ static void registry_global(void *data, struct wl_registry *registry, } else if (strcmp(iface, zxdg_decoration_manager_v1_interface.name) == 0) { wl->zxdg_decoration_manager_v1 = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1); + } else if (strcmp(iface, zwp_pointer_gestures_v1_interface.name) == 0) { + wl->zwp_pointer_gestures_v1 = wl_registry_bind(registry, name, + &zwp_pointer_gestures_v1_interface, 1); } } @@ -149,6 +153,9 @@ static void backend_destroy(struct wlr_backend *backend) { if (wl->zxdg_decoration_manager_v1) { zxdg_decoration_manager_v1_destroy(wl->zxdg_decoration_manager_v1); } + if (wl->zwp_pointer_gestures_v1) { + zwp_pointer_gestures_v1_destroy(wl->zwp_pointer_gestures_v1); + } xdg_wm_base_destroy(wl->xdg_wm_base); wl_compositor_destroy(wl->compositor); wl_registry_destroy(wl->registry); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 6648f97e..96c083ed 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -15,6 +15,7 @@ #include <wlr/interfaces/wlr_touch.h> #include <wlr/util/log.h> +#include "pointer-gestures-unstable-v1-client-protocol.h" #include "backend/wayland.h" #include "util/signal.h" @@ -344,6 +345,107 @@ static struct wlr_pointer_impl pointer_impl = { .destroy = pointer_destroy, }; +static void gesture_swipe_begin(void *data, + struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, + uint32_t serial, uint32_t time, + struct wl_surface *surface, uint32_t fingers) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_swipe_begin wlr_event = { + .device = wlr_dev, + .time_msec = time, + .fingers = fingers, + }; + input_device->fingers = fingers; + wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_begin, &wlr_event); +} + +static void gesture_swipe_update(void *data, + struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, + uint32_t time, wl_fixed_t dx, wl_fixed_t dy) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_swipe_update wlr_event = { + .device = wlr_dev, + .time_msec = time, + .fingers = input_device->fingers, + .dx = wl_fixed_to_double(dx), + .dy = wl_fixed_to_double(dy), + }; + wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_update, &wlr_event); +} + +static void gesture_swipe_end(void *data, + struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, + uint32_t serial, uint32_t time, int32_t cancelled) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_swipe_end wlr_event = { + .device = wlr_dev, + .time_msec = time, + .cancelled = cancelled, + }; + wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_end, &wlr_event); +} + +static struct zwp_pointer_gesture_swipe_v1_listener gesture_swipe_impl = { + .begin = gesture_swipe_begin, + .update = gesture_swipe_update, + .end = gesture_swipe_end, +}; + +static void gesture_pinch_begin(void *data, + struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, + uint32_t serial, uint32_t time, + struct wl_surface *surface, uint32_t fingers) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_pinch_begin wlr_event = { + .device = wlr_dev, + .time_msec = time, + .fingers = fingers, + }; + input_device->fingers = fingers; + wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_begin, &wlr_event); +} + +static void gesture_pinch_update(void *data, + struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, + uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_pinch_update wlr_event = { + .device = wlr_dev, + .time_msec = time, + .fingers = input_device->fingers, + .dx = wl_fixed_to_double(dx), + .dy = wl_fixed_to_double(dy), + .scale = wl_fixed_to_double(scale), + .rotation = wl_fixed_to_double(rotation), + }; + wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_update, &wlr_event); +} + +static void gesture_pinch_end(void *data, + struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, + uint32_t serial, uint32_t time, int32_t cancelled) { + struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data; + struct wlr_input_device *wlr_dev = &input_device->wlr_input_device; + struct wlr_event_pointer_pinch_end wlr_event = { + .device = wlr_dev, + .time_msec = time, + .cancelled = cancelled, + }; + wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_end, &wlr_event); +} + +static struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_impl = { + .begin = gesture_pinch_begin, + .update = gesture_pinch_update, + .end = gesture_pinch_end, +}; + + static void pointer_handle_output_destroy(struct wl_listener *listener, void *data) { struct wlr_wl_pointer *pointer = @@ -390,6 +492,15 @@ void create_wl_pointer(struct wl_pointer *wl_pointer, struct wlr_wl_output *outp wlr_dev->output_name = strdup(output->wlr_output.name); wlr_pointer_init(wlr_dev->pointer, &pointer_impl); + if (backend->zwp_pointer_gestures_v1) { + pointer->gesture_swipe = zwp_pointer_gestures_v1_get_swipe_gesture( + backend->zwp_pointer_gestures_v1, wl_pointer); + zwp_pointer_gesture_swipe_v1_add_listener(pointer->gesture_swipe, &gesture_swipe_impl, dev); + pointer->gesture_pinch = zwp_pointer_gestures_v1_get_pinch_gesture( + backend->zwp_pointer_gestures_v1, wl_pointer); + zwp_pointer_gesture_pinch_v1_add_listener(pointer->gesture_pinch, &gesture_pinch_impl, dev); + } + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } |