summaryrefslogtreecommitdiff
path: root/gui-wm/wayfire/files/wayfire-0.11.0-launch-origin-aliases.patch
blob: f41c75a8156192d998cb8c1b8d8b1d3a01f79489 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
--- a/plugins/animate/animate.cpp
+++ b/plugins/animate/animate.cpp
@@ -7,6 +7,7 @@
 #include <wayfire/core.hpp>
 #include <wayfire/util.hpp>
 #include "animate.hpp"
+#include "animate-alias.hpp"
 #include "plugins/common/wayfire/plugins/common/shared-core-data.hpp"
 #include "system_fade.hpp"
 #include "basic_animations.hpp"
@@ -29,7 +30,7 @@
   public:
     std::shared_ptr<wf::view_interface_t> view;
     wf::animate::animation_type type;
-    std::string name;
+    std::string name, effect_name;
     wf::output_t *current_output = nullptr;
     std::unique_ptr<wf::animate::animation_base_t> animation;
     std::shared_ptr<wf::unmapped_view_snapshot_node> unmapped_contents;
@@ -85,11 +86,12 @@
         std::unique_ptr<wf::animate::animation_base_t> _animation,
         wf::animation_description_t duration,
         wf::animate::animation_type type,
-        std::string name)
+        std::string name, std::string effect_name)
     {
         this->type = type;
         this->view = view->shared_from_this();
         this->name = name;
+        this->effect_name = std::move(effect_name);
 
         this->animation = std::move(_animation);
         this->animation->init(view, duration, type);
@@ -203,6 +205,10 @@
     wf::view_matcher_t fire_enabled_for{"animate/fire_enabled_for"};
 
     wf::shared_data::ref_ptr_t<wf::animate::animate_effects_registry_t> effects_registry;
+    wf::shared_data::ref_ptr_t<wf::animate::animate_hook_alias_registry_t> hook_aliases;
+    // Retain the identities actually used, including none and aliases removed
+    // while a hook is alive. Cleanup must not depend on current registrations.
+    std::set<std::string> used_hook_names;
 
     /**
      * Single-shot inhibit timer to uninhibit output rendering in case a
@@ -223,6 +229,7 @@
     void init() override
     {
         init_output_tracking();
+        wf::get_core().connect(&effect_cleanup);
 
         register_effect<fade_animation>("fade", default_duration);
         register_effect<zoom_animation>("zoom", default_duration);
@@ -263,6 +270,7 @@
 
     void fini() override
     {
+        effect_cleanup.disconnect();
         cleanup_views_on_output(nullptr);
 
         effects_registry->unregister_effect("fade");
@@ -289,18 +297,11 @@
                 continue;
             }
 
-            for (auto& anim : effects_registry->effects)
-            {
-                auto map_name = get_map_animation_cdata_name(anim.first);
-                if (view->has_data(map_name))
+            for (const auto& name : used_hook_names)
+            {
+                if (view->has_data(name))
                 {
-                    view->get_data<animation_hook>(map_name)->stop_hook(false);
-                }
-
-                auto minimize_name = get_minimize_animation_cdata_name(anim.first);
-                if (view->has_data(minimize_name))
-                {
-                    view->get_data<animation_hook>(minimize_name)->stop_hook(false);
+                    view->get_data<animation_hook>(name)->stop_hook(false);
                 }
             }
         }
@@ -390,6 +391,16 @@
 
     std::string get_map_animation_cdata_name(std::string animation_name)
     {
+        auto identity = hook_aliases->resolve(animation_name, *effects_registry.get());
+        if (identity)
+        {
+            animation_name = *identity;
+        } else
+        {
+            LOGE("Invalid MAP/UNMAP animation alias for ", animation_name,
+                "; retaining its own hook identity");
+        }
+
         return "animation-hook-" + animation_name;
     }
 
@@ -418,9 +429,21 @@
         }
 
         auto hook = std::make_unique<animation_hook>(view, effect.generator(),
-            duration, type, cdata_name);
+            duration, type, cdata_name, animation_name);
+        used_hook_names.insert(cdata_name);
         view->store_data(std::move(hook), cdata_name);
     }
+
+    wf::signal::connection_t<wf::animate::animate_effect_cleanup_signal> effect_cleanup =
+        [this] (auto *ev)
+    {
+        std::vector<std::shared_ptr<wf::view_interface_t>> views;
+        for (auto view : wf::get_core().get_all_views()) views.push_back(view->shared_from_this());
+        for (auto& view : views)
+            for (const auto& name : used_hook_names)
+                if (auto hook = view->get_data<animation_hook>(name); hook && hook->effect_name == ev->effect)
+                    hook->stop_hook(false);
+    };
 
     /* TODO: enhance - add more animations */
     wf::signal::connection_t<wf::view_mapped_signal> on_view_mapped = [=] (wf::view_mapped_signal *ev)
--- /dev/null
+++ b/plugins/animate/animate-alias.hpp
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: MIT
+#pragma once
+#include "animate.hpp"
+#include <set>
+
+namespace wf::animate
+{
+// Synchronously stop a provider's active hooks before removing its callbacks.
+// Emit on core during provider fini; existing effect registry layouts stay intact.
+struct animate_effect_cleanup_signal { std::string effect; };
+
+/**
+ * Optional MAP/UNMAP identities, held in separate shared core data so existing
+ * effect_description_t and animate_effects_registry_t layouts stay unchanged.
+ * Providers must remove their callbacks after stopping their active hooks and
+ * before unloading their code. Minimize/restore never consult this registry.
+ */
+class animate_hook_alias_registry_t
+{
+  public:
+    std::map<std::string, std::function<std::string()>> aliases;
+
+    std::optional<std::string> resolve(const std::string& effect,
+        const animate_effects_registry_t& registry) const
+    {
+        std::set<std::string> visited;
+        auto name = effect;
+        while (true)
+        {
+            if (!visited.insert(name).second ||
+                ((name != "none") && !registry.effects.count(name)))
+            {
+                return std::nullopt;
+            }
+
+            auto alias = aliases.find(name);
+            if (alias == aliases.end())
+            {
+                return name;
+            }
+
+            name = alias->second();
+        }
+    }
+};
+}
--- a/plugins/animate/meson.build
+++ b/plugins/animate/meson.build
@@ -16,4 +16,4 @@
                          install: true,
                          install_dir: join_paths(get_option('libdir'), 'wayfire'))
 
-install_headers(['animate.hpp'], subdir: 'wayfire/plugins/animate')
+install_headers(['animate.hpp', 'animate-alias.hpp'], subdir: 'wayfire/plugins/animate')