summaryrefslogtreecommitdiff
path: root/src/desktop/rule/windowRule/WindowRuleApplicator.hpp
blob: ad80a08184c79cc7d502e8f6159447ba2fdb3f1c (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#pragma once

#include <unordered_map>

#include "WindowRuleEffectContainer.hpp"
#include "../../DesktopTypes.hpp"
#include "../Rule.hpp"
#include "../../types/OverridableVar.hpp"
#include "../../../helpers/math/Math.hpp"
#include "../../../helpers/TagKeeper.hpp"
#include "../../../config/ConfigDataValues.hpp"

namespace Desktop::Rule {
    class CWindowRule;

    enum eIdleInhibitMode : uint8_t {
        IDLEINHIBIT_NONE = 0,
        IDLEINHIBIT_ALWAYS,
        IDLEINHIBIT_FULLSCREEN,
        IDLEINHIBIT_FOCUS
    };

    class CWindowRuleApplicator {
      public:
        CWindowRuleApplicator(PHLWINDOW w);
        ~CWindowRuleApplicator() = default;

        CWindowRuleApplicator(const CWindowRuleApplicator&) = delete;
        CWindowRuleApplicator(CWindowRuleApplicator&)       = delete;
        CWindowRuleApplicator(CWindowRuleApplicator&&)      = delete;

        void propertiesChanged(std::underlying_type_t<eRuleProperty> props);
        void resetProps(std::underlying_type_t<eRuleProperty> props, Types::eOverridePriority prio = Types::PRIORITY_WINDOW_RULE);
        void readStaticRules();
        void applyStaticRules();

        // static props
        struct {
            std::string              monitor, workspace, group;

            std::optional<bool>      floating;

            bool                     fullscreen     = false;
            bool                     maximize       = false;
            bool                     pseudo         = false;
            bool                     pin            = false;
            bool                     noInitialFocus = false;

            std::optional<int>       fullscreenStateClient;
            std::optional<int>       fullscreenStateInternal;
            std::optional<int>       center;
            std::optional<int>       content;
            std::optional<int>       noCloseFor;

            std::string              size, position;

            std::vector<std::string> suppressEvent;
        } static_;

        struct SCustomPropContainer {
            CWindowRuleEffectContainer::storageType idx      = WINDOW_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<CWindowRuleEffectContainer::storageType, UP<SCustomPropContainer>> props;
        } m_otherProps;

#define COMMA ,
#define DEFINE_PROP(type, name, def)                                                                                                                                               \
  private:                                                                                                                                                                         \
    std::pair<Types::COverridableVar<type>, std::underlying_type_t<eRuleProperty>> m_##name = {def, RULE_PROP_NONE};                                                               \
                                                                                                                                                                                   \
  public:                                                                                                                                                                          \
    Types::COverridableVar<type>& name() {                                                                                                                                         \
        return m_##name.first;                                                                                                                                                     \
    }                                                                                                                                                                              \
    void name##Override(const Types::COverridableVar<type>& other) {                                                                                                               \
        m_##name.first = other;                                                                                                                                                    \
    }

        // dynamic props
        DEFINE_PROP(Types::SAlphaValue, alpha, Types::SAlphaValue{})
        DEFINE_PROP(Types::SAlphaValue, alphaInactive, Types::SAlphaValue{})
        DEFINE_PROP(Types::SAlphaValue, alphaFullscreen, Types::SAlphaValue{})

        DEFINE_PROP(bool, allowsInput, false)
        DEFINE_PROP(bool, decorate, true)
        DEFINE_PROP(bool, focusOnActivate, false)
        DEFINE_PROP(bool, keepAspectRatio, false)
        DEFINE_PROP(bool, nearestNeighbor, false)
        DEFINE_PROP(bool, noAnim, false)
        DEFINE_PROP(bool, noBlur, false)
        DEFINE_PROP(bool, noDim, false)
        DEFINE_PROP(bool, noFocus, false)
        DEFINE_PROP(bool, noMaxSize, false)
        DEFINE_PROP(bool, noShadow, false)
        DEFINE_PROP(bool, noShortcutsInhibit, false)
        DEFINE_PROP(bool, opaque, false)
        DEFINE_PROP(bool, dimAround, false)
        DEFINE_PROP(bool, RGBX, false)
        DEFINE_PROP(bool, syncFullscreen, true)
        DEFINE_PROP(bool, tearing, false)
        DEFINE_PROP(bool, xray, false)
        DEFINE_PROP(bool, renderUnfocused, false)
        DEFINE_PROP(bool, noFollowMouse, false)
        DEFINE_PROP(bool, noScreenShare, false)
        DEFINE_PROP(bool, noVRR, false)
        DEFINE_PROP(bool, persistentSize, false)
        DEFINE_PROP(bool, stayFocused, false)

        DEFINE_PROP(int, idleInhibitMode, false)

        DEFINE_PROP(Hyprlang::INT, borderSize, {std::string("general:border_size") COMMA sc<Hyprlang::INT>(0) COMMA std::nullopt})
        DEFINE_PROP(Hyprlang::INT, rounding, {std::string("decoration:rounding") COMMA sc<Hyprlang::INT>(0) COMMA std::nullopt})

        DEFINE_PROP(Hyprlang::FLOAT, roundingPower, {std::string("decoration:rounding_power")})
        DEFINE_PROP(Hyprlang::FLOAT, scrollMouse, {std::string("input:scroll_factor")})
        DEFINE_PROP(Hyprlang::FLOAT, scrollTouchpad, {std::string("input:touchpad:scroll_factor")})

        DEFINE_PROP(std::string, animationStyle, std::string(""))

        DEFINE_PROP(Vector2D, maxSize, Vector2D{})
        DEFINE_PROP(Vector2D, minSize, Vector2D{})

        DEFINE_PROP(CGradientValueData, activeBorderColor, {})
        DEFINE_PROP(CGradientValueData, inactiveBorderColor, {})

        std::vector<std::pair<std::string, std::underlying_type_t<eRuleProperty>>> m_dynamicTags;
        CTagKeeper                                                                 m_tagKeeper;

#undef COMMA
#undef DEFINE_PROP

      private:
        PHLWINDOWREF m_window;

        struct SRuleResult {
            bool needsRelayout = false;
            bool tagsChanged   = false;
        };

        SRuleResult applyDynamicRule(const SP<CWindowRule>& rule);
        SRuleResult applyStaticRule(const SP<CWindowRule>& rule);
    };
};