added layer rules

This commit is contained in:
vaxerski 2023-01-25 15:34:13 +00:00
parent 9813ba2f56
commit 8ae1fd0173
4 changed files with 71 additions and 5 deletions

View file

@ -740,6 +740,10 @@ bool windowRuleValid(const std::string& RULE) {
RULE.find("rounding") != 0 && RULE.find("workspace") != 0 && RULE.find("bordercolor") != 0); 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) { void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(',')));
const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); 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}); 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) { void CConfigManager::handleWindowRuleV2(const std::string& command, const std::string& value) {
const auto RULE = value.substr(0, value.find_first_of(',')); const auto RULE = value.substr(0, value.find_first_of(','));
const auto VALUE = value.substr(value.find_first_of(',') + 1); 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); handleWindowRule(COMMAND, VALUE);
else if (COMMAND == "windowrulev2") else if (COMMAND == "windowrulev2")
handleWindowRuleV2(COMMAND, VALUE); handleWindowRuleV2(COMMAND, VALUE);
else if (COMMAND == "layerrule")
handleLayerRule(COMMAND, VALUE);
else if (COMMAND == "bezier") else if (COMMAND == "bezier")
handleBezier(COMMAND, VALUE); handleBezier(COMMAND, VALUE);
else if (COMMAND == "animation") else if (COMMAND == "animation")
@ -1525,6 +1554,22 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
return returns; return returns;
} }
std::vector<SLayerRule> CConfigManager::getMatchingRules(SLayerSurface* pLS) {
std::vector<SLayerRule> 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() { void CConfigManager::dispatchExecOnce() {
if (firstExecDispatched || isFirstLaunch) if (firstExecDispatched || isFirstLaunch)
return; return;

View file

@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include "../Window.hpp" #include "../Window.hpp"
#include "../helpers/WLClasses.hpp"
#include "defaultConfig.hpp" #include "defaultConfig.hpp"
#include "ConfigDataValues.hpp" #include "ConfigDataValues.hpp"
@ -152,6 +153,7 @@ class CConfigManager {
std::string getBoundMonitorStringForWS(const std::string&); std::string getBoundMonitorStringForWS(const std::string&);
std::vector<SWindowRule> getMatchingRules(CWindow*); std::vector<SWindowRule> getMatchingRules(CWindow*);
std::vector<SLayerRule> getMatchingRules(SLayerSurface*);
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas; std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
@ -200,6 +202,7 @@ class CConfigManager {
std::deque<SMonitorRule> m_dMonitorRules; std::deque<SMonitorRule> m_dMonitorRules;
std::deque<SWindowRule> m_dWindowRules; std::deque<SWindowRule> m_dWindowRules;
std::deque<SLayerRule> m_dLayerRules;
std::deque<std::string> m_dBlurLSNamespaces; std::deque<std::string> m_dBlurLSNamespaces;
bool firstExecDispatched = false; bool firstExecDispatched = false;
@ -224,6 +227,7 @@ class CConfigManager {
void handleBind(const std::string&, const std::string&); void handleBind(const std::string&, const std::string&);
void handleUnbind(const std::string&, const std::string&); void handleUnbind(const std::string&, const std::string&);
void handleWindowRule(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 handleWindowRuleV2(const std::string&, const std::string&);
void handleDefaultWorkspace(const std::string&, const std::string&); void handleDefaultWorkspace(const std::string&, const std::string&);
void handleBezier(const std::string&, const std::string&); void handleBezier(const std::string&, const std::string&);

View file

@ -121,6 +121,11 @@ void Events::listener_mapLayerSurface(void* owner, void* data) {
if (!PMONITOR) if (!PMONITOR)
return; return;
for (auto& rule : g_pConfigManager->getMatchingRules(layersurface)) {
if (rule.rule == "noanim")
layersurface->noAnimations = true;
}
if ((uint64_t)layersurface->monitorID != PMONITOR->ID) { if ((uint64_t)layersurface->monitorID != PMONITOR->ID) {
const auto POLDMON = g_pCompositor->getMonitorFromID(layersurface->monitorID); 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++) { 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->readyToDelete = false;
layersurface->fadingOut = 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 : "")}); 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); g_pHyprOpenGL->makeLayerSnapshot(layersurface);
layersurface->alpha = 0.f; layersurface->alpha = 0.f;
if (layersurface->noAnimations)
layersurface->alpha.setValueAndWarp(0.f);
layersurface->mapped = false; layersurface->mapped = false;
layersurface->fadingOut = true; layersurface->fadingOut = true;

View file

@ -7,6 +7,11 @@
#include "SubsurfaceTree.hpp" #include "SubsurfaceTree.hpp"
#include "AnimatedVariable.hpp" #include "AnimatedVariable.hpp"
struct SLayerRule {
std::string targetNamespace = "";
std::string rule = "";
};
struct SLayerSurface { struct SLayerSurface {
SLayerSurface(); SLayerSurface();
@ -33,6 +38,7 @@ struct SLayerSurface {
bool fadingOut = false; bool fadingOut = false;
bool readyToDelete = false; bool readyToDelete = false;
bool noProcess = false; bool noProcess = false;
bool noAnimations = false;
bool forceBlur = false; bool forceBlur = false;