summaryrefslogtreecommitdiff
path: root/gui-libs/wayfire-plugins-extra/files/wayfire-plugins-extra-0.11.2-force-fullscreen-physical-scope.patch
blob: be86387fad037d5f81b9292f0e595c50071e5acd (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
--- a/src/force-fullscreen.cpp
+++ b/src/force-fullscreen.cpp
@@ -33,6 +33,7 @@
 #include <wayfire/view-transform.hpp>
 #include <wayfire/compositor-view.hpp>
 #include <wayfire/workspace-set.hpp>
+#include <wayfire/window-scope.hpp>
 #include <wayfire/signal-definitions.hpp>
 #include <wayfire/scene-operations.hpp>
 #include <wayfire/render-manager.hpp>
@@ -44,6 +45,9 @@
 namespace scene
 {
 namespace force_fullscreen
+{
+// Keep reloads independent of older libraries retained by the plugin loader.
+namespace
 {
 class simple_node_render_instance_t : public render_instance_t
 {
@@ -102,7 +106,9 @@
             bbox.y     += 1;
             bbox.width -= 2;
             bbox.height    -= 2;
-            scissor_region ^= wf::regionf_t{bbox};
+            // Subtract only the damaged intersection; XOR with the entire
+            // hole would introduce damage outside the scoped backdrop.
+            scissor_region ^= (scissor_region & bbox);
         }
 
         data.pass->clear(scissor_region, {0, 0, 0, 1});
@@ -149,7 +155,6 @@
 class fullscreen_background
 {
   public:
-    wf::geometry_t saved_geometry;
     wf::geometry_t undecorated_geometry;
     std::shared_ptr<wf::scene::view_2d_transformer_t> transformer;
     std::shared_ptr<black_border_node_t> black_border_node;
@@ -199,31 +204,25 @@
         output->connect(&viewport_changed);
     }
 
-    wf::signal::connection_t<wf::workspace_changed_signal> viewport_changed{[this] (wf::
-                                                                                    workspace_changed_signal*
-                                                                                    ev)
-        {
-            auto og  = output->get_relative_geometry();
-            auto nvp = ev->new_viewport;
-
-            for (auto& b : backgrounds)
-            {
-                int w   = (og.width - b.second->transformed_view_box.width) / 2.0f;
-                auto ws = output->wset()->get_view_main_workspace(b.first);
-                auto offset = ws - nvp;
-                int x = offset.x * og.width;
-                int y = offset.y * og.height;
-                b.second->transformed_view_box.x = x + w;
-                b.second->black_border_node->geometry.x     = x;
-                b.second->black_border_node->geometry.y     = y;
-                b.second->black_border_node->geometry.width = og.width;
-                b.second->black_border_node->geometry.height = og.height;
-                b.second->transformed_view_box.y = b.second->black_border_node->geometry.y =
-                    y;
-            }
-
-            output->render->damage_whole();
-        }
+    // Window geometry and these regions are output-local. Preserve the view's
+    // real position so monitor selection and restoration do not depend on an
+    // artificial move to the logical output's origin.
+    wf::geometry_t scope_geometry(wayfire_toplevel_view view)
+    {
+        auto box = wf::window_scope_fullscreen(view);
+        auto size = output->get_relative_geometry();
+        auto offset = output->wset()->get_view_main_workspace(view) -
+            output->wset()->get_current_workspace();
+        box.x += offset.x * size.width;
+        box.y += offset.y * size.height;
+        return box;
+    }
+
+    wf::signal::connection_t<wf::workspace_changed_signal> viewport_changed =
+        [this] (wf::workspace_changed_signal*)
+    {
+        update_backgrounds();
+        output->render->damage_whole();
     };
 
     void ensure_subsurface(wayfire_toplevel_view view, wf::geometry_t transformed_view_box)
@@ -245,9 +244,9 @@
                 return;
             }
 
-            auto og = output->get_relative_geometry();
+            auto og = scope_geometry(view);
             background->black_border_node = std::make_shared<black_border_node_t>(
-                view, 0, 0, og.width, og.height, transformed_view_box);
+                view, og.x, og.y, og.width, og.height, transformed_view_box);
             wf::scene::add_back(view->get_root_node(),
                 background->black_border_node);
             background->black_border = true;
@@ -274,13 +273,17 @@
 
     void setup_transform(wayfire_toplevel_view view)
     {
-        auto og = output->get_relative_geometry();
+        auto og = scope_geometry(view);
         auto vg = view->get_geometry();
+        if (vg.width <= 0 || vg.height <= 0 || og.width <= 0 || og.height <= 0)
+        {
+            return;
+        }
 
         double scale_x = (double)og.width / vg.width;
         double scale_y = (double)og.height / vg.height;
-        double translation_x = (og.width - vg.width) / 2.0;
-        double translation_y = (og.height - vg.height) / 2.0;
+        double translation_x = og.x + (og.width - vg.width) / 2.0 - vg.x;
+        double translation_y = og.y + (og.height - vg.height) / 2.0 - vg.y;
 
         if (preserve_aspect)
         {
@@ -288,21 +291,15 @@
         }
 
         wf::geometry_t box;
-        box.width  = std::floor(vg.width * scale_x);
-        box.height = std::floor(vg.height * scale_y);
-        box.x = std::ceil((og.width - box.width) / 2.0);
-        box.y = std::ceil((og.height - box.height) / 2.0);
+        box.width  = vg.width * scale_x;
+        box.height = vg.height * scale_y;
+        box.x = og.x + (og.width - box.width) / 2.0;
+        box.y = og.y + (og.height - box.height) / 2.0;
 
         destroy_subsurface(view);
         if (!transparent_behind_views || preserve_aspect)
         {
             ensure_subsurface(view, box);
-        }
-
-        if (preserve_aspect)
-        {
-            scale_x += 1.0 / vg.width;
-            translation_x -= 1.0;
         }
 
         backgrounds[view]->transformed_view_box = box;
@@ -318,7 +315,6 @@
     {
         for (auto& b : backgrounds)
         {
-            destroy_subsurface(b.first);
             setup_transform(b.first);
         }
     }
@@ -329,8 +325,6 @@
         {
             return false;
         }
-
-        wf::geometry_t saved_geometry = view->get_geometry();
 
         auto background = backgrounds.find(view);
         bool fullscreen = background == backgrounds.end() ? true : false;
@@ -359,7 +353,6 @@
         }
 
         background->second->undecorated_geometry = undecorated_geometry;
-        background->second->saved_geometry = saved_geometry;
 
         setup_transform(view);
 
@@ -380,7 +373,6 @@
 
     void activate(wayfire_toplevel_view view)
     {
-        view->move(0, 0);
         backgrounds[view] = std::make_unique<fullscreen_background>(view);
         backgrounds[view]->transformer =
             std::make_shared<wf::scene::view_2d_transformer_t>(view);
@@ -419,10 +411,6 @@
             view_focused.disconnect();
         }
 
-        view->move(
-            background->second->saved_geometry.x,
-            background->second->saved_geometry.y);
-
         if (view->get_transformed_node()->get_transformer(background_name))
         {
             view->get_transformed_node()->rem_transformer(
@@ -511,7 +499,9 @@
 
             if (std::string(constraint_area) == "output")
             {
-                box = og;
+                box = scope_geometry(b.first);
+                box.x += og.x;
+                box.y += og.y;
             }
 
             if ((b.first == view) &&
@@ -548,8 +538,8 @@
         }
     };
 
-    wf::signal::connection_t<wf::view_pre_moved_to_wset_signal> view_output_changed{[this] (wf::
-                                                                                            view_pre_moved_to_wset_signal
+    wf::signal::connection_t<wf::view_moved_to_wset_signal> view_output_changed{[this] (wf::
+                                                                                            view_moved_to_wset_signal
                                                                                             *ev)
         {
             auto view = ev->view;
@@ -560,15 +550,18 @@
                 return;
             }
 
-            if (!ev->new_wset->get_attached_output())
-            {
-                return;
-            }
-
-            toggle_fullscreen(view);
-
-            auto instance = wayfire_force_fullscreen_instances[ev->new_wset->get_attached_output()];
-            instance->toggle_fullscreen(view);
+            auto target = ev->new_wset ? ev->new_wset->get_attached_output() : nullptr;
+
+            // The move has completed, so scope resolution sees the new output.
+            view->toplevel()->pending().fullscreen = false;
+            wf::get_core().tx_manager->schedule_object(view->toplevel());
+            deactivate(view);
+
+            auto instance = wayfire_force_fullscreen_instances.find(target);
+            if (instance != wayfire_force_fullscreen_instances.end())
+            {
+                instance->second->toggle_fullscreen(view);
+            }
         }
     };
 
@@ -590,7 +583,11 @@
                 return;
             }
 
-            toggle_fullscreen(view);
+            // A disappearing client must be cleaned up even while actions
+            // are inhibited by a lock screen or another plugin.
+            view->toplevel()->pending().fullscreen = false;
+            wf::get_core().tx_manager->schedule_object(view->toplevel());
+            deactivate(view);
         }
     };
 
@@ -606,8 +603,17 @@
                 return;
             }
 
-            if (ev->state || ev->carried_out)
-            {
+            if (ev->carried_out)
+            {
+                return;
+            }
+
+            if (ev->state)
+            {
+                // Scope/configuration reflow must not turn this transformed
+                // window into native fullscreen and overwrite its real size.
+                setup_transform(view);
+                ev->carried_out = true;
                 return;
             }
 
@@ -661,6 +667,8 @@
     }
 };
 
+}
+
 DECLARE_WAYFIRE_PLUGIN(wf::per_output_plugin_t<wayfire_force_fullscreen>);
 }
 }