From c707b00a2a5c1c9c8391c7a0ab2fe6228fb22131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 28 Apr 2020 18:57:32 +0200 Subject: [PATCH] bar/wayland: don't destroy pointer unnecessarily We only need to create/destroy the pointer when the POINTER capability changes. --- bar/wayland.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bar/wayland.c b/bar/wayland.c index 8303236..97cb54f 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -235,14 +235,16 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat, { struct wayland_backend *backend = data; - if (backend->pointer.pointer != NULL) { - wl_pointer_release(backend->pointer.pointer); - backend->pointer.pointer = NULL; - } - - if ((caps & WL_SEAT_CAPABILITY_POINTER)) { - backend->pointer.pointer = wl_seat_get_pointer(wl_seat); - wl_pointer_add_listener(backend->pointer.pointer, &pointer_listener, backend); + if (caps & WL_SEAT_CAPABILITY_POINTER) { + if (backend->pointer.pointer == NULL) { + backend->pointer.pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(backend->pointer.pointer, &pointer_listener, backend); + } + } else { + if (backend->pointer.pointer != NULL) { + wl_pointer_release(backend->pointer.pointer); + backend->pointer.pointer = NULL; + } } }