From eb1f29cfabffc1a9a5403952565300bb96b0406c Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 3 May 2024 05:05:40 -0700 Subject: [PATCH] protocols/focus_grab: fix keyboard focus staying on unlisted windows When creating a focus grab with layershell surfaces, the last active toplevel kept keyboard focus. --- src/protocols/FocusGrab.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/protocols/FocusGrab.cpp b/src/protocols/FocusGrab.cpp index 48c1ef5a..5a8ddb2f 100644 --- a/src/protocols/FocusGrab.cpp +++ b/src/protocols/FocusGrab.cpp @@ -183,6 +183,12 @@ void CFocusGrab::start() { hyprListener_touchGrabStarted.initCallback( &g_pCompositor->m_sSeat.seat->events.touch_grab_begin, [this](void*, void*) { this->finish(true); }, this, "CFocusGrab"); + + // If the current keyboard focus surface isn't whitelisted, kick it out. + auto focusedSurface = g_pCompositor->m_sSeat.seat->keyboard_state.focused_surface; + if (focusedSurface != nullptr && !isSurfaceComitted(focusedSurface)) { + wlr_seat_keyboard_clear_focus(g_pCompositor->m_sSeat.seat); + } } // Ensure new surfaces are focused if under the mouse when comitted.