aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Benjamin Cheng <ben@bcheng.me>2019-12-07 11:21:20 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-12-07 12:26:21 -0500
commit9ef026e8047a012e06497a71923c4b3bc0c9df71 (patch)
treee5dffb24c9f042988e9279a6bb2d70ee3dbc117c
parentA Script to change sway workspace name. (diff)
downloadsway-9ef026e8047a012e06497a71923c4b3bc0c9df71.tar.gz
sway-9ef026e8047a012e06497a71923c4b3bc0c9df71.tar.zst
sway-9ef026e8047a012e06497a71923c4b3bc0c9df71.zip
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
-rw-r--r--include/sway/input/cursor.h9
-rw-r--r--sway/input/cursor.c68
2 files changed, 77 insertions, 0 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index e46c9b18..0bcd262f 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -3,6 +3,7 @@
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdint.h> 4#include <stdint.h>
5#include <wlr/types/wlr_pointer_constraints_v1.h> 5#include <wlr/types/wlr_pointer_constraints_v1.h>
6#include <wlr/types/wlr_pointer_gestures_v1.h>
6#include <wlr/types/wlr_surface.h> 7#include <wlr/types/wlr_surface.h>
7#include "sway/input/seat.h" 8#include "sway/input/seat.h"
8 9
@@ -32,6 +33,14 @@ struct sway_cursor {
32 struct wlr_pointer_constraint_v1 *active_constraint; 33 struct wlr_pointer_constraint_v1 *active_constraint;
33 pixman_region32_t confine; // invalid if active_constraint == NULL 34 pixman_region32_t confine; // invalid if active_constraint == NULL
34 35
36 struct wlr_pointer_gestures_v1 *pointer_gestures;
37 struct wl_listener pinch_begin;
38 struct wl_listener pinch_update;
39 struct wl_listener pinch_end;
40 struct wl_listener swipe_begin;
41 struct wl_listener swipe_update;
42 struct wl_listener swipe_end;
43
35 struct wl_listener motion; 44 struct wl_listener motion;
36 struct wl_listener motion_absolute; 45 struct wl_listener motion_absolute;
37 struct wl_listener button; 46 struct wl_listener button;
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,
735 event->hotspot_y, focused_client); 735 event->hotspot_y, focused_client);
736} 736}
737 737
738static void handle_pointer_pinch_begin(struct wl_listener *listener, void *data) {
739 struct sway_cursor *cursor = wl_container_of(
740 listener, cursor, pinch_begin);
741 struct wlr_event_pointer_pinch_begin *event = data;
742 wlr_pointer_gestures_v1_send_pinch_begin(
743 cursor->pointer_gestures, cursor->seat->wlr_seat,
744 event->time_msec, event->fingers);
745}
746
747static void handle_pointer_pinch_update(struct wl_listener *listener, void *data) {
748 struct sway_cursor *cursor = wl_container_of(
749 listener, cursor, pinch_update);
750 struct wlr_event_pointer_pinch_update *event = data;
751 wlr_pointer_gestures_v1_send_pinch_update(
752 cursor->pointer_gestures, cursor->seat->wlr_seat,
753 event->time_msec, event->dx, event->dy,
754 event->scale, event->rotation);
755}
756
757static void handle_pointer_pinch_end(struct wl_listener *listener, void *data) {
758 struct sway_cursor *cursor = wl_container_of(
759 listener, cursor, pinch_end);
760 struct wlr_event_pointer_pinch_end *event = data;
761 wlr_pointer_gestures_v1_send_pinch_end(
762 cursor->pointer_gestures, cursor->seat->wlr_seat,
763 event->time_msec, event->cancelled);
764}
765
766static void handle_pointer_swipe_begin(struct wl_listener *listener, void *data) {
767 struct sway_cursor *cursor = wl_container_of(
768 listener, cursor, swipe_begin);
769 struct wlr_event_pointer_swipe_begin *event = data;
770 wlr_pointer_gestures_v1_send_swipe_begin(
771 cursor->pointer_gestures, cursor->seat->wlr_seat,
772 event->time_msec, event->fingers);
773}
774
775static void handle_pointer_swipe_update(struct wl_listener *listener, void *data) {
776 struct sway_cursor *cursor = wl_container_of(
777 listener, cursor, swipe_update);
778 struct wlr_event_pointer_swipe_update *event = data;
779 wlr_pointer_gestures_v1_send_swipe_update(
780 cursor->pointer_gestures, cursor->seat->wlr_seat,
781 event->time_msec, event->dx, event->dy);
782}
783
784static void handle_pointer_swipe_end(struct wl_listener *listener, void *data) {
785 struct sway_cursor *cursor = wl_container_of(
786 listener, cursor, swipe_end);
787 struct wlr_event_pointer_swipe_end *event = data;
788 wlr_pointer_gestures_v1_send_swipe_end(
789 cursor->pointer_gestures, cursor->seat->wlr_seat,
790 event->time_msec, event->cancelled);
791}
738void cursor_set_image(struct sway_cursor *cursor, const char *image, 792void cursor_set_image(struct sway_cursor *cursor, const char *image,
739 struct wl_client *client) { 793 struct wl_client *client) {
740 if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { 794 if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
@@ -825,6 +879,20 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
825 cursor->hide_source = wl_event_loop_add_timer(server.wl_event_loop, 879 cursor->hide_source = wl_event_loop_add_timer(server.wl_event_loop,
826 hide_notify, cursor); 880 hide_notify, cursor);
827 881
882 cursor->pointer_gestures = wlr_pointer_gestures_v1_create(server.wl_display);
883 cursor->pinch_begin.notify = handle_pointer_pinch_begin;
884 wl_signal_add(&wlr_cursor->events.pinch_begin, &cursor->pinch_begin);
885 cursor->pinch_update.notify = handle_pointer_pinch_update;
886 wl_signal_add(&wlr_cursor->events.pinch_update, &cursor->pinch_update);
887 cursor->pinch_end.notify = handle_pointer_pinch_end;
888 wl_signal_add(&wlr_cursor->events.pinch_end, &cursor->pinch_end);
889 cursor->swipe_begin.notify = handle_pointer_swipe_begin;
890 wl_signal_add(&wlr_cursor->events.swipe_begin, &cursor->swipe_begin);
891 cursor->swipe_update.notify = handle_pointer_swipe_update;
892 wl_signal_add(&wlr_cursor->events.swipe_update, &cursor->swipe_update);
893 cursor->swipe_end.notify = handle_pointer_swipe_end;
894 wl_signal_add(&wlr_cursor->events.swipe_end, &cursor->swipe_end);
895
828 // input events 896 // input events
829 wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); 897 wl_signal_add(&wlr_cursor->events.motion, &cursor->motion);
830 cursor->motion.notify = handle_cursor_motion_relative; 898 cursor->motion.notify = handle_cursor_motion_relative;