summaryrefslogtreecommitdiff
path: root/gui-libs/pixdecor/files/pixdecor-render-hook-tracking.patch
blob: 867bfe8105b58fcd9d46dd8fa084d83f12656c4b (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
--- a/src/decoration.cpp
+++ b/src/decoration.cpp
@@ -24,6 +24,7 @@
 #include <wayfire/plugins/ipc/ipc-method-repository.hpp>
 #include <wayfire/util.hpp>
 #include <chrono>
+#include <set>
 #include "shell-theme.hpp"
 
 namespace wf
@@ -92,7 +93,31 @@
     wf::wl_idle_call idle_update_views;
     std::function<void(void)> update_event;
     wf::effect_hook_t pre_hook;
-    bool hook_set = false;
+    /* Outputs that currently have pre_hook registered, tracked per-output so
+     * hotplug and option changes cannot desync a single global flag. */
+    std::set<wf::output_t*> hook_outputs;
+
+    bool effect_needs_hook()
+    {
+        return effect_animate || (std::string(effect_type) == "smoke") ||
+            (std::string(effect_type) == "ink");
+    }
+
+    void add_pre_hook(wf::output_t *o)
+    {
+        if (hook_outputs.insert(o).second)
+        {
+            o->render->add_effect(&pre_hook, wf::OUTPUT_EFFECT_PRE);
+        }
+    }
+
+    void remove_pre_hook(wf::output_t *o)
+    {
+        if (hook_outputs.erase(o))
+        {
+            o->render->rem_effect(&pre_hook);
+        }
+    }
 
     wf::axis_callback shade_axis_cb;
 
@@ -170,16 +195,16 @@
     wf::signal::connection_t<wf::output_added_signal> on_output_added =
         [=] (wf::output_added_signal *ev)
     {
-        if (effect_animate || (std::string(effect_type) == "smoke") || (std::string(effect_type) == "ink"))
+        if (effect_needs_hook())
         {
-            ev->output->render->add_effect(&pre_hook, wf::OUTPUT_EFFECT_PRE);
+            add_pre_hook(ev->output);
         }
     };
 
     wf::signal::connection_t<wf::output_removed_signal> on_output_removed =
         [=] (wf::output_removed_signal *ev)
     {
-        ev->output->render->rem_effect(&pre_hook);
+        remove_pre_hook(ev->output);
     };
 
     void pop_transformer(wayfire_view view)
@@ -473,14 +498,12 @@
             }
         };
 
-        if (std::string(effect_type) != "none")
+        if (effect_needs_hook())
         {
             for (auto& o : wf::get_core().output_layout->get_outputs())
             {
-                o->render->add_effect(&pre_hook, wf::OUTPUT_EFFECT_PRE);
+                add_pre_hook(o);
             }
-
-            hook_set = true;
         }
 
         titlebar.set_callback([=] {recreate_frames();});
@@ -630,13 +653,11 @@
             }
         }
 
-        if (hook_set)
+        for (auto& o : wf::get_core().output_layout->get_outputs())
         {
-            for (auto& o : wf::get_core().output_layout->get_outputs())
-            {
-                o->render->rem_effect(&pre_hook);
-            }
+            remove_pre_hook(o);
         }
+        hook_outputs.clear();
 
         on_output_added.disconnect();
         on_output_removed.disconnect();
@@ -676,27 +697,17 @@
 
     void option_changed_cb(bool resize_decorations, bool recreate_decorations)
     {
-        if (effect_animate || (std::string(effect_type) == "smoke") || (std::string(effect_type) == "ink"))
+        if (effect_needs_hook())
         {
-            if (!hook_set)
+            for (auto& o : wf::get_core().output_layout->get_outputs())
             {
-                for (auto& o : wf::get_core().output_layout->get_outputs())
-                {
-                    o->render->add_effect(&pre_hook, wf::OUTPUT_EFFECT_PRE);
-                }
-
-                hook_set = true;
+                add_pre_hook(o);
             }
         } else
         {
-            if (hook_set)
+            for (auto& o : wf::get_core().output_layout->get_outputs())
             {
-                for (auto& o : wf::get_core().output_layout->get_outputs())
-                {
-                    o->render->rem_effect(&pre_hook);
-                }
-
-                hook_set = false;
+                remove_pre_hook(o);
             }
         }