summaryrefslogtreecommitdiff
path: root/gui-wm/wayfire/files/wayfire-0.11.0-physical-grid.patch
blob: e21a001b1acf23a37d4913b420d72c45c33cdc30 (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
--- a/metadata/move.xml
+++ b/metadata/move.xml
@@ -17,7 +17,7 @@
 		<!-- "Aero Snap" -->
 		<option name="enable_snap" type="bool">
 			<_short>Snap</_short>
-			<_long>Enables or disables snapping the window being moved to an edge of the screen.</_long>
+			<_long>Snap a dragged window at screen edges and corners. Physical-scope windows use the monitor under the pointer, including internal monitor seams; virtual-scope windows use the combined desktop. Left/right edges select halves, corners select quarters, the top edge maximizes, and the bottom edge selects the bottom half. The preview shows the placement on release.</_long>
 			<default>true</default>
 		</option>
 		<option name="snap_threshold" type="int">
--- a/plugins/grid/grid.cpp
+++ b/plugins/grid/grid.cpp
@@ -90,6 +90,7 @@
         std::shared_ptr<wf::preview_indication_t> preview;
         wf::grid::slot_t slot_id = wf::grid::SLOT_NONE;
         std::string zone;
+        wf::geometry_t geometry = {0, 0, 0, 0};
     } slot;
 
     wf::plugin_activation_data_t grab_interface{
@@ -231,6 +232,10 @@
         {
             if (can_adjust_view(ev->view) && get_view_wset(ev->view))
             {
+                if (wf::window_scope_policy(ev->view) == "physical")
+                {
+                    wf::select_window_scope_monitor(ev->view, zone->name);
+                }
                 place_in_zone(ev->view, *zone, get_view_wset(ev->view)->get_current_workspace());
             }
 
@@ -383,37 +388,82 @@
         [=] (wf::grid::grid_handle_move_signal *ev)
     {
         ev->carried_out = true;
+        if (ev->operation == wf::grid::MOVE_OP_CLEAR_PREVIEW || !ev->view ||
+            !can_adjust_view(ev->view) || ev->view->pending_fullscreen())
+        {
+            clear_zone_preview();
+            slot.zone.clear();
+            slot.slot_id = wf::grid::SLOT_NONE;
+            return;
+        }
+
         if (handle_zone_move(ev))
         {
             return;
         }
         auto drag_area = ev->output->workarea->get_workarea();
-        if (wf::window_scope_policy(ev->view) != "virtual")
+        auto policy = wf::window_scope_policy(ev->view);
+        std::optional<wf::output_stitch_zone_t> drag_zone;
+        if (policy != "virtual")
         {
             if (auto layout = ev->output->get_data<wf::output_stitch_layout_t>())
+            {
                 for (auto& zone : layout->zones)
-                    if (zone.geometry & wf::pointf_t{double(ev->input.x), double(ev->input.y)})
-                        drag_area = wf::physical_zone_workarea(ev->output, zone);
-        }
-        wf::grid::slot_t new_slot_id = ev->operation == wf::grid::MOVE_OP_CLEAR_PREVIEW ?
-            wf::grid::slot_t::SLOT_NONE :
+                {
+                    // Half-open bounds give each seam to exactly one monitor.
+                    auto& g = zone.geometry;
+                    if (ev->input.x >= g.x && ev->input.x < g.x + g.width &&
+                        ev->input.y >= g.y && ev->input.y < g.y + g.height &&
+                        (policy == "physical" || zone.name == policy))
+                    {
+                        drag_zone = zone;
+                        break;
+                    }
+                }
+
+                // Empty space in an uneven layout is not a VIRTUAL snap target.
+                if (!drag_zone)
+                {
+                    clear_zone_preview();
+                    slot.slot_id = wf::grid::SLOT_NONE;
+                    return;
+                }
+
+                drag_area = wf::physical_zone_workarea(ev->output, *drag_zone);
+            }
+        }
+        wf::grid::slot_t new_slot_id =
             wf::grid::calc_slot(drag_area, ev->input, snap_threshold, quarter_snap_threshold);
+        auto slot_geometry = wf::grid::get_slot_dimensions(drag_area, new_slot_id);
 
         if ((ev->operation == wf::grid::MOVE_OP_DROP) && new_slot_id)
         {
+            if (!get_view_wset(ev->view))
+            {
+                clear_zone_preview();
+                slot.slot_id = wf::grid::SLOT_NONE;
+                return;
+            }
+
+            // The pointer chooses the drop monitor, even when the grabbed
+            // window's center is still on the other side of a seam.
+            if (drag_zone && policy == "physical")
+            {
+                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);
-            auto desired_size = slot_dimensions(ev->view, new_slot_id);
             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(
-                adjust_for_workspace(get_view_wset(ev->view), desired_size,
+                adjust_for_workspace(get_view_wset(ev->view), slot_geometry,
                     get_view_wset(ev->view)->get_current_workspace()),
                 ev->view->toplevel()->pending().tiled_edges);
             new_slot_id = wf::grid::slot_t::SLOT_NONE;
         }
 
         /* No changes in the slot, just return */
-        if (slot.slot_id == new_slot_id)
+        if (slot.slot_id == new_slot_id && (!new_slot_id ||
+            (slot.preview && slot.preview->get_output() == ev->output && slot.geometry == slot_geometry)))
         {
             return;
         }
@@ -428,11 +478,11 @@
         }
 
         slot.slot_id = new_slot_id;
+        slot.geometry = slot_geometry;
 
         /* Show a preview overlay */
         if (new_slot_id)
         {
-            wf::geometry_t slot_geometry = wf::grid::get_slot_dimensions(drag_area, new_slot_id);
             /* Unknown slot geometry, can't show a preview */
             if ((slot_geometry.width <= 0) || (slot_geometry.height <= 0))
             {
--- a/plugins/grid/wayfire/plugins/grid.hpp
+++ b/plugins/grid/wayfire/plugins/grid.hpp
@@ -146,12 +146,12 @@
     bool is_left   = point.x - g.x <= threshold;
     bool is_right  = g.x + g.width - point.x <= threshold;
     bool is_top    = point.y - g.y < threshold;
-    bool is_bottom = g.x + g.height - point.y < threshold;
+    bool is_bottom = g.y + g.height - point.y < threshold;
 
     bool is_far_left   = point.x - g.x <= quarter_snap_threshold;
     bool is_far_right  = g.x + g.width - point.x <= quarter_snap_threshold;
     bool is_far_top    = point.y - g.y < quarter_snap_threshold;
-    bool is_far_bottom = g.x + g.height - point.y < quarter_snap_threshold;
+    bool is_far_bottom = g.y + g.height - point.y < quarter_snap_threshold;
 
     wf::grid::slot_t slot = wf::grid::SLOT_NONE;
     if ((is_left && is_far_top) || (is_far_left && is_top))
--- a/plugins/single_plugins/move.cpp
+++ b/plugins/single_plugins/move.cpp
@@ -28,6 +28,10 @@
 #include <wayfire/plugins/common/move-drag-interface.hpp>
 #include <wayfire/plugins/grid.hpp>
 
+namespace
+{
+// Keep implementation symbols local so a replacement plugin cannot bind to
+// an older Move implementation still cached by the running compositor.
 class wayfire_move : public wf::per_output_plugin_instance_t,
     public wf::pointer_interaction_t, public wf::touch_interaction_t
 {
@@ -481,6 +485,7 @@
         grid_signal.output    = output;
         grid_signal.input     = input;
         grid_signal.operation = operation;
+        grid_signal.view      = drag_helper->view;
         wf::get_core().emit(&grid_signal);
 
         if (grid_signal.carried_out)
@@ -591,5 +596,6 @@
         output->rem_binding(&activate_zone_binding);
     }
 };
+}
 
 DECLARE_WAYFIRE_PLUGIN(wf::per_output_plugin_t<wayfire_move>);