From 21045044ba808b164bbb49d804337401d6907d30 Mon Sep 17 00:00:00 2001 From: mojyack Date: Fri, 1 Sep 2023 23:18:29 +0900 Subject: [PATCH] fix seat_handle_capabilities seat_handle_capabilities may be called more than once with different caps. In the current implementation, wl_{pointer,touch}_add_listener can be called multiple times for the same seat, causing the buttons to be pressed more than once in a single tap. This commit implements seat_handle_capabilities correctly and avoids setting duplicate handlers, and also handles the removal of capabilities. Signed-off-by: Maarten van Gompel --- main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 35eea1d..5bfefe1 100644 --- a/main.c +++ b/main.c @@ -276,12 +276,24 @@ void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capability caps) { if ((caps & WL_SEAT_CAPABILITY_POINTER)) { - pointer = wl_seat_get_pointer(wl_seat); - wl_pointer_add_listener(pointer, &pointer_listener, NULL); + if (pointer == NULL) { + pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(pointer, &pointer_listener, NULL); + } + } else { + if (pointer != NULL) { + wl_pointer_destroy(pointer); + } } if ((caps & WL_SEAT_CAPABILITY_TOUCH)) { - touch = wl_seat_get_touch(wl_seat); - wl_touch_add_listener(touch, &touch_listener, NULL); + if (touch == NULL) { + touch = wl_seat_get_touch(wl_seat); + wl_touch_add_listener(touch, &touch_listener, NULL); + } + } else { + if (touch != NULL) { + wl_touch_destroy(touch); + } } }