From 0500213086f8402ccbdb2acb4748dbc6d22e21f6 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 6 Sep 2024 17:06:55 -0700 Subject: [PATCH] input: try to refocus a focusable window when seat grabs are reset (#7669) --- src/desktop/Popup.cpp | 7 +++++++ src/desktop/Popup.hpp | 23 ++++++++++++----------- src/managers/SeatManager.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index a4952ef7..9e254fa6 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -202,6 +202,13 @@ void CPopup::reposition() { m_pResource->applyPositioning(box, COORDS); } +SP CPopup::getT1Owner() { + if (m_pWindowOwner) + return m_pWindowOwner->m_pWLSurface; + else + return m_pLayerOwner->surface; +} + Vector2D CPopup::coordsRelativeToParent() { Vector2D offset; diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index eea3fb84..04996612 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -18,21 +18,22 @@ class CPopup { ~CPopup(); - Vector2D coordsRelativeToParent(); - Vector2D coordsGlobal(); + SP getT1Owner(); + Vector2D coordsRelativeToParent(); + Vector2D coordsGlobal(); - Vector2D size(); + Vector2D size(); - void onNewPopup(SP popup); - void onDestroy(); - void onMap(); - void onUnmap(); - void onCommit(bool ignoreSiblings = false); - void onReposition(); + void onNewPopup(SP popup); + void onDestroy(); + void onMap(); + void onUnmap(); + void onCommit(bool ignoreSiblings = false); + void onReposition(); - void recheckTree(); + void recheckTree(); - bool visible(); + bool visible(); // will also loop over this node void breadthfirst(std::function fn, void* data); diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index 3e4063f4..b40d6cad 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -6,6 +6,7 @@ #include "../protocols/core/Compositor.hpp" #include "../Compositor.hpp" #include "../devices/IKeyboard.hpp" +#include "wlr-layer-shell-unstable-v1.hpp" #include #include @@ -584,6 +585,36 @@ void CSeatManager::setGrab(SP grab) { auto oldGrab = seatGrab; seatGrab.reset(); g_pInputManager->refocus(); + + auto currentFocus = state.keyboardFocus.lock(); + auto refocus = !currentFocus; + + SP surf; + PHLLS layer; + + if (!refocus) { + surf = CWLSurface::fromResource(currentFocus); + layer = surf->getLayer(); + } + + if (!refocus && !layer) { + auto popup = surf->getPopup(); + if (popup) { + auto parent = popup->getT1Owner(); + layer = parent->getLayer(); + } + } + + if (!refocus && layer) + refocus = layer->interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE; + + if (refocus) { + auto candidate = g_pCompositor->m_pLastWindow.lock(); + + if (candidate) + g_pCompositor->focusWindow(candidate); + } + if (oldGrab->onEnd) oldGrab->onEnd(); }