aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRose Hudson <rose@krx.sh>2023-03-17 16:08:56 +0000
committerSimon Ser <contact@emersion.fr>2023-03-24 11:47:08 +0000
commit12e28c349216deb3798ff509ff9c6044bfe4ab80 (patch)
tree9d14badbbc0a7ebf062f191097001fb78a683e72
parent37f42e2df26ff694801e3b6593462f303c83b0fa (diff)
examples/touch: support touch cancel events
-rw-r--r--examples/touch.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/touch.c b/examples/touch.c
index 6d13c80e..7a9002e1 100644
--- a/examples/touch.c
+++ b/examples/touch.c
@@ -46,6 +46,7 @@ struct touch_state {
struct wl_listener down;
struct wl_listener up;
struct wl_listener motion;
+ struct wl_listener cancel;
struct wl_list link;
void *data;
};
@@ -130,6 +131,19 @@ static void touch_motion_notify(struct wl_listener *listener, void *data) {
}
}
+static void touch_cancel_notify(struct wl_listener *listener, void *data) {
+ struct wlr_touch_cancel_event *event = data;
+ struct touch_state *tstate = wl_container_of(listener, tstate, cancel);
+ struct sample_state *sample = tstate->sample;
+ struct touch_point *point, *tmp;
+ wl_list_for_each_safe(point, tmp, &sample->touch_points, link) {
+ if (point->touch_id == event->touch_id) {
+ wl_list_remove(&point->link);
+ break;
+ }
+ }
+}
+
static void touch_destroy_notify(struct wl_listener *listener, void *data) {
struct touch_state *tstate = wl_container_of(listener, tstate, destroy);
wl_list_remove(&tstate->link);
@@ -137,6 +151,7 @@ static void touch_destroy_notify(struct wl_listener *listener, void *data) {
wl_list_remove(&tstate->down.link);
wl_list_remove(&tstate->up.link);
wl_list_remove(&tstate->motion.link);
+ wl_list_remove(&tstate->cancel.link);
free(tstate);
}
@@ -231,6 +246,8 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
wl_signal_add(&tstate->wlr_touch->events.motion, &tstate->motion);
tstate->up.notify = touch_up_notify;
wl_signal_add(&tstate->wlr_touch->events.up, &tstate->up);
+ tstate->cancel.notify = touch_cancel_notify;
+ wl_signal_add(&tstate->wlr_touch->events.cancel, &tstate->cancel);
wl_list_insert(&sample->touch, &tstate->link);
break;
default: