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 <proycon@anaproy.nl>
This commit is contained in:
mojyack 2023-09-01 23:18:29 +09:00 committed by Maarten van Gompel
parent 9e03e120c3
commit 21045044ba

20
main.c
View File

@ -276,12 +276,24 @@ void
seat_handle_capabilities(void *data, struct wl_seat *wl_seat, seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) { enum wl_seat_capability caps) {
if ((caps & WL_SEAT_CAPABILITY_POINTER)) { if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
pointer = wl_seat_get_pointer(wl_seat); if (pointer == NULL) {
wl_pointer_add_listener(pointer, &pointer_listener, 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)) { if ((caps & WL_SEAT_CAPABILITY_TOUCH)) {
touch = wl_seat_get_touch(wl_seat); if (touch == NULL) {
wl_touch_add_listener(touch, &touch_listener, NULL); touch = wl_seat_get_touch(wl_seat);
wl_touch_add_listener(touch, &touch_listener, NULL);
}
} else {
if (touch != NULL) {
wl_touch_destroy(touch);
}
} }
} }