From 12e28c349216deb3798ff509ff9c6044bfe4ab80 Mon Sep 17 00:00:00 2001 From: Rose Hudson Date: Fri, 17 Mar 2023 16:08:56 +0000 Subject: examples/touch: support touch cancel events --- examples/touch.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'examples') 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: -- cgit v1.2.3