From 9ef026e8047a012e06497a71923c4b3bc0c9df71 Mon Sep 17 00:00:00 2001 From: Benjamin Cheng Date: Sat, 7 Dec 2019 11:21:20 -0500 Subject: input/cursor: pass gesture events to clients Some wayland clients (mostly GTK3 apps) like eog or evince support gestures like pinch-to-zoom. These gestures are given to clients via the pointer_gestures_v1 protocol. This is already supported in wlroots, so we just need to hook up the events here in sway. Fixes #4724 --- sway/input/cursor.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'sway/input/cursor.c') diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 574186d7..6d88cd54 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -735,6 +735,60 @@ static void handle_request_set_cursor(struct wl_listener *listener, event->hotspot_y, focused_client); } +static void handle_pointer_pinch_begin(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, pinch_begin); + struct wlr_event_pointer_pinch_begin *event = data; + wlr_pointer_gestures_v1_send_pinch_begin( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->fingers); +} + +static void handle_pointer_pinch_update(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, pinch_update); + struct wlr_event_pointer_pinch_update *event = data; + wlr_pointer_gestures_v1_send_pinch_update( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->dx, event->dy, + event->scale, event->rotation); +} + +static void handle_pointer_pinch_end(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, pinch_end); + struct wlr_event_pointer_pinch_end *event = data; + wlr_pointer_gestures_v1_send_pinch_end( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->cancelled); +} + +static void handle_pointer_swipe_begin(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, swipe_begin); + struct wlr_event_pointer_swipe_begin *event = data; + wlr_pointer_gestures_v1_send_swipe_begin( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->fingers); +} + +static void handle_pointer_swipe_update(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, swipe_update); + struct wlr_event_pointer_swipe_update *event = data; + wlr_pointer_gestures_v1_send_swipe_update( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->dx, event->dy); +} + +static void handle_pointer_swipe_end(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = wl_container_of( + listener, cursor, swipe_end); + struct wlr_event_pointer_swipe_end *event = data; + wlr_pointer_gestures_v1_send_swipe_end( + cursor->pointer_gestures, cursor->seat->wlr_seat, + event->time_msec, event->cancelled); +} void cursor_set_image(struct sway_cursor *cursor, const char *image, struct wl_client *client) { if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { @@ -825,6 +879,20 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { cursor->hide_source = wl_event_loop_add_timer(server.wl_event_loop, hide_notify, cursor); + cursor->pointer_gestures = wlr_pointer_gestures_v1_create(server.wl_display); + cursor->pinch_begin.notify = handle_pointer_pinch_begin; + wl_signal_add(&wlr_cursor->events.pinch_begin, &cursor->pinch_begin); + cursor->pinch_update.notify = handle_pointer_pinch_update; + wl_signal_add(&wlr_cursor->events.pinch_update, &cursor->pinch_update); + cursor->pinch_end.notify = handle_pointer_pinch_end; + wl_signal_add(&wlr_cursor->events.pinch_end, &cursor->pinch_end); + cursor->swipe_begin.notify = handle_pointer_swipe_begin; + wl_signal_add(&wlr_cursor->events.swipe_begin, &cursor->swipe_begin); + cursor->swipe_update.notify = handle_pointer_swipe_update; + wl_signal_add(&wlr_cursor->events.swipe_update, &cursor->swipe_update); + cursor->swipe_end.notify = handle_pointer_swipe_end; + wl_signal_add(&wlr_cursor->events.swipe_end, &cursor->swipe_end); + // input events wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); cursor->motion.notify = handle_cursor_motion_relative; -- cgit v1.2.3-54-g00ecf