From 650744578753e34991efbadc0dd06b29c20db9be Mon Sep 17 00:00:00 2001 From: Aurelle Date: Mon, 9 Feb 2026 12:51:25 +0000 Subject: [PATCH] layershell: restore focus to layer shell surface after popup is destroyed (#13225) --- src/managers/SeatManager.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index f40c55e3..5b428e37 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -5,6 +5,7 @@ #include "../protocols/ExtDataDevice.hpp" #include "../protocols/PrimarySelection.hpp" #include "../protocols/core/Compositor.hpp" +#include "../protocols/LayerShell.hpp" #include "../Compositor.hpp" #include "../desktop/state/FocusState.hpp" #include "../devices/IKeyboard.hpp" @@ -618,8 +619,9 @@ void CSeatManager::setGrab(SP grab) { if (m_seatGrab) { auto oldGrab = m_seatGrab; - // Try to find the parent window from the grab + // Try to find the parent window or layer surface from the grab PHLWINDOW parentWindow; + PHLLS parentLayer; if (oldGrab && oldGrab->m_surfs.size()) { // Try to find the surface that had focus when the grab ended SP focusedSurf; @@ -645,8 +647,11 @@ void CSeatManager::setGrab(SP grab) { auto popup = Desktop::View::CPopup::fromView(hlSurface->view()); if (popup) { auto t1Owner = popup->getT1Owner(); - if (t1Owner) + if (t1Owner) { parentWindow = Desktop::View::CWindow::fromView(t1Owner->view()); + if (!parentWindow) + parentLayer = Desktop::View::CLayerSurface::fromView(t1Owner->view()); + } } } } @@ -654,18 +659,22 @@ void CSeatManager::setGrab(SP grab) { m_seatGrab.reset(); - static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); - if (*PFOLLOWMOUSE == 0 || *PFOLLOWMOUSE == 2 || *PFOLLOWMOUSE == 3) { - const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); + if (parentLayer && parentLayer->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) { + Desktop::focusState()->rawSurfaceFocus(parentLayer->wlSurface()->resource()); + } else { + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); + if (*PFOLLOWMOUSE == 0 || *PFOLLOWMOUSE == 2 || *PFOLLOWMOUSE == 3) { + const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); - // If this was a popup grab, focus its parent window to maintain context - if (validMapped(parentWindow)) { - Desktop::focusState()->rawWindowFocus(parentWindow); - Log::logger->log(Log::DEBUG, "[seatmgr] Refocused popup parent window {} (follow_mouse={})", parentWindow->m_title, *PFOLLOWMOUSE); + // If this was a popup grab, focus its parent window to maintain context + if (validMapped(parentWindow)) { + Desktop::focusState()->rawWindowFocus(parentWindow); + Log::logger->log(Log::DEBUG, "[seatmgr] Refocused popup parent window {} (follow_mouse={})", parentWindow->m_title, *PFOLLOWMOUSE); + } else + g_pInputManager->refocusLastWindow(PMONITOR); } else - g_pInputManager->refocusLastWindow(PMONITOR); - } else - g_pInputManager->refocus(); + g_pInputManager->refocus(); + } auto currentFocus = m_state.keyboardFocus.lock(); auto refocus = !currentFocus;