summaryrefslogtreecommitdiff
path: root/src/desktop/rule/windowRule/WindowRule.hpp
blob: 3701ae35f7f6d2311aef08a7d53b3e62f6fc8815 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once

#include "../RuleWithEffects.hpp"
#include "../../DesktopTypes.hpp"
#include "../../types/OverridableVar.hpp"
#include "WindowRuleEffectContainer.hpp"
#include "../../../config/shared/complex/ComplexDataTypes.hpp"
#include "../../../helpers/math/Expression.hpp"
#include "../../../helpers/math/Math.hpp"

#include <expected>
#include <unordered_set>
#include <variant>

namespace Desktop::Rule {
    constexpr const char* EXEC_RULE_ENV_NAME = "HL_EXEC_RULE_TOKEN";

    struct SFullscreenStateRule {
        int                internal = 0;
        std::optional<int> client;
    };

    struct SOpacityRule {
        Types::SAlphaValue alpha;
        Types::SAlphaValue alphaInactive;
        Types::SAlphaValue alphaFullscreen;
    };

    struct SBorderColorRule {
        Config::CGradientValueData                active;
        std::optional<Config::CGradientValueData> inactive;
    };

    using WindowRuleEffectValue =
        std::variant<std::monostate, bool, int64_t, float, std::string, std::vector<std::string>, SFullscreenStateRule, SOpacityRule, SBorderColorRule, Math::SExpressionVec2>;

    struct SWindowRuleEffect {
        using storageType = CWindowRuleEffectContainer::storageType;
        using valueType   = WindowRuleEffectValue;

        CWindowRuleEffectContainer::storageType key = WINDOW_RULE_EFFECT_NONE;
        std::string                             raw;
        WindowRuleEffectValue                   value;
    };

    class CWindowRule : public CRuleWithEffects<SWindowRuleEffect, RULE_TYPE_WINDOW> {
      private:
        using Base        = CRuleWithEffects<SWindowRuleEffect, RULE_TYPE_WINDOW>;
        using storageType = Base::storageType;

      public:
        CWindowRule(const std::string& name = "");
        virtual ~CWindowRule() = default;

        using Base::addEffect;

        CWindowRule(const CWindowRule&) = default;
        CWindowRule(CWindowRule&)       = default;
        CWindowRule(CWindowRule&&)      = default;

        static std::expected<SP<CWindowRule>, std::string> buildFromExecString(std::string&&);

        std::expected<void, std::string>                   addEffect(storageType e, const Math::SExpressionVec2& expr);

        bool                                               matches(PHLWINDOW w, bool allowEnvLookup = false);

      private:
        std::expected<WindowRuleEffectValue, std::string> parseEffect(storageType e, const std::string& result) override;
    };
};