From 8ae1fd01730ebd8382d850d1d5526fee0fb076f1 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:34:13 +0000 Subject: added layer rules --- src/config/ConfigManager.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/config/ConfigManager.hpp | 4 ++++ 2 files changed, 49 insertions(+) (limited to 'src/config') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 397ec6c9..0c8ca2f0 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -740,6 +740,10 @@ bool windowRuleValid(const std::string& RULE) { RULE.find("rounding") != 0 && RULE.find("workspace") != 0 && RULE.find("bordercolor") != 0); } +bool layerRuleValid(const std::string& RULE) { + return !(RULE != "noanim"); +} + void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); @@ -764,6 +768,29 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str m_dWindowRules.push_back({RULE, VALUE}); } +void CConfigManager::handleLayerRule(const std::string& command, const std::string& value) { + const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); + const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); + + // check rule and value + if (RULE == "" || VALUE == "") { + return; + } + + if (RULE == "unset") { + std::erase_if(m_dLayerRules, [&](const SLayerRule& other) { return other.targetNamespace == VALUE; }); + return; + } + + 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}); +} + void CConfigManager::handleWindowRuleV2(const std::string& command, const std::string& value) { const auto RULE = value.substr(0, value.find_first_of(',')); const auto VALUE = value.substr(value.find_first_of(',') + 1); @@ -1009,6 +1036,8 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: handleWindowRule(COMMAND, VALUE); else if (COMMAND == "windowrulev2") handleWindowRuleV2(COMMAND, VALUE); + else if (COMMAND == "layerrule") + handleLayerRule(COMMAND, VALUE); else if (COMMAND == "bezier") handleBezier(COMMAND, VALUE); else if (COMMAND == "animation") @@ -1525,6 +1554,22 @@ std::vector CConfigManager::getMatchingRules(CWindow* pWindow) { return returns; } +std::vector CConfigManager::getMatchingRules(SLayerSurface* pLS) { + std::vector returns; + + for (auto& lr : m_dLayerRules) { + std::regex NSCHECK(lr.targetNamespace); + + if (!pLS->layerSurface->_namespace || !std::regex_search(pLS->layerSurface->_namespace, NSCHECK)) + continue; + + // hit + returns.push_back(lr); + } + + return returns; +} + void CConfigManager::dispatchExecOnce() { if (firstExecDispatched || isFirstLaunch) return; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 2b8ea8ab..80971966 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -11,6 +11,7 @@ #include #include #include "../Window.hpp" +#include "../helpers/WLClasses.hpp" #include "defaultConfig.hpp" #include "ConfigDataValues.hpp" @@ -152,6 +153,7 @@ class CConfigManager { std::string getBoundMonitorStringForWS(const std::string&); std::vector getMatchingRules(CWindow*); + std::vector getMatchingRules(SLayerSurface*); std::unordered_map m_mAdditionalReservedAreas; @@ -200,6 +202,7 @@ class CConfigManager { std::deque m_dMonitorRules; std::deque m_dWindowRules; + std::deque m_dLayerRules; std::deque m_dBlurLSNamespaces; bool firstExecDispatched = false; @@ -224,6 +227,7 @@ class CConfigManager { void handleBind(const std::string&, const std::string&); void handleUnbind(const std::string&, const std::string&); void handleWindowRule(const std::string&, const std::string&); + void handleLayerRule(const std::string&, const std::string&); void handleWindowRuleV2(const std::string&, const std::string&); void handleDefaultWorkspace(const std::string&, const std::string&); void handleBezier(const std::string&, const std::string&); -- cgit v1.2.3