examples/touch: support touch cancel events

This commit is contained in:
Rose Hudson 2023-03-17 16:08:56 +00:00 committed by Simon Ser
parent 37f42e2df2
commit 12e28c3492

View file

@ -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: