aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar hrdl <31923882+hrdl-github@users.noreply.github.com>2023-05-04 01:13:33 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2023-05-04 13:30:57 +0200
commite8f7551e46052a8df04b630bf06565ca77f830fb (patch)
tree00a8dd81570767262252188f183fac647bfa253b
parentDon't crash if there is no damage during render (diff)
downloadsway-e8f7551e46052a8df04b630bf06565ca77f830fb.tar.gz
sway-e8f7551e46052a8df04b630bf06565ca77f830fb.tar.zst
sway-e8f7551e46052a8df04b630bf06565ca77f830fb.zip
Add support for touch cancel events
-rw-r--r--include/sway/input/cursor.h1
-rw-r--r--include/sway/input/seat.h5
-rw-r--r--sway/input/cursor.c22
-rw-r--r--sway/input/seat.c6
-rw-r--r--sway/input/seatop_down.c19
5 files changed, 53 insertions, 0 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index 4a3774d9..c7da8829 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -53,6 +53,7 @@ struct sway_cursor {
53 53
54 struct wl_listener touch_down; 54 struct wl_listener touch_down;
55 struct wl_listener touch_up; 55 struct wl_listener touch_up;
56 struct wl_listener touch_cancel;
56 struct wl_listener touch_motion; 57 struct wl_listener touch_motion;
57 struct wl_listener touch_frame; 58 struct wl_listener touch_frame;
58 bool simulating_pointer_from_touch; 59 bool simulating_pointer_from_touch;
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index 6d29cf3b..5ef8e2f3 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -44,6 +44,8 @@ struct sway_seatop_impl {
44 struct wlr_touch_up_event *event); 44 struct wlr_touch_up_event *event);
45 void (*touch_down)(struct sway_seat *seat, 45 void (*touch_down)(struct sway_seat *seat,
46 struct wlr_touch_down_event *event, double lx, double ly); 46 struct wlr_touch_down_event *event, double lx, double ly);
47 void (*touch_cancel)(struct sway_seat *seat,
48 struct wlr_touch_cancel_event *event);
47 void (*tablet_tool_motion)(struct sway_seat *seat, 49 void (*tablet_tool_motion)(struct sway_seat *seat,
48 struct sway_tablet_tool *tool, uint32_t time_msec); 50 struct sway_tablet_tool *tool, uint32_t time_msec);
49 void (*tablet_tool_tip)(struct sway_seat *seat, struct sway_tablet_tool *tool, 51 void (*tablet_tool_tip)(struct sway_seat *seat, struct sway_tablet_tool *tool,
@@ -338,6 +340,9 @@ void seatop_touch_up(struct sway_seat *seat,
338void seatop_touch_down(struct sway_seat *seat, 340void seatop_touch_down(struct sway_seat *seat,
339 struct wlr_touch_down_event *event, double lx, double ly); 341 struct wlr_touch_down_event *event, double lx, double ly);
340 342
343void seatop_touch_cancel(struct sway_seat *seat,
344 struct wlr_touch_cancel_event *event);
345
341void seatop_rebase(struct sway_seat *seat, uint32_t time_msec); 346void seatop_rebase(struct sway_seat *seat, uint32_t time_msec);
342 347
343/** 348/**
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 75d055cd..d8ec11ac 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -509,6 +509,24 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
509 } 509 }
510} 510}
511 511
512static void handle_touch_cancel(struct wl_listener *listener, void *data) {
513 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_cancel);
514 struct wlr_touch_cancel_event *event = data;
515 cursor_handle_activity_from_device(cursor, &event->touch->base);
516
517 struct sway_seat *seat = cursor->seat;
518
519 if (cursor->simulating_pointer_from_touch) {
520 if (cursor->pointer_touch_id == cursor->seat->touch_id) {
521 cursor->pointer_touch_up = true;
522 dispatch_cursor_button(cursor, &event->touch->base,
523 event->time_msec, BTN_LEFT, WLR_BUTTON_RELEASED);
524 }
525 } else {
526 seatop_touch_cancel(seat, event);
527 }
528}
529
512static void handle_touch_motion(struct wl_listener *listener, void *data) { 530static void handle_touch_motion(struct wl_listener *listener, void *data) {
513 struct sway_cursor *cursor = 531 struct sway_cursor *cursor =
514 wl_container_of(listener, cursor, touch_motion); 532 wl_container_of(listener, cursor, touch_motion);
@@ -1100,6 +1118,7 @@ void sway_cursor_destroy(struct sway_cursor *cursor) {
1100 wl_list_remove(&cursor->frame.link); 1118 wl_list_remove(&cursor->frame.link);
1101 wl_list_remove(&cursor->touch_down.link); 1119 wl_list_remove(&cursor->touch_down.link);
1102 wl_list_remove(&cursor->touch_up.link); 1120 wl_list_remove(&cursor->touch_up.link);
1121 wl_list_remove(&cursor->touch_cancel.link);
1103 wl_list_remove(&cursor->touch_motion.link); 1122 wl_list_remove(&cursor->touch_motion.link);
1104 wl_list_remove(&cursor->touch_frame.link); 1123 wl_list_remove(&cursor->touch_frame.link);
1105 wl_list_remove(&cursor->tool_axis.link); 1124 wl_list_remove(&cursor->tool_axis.link);
@@ -1181,6 +1200,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
1181 wl_signal_add(&wlr_cursor->events.touch_up, &cursor->touch_up); 1200 wl_signal_add(&wlr_cursor->events.touch_up, &cursor->touch_up);
1182 cursor->touch_up.notify = handle_touch_up; 1201 cursor->touch_up.notify = handle_touch_up;
1183 1202
1203 wl_signal_add(&wlr_cursor->events.touch_cancel, &cursor->touch_cancel);
1204 cursor->touch_cancel.notify = handle_touch_cancel;
1205
1184 wl_signal_add(&wlr_cursor->events.touch_motion, 1206 wl_signal_add(&wlr_cursor->events.touch_motion,
1185 &cursor->touch_motion); 1207 &cursor->touch_motion);
1186 cursor->touch_motion.notify = handle_touch_motion; 1208 cursor->touch_motion.notify = handle_touch_motion;
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 6b95e46a..bcb89b48 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -1638,6 +1638,12 @@ void seatop_touch_down(struct sway_seat *seat, struct wlr_touch_down_event *even
1638 } 1638 }
1639} 1639}
1640 1640
1641void seatop_touch_cancel(struct sway_seat *seat, struct wlr_touch_cancel_event *event) {
1642 if (seat->seatop_impl->touch_cancel) {
1643 seat->seatop_impl->touch_cancel(seat, event);
1644 }
1645}
1646
1641void seatop_tablet_tool_tip(struct sway_seat *seat, 1647void seatop_tablet_tool_tip(struct sway_seat *seat,
1642 struct sway_tablet_tool *tool, uint32_t time_msec, 1648 struct sway_tablet_tool *tool, uint32_t time_msec,
1643 enum wlr_tablet_tool_tip_state state) { 1649 enum wlr_tablet_tool_tip_state state) {
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c
index 6447134e..c5901f6a 100644
--- a/sway/input/seatop_down.c
+++ b/sway/input/seatop_down.c
@@ -104,6 +104,24 @@ static void handle_touch_down(struct sway_seat *seat,
104 } 104 }
105} 105}
106 106
107static void handle_touch_cancel(struct sway_seat *seat,
108 struct wlr_touch_cancel_event *event) {
109 struct seatop_down_event *e = seat->seatop_data;
110 struct seatop_touch_point_event *point_event, *tmp;
111
112 wl_list_for_each_safe(point_event, tmp, &e->point_events, link) {
113 if (point_event->touch_id == event->touch_id) {
114 wl_list_remove(&point_event->link);
115 free(point_event);
116 break;
117 }
118 }
119
120 if (e->surface) {
121 wlr_seat_touch_notify_cancel(seat->wlr_seat, e->surface);
122 }
123}
124
107static void handle_pointer_axis(struct sway_seat *seat, 125static void handle_pointer_axis(struct sway_seat *seat,
108 struct wlr_pointer_axis_event *event) { 126 struct wlr_pointer_axis_event *event) {
109 struct sway_input_device *input_device = 127 struct sway_input_device *input_device =
@@ -189,6 +207,7 @@ static const struct sway_seatop_impl seatop_impl = {
189 .touch_motion = handle_touch_motion, 207 .touch_motion = handle_touch_motion,
190 .touch_up = handle_touch_up, 208 .touch_up = handle_touch_up,
191 .touch_down = handle_touch_down, 209 .touch_down = handle_touch_down,
210 .touch_cancel = handle_touch_cancel,
192 .unref = handle_unref, 211 .unref = handle_unref,
193 .end = handle_end, 212 .end = handle_end,
194 .allow_set_cursor = true, 213 .allow_set_cursor = true,