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: [PATCH] added layer rules --- src/config/ConfigManager.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/config/ConfigManager.hpp | 4 ++++ src/events/Layers.cpp | 13 ++++++++++- src/helpers/WLClasses.hpp | 14 +++++++---- 4 files changed, 71 insertions(+), 5 deletions(-) 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&); diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 4ecb8ed8..0d581267 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -121,6 +121,11 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { if (!PMONITOR) return; + for (auto& rule : g_pConfigManager->getMatchingRules(layersurface)) { + if (rule.rule == "noanim") + layersurface->noAnimations = true; + } + if ((uint64_t)layersurface->monitorID != PMONITOR->ID) { const auto POLDMON = g_pCompositor->getMonitorFromID(layersurface->monitorID); for (auto it = POLDMON->m_aLayerSurfaceLayers[layersurface->layer].begin(); it != POLDMON->m_aLayerSurfaceLayers[layersurface->layer].end(); it++) { @@ -160,6 +165,9 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { layersurface->readyToDelete = false; layersurface->fadingOut = false; + if (layersurface->noAnimations) + layersurface->alpha.setValueAndWarp(1.f); + g_pEventManager->postEvent(SHyprIPCEvent{"openlayer", std::string(layersurface->layerSurface->_namespace ? layersurface->layerSurface->_namespace : "")}); } @@ -190,6 +198,9 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { g_pHyprOpenGL->makeLayerSnapshot(layersurface); layersurface->alpha = 0.f; + if (layersurface->noAnimations) + layersurface->alpha.setValueAndWarp(0.f); + layersurface->mapped = false; layersurface->fadingOut = true; @@ -241,7 +252,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { g_pHyprRenderer->damageBox(&geomFixed); geomFixed = {layersurface->geometry.x, layersurface->geometry.y, (int)layersurface->layerSurface->surface->current.width, - (int)layersurface->layerSurface->surface->current.height}; + (int)layersurface->layerSurface->surface->current.height}; layersurface->geometry = geomFixed; // because the surface can overflow... for some reason? } diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index af070c78..41f7b6a7 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -7,6 +7,11 @@ #include "SubsurfaceTree.hpp" #include "AnimatedVariable.hpp" +struct SLayerRule { + std::string targetNamespace = ""; + std::string rule = ""; +}; + struct SLayerSurface { SLayerSurface(); @@ -33,6 +38,7 @@ struct SLayerSurface { bool fadingOut = false; bool readyToDelete = false; bool noProcess = false; + bool noAnimations = false; bool forceBlur = false; @@ -45,9 +51,9 @@ struct SLayerSurface { class CMonitor; struct SRenderData { - CMonitor* pMonitor; - timespec* when; - int x, y; + CMonitor* pMonitor; + timespec* when; + int x, y; // for iters void* data = nullptr; @@ -224,7 +230,7 @@ struct STablet { std::string name = ""; bool operator==(const STablet& b) { - return wlrDevice == b.wlrDevice; + return wlrDevice == b.wlrDevice; } };