diff options
| author | Virt <41426325+VirtCode@users.noreply.github.com> | 2026-03-06 21:11:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-06 20:11:42 +0000 |
| commit | e0c571005912c342d8d812b368bc490cb6f28796 (patch) | |
| tree | 8591722027f451f2714e982c76421d70fd4b4f24 /src | |
| parent | 42f0a6005b7c502b1486f1f3b4d9883035be3dd8 (diff) | |
layerrules: add dynamically registered rules for plugins (#13331)
* layerrules: add dynamically registered rules for plugins
* be gone
* layerrules: add layer tests with waybar
* fix: use kitty layers instead of waybar
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop/rule/layerRule/LayerRuleApplicator.cpp | 31 | ||||
| -rw-r--r-- | src/desktop/rule/layerRule/LayerRuleApplicator.hpp | 12 | ||||
| -rw-r--r-- | src/event/EventBus.hpp | 3 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/desktop/rule/layerRule/LayerRuleApplicator.cpp b/src/desktop/rule/layerRule/LayerRuleApplicator.cpp index 4237e4f7..fec3a5b2 100644 --- a/src/desktop/rule/layerRule/LayerRuleApplicator.cpp +++ b/src/desktop/rule/layerRule/LayerRuleApplicator.cpp @@ -4,6 +4,7 @@ #include "../../view/LayerSurface.hpp" #include "../../types/OverridableVar.hpp" #include "../../../helpers/MiscFunctions.hpp" +#include "../../../event/EventBus.hpp" using namespace Desktop; using namespace Desktop::Rule; @@ -32,11 +33,38 @@ void CLayerRuleApplicator::resetProps(std::underlying_type_t<eRuleProperty> prop UNSET(aboveLock) UNSET(ignoreAlpha) UNSET(animationStyle) + +#undef UNSET + + if (prio == Types::PRIORITY_WINDOW_RULE) + std::erase_if(m_otherProps.props, [props](const auto& el) { return !el.second || el.second->propMask & props; }); } void CLayerRuleApplicator::applyDynamicRule(const SP<CLayerRule>& rule) { for (const auto& [key, effect] : rule->effects()) { switch (key) { + default: { + if (key <= LAYER_RULE_EFFECT_LAST_STATIC) { + Log::logger->log(Log::TRACE, "CLayerRuleApplicator::applyDynamicRule: Skipping effect {}, not dynamic", sc<std::underlying_type_t<eLayerRuleEffect>>(key)); + break; + } + + // custom type, add to our vec + if (!m_otherProps.props.contains(key)) { + m_otherProps.props.emplace(key, + makeUnique<SCustomPropContainer>(SCustomPropContainer{ + .idx = key, + .propMask = rule->getPropertiesMask(), + .effect = effect, + })); + } else { + auto& e = m_otherProps.props[key]; + e->propMask |= rule->getPropertiesMask(); + e->effect = effect; + } + + break; + } case LAYER_RULE_EFFECT_NONE: { Log::logger->log(Log::ERR, "CLayerRuleApplicator::applyDynamicRule: BUG THIS: LAYER_RULE_EFFECT_NONE??"); break; @@ -125,4 +153,7 @@ void CLayerRuleApplicator::propertiesChanged(std::underlying_type_t<eRulePropert applyDynamicRule(wr); } + + // for plugins + Event::bus()->m_events.layer.updateRules.emit(m_ls.lock()); } diff --git a/src/desktop/rule/layerRule/LayerRuleApplicator.hpp b/src/desktop/rule/layerRule/LayerRuleApplicator.hpp index 97f15b04..35aa18c5 100644 --- a/src/desktop/rule/layerRule/LayerRuleApplicator.hpp +++ b/src/desktop/rule/layerRule/LayerRuleApplicator.hpp @@ -1,5 +1,6 @@ #pragma once +#include "LayerRuleEffectContainer.hpp" #include "../../DesktopTypes.hpp" #include "../Rule.hpp" #include "../../types/OverridableVar.hpp" @@ -21,6 +22,17 @@ namespace Desktop::Rule { void propertiesChanged(std::underlying_type_t<eRuleProperty> props); void resetProps(std::underlying_type_t<eRuleProperty> props, Types::eOverridePriority prio = Types::PRIORITY_WINDOW_RULE); + struct SCustomPropContainer { + CLayerRuleEffectContainer::storageType idx = LAYER_RULE_EFFECT_NONE; + std::underlying_type_t<eRuleProperty> propMask = RULE_PROP_NONE; + std::string effect; + }; + + // This struct holds props that were dynamically registered. Plugins may read this. + struct { + std::unordered_map<CLayerRuleEffectContainer::storageType, UP<SCustomPropContainer>> props; + } m_otherProps; + #define COMMA , #define DEFINE_PROP(type, name, def) \ private: \ diff --git a/src/event/EventBus.hpp b/src/event/EventBus.hpp index 60bd1511..a30288f0 100644 --- a/src/event/EventBus.hpp +++ b/src/event/EventBus.hpp @@ -55,6 +55,7 @@ namespace Event { struct { Event<PHLLS> opened; Event<PHLLS> closed; + Event<PHLLS> updateRules; } layer; struct { @@ -140,4 +141,4 @@ namespace Event { }; UP<CEventBus>& bus(); -};
\ No newline at end of file +}; |
