From d96b2ef1fb0196450cd4fa1a34571141b5bcc66b Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 6 Dec 2021 20:45:52 -0500 Subject: [PATCH] [client] wayland: clean up objects when wl_pointer disappears --- client/displayservers/Wayland/input.c | 35 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/client/displayservers/Wayland/input.c b/client/displayservers/Wayland/input.c index 765a4543..0d9d24a6 100644 --- a/client/displayservers/Wayland/input.c +++ b/client/displayservers/Wayland/input.c @@ -290,16 +290,39 @@ static const struct wl_keyboard_listener keyboardListener = { .modifiers = keyboardModifiersHandler, }; +static void waylandCleanUpPointer(void) +{ + INTERLOCKED_SECTION(wlWm.confineLock, { + if (wlWm.lockedPointer) + { + zwp_locked_pointer_v1_destroy(wlWm.lockedPointer); + wlWm.lockedPointer = NULL; + } + + if (wlWm.confinedPointer) + { + zwp_confined_pointer_v1_destroy(wlWm.confinedPointer); + wlWm.confinedPointer = NULL; + } + }); + + if (wlWm.relativePointer) + { + zwp_relative_pointer_v1_destroy(wlWm.relativePointer); + wlWm.relativePointer = NULL; + } + + wl_pointer_destroy(wlWm.pointer); + wlWm.pointer = NULL; +} + // Seat-handling listeners. static void handlePointerCapability(uint32_t capabilities) { bool hasPointer = capabilities & WL_SEAT_CAPABILITY_POINTER; if (!hasPointer && wlWm.pointer) - { - wl_pointer_destroy(wlWm.pointer); - wlWm.pointer = NULL; - } + waylandCleanUpPointer(); else if (hasPointer && !wlWm.pointer) { wlWm.pointer = wl_seat_get_pointer(wlWm.seat); @@ -394,7 +417,9 @@ void waylandInputFree(void) { waylandUngrabPointer(); LG_LOCK_FREE(wlWm.confineLock); - wl_pointer_destroy(wlWm.pointer); + + if (wlWm.pointer) + waylandCleanUpPointer(); wl_keyboard_destroy(wlWm.keyboard); wl_seat_destroy(wlWm.seat);