summaryrefslogtreecommitdiff
path: root/src/desktop/rule/Engine.cpp
blob: fa0c2e27bde32cd85d6a213aa7aec3b047bc9bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Engine.hpp"
#include "Rule.hpp"
#include "../view/LayerSurface.hpp"
#include "../../Compositor.hpp"

using namespace Desktop;
using namespace Desktop::Rule;

SP<CRuleEngine> Rule::ruleEngine() {
    static SP<CRuleEngine> engine = makeShared<CRuleEngine>();
    return engine;
}

void CRuleEngine::registerRule(SP<IRule>&& rule) {
    m_rules.emplace_back(std::move(rule));
}

void CRuleEngine::unregisterRule(const std::string& name) {
    if (name.empty())
        return;

    std::erase_if(m_rules, [&name](const auto& el) { return el->name() == name; });
}

void CRuleEngine::unregisterRule(const SP<IRule>& rule) {
    std::erase(m_rules, rule);
    cleanExecRules();
}

void CRuleEngine::cleanExecRules() {
    std::erase_if(m_rules, [](const auto& e) { return e->isExecRule() && e->execExpired(); });
}

void CRuleEngine::updateAllRules() {
    cleanExecRules();
    for (const auto& w : g_pCompositor->m_windows) {
        if (!validMapped(w) || w->isHidden())
            continue;

        w->m_ruleApplicator->propertiesChanged(RULE_PROP_ALL);
    }
    for (const auto& ls : g_pCompositor->m_layers) {
        if (!validMapped(ls))
            continue;

        ls->m_ruleApplicator->propertiesChanged(RULE_PROP_ALL);
    }
}

void CRuleEngine::clearAllRules() {
    std::erase_if(m_rules, [](const auto& e) { return !e->isExecRule() || e->execExpired(); });
}

const std::vector<SP<IRule>>& CRuleEngine::rules() {
    return m_rules;
}