From 9eb750c00b576d6c1de0a80239c7085de504f72d Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 10 Aug 2022 17:46:01 +0200 Subject: [PATCH] added misc:layers_hog_keyboard_focus --- src/Compositor.cpp | 13 +++++++++++++ src/Compositor.hpp | 1 + src/config/ConfigManager.cpp | 1 + src/managers/input/InputManager.cpp | 21 +++++++++++++++++---- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index b6dd4d27..15e6fa1b 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1573,4 +1573,17 @@ void CCompositor::closeWindow(CWindow* pWindow) { focusWindow(windowFromCursor()); } } +} + +SLayerSurface* CCompositor::getLayerSurfaceFromSurface(wlr_surface* pSurface) { + for (auto& m : m_vMonitors) { + for (auto& lsl : m->m_aLayerSurfaceLists) { + for (auto& ls : lsl) { + if (ls->layerSurface && ls->layerSurface->surface == pSurface) + return ls.get(); + } + } + } + + return nullptr; } \ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index fdbd7319..73394d89 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -156,6 +156,7 @@ public: CWindow* getWindowByRegex(const std::string&); void warpCursorTo(const Vector2D&); SLayerSurface* getLayerSurfaceFromWlr(wlr_layer_surface_v1*); + SLayerSurface* getLayerSurfaceFromSurface(wlr_surface*); void closeWindow(CWindow*); std::string explicitConfigPath; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 2d8a62ca..4b47e096 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -55,6 +55,7 @@ void CConfigManager::setDefaultVars() { configValues["misc:damage_entire_on_snapshot"].intValue = 0; configValues["misc:mouse_move_enables_dpms"].intValue = 0; configValues["misc:always_follow_on_dnd"].intValue = 1; + configValues["misc:layers_hog_keyboard_focus"].intValue = 0; configValues["debug:int"].intValue = 0; configValues["debug:log_damage"].intValue = 0; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 597d87fa..9d63ec71 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -31,6 +31,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { static auto *const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; static auto *const PMOUSEDPMS = &g_pConfigManager->getConfigValuePtr("misc:mouse_move_enables_dpms")->intValue; static auto *const PFOLLOWONDND = &g_pConfigManager->getConfigValuePtr("misc:always_follow_on_dnd")->intValue; + static auto *const PHOGFOCUS = &g_pConfigManager->getConfigValuePtr("misc:layers_hog_keyboard_focus")->intValue; if (!g_pCompositor->m_bReadyToProcess) return; @@ -229,11 +230,21 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { surfaceLocal = mouseCoords - surfacePos + Vector2D(geom.x, geom.y); } + bool allowKeyboardRefocus = true; + + if (*PHOGFOCUS && !refocus && g_pCompositor->m_pLastFocus) { + const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus); + + if (PLS && PLS->layerSurface->current.keyboard_interactive) { + allowKeyboardRefocus = false; + } + } + if (pFoundWindow) { if (*PFOLLOWMOUSE != 1 && !refocus) { if (pFoundWindow != g_pCompositor->m_pLastWindow && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) && (g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating)) { // enter if change floating style - if (*PFOLLOWMOUSE != 3) + if (*PFOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); } else if (*PFOLLOWMOUSE == 2) { @@ -252,11 +263,13 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); return; // don't enter any new surfaces } else { - if (*PFOLLOWMOUSE != 3) + if (*PFOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); } - } else if (pFoundLayerSurface && pFoundLayerSurface->layerSurface->current.keyboard_interactive && *PFOLLOWMOUSE != 3) - g_pCompositor->focusSurface(foundSurface); + } else { + if (pFoundLayerSurface && pFoundLayerSurface->layerSurface->current.keyboard_interactive && *PFOLLOWMOUSE != 3 && allowKeyboardRefocus) + g_pCompositor->focusSurface(foundSurface); + } wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y);