From 9bab7b2d6524af0e4fcb505a714b8c544b6ee420 Mon Sep 17 00:00:00 2001 From: maqrrr Date: Mon, 8 May 2023 00:59:21 -0400 Subject: [PATCH] Add layerrule ignorefocus --- src/Compositor.cpp | 6 ++++- src/config/ConfigManager.cpp | 18 ++++++------- src/events/Layers.cpp | 28 ++----------------- src/helpers/WLClasses.cpp | 42 ++++++++++++++++++++++++++++- src/helpers/WLClasses.hpp | 6 +++-- src/managers/input/InputManager.cpp | 2 +- 6 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index c95cd58e..0a641c82 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -996,14 +996,18 @@ wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector< SURFACEAT = ls->layerSurface->surface; *ppLayerSurfaceFound = ls.get(); + if ((*ppLayerSurfaceFound)->ignoreFocus) + continue; + return SURFACEAT; } if (SURFACEAT) { if (!pixman_region32_not_empty(&SURFACEAT->input_region)) continue; - *ppLayerSurfaceFound = ls.get(); + if ((*ppLayerSurfaceFound)->ignoreFocus) + continue; return SURFACEAT; } } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 04764779..cc2ae5a6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -803,7 +803,7 @@ bool windowRuleValid(const std::string& RULE) { } bool layerRuleValid(const std::string& RULE) { - return !(RULE != "noanim" && RULE != "blur" && RULE != "ignorezero"); + return !(RULE != "noanim" && RULE != "blur" && RULE != "ignorezero" && RULE != "ignorefocus"); } void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { @@ -840,17 +840,15 @@ void CConfigManager::handleLayerRule(const std::string& command, const std::stri if (RULE == "unset") { std::erase_if(m_dLayerRules, [&](const SLayerRule& other) { return other.targetNamespace == VALUE; }); - return; + } else { + if (!layerRuleValid(RULE)) { + Debug::log(ERR, "Invalid rule found: %s", RULE.c_str()); + parseError = "Invalid rule found: " + RULE; + return; + } + m_dLayerRules.push_back({VALUE, RULE}); } - if (!layerRuleValid(RULE)) { - Debug::log(ERR, "Invalid rule found: %s", RULE.c_str()); - parseError = "Invalid rule found: " + RULE; - return; - } - - m_dLayerRules.push_back({VALUE, RULE}); - for (auto& m : g_pCompositor->m_vMonitors) for (auto& lsl : m->m_aLayerSurfaceLayers) for (auto& ls : lsl) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index fa3e668c..fdb86d72 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -143,7 +143,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { wlr_surface_send_enter(layersurface->layerSurface->surface, layersurface->layerSurface->output); - if (layersurface->layerSurface->current.keyboard_interactive && + if (layersurface->layerSurface->current.keyboard_interactive && !layersurface->ignoreFocus && (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint)) { // don't focus if constrained g_pCompositor->focusSurface(layersurface->layerSurface->surface); @@ -218,31 +218,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { // refocus if needed if (WASLASTFOCUS) { - g_pInputManager->releaseAllMouseButtons(); - - Vector2D surfaceCoords; - SLayerSurface* pFoundLayerSurface = nullptr; - wlr_surface* foundSurface = nullptr; - - g_pCompositor->m_pLastFocus = nullptr; - - // find LS-es to focus - foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], - &surfaceCoords, &pFoundLayerSurface); - - if (!foundSurface) - foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], - &surfaceCoords, &pFoundLayerSurface); - - if (!foundSurface) { - // if there isn't any, focus the last window - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; - g_pCompositor->focusWindow(nullptr); - g_pCompositor->focusWindow(PLASTWINDOW); - } else { - // otherwise, full refocus - g_pInputManager->refocus(); - } + layersurface->unfocus(); } wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 29e10a54..99b7db84 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -1,5 +1,6 @@ #include "WLClasses.hpp" #include "../config/ConfigManager.hpp" +#include "src/Compositor.hpp" SLayerSurface::SLayerSurface() { alpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_ENTIRE); @@ -11,6 +12,7 @@ void SLayerSurface::applyRules() { noAnimations = false; forceBlur = false; ignoreZero = false; + ignoreFocus = false; for (auto& rule : g_pConfigManager->getMatchingRules(this)) { if (rule.rule == "noanim") @@ -19,5 +21,43 @@ void SLayerSurface::applyRules() { forceBlur = true; else if (rule.rule == "ignorezero") ignoreZero = true; + else if (rule.rule == "ignorefocus") { + ignoreFocus = true; + if(g_pCompositor->m_pLastFocus == layerSurface->surface) { + unfocus(); + } + } } -} \ No newline at end of file +} + +void SLayerSurface::unfocus() { + const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layerSurface->output); + if (!PMONITOR) + return; + + g_pInputManager->releaseAllMouseButtons(); + + Vector2D surfaceCoords; + SLayerSurface* pFoundLayerSurface = nullptr; + wlr_surface* foundSurface = nullptr; + + g_pCompositor->m_pLastFocus = nullptr; + + // find LS-es to focus + foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + &surfaceCoords, &pFoundLayerSurface); + + if (!foundSurface) + foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + &surfaceCoords, &pFoundLayerSurface); + + if (!foundSurface) { + // if there isn't any, focus the last window + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + g_pCompositor->focusWindow(nullptr); + g_pCompositor->focusWindow(PLASTWINDOW); + } else { + // otherwise, full refocus + g_pInputManager->refocus(); + } +} diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 0e5138b3..738b520a 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -17,6 +17,7 @@ struct SLayerSurface { SLayerSurface(); void applyRules(); + void unfocus(); wlr_layer_surface_v1* layerSurface; wl_list link; @@ -46,8 +47,9 @@ struct SLayerSurface { bool noProcess = false; bool noAnimations = false; - bool forceBlur = false; - bool ignoreZero = false; + bool forceBlur = false; + bool ignoreZero = false; + bool ignoreFocus = false; // For the list lookup bool operator==(const SLayerSurface& rhs) const { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 189cdf84..b1339b7b 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -325,7 +325,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (*PHOGFOCUS && !refocus && g_pCompositor->m_pLastFocus) { const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus); - if (PLS && PLS->layerSurface->current.keyboard_interactive) { + if (PLS && !PLS->ignoreFocus && PLS->layerSurface->current.keyboard_interactive) { allowKeyboardRefocus = false; } }