summaryrefslogtreecommitdiff
path: root/gui-wm/wayfire/files/wayfire-0.11.0-grid-cycle.patch
blob: 2af1b74107ab2f9f0fbcdd17c04edf5f16445aa6 (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
--- a/plugins/grid/grid.cpp
+++ b/plugins/grid/grid.cpp
@@ -83,6 +83,14 @@
     std::string zone;
 };
 
+// Keep this separate from slot data: existing views can survive a plugin reload.
+class grid_size_cycle_data_t : public wf::custom_data_t
+{
+  public:
+    int slot = 0;
+    int step = 0;
+};
+
 nonstd::observer_ptr<wf::grid::grid_animation_t> ensure_grid_view(wayfire_toplevel_view view)
 {
     if (!view->has_data<wf::grid::grid_animation_t>())
@@ -118,7 +126,21 @@
     wf::option_wrapper_t<std::string> default_scope{"core/window_scope"}, scope_rules{"core/window_scope_rules"};
     wf::geometry_t slot_dimensions(wayfire_toplevel_view view, int n)
     {
-        return wf::grid::get_slot_dimensions(wf::window_scope_workarea(view), n);
+        auto normal = wf::grid::get_slot_dimensions(wf::window_scope_workarea(view), n);
+        auto cycle = view->get_data<grid_size_cycle_data_t>();
+        if (!cycle || cycle->slot != n || !cycle->step)
+        {
+            return normal;
+        }
+
+        const double scale = cycle->step == 1 ? 0.8 : 0.6;
+        auto scaled = normal;
+        scaled.width = std::max(1.0, std::round(normal.width * scale));
+        scaled.height = std::max(1.0, std::round(normal.height * scale));
+        // Corners stay anchored; side slots center along their outer edge.
+        scaled.x += (normal.width - scaled.width) * (n % 3 == 1 ? 0 : n % 3 == 0 ? 1 : 0.5);
+        scaled.y += (normal.height - scaled.height) * (n >= 7 ? 0 : n <= 3 ? 1 : 0.5);
+        return scaled;
     }
     wf::option_wrapper_t<bool> zone_shift{"grid/zone_shift"};
     wf::option_wrapper_t<int> zone_gap{"grid/zone_gap"};
@@ -218,6 +240,7 @@
     void place_in_zone(wayfire_toplevel_view view, const wf::output_stitch_zone_t& zone,
         wf::point_t workspace)
     {
+        view->erase_data<grid_size_cycle_data_t>();
         auto data = view->get_data_safe<wf_grid_slot_data>();
         data->slot = wf::grid::SLOT_CENTER;
         data->zone = zone.name;
@@ -402,7 +425,7 @@
 
                 if (auto toplevel = toplevel_cast(view))
                 {
-                    handle_slot(toplevel, i);
+                    cycle_slot(toplevel, i);
                     return true;
                 }
 
@@ -482,6 +505,7 @@
                 wf::select_window_scope_monitor(ev->view, drag_zone->name);
             }
             ev->view->toplevel()->pending().tiled_edges = wf::grid::get_tiled_edges_for_slot(new_slot_id);
+            ev->view->erase_data<grid_size_cycle_data_t>();
             ev->view->get_data_safe<wf_grid_slot_data>()->slot = new_slot_id;
             ev->view->get_data_safe<wf_grid_slot_data>()->zone.clear();
             ensure_grid_view(ev->view)->adjust_target_geometry(
@@ -550,6 +574,23 @@
         return is_floating && (view->get_output() != nullptr) && view->toplevel()->pending().mapped;
     }
 
+    void cycle_slot(wayfire_toplevel_view view, int slot)
+    {
+        if (!can_adjust_view(view))
+        {
+            return;
+        }
+
+        auto previous = view->get_data<wf_grid_slot_data>();
+        auto cycle = view->get_data_safe<grid_size_cycle_data_t>();
+        const bool repeat = view->pending_tiled_edges() == wf::grid::get_tiled_edges_for_slot(slot) &&
+            (!previous || (previous->slot == slot && previous->zone.empty()));
+        cycle->step = repeat ? ((cycle->slot == slot ? cycle->step : 0) + 1) % 3 : 0;
+        cycle->slot = slot;
+        handle_slot(view, slot);
+    }
+
+    // Reflows reuse the selected size; only the activator advances the cycle.
     void handle_slot(wayfire_toplevel_view view, int slot, wf::pointf_t delta = {0, 0})
     {
         if (!can_adjust_view(view))
@@ -699,6 +740,11 @@
         }
 
         uint32_t slot = wf::grid::get_slot_from_tiled_edges(data->edges);
+        if (auto cycle = data->view->get_data<grid_size_cycle_data_t>();
+            cycle && (!slot || cycle->slot != (int)slot))
+        {
+            data->view->erase_data<grid_size_cycle_data_t>();
+        }
         if (slot > 0)
         {
             data->desired_size = slot_dimensions(data->view, slot);
@@ -752,9 +798,12 @@
         }
 
         auto data = ev->view->get_data_safe<wf_grid_slot_data>();
-        if (ev->new_edges != wf::grid::get_tiled_edges_for_slot(data->slot))
+        // A superseded transaction must not erase the newer requested slot.
+        if (ev->new_edges == ev->view->pending_tiled_edges() &&
+            ev->new_edges != wf::grid::get_tiled_edges_for_slot(data->slot))
         {
             ev->view->erase_data<wf_grid_slot_data>();
+            ev->view->erase_data<grid_size_cycle_data_t>();
         }
     };
 };
--- a/plugins/grid/wayfire/plugins/crossfade.hpp
+++ b/plugins/grid/wayfire/plugins/crossfade.hpp
@@ -26,6 +26,9 @@
 {
 namespace grid
 {
+// Distinct types keep cached older plugin implementations out of a live upgrade.
+namespace transition
+{
 /**
  * A transformer used for a simple crossfade + scale animation.
  *
@@ -46,14 +49,13 @@
     crossfade_node_t(wayfire_toplevel_view view) : view_2d_transformer_t(view)
     {
         this->view = view;
-        capture_current_contents();
-    }
-
-    void capture_current_contents()
-    {
         displayed_geometry = view->get_geometry();
         overlay_alpha = 0.0;
-
+        capture_current_contents();
+    }
+
+    void capture_current_contents()
+    {
         auto root_node = view->get_surface_root_node();
         const wf::geometry_t bbox = root_node->get_bounding_box();
         const wf::geometry_t g    = view->get_geometry();
@@ -151,16 +153,10 @@
         scene::damage_callback push_damage)
     {
         this->self = std::dynamic_pointer_cast<crossfade_node_t>(self->shared_from_this());
-        scene::damage_callback push_damage_child = [=] (const wf::regionf_t&)
-        {
-            // XXX: we could attempt to calculate a meaningful damage, but
-            // we update on each frame anyway so ..
-            push_damage(self->get_bounding_box());
-        };
-
-        on_damage = [=] (auto)
-        {
-            push_damage(self->get_bounding_box());
+        on_damage = [=] (scene::node_damage_signal *ev)
+        {
+            // Damage can include pixels vacated by the preceding geometry.
+            push_damage(ev->region);
         };
         self->connect(&on_damage);
     }
@@ -367,18 +363,25 @@
 
     void start_crossfade(wf::geometry_t start_geometry, wf::geometry_t target_geometry)
     {
-        const auto current_displayed = animation.running() ? wf::geometry_t(animation) : start_geometry;
-        auto tr = view->get_transformed_node()->get_transformer<crossfade_node_t>();
+        auto transforms = view->get_transformed_node();
+        auto tr = transforms->get_transformer<crossfade_node_t>();
+        // Continue from the last displayed frame, even while waiting for a
+        // client to commit. Recapturing must not reset the displayed rectangle
+        // to the previous, possibly still distant, destination.
+        const auto current_displayed = tr ? tr->displayed_geometry : start_geometry;
+        transforms->begin_transform_update();
         if (!tr)
         {
-            view->get_transformed_node()->add_transformer(
-                std::make_shared<crossfade_node_t>(view),
-                wf::TRANSFORMER_2D);
+            tr = std::make_shared<crossfade_node_t>(view);
+            transforms->add_transformer(tr, wf::TRANSFORMER_2D);
         } else
         {
             tr->capture_current_contents();
         }
 
+        tr->displayed_geometry = current_displayed;
+        tr->overlay_alpha = 0.0;
+        transforms->end_transform_update();
         waiting_for_transaction = false;
         original = current_displayed;
         animation.set_start(current_displayed);
@@ -403,4 +406,7 @@
     type_t type;
 };
 }
+using transition::crossfade_node_t;
+using transition::grid_animation_t;
 }
+}
--- a/metadata/grid.xml
+++ b/metadata/grid.xml
@@ -2,7 +2,7 @@
 <wayfire>
 	<plugin name="grid">
 		<_short>Grid</_short>
-		<_long>A plugin to position the windows in certain regions of the output.</_long>
+		<_long>Position windows within their physical or VIRTUAL workarea. Repeating a position shortcut cycles through 100%, 80%, and 60% of that slot's normal width and height. Corners remain anchored; sides and center stay centered. A different position starts at 100%.</_long>
 		<category>Window Management</category>
 		<option name="toggle_scope" type="activator">
 			<_short>Toggle physical and VIRTUAL scope</_short>
@@ -54,47 +54,47 @@
 		<!-- Key-bindings -->
 		<option name="slot_bl" type="activator">
 			<_short>Bottom left</_short>
-			<_long>Positions the window in the bottom left corner of the screen with the specified activator.  The window takes 1/4 of the screen.</_long>
+			<_long>Positions the window in the bottom left corner of the screen with the specified activator.  The window takes 1/4 of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP1</default>
 		</option>
 		<option name="slot_b" type="activator">
 			<_short>Bottom</_short>
-			<_long>Positions the window in the bottom edge of the screen with the specified activator.  The window takes half of the screen.</_long>
+			<_long>Positions the window in the bottom edge of the screen with the specified activator.  The window takes half of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP2</default>
 		</option>
 		<option name="slot_br" type="activator">
 			<_short>Bottom right</_short>
-			<_long>Positions the window in the bottom right corner of the screen with the specified activator.  The window takes 1/4 of the screen.</_long>
+			<_long>Positions the window in the bottom right corner of the screen with the specified activator.  The window takes 1/4 of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP3</default>
 		</option>
 		<option name="slot_l" type="activator">
 			<_short>Left</_short>
-			<_long>Positions the window in the left edge of the screen with the specified activator.  The window takes half of the screen.</_long>
+			<_long>Positions the window in the left edge of the screen with the specified activator.  The window takes half of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_LEFT | &lt;super&gt; KEY_KP4</default>
 		</option>
 		<option name="slot_c" type="activator">
 			<_short>Center</_short>
-			<_long>Positions the window in the center of the screen with the specified activator.  The window is maximized.</_long>
+			<_long>Positions the window in the center of the screen with the specified activator.  The window is maximized. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_UP | &lt;super&gt; KEY_KP5</default>
 		</option>
 		<option name="slot_r" type="activator">
 			<_short>Right</_short>
-			<_long>Positions the window in the right edge of the screen with the specified activator.  The window takes half of the screen.</_long>
+			<_long>Positions the window in the right edge of the screen with the specified activator.  The window takes half of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_RIGHT | &lt;super&gt; KEY_KP6</default>
 		</option>
 		<option name="slot_tl" type="activator">
 			<_short>Top left</_short>
-			<_long>Positions the window in the top left corner of the screen with the specified activator.  The window takes 1/4 of the screen.</_long>
+			<_long>Positions the window in the top left corner of the screen with the specified activator.  The window takes 1/4 of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP7</default>
 		</option>
 		<option name="slot_t" type="activator">
 			<_short>Top</_short>
-			<_long>Positions the window in the top edge of the screen with the specified activator.  The window takes half of the screen.</_long>
+			<_long>Positions the window in the top edge of the screen with the specified activator.  The window takes half of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP8</default>
 		</option>
 		<option name="slot_tr" type="activator">
 			<_short>Top right</_short>
-			<_long>Positions the window in the top right corner of the screen with the specified activator.  The window takes 1/4 of the screen.</_long>
+			<_long>Positions the window in the top right corner of the screen with the specified activator.  The window takes 1/4 of the screen. Repeat to cycle its normal width and height through 100%, 80%, and 60%.</_long>
 			<default>&lt;super&gt; KEY_KP9</default>
 		</option>
 		<option name="restore" type="activator">