From ba3243f88a046992c39fd63d51e4e65bc573ddd5 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 6 Mar 2021 17:17:11 -0500 Subject: [PATCH] [client] wayland: make input handlers aware of multiple surfaces This prevents input handlers from breaking in presence of subsurfaces, which are used by libdecor for client-side decorations. --- client/displayservers/Wayland/input.c | 22 ++++++++++++++++++++++ client/displayservers/Wayland/wayland.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/client/displayservers/Wayland/input.c b/client/displayservers/Wayland/input.c index 714f8d79..97053d38 100644 --- a/client/displayservers/Wayland/input.c +++ b/client/displayservers/Wayland/input.c @@ -46,6 +46,10 @@ static void pointerEnterHandler(void * data, struct wl_pointer * pointer, uint32_t serial, struct wl_surface * surface, wl_fixed_t sxW, wl_fixed_t syW) { + if (surface != wlWm.surface) + return; + + wlWm.pointerInSurface = true; app_handleEnterEvent(true); wl_pointer_set_cursor(pointer, serial, wlWm.showPointer ? wlWm.cursor : NULL, 0, 0); @@ -71,6 +75,10 @@ static void pointerEnterHandler(void * data, struct wl_pointer * pointer, static void pointerLeaveHandler(void * data, struct wl_pointer * pointer, uint32_t serial, struct wl_surface * surface) { + if (surface != wlWm.surface) + return; + + wlWm.pointerInSurface = false; app_handleEnterEvent(false); } @@ -153,6 +161,10 @@ static void keyboardKeymapHandler(void * data, struct wl_keyboard * keyboard, static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard, uint32_t serial, struct wl_surface * surface, struct wl_array * keys) { + if (surface != wlWm.surface) + return; + + wlWm.focusedOnSurface = true; app_handleFocusEvent(true); wlWm.keyboardEnterSerial = serial; @@ -164,12 +176,19 @@ static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard, static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard, uint32_t serial, struct wl_surface * surface) { + if (surface != wlWm.surface) + return; + + wlWm.focusedOnSurface = false; app_handleFocusEvent(false); } static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { + if (!wlWm.focusedOnSurface) + return; + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) app_handleKeyPress(key); else @@ -358,6 +377,9 @@ void waylandUngrabKeyboard(void) void waylandWarpPointer(int x, int y, bool exiting) { + if (!wlWm.pointerInSurface) + return; + if (x < 0) x = 0; else if (x >= wlWm.width) x = wlWm.width - 1; if (y < 0) y = 0; diff --git a/client/displayservers/Wayland/wayland.h b/client/displayservers/Wayland/wayland.h index 0d350f68..2f3d95c9 100644 --- a/client/displayservers/Wayland/wayland.h +++ b/client/displayservers/Wayland/wayland.h @@ -70,6 +70,8 @@ struct WaylandDSState { bool pointerGrabbed; bool keyboardGrabbed; + bool pointerInSurface; + bool focusedOnSurface; struct wl_display * display; struct wl_surface * surface;