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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
|
--- a/metadata/move.xml
+++ b/metadata/move.xml
@@ -6,29 +6,13 @@
<category>Window Management</category>
<option name="activate_zone" type="button">
<_short>Move into a monitor zone</_short>
- <_long>Starts a move with Shift held on a combined output, allowing Grid to show monitor zones.</_long>
+ <_long>Starts a move with Shift held on a combined output, previewing monitor-sized destinations.</_long>
<default><super> <shift> BTN_LEFT</default>
</option>
<option name="activate" type="button">
<_short>Activate</_short>
<_long>When the specified button is held down, you can drag windows to move them.</_long>
<default><super> BTN_LEFT</default>
- </option>
- <!-- "Aero Snap" -->
- <option name="enable_snap" type="bool">
- <_short>Snap</_short>
- <_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">
- <_short>Snap threshold</_short>
- <_long>Sets the amount of pixels from the edge of the screen for which aero-snap gets triggered.</_long>
- <default>10</default>
- </option>
- <option name="quarter_snap_threshold" type="int">
- <_short>Quarter snap threshold</_short>
- <_long>Sets the amount of pixels from the corner of the screen for which quarter aero-snap gets triggered. The mouse should still be within snap_threshold of at least one edge of the screen.</_long>
- <default>50</default>
</option>
<option name="enable_snap_off" type="bool">
<_short>Snap off</_short>
@@ -45,25 +29,37 @@
<_long>Disallows independently moving dialogues.</_long>
<default>false</default>
</option>
- <option name="preview_base_color" type="color">
+ <option name="workspace_switch_after" type="int">
+ <_short>Switch workspace after</_short>
+ <_long>Switch workspace when the mouse stays on the output edge for the
+ given duration in milliseconds, wrapping to the opposite side after the last workspace (-1 to disable).</_long>
+ <default>-1</default>
+ <min>-1</min>
+ </option>
+ <group>
+ <_short>Snapping</_short>
+ <option name="enable_snap" type="bool"><_short>Snap</_short><_long>Preview the held window after a short dwell at an edge or corner. Release to snap, or pull away to keep moving. Top and bottom edges select halves.</_long><default>true</default></option>
+ <option name="snap_threshold" type="int"><_short>Edge distance (px)</_short><default>10</default><min>0</min><max>16384</max></option>
+ <option name="quarter_snap_threshold" type="int"><_short>Corner reach (px)</_short><default>50</default><min>0</min><max>16384</max></option>
+ <option name="snap_delay" type="int"><_short>Snap delay (ms)</_short><_long>Stay in the same snap region for this long before previewing the held window. This is separate from the workspace-switch delay. Zero activates immediately.</_long><default>500</default><min>0</min><max>5000</max></option>
+ </group>
+ <group>
+ <_short>Monitor zones</_short>
+ <option name="zone_shift" type="bool"><_short>Shift fills a physical monitor</_short><_long>Hold Shift during a drag to select the physical monitor's usable area instead of an edge or corner.</_long><default>true</default></option>
+ </group>
+ <!-- Legacy metadata allows older resident Move/Grid modules to unload safely. -->
+ <option hidden="true" name="preview_base_color" type="color">
<_short>Preview fill color</_short>
<default>0.5 0.5 1 0.5</default>
</option>
- <option name="preview_base_border" type="color">
+ <option hidden="true" name="preview_base_border" type="color">
<_short>Preview border color</_short>
<default>0.25 0.25 0.5 0.8</default>
</option>
- <option name="preview_border_width" type="int">
+ <option hidden="true" name="preview_border_width" type="int">
<_short>Preview border width</_short>
<default>3</default>
<min>0</min>
</option>
- <option name="workspace_switch_after" type="int">
- <_short>Switch workspace after</_short>
- <_long>Switch workspace when the mouse stays on the output edge for the
- given duration in milliseconds (-1 to disable).</_long>
- <default>-1</default>
- <min>-1</min>
- </option>
</plugin>
</wayfire>
--- a/metadata/grid.xml
+++ b/metadata/grid.xml
@@ -2,7 +2,7 @@
<wayfire>
<plugin name="grid">
<_short>Grid</_short>
- <_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>
+ <_long>Position windows on a physical monitor or the VIRTUAL desktop. Repeating a position shortcut cycles through 100%, 80%, and 60% of its normal size.</_long>
<category>Window Management</category>
<option name="toggle_scope" type="activator">
<_short>Toggle physical and VIRTUAL scope</_short>
@@ -20,7 +20,7 @@
</option>
<option name="zone_shift" type="bool">
<_short>Shift selects monitor zones</_short>
- <_long>On combined outputs, hold Shift while maximizing or dragging to fill a physical monitor zone. Dragging shows a preview.</_long>
+ <_long>On combined outputs, hold Shift while maximizing to fill a physical monitor zone. Drag snapping is configured in Move.</_long>
<default>true</default>
</option>
<option name="zone_gap" type="int">
--- a/plugins/grid/grid.cpp
+++ b/plugins/grid/grid.cpp
@@ -15,7 +15,6 @@
#include "wayfire/plugin.hpp"
#include "wayfire/signal-definitions.hpp"
#include <wayfire/plugins/common/geometry-animation.hpp>
-#include <wayfire/plugins/common/preview-indication.hpp>
#include "wayfire/plugins/grid.hpp"
#include "wayfire/plugins/crossfade.hpp"
#include <wayfire/window-manager.hpp>
@@ -31,43 +30,6 @@
namespace
{
const std::string grid_view_id = "grid-view";
-
-class grid_preview_node_t : public wf::scene::translation_node_t
-{
- public:
- std::optional<wf::scene::input_node_t> find_node_at(const wf::pointf_t&) override
- {
- return {};
- }
-};
-
-class grid_preview_t : public wf::preview_indication_t
-{
- std::shared_ptr<grid_preview_node_t> overlay;
-
- public:
- grid_preview_t(wf::geometry_t target, wf::output_t *output) :
- wf::preview_indication_t(target, output, "move")
- {
- // The move helper renders the held window above all ordinary layers.
- // Keep its drop target visible above that window, without taking input.
- overlay = std::make_shared<grid_preview_node_t>();
- overlay->set_offset(wf::origin(output->get_layout_geometry()));
- wf::scene::readd_front(overlay, view->get_root_node());
- wf::scene::add_front(wf::get_core().scene(), overlay);
- view->set_geometry(target);
- // Fade in at the actual destination; growing from the pointer makes
- // short visits to an edge look like incomplete or moving targets.
- set_target_geometry(target, 1);
- }
-
- ~grid_preview_t() override
- {
- view->damage();
- view->close();
- wf::scene::remove_child(overlay);
- }
-};
class grid_scope_toggle_data_t : public wf::custom_data_t
{
@@ -144,16 +106,6 @@
}
wf::option_wrapper_t<bool> zone_shift{"grid/zone_shift"};
wf::option_wrapper_t<int> zone_gap{"grid/zone_gap"};
- wf::option_wrapper_t<int> snap_threshold{"move/snap_threshold"};
- wf::option_wrapper_t<int> quarter_snap_threshold{"move/quarter_snap_threshold"};
- struct
- {
- std::shared_ptr<grid_preview_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{
.name = "grid",
.capabilities = wf::CAPABILITY_MANAGE_DESKTOP,
@@ -246,69 +198,6 @@
data->zone = zone.name;
ensure_grid_view(view)->adjust_target_geometry(
adjust_for_workspace(get_view_wset(view), zone.geometry, workspace), wf::TILED_EDGES_ALL);
- }
-
- void clear_zone_preview()
- {
- slot.preview.reset();
- }
-
- bool handle_zone_move(wf::grid::grid_handle_move_signal *ev)
- {
- auto layout = ev->output->get_data<wf::output_stitch_layout_t>();
- std::optional<wf::output_stitch_zone_t> zone;
- if (layout && shift_zones_active() && (ev->operation != wf::grid::MOVE_OP_CLEAR_PREVIEW))
- {
- for (auto& candidate : layout->zones)
- {
- auto& g = candidate.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)
- {
- zone = find_zone(ev->output, candidate.name);
- break;
- }
- }
- }
-
- if (!zone)
- {
- if (!slot.zone.empty())
- {
- clear_zone_preview();
- slot.zone.clear();
- slot.slot_id = wf::grid::SLOT_NONE;
- }
-
- return false;
- }
-
- if (ev->operation == wf::grid::MOVE_OP_DROP)
- {
- 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());
- }
-
- clear_zone_preview();
- slot.zone.clear();
- slot.slot_id = wf::grid::SLOT_NONE;
- return true;
- }
-
- if (slot.zone != zone->name)
- {
- clear_zone_preview();
- slot.slot_id = wf::grid::SLOT_NONE;
- slot.zone = zone->name;
- slot.preview = std::make_shared<grid_preview_t>(zone->geometry, ev->output);
- }
-
- return true;
}
public:
@@ -433,113 +322,25 @@
});
}
- wf::get_core().connect(&grid_handle_move_signal_cb);
+ wf::get_core().connect(&on_snap_placement);
wf::get_core().output_layout->connect(&on_layout_changed);
}
- wf::signal::connection_t<wf::grid::grid_handle_move_signal> grid_handle_move_signal_cb =
- [=] (wf::grid::grid_handle_move_signal *ev)
- {
+ wf::signal::connection_t<wf::grid::snap_placement_signal> on_snap_placement =
+ [this] (wf::grid::snap_placement_signal *ev)
+ {
+ if (ev->carried_out || !can_adjust_view(ev->view) || !get_view_wset(ev->view)) return;
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();
- 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)
- {
- // 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);
- 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(
- 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 && (!new_slot_id ||
- (slot.preview && slot.preview->get_output() == ev->output && slot.geometry == slot_geometry)))
- {
- return;
- }
-
- // Remove the old target immediately, including its scene node. A
- // shrinking ghost should not trail the pointer or outlive the drag.
- clear_zone_preview();
-
- slot.slot_id = new_slot_id;
- slot.geometry = slot_geometry;
-
- /* Show a preview overlay */
- if (new_slot_id)
- {
- /* Unknown slot geometry, can't show a preview */
- if ((slot_geometry.width <= 0) || (slot_geometry.height <= 0))
- {
- return;
- }
-
- slot.preview = std::make_shared<grid_preview_t>(slot_geometry, ev->output);
- }
+ ev->view->erase_data<grid_size_cycle_data_t>();
+ auto data = ev->view->get_data_safe<wf_grid_slot_data>();
+ data->slot = ev->slot;
+ data->zone = ev->monitor_zone;
+ // Snap Zones already animates the held window with Wobbly. Commit
+ // once, without starting Grid's separate keyboard-placement effect.
+ ev->view->erase_data<wf::grid::grid_animation_t>();
+ wf::get_core().default_wm->update_last_windowed_geometry(ev->view);
+ ev->view->toplevel()->pending().tiled_edges = wf::grid::get_tiled_edges_for_slot(ev->slot);
+ ev->view->set_geometry(ev->geometry);
};
void handle_new_output(wf::output_t *output) override
@@ -550,20 +351,10 @@
output->connect(&on_tiled);
}
- void handle_output_removed(wf::output_t *output) override
- {
- // A group can disappear during an active drag.
- if (slot.preview && slot.preview->get_output() == output)
- {
- clear_zone_preview();
- slot.zone.clear();
- slot.slot_id = wf::grid::SLOT_NONE;
- }
- }
+ void handle_output_removed(wf::output_t*) override {}
void fini() override
{
- clear_zone_preview();
fini_output_tracking();
}
@@ -649,13 +440,7 @@
}
}
- if (slot.preview && !slot.zone.empty())
- {
- if (auto zone = find_zone(slot.preview->get_output(), slot.zone))
- {
- slot.preview->set_target_geometry(zone->geometry, 1);
- }
- }
+
}
wf::signal::connection_t<wf::output_layout_configuration_changed_signal> on_layout_changed =
--- a/plugins/grid/wayfire/plugins/grid.hpp
+++ b/plugins/grid/wayfire/plugins/grid.hpp
@@ -13,6 +13,9 @@
MOVE_OP_CLEAR_PREVIEW = 0,
MOVE_OP_UPDATE_PREVIEW = 1,
MOVE_OP_DROP = 2,
+ // Remove temporary drag transforms before the shared helper ungrabs.
+ // Keep the armed destination until MOVE_OP_DROP commits the placement.
+ MOVE_OP_FINISH_PREVIEW = 3,
};
/**
@@ -30,6 +33,19 @@
/* input coordinates in output-local space */
wf::point_t input;
wayfire_toplevel_view view;
+};
+
+/** Optional Grid integration for an independently selected snap destination.
+ * Emitted on core by Move. Without Grid the caller applies the geometry.
+ * Grid records the selected slot for its normal keyboard and scope reflows.
+ */
+struct snap_placement_signal
+{
+ wayfire_toplevel_view view;
+ wf::geometry_t geometry;
+ int slot;
+ std::string monitor_zone;
+ bool carried_out = false;
};
/**
--- a/plugins/single_plugins/move.cpp
+++ b/plugins/single_plugins/move.cpp
@@ -22,11 +22,11 @@
#include <linux/input.h>
#include <wayfire/signal-definitions.hpp>
-#include <wayfire/plugins/common/preview-indication.hpp>
#include <wayfire/plugins/common/shared-core-data.hpp>
#include <wayfire/plugins/common/move-drag-interface.hpp>
#include <wayfire/plugins/grid.hpp>
+#include "move-snap.hpp"
namespace
{
@@ -47,7 +47,6 @@
}
};
- wf::option_wrapper_t<bool> enable_snap{"move/enable_snap"};
wf::option_wrapper_t<bool> join_views{"move/join_views"};
wf::option_wrapper_t<int> snap_threshold{"move/snap_threshold"};
wf::option_wrapper_t<int> quarter_snap_threshold{"move/quarter_snap_threshold"};
@@ -56,12 +55,6 @@
wf::option_wrapper_t<bool> move_enable_snap_off{"move/enable_snap_off"};
wf::option_wrapper_t<int> move_snap_off_threshold{"move/snap_off_threshold"};
-
- struct
- {
- std::shared_ptr<wf::preview_indication_t> preview;
- wf::grid::slot_t slot_id = wf::grid::SLOT_NONE;
- } slot;
wf::wl_timer<false> workspace_switch_timer;
wf::grid::slot_t workspace_switch_slot_id = wf::grid::SLOT_NONE;
@@ -122,25 +115,13 @@
wf::move_drag::adjust_view_on_output(ev);
wf::update_window_scope_after_move(ev->main_view);
- if (enable_snap)
- {
- auto input = get_input_coords();
- wf::grid::grid_handle_move_signal grid_signal;
- grid_signal.output = output;
- grid_signal.input = input;
- grid_signal.operation = wf::grid::MOVE_OP_DROP;
- grid_signal.view = ev->main_view;
- wf::get_core().emit(&grid_signal);
-
- if (!grid_signal.carried_out && (slot.slot_id != wf::grid::SLOT_NONE))
- {
- wf::get_core().default_wm->tile_request(ev->main_view,
- wf::grid::get_tiled_edges_for_slot(slot.slot_id));
-
- /* Update slot, will hide the preview as well */
- update_slot(wf::grid::MOVE_OP_CLEAR_PREVIEW);
- }
- }
+ // Move owns delayed snapping and the provisional held-window preview.
+ wf::grid::grid_handle_move_signal snap_signal;
+ snap_signal.output = output;
+ snap_signal.input = get_input_coords();
+ snap_signal.operation = wf::grid::MOVE_OP_DROP;
+ snap_signal.view = ev->main_view;
+ wf::get_core().emit(&snap_signal);
wf::get_core().default_wm->set_view_grabbed(ev->main_view, false);
@@ -242,6 +223,7 @@
return;
}
+ update_slot(wf::grid::MOVE_OP_FINISH_PREVIEW);
drag_helper->handle_input_released();
return;
}
@@ -404,6 +386,7 @@
return;
}
+ update_slot(wf::grid::MOVE_OP_FINISH_PREVIEW);
drag_helper->handle_input_released();
}
@@ -452,24 +435,17 @@
return;
}
- wf::point_t cws = output->wset()->get_current_workspace();
- wf::point_t tws = {cws.x + dx, cws.y + dy};
- wf::dimensions_t ws_dim = output->wset()->get_workspace_grid_size();
- wf::geometry_t possible = {
- 0.0, 0.0, (double)ws_dim.width, (double)ws_dim.height
- };
-
- /* Outside of workspace grid */
- if (!(possible & tws))
- {
- workspace_switch_timer.disconnect();
-
- return;
- }
-
- workspace_switch_timer.set_timeout(workspace_switch_after, [this, tws] ()
- {
- output->wset()->request_workspace(tws);
+ workspace_switch_timer.set_timeout(workspace_switch_after, [this, dx, dy] ()
+ {
+ auto current = output->wset()->get_current_workspace();
+ auto size = output->wset()->get_workspace_grid_size();
+ if (size.width < 1 || size.height < 1) return;
+ // Continue at the opposite edge, including the last-to-first and
+ // first-to-last transitions of a horizontal workspace row.
+ wf::point_t target{
+ (current.x + dx + size.width) % size.width,
+ (current.y + dy + size.height) % size.height};
+ if (target != current) output->wset()->request_workspace(target);
});
}
@@ -488,45 +464,6 @@
grid_signal.view = drag_helper->view;
wf::get_core().emit(&grid_signal);
- if (grid_signal.carried_out)
- {
- update_workspace_switch_timeout(input, !operation);
- return;
- }
-
- /* if the grid plugin isn't loaded, we're handling the preview for maximize */
- wf::grid::slot_t old_slot_id = slot.slot_id;
- slot.slot_id = !operation ? wf::grid::SLOT_NONE :
- wf::grid::calc_slot(output, input, snap_threshold, quarter_snap_threshold);
- if (slot.slot_id != wf::grid::SLOT_CENTER)
- {
- slot.slot_id = wf::grid::SLOT_NONE;
- }
-
- if (old_slot_id == slot.slot_id)
- {
- return;
- }
-
- if (slot.preview)
- {
- slot.preview->set_target_geometry(wf::pointf_t{(double)input.x, (double)input.y}, 0,
- true);
- slot.preview = nullptr;
- }
-
- if (slot.slot_id)
- {
- wf::geometry_t slot_geometry = output->workarea->get_workarea();
- /* only show a preview with valid geometry */
- if ((slot_geometry.width > 0) || (slot_geometry.height > 0))
- {
- slot.preview = std::make_shared<wf::preview_indication_t>(
- wf::pointf_t{(double)input.x, (double)input.y}, output, "move");
- slot.preview->set_target_geometry(slot_geometry, 1);
- }
- }
-
update_workspace_switch_timeout(input, !operation);
}
@@ -556,7 +493,7 @@
bool is_snap_enabled()
{
- if (!enable_snap || !drag_helper->view || drag_helper->is_view_held_in_place())
+ if (!drag_helper->view || drag_helper->is_view_held_in_place())
{
return false;
}
@@ -596,6 +533,22 @@
output->rem_binding(&activate_zone_binding);
}
};
+
+class wayfire_move_plugin : public wf::per_output_plugin_t<wayfire_move>
+{
+ move_snap_t snapping;
+ public:
+ void init() override
+ {
+ snapping.init();
+ wf::per_output_plugin_t<wayfire_move>::init();
+ }
+ void fini() override
+ {
+ snapping.fini();
+ wf::per_output_plugin_t<wayfire_move>::fini();
+ }
+};
}
-DECLARE_WAYFIRE_PLUGIN(wf::per_output_plugin_t<wayfire_move>);
+DECLARE_WAYFIRE_PLUGIN(wayfire_move_plugin);
--- /dev/null
+++ b/plugins/single_plugins/move-snap.hpp
@@ -0,0 +1,293 @@
+#pragma once
+#include <wayfire/core.hpp>
+#include <wayfire/plugin.hpp>
+#include <wayfire/per-output-plugin.hpp>
+#include <wayfire/seat.hpp>
+#include <wayfire/view-helpers.hpp>
+#include <wayfire/view-transform.hpp>
+#include <wayfire/window-manager.hpp>
+#include <wayfire/workspace-set.hpp>
+#include <wayfire/toplevel.hpp>
+#include <wayfire/plugins/common/move-drag-interface.hpp>
+#include <wayfire/plugins/wobbly/wobbly-signal.hpp>
+#include <chrono>
+#include "move-snap-map.hpp"
+
+namespace
+{
+using Clock = std::chrono::steady_clock;
+constexpr const char *preview_name = "move-held-preview";
+
+// This changes only the rendered drag texture. The client keeps its original
+// geometry until release. Wobbly, above this node, supplies the existing spring
+// animation; there is no separate animation clock or destination overlay.
+class held_preview_t : public wf::scene::transformer_base_node_t
+{
+ class instance_t : public wf::scene::transformer_render_instance_t<held_preview_t>
+ {
+ public:
+ using transformer_render_instance_t::transformer_render_instance_t;
+ void transform_damage_region(wf::regionf_t& region) override
+ {
+ region |= self->target;
+ }
+ void render(const wf::scene::render_instruction_t& data) override
+ {
+ data.pass->add_texture(get_texture(data.target.scale), data.target,
+ self->target, data.damage);
+ }
+ };
+ public:
+ wf::geometry_t target;
+ explicit held_preview_t(wf::geometry_t target) : transformer_base_node_t(false), target(target) {}
+ wf::geometry_t get_bounding_box() override { return target; }
+ std::optional<wf::scene::input_node_t> find_node_at(const wf::pointf_t&) override { return {}; }
+ std::string stringify() const override { return preview_name; }
+ void gen_render_instances(std::vector<wf::scene::render_instance_uptr>& instances,
+ wf::scene::damage_callback damage, wf::output_t *output) override
+ {
+ instances.push_back(std::make_unique<instance_t>(this, damage, output));
+ }
+};
+
+class move_snap_t : public wf::per_output_tracker_mixin_t<>
+{
+ wf::shared_data::ref_ptr_t<wf::ipc::method_repository_t> repository;
+ wf::shared_data::ref_ptr_t<wf::move_drag::core_drag_t> drag;
+ move_snap_map_t map;
+ wf::option_wrapper_t<int> edge{"move/snap_threshold"}, corner{"move/quarter_snap_threshold"},
+ delay{"move/snap_delay"};
+ wf::option_wrapper_t<bool> enabled{"move/enable_snap"}, shift_zones{"move/zone_shift"};
+ wf::wl_timer<false> dwell, handoff_timeout;
+ struct destination_t
+ {
+ std::weak_ptr<wf::toplevel_view_interface_t> view;
+ wf::output_t *output = nullptr;
+ wf::geometry_t geometry{};
+ int slot = 0;
+ std::string monitor;
+ bool whole_monitor = false;
+ } destination;
+ Clock::time_point deadline;
+ bool ready = false, handing_off = false;
+ bool wobbly_grab_suspended = false;
+ wf::pointf_t grab_position{};
+ std::weak_ptr<wf::toplevel_view_interface_t> preview_view;
+ std::shared_ptr<held_preview_t> preview;
+
+ bool eligible(wayfire_toplevel_view view)
+ {
+ const auto actions = wf::VIEW_ALLOW_MOVE | wf::VIEW_ALLOW_RESIZE;
+ return view && view->is_mapped() && view->get_output() && !view->pending_fullscreen() &&
+ view->role != wf::VIEW_ROLE_DESKTOP_ENVIRONMENT &&
+ (view->get_allowed_actions() & actions) == actions;
+ }
+
+ destination_t select(wf::grid::grid_handle_move_signal *ev)
+ {
+ destination_t result;
+ if (!enabled || !eligible(ev->view) || !ev->output || !(ev->output->get_relative_geometry() & ev->input)) return result;
+ auto area = ev->output->workarea->get_workarea();
+ auto policy = wf::window_scope_policy(ev->view);
+ const bool whole = shift_zones && (wf::get_core().seat->get_keyboard_modifiers() & WLR_MODIFIER_SHIFT);
+ if (auto layout = ev->output->get_data<wf::output_stitch_layout_t>();
+ layout && !layout->zones.empty() && (policy != "virtual" || whole))
+ {
+ bool found = false;
+ for (const auto& zone : layout->zones)
+ {
+ const 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 &&
+ (whole || policy == "physical" || zone.name == policy))
+ {
+ result.monitor = zone.name;
+ area = wf::physical_zone_workarea(ev->output, zone);
+ found = true;
+ break;
+ }
+ }
+ if (!found) return result;
+ }
+ result.whole_monitor = whole && !result.monitor.empty();
+ result.slot = result.whole_monitor ? wf::grid::SLOT_CENTER : snap_slot(area, ev->input, edge, corner);
+ if (!result.slot) return {};
+ result.geometry = wf::grid::get_slot_dimensions(area, result.slot);
+ if (result.geometry.width <= 0 || result.geometry.height <= 0) return {};
+ result.view = ev->view->weak_from_this();
+ result.output = ev->output;
+ return result;
+ }
+
+ bool same(const destination_t& a, const destination_t& b)
+ {
+ return a.slot && a.slot == b.slot && a.view.lock() == b.view.lock() && a.output == b.output &&
+ a.geometry == b.geometry && a.monitor == b.monitor && a.whole_monitor == b.whole_monitor;
+ }
+
+ void remove_preview(bool restore_grab = true)
+ {
+ if (auto view = preview_view.lock())
+ {
+ view->get_transformed_node()->rem_transformer(preview_name);
+ if (restore_grab)
+ {
+ // Resume the visual grab before unpinning the corners. The
+ // actual Move grab has stayed active throughout the preview.
+ if (wobbly_grab_suspended && view->is_mapped() && drag->view.get() == view.get())
+ start_wobbly(view, grab_position.x, grab_position.y);
+ set_tiled_wobbly(view, false);
+ }
+ }
+ wobbly_grab_suspended = false;
+ preview.reset(); preview_view.reset();
+ handing_off = false; handoff_timeout.disconnect();
+ }
+
+ void clear()
+ {
+ dwell.disconnect(); remove_preview(); destination = {}; ready = false;
+ }
+
+ void show_preview(wayfire_toplevel_view view, wf::geometry_t geometry)
+ {
+ remove_preview();
+ // Move starts Wobbly first. Equal priority inserts this node directly
+ // below that existing transformer and above Move's drag transformer.
+ activate_wobbly(view);
+ preview = std::make_shared<held_preview_t>(geometry);
+ preview_view = view->weak_from_this();
+ view->get_transformed_node()->add_transformer(preview, wf::TRANSFORMER_HIGHLEVEL, preview_name);
+ set_tiled_wobbly(view, true);
+ if (drag->view.get() == view.get())
+ {
+ // Let the existing springs finish at the destination while the
+ // mouse remains held. Keeping Wobbly grabbed would bow the surface
+ // toward the pointer indefinitely instead of completing the resize.
+ end_wobbly(view);
+ wobbly_grab_suspended = true;
+ }
+ }
+
+ void arm()
+ {
+ auto view = destination.view.lock();
+ if (!enabled || !eligible(view) || drag->view.get() != view.get() || drag->is_view_held_in_place()) { clear(); return; }
+ ready = true;
+ show_preview(view, destination.geometry + wf::origin(destination.output->get_layout_geometry()));
+ }
+
+ void place(wayfire_toplevel_view view)
+ {
+ if (wf::window_scope_policy(view) == "physical" && !destination.monitor.empty())
+ wf::select_window_scope_monitor(view, destination.monitor);
+ // Hand the same rendered destination to the real surface while its
+ // resize transaction waits for the client. No flash of the old size.
+ show_preview(view, destination.geometry);
+ handing_off = true;
+ modify_wobbly(view, destination.geometry);
+ wf::grid::snap_placement_signal placement{
+ view, destination.geometry, destination.slot,
+ destination.whole_monitor ? destination.monitor : std::string{}, false};
+ wf::get_core().emit(&placement);
+ if (!placement.carried_out)
+ {
+ wf::get_core().default_wm->update_last_windowed_geometry(view);
+ view->toplevel()->pending().tiled_edges = wf::grid::get_tiled_edges_for_slot(destination.slot);
+ view->set_geometry(destination.geometry);
+ }
+ // A nonresponsive client must not leave a permanent visual transform.
+ handoff_timeout.set_timeout(1200, [this] { remove_preview(); });
+ }
+
+ wf::signal::connection_t<wf::grid::grid_handle_move_signal> on_move = [this] (auto *ev)
+ {
+ ev->carried_out = true;
+ if (ev->output)
+ {
+ auto origin = wf::origin(ev->output->get_layout_geometry());
+ grab_position = {double(ev->input.x + origin.x), double(ev->input.y + origin.y)};
+ }
+ if (ev->operation == wf::grid::MOVE_OP_CLEAR_PREVIEW) { clear(); return; }
+ auto next = select(ev);
+ if (ev->operation == wf::grid::MOVE_OP_FINISH_PREVIEW)
+ {
+ ready = same(destination, next) && Clock::now() >= deadline;
+ dwell.disconnect(); remove_preview(!ready);
+ return;
+ }
+ if (ev->operation == wf::grid::MOVE_OP_DROP)
+ {
+ const bool commit = ready && same(destination, next);
+ dwell.disconnect();
+ if (commit) place(ev->view); else remove_preview();
+ destination = {}; ready = false;
+ return;
+ }
+ if (!next.slot) { clear(); return; }
+ if (same(destination, next)) return;
+ clear(); destination = next;
+ const int ms = std::clamp(delay.value(), 0, 5000);
+ deadline = Clock::now() + std::chrono::milliseconds(ms);
+ if (!ms) arm(); else dwell.set_timeout(ms, [this] { arm(); });
+ };
+
+ // Without Grid, ordinary tiling reflows still preserve half/quarter sizes.
+ wf::signal::connection_t<wf::view_tile_request_signal> on_tile = [this] (auto *ev)
+ {
+ if (ev->carried_out || !eligible(ev->view) || !ev->edges) return;
+ int slot = wf::grid::get_slot_from_tiled_edges(ev->edges);
+ if (!slot) return;
+ auto area = wf::window_scope_workarea(ev->view);
+ auto g = wf::grid::get_slot_dimensions(area, slot);
+ auto output = ev->view->get_output();
+ auto delta = ev->workspace - output->wset()->get_current_workspace();
+ g.x += delta.x * output->get_screen_size().width;
+ g.y += delta.y * output->get_screen_size().height;
+ ev->carried_out = true;
+ ev->view->set_geometry(g);
+ };
+ wf::signal::connection_t<wf::view_geometry_changed_signal> on_geometry = [this] (auto *ev)
+ {
+ if (handing_off && preview_view.lock().get() == ev->view.get()) remove_preview();
+ };
+ wf::signal::connection_t<wf::view_pre_unmap_signal> on_unmap = [this] (auto *ev)
+ {
+ if (destination.view.lock().get() == ev->view.get() || preview_view.lock().get() == ev->view.get()) clear();
+ };
+ wf::signal::connection_t<wf::output_layout_configuration_changed_signal> on_layout = [this] (auto) { clear(); };
+ wf::signal::connection_t<wf::workarea_changed_signal> on_workarea = [this] (auto) { clear(); };
+ wf::signal::connection_t<wf::reload_config_signal> on_config = [this] (auto) { clear(); };
+ public:
+ void handle_new_output(wf::output_t *output) override
+ {
+ output->connect(&on_tile); output->connect(&on_workarea);
+ }
+ void handle_output_removed(wf::output_t*) override { clear(); }
+ void init()
+ {
+ init_output_tracking(); map.init();
+ enabled.set_callback([this] { if (!enabled) clear(); });
+ wf::get_core().connect(&on_move);
+ wf::get_core().connect(&on_geometry);
+ wf::get_core().connect(&on_unmap);
+ wf::get_core().connect(&on_config);
+ wf::get_core().output_layout->connect(&on_layout);
+ repository->register_method("move/snap-status", [this] (wf::json_t)
+ {
+ auto reply = wf::ipc::json_ok();
+ reply["ready"] = ready; reply["preview"] = bool(preview); reply["handoff"] = handing_off;
+ reply["slot"] = destination.slot; reply["monitor"] = destination.monitor;
+ reply["target"] = wf::ipc::geometry_to_json(preview ? preview->target : destination.geometry);
+ reply["delay"] = delay.value(); reply["preview_style"] = "held-window-wobbly";
+ return reply;
+ });
+ }
+ void fini()
+ {
+ clear(); map.fini(); repository->unregister_method("move/snap-status"); fini_output_tracking();
+ on_move.disconnect(); on_geometry.disconnect(); on_unmap.disconnect();
+ on_config.disconnect(); on_layout.disconnect();
+ }
+};
+}
--- /dev/null
+++ b/plugins/single_plugins/move-snap-map.hpp
@@ -0,0 +1,224 @@
+#pragma once
+
+#include "move-snap-geometry.hpp"
+#include <wayfire/output-layout.hpp>
+#include <wayfire/output-stitch.hpp>
+#include <wayfire/window-scope.hpp>
+#include <wayfire/scene-render.hpp>
+#include <wayfire/scene-operations.hpp>
+#include <wayfire/plugins/ipc/ipc-helpers.hpp>
+#include <wayfire/plugins/ipc/ipc-method-repository.hpp>
+#include <wayfire/plugins/common/shared-core-data.hpp>
+#include <wayfire/util.hpp>
+#include <algorithm>
+
+namespace
+{
+struct snap_region_t
+{
+ wf::geometry_t geometry;
+ int slot;
+};
+
+// Split only where calc_slot can change its answer. Both the map and desktop
+// overlay use this partition of the same workarea and physical pointer bounds
+// used by a real drag; panel reservations and gaps are included naturally.
+std::vector<snap_region_t> snap_regions(wf::geometry_t bounds, wf::geometry_t area, int edge, int corner)
+{
+ auto cuts = [] (double lo, double hi, double a, double b, int edge, int corner, bool horizontal)
+ {
+ std::vector<double> values{lo, hi};
+ // Match calc_slot's integer pointer coordinates and asymmetric < / <= tests.
+ auto near = [horizontal] (double v) { return horizontal ? std::floor(v) + 1 : std::ceil(v); };
+ auto far = [horizontal] (double v) { return horizontal ? std::ceil(v) : std::floor(v) + 1; };
+ for (double v : {near(a + edge), far(b - edge), near(a + corner), far(b - corner)})
+ if (v > lo && v < hi) values.push_back(v);
+ std::sort(values.begin(), values.end());
+ values.erase(std::unique(values.begin(), values.end()), values.end());
+ return values;
+ };
+ auto xs = cuts(bounds.x, bounds.x + bounds.width, area.x, area.x + area.width, edge, corner, true);
+ auto ys = cuts(bounds.y, bounds.y + bounds.height, area.y, area.y + area.height, edge, corner, false);
+ std::vector<snap_region_t> regions;
+ for (size_t y = 1; y < ys.size(); ++y)
+ for (size_t x = 1; x < xs.size(); ++x)
+ {
+ // calc_slot accepts integer pointer coordinates, as does Move.
+ wf::point_t p{int(std::ceil(xs[x - 1])), int(std::ceil(ys[y - 1]))};
+ if (p.x >= xs[x] || p.y >= ys[y]) continue;
+ int slot = snap_slot(area, p, edge, corner);
+ if (!slot) continue;
+ wf::geometry_t g{xs[x - 1], ys[y - 1], xs[x] - xs[x - 1], ys[y] - ys[y - 1]};
+ // Merge adjacent cells to avoid displaying implementation seams.
+ if (!regions.empty() && regions.back().slot == slot && regions.back().geometry.y == g.y &&
+ regions.back().geometry.height == g.height &&
+ regions.back().geometry.x + regions.back().geometry.width == g.x)
+ regions.back().geometry.width += g.width;
+ else regions.push_back({g, slot});
+ }
+ for (size_t i = 0; i < regions.size(); ++i)
+ for (size_t j = i + 1; j < regions.size();)
+ {
+ auto& a = regions[i]; auto& b = regions[j];
+ if (a.slot == b.slot && a.geometry.x == b.geometry.x && a.geometry.width == b.geometry.width &&
+ a.geometry.y + a.geometry.height == b.geometry.y)
+ {
+ a.geometry.height += b.geometry.height;
+ regions.erase(regions.begin() + j);
+ } else ++j;
+ }
+ return regions;
+}
+
+class move_snap_map_node_t : public wf::scene::node_t
+{
+ class render_instance_t : public wf::scene::simple_render_instance_t<move_snap_map_node_t>
+ {
+ public:
+ using simple_render_instance_t::simple_render_instance_t;
+ void render(const wf::scene::render_instruction_t& data) override
+ {
+ for (auto& r : self->regions)
+ {
+ bool corner = r.slot == 1 || r.slot == 3 || r.slot == 7 || r.slot == 9;
+ wf::color_t color = corner ? wf::color_t{0.68, 0.48, 0.96, 0.42} : wf::color_t{0.26, 0.72, 0.90, 0.38};
+ data.pass->add_rect(color, data.target, r.geometry, data.damage);
+ }
+ }
+ };
+ std::vector<snap_region_t> regions;
+ wf::geometry_t bounds;
+ public:
+ move_snap_map_node_t(std::vector<snap_region_t> regions, wf::geometry_t bounds) :
+ node_t(false), regions(std::move(regions)), bounds(bounds) {}
+ std::optional<wf::scene::input_node_t> find_node_at(const wf::pointf_t&) override { return {}; }
+ wf::geometry_t get_bounding_box() override { return bounds; }
+ std::string stringify() const override { return "move-snap-map"; }
+ void gen_render_instances(std::vector<wf::scene::render_instance_uptr>& instances,
+ wf::scene::damage_callback damage, wf::output_t *output) override
+ {
+ instances.push_back(std::make_unique<render_instance_t>(this, damage, output));
+ }
+};
+
+class move_snap_map_t
+{
+ wf::shared_data::ref_ptr_t<wf::ipc::method_repository_t> repository;
+ wf::option_wrapper_t<int> edge{"move/snap_threshold"}, corner{"move/quarter_snap_threshold"};
+ wf::option_wrapper_t<int> delay{"move/snap_delay"};
+ wf::option_wrapper_t<bool> enabled{"move/enable_snap"};
+ wf::wl_timer<false> lease;
+ std::shared_ptr<move_snap_map_node_t> overlay;
+ std::string owner, scope = "physical", displayed;
+ std::vector<snap_region_t> render_regions;
+ wf::geometry_t render_bounds;
+
+ wf::json_t snapshot(const std::string& selected_scope)
+ {
+ auto reply = wf::ipc::json_ok(); reply["version"] = 1;
+ reply["edge"] = edge.value(); reply["corner"] = corner.value(); reply["enabled"] = enabled.value(); reply["delay"] = delay.value();
+ reply["config_file"] = std::string(getenv("WAYFIRE_CONFIG_FILE") ?: "");
+ reply["scope"] = selected_scope; reply["monitors"] = wf::json_t::array();
+ render_regions.clear();
+ const std::vector<std::string> names{"", "bl", "b", "br", "l", "c", "r", "tl", "t", "tr"};
+ bool first = true;
+ auto add = [&] (wf::output_t *output, std::string name, wf::geometry_t bounds, wf::geometry_t area)
+ {
+ auto origin = wf::origin(output->get_layout_geometry());
+ auto global_bounds = bounds + origin;
+ auto monitor = wf::json_t(); monitor["name"] = name;
+ monitor["geometry"] = wf::ipc::geometry_to_json(global_bounds);
+ monitor["workarea"] = wf::ipc::geometry_to_json(area + origin);
+ monitor["regions"] = wf::json_t::array();
+ if (first) { render_bounds = global_bounds; first = false; }
+ else
+ {
+ auto x = std::min(render_bounds.x, global_bounds.x), y = std::min(render_bounds.y, global_bounds.y);
+ render_bounds = {x, y, std::max(render_bounds.x + render_bounds.width, global_bounds.x + global_bounds.width) - x,
+ std::max(render_bounds.y + render_bounds.height, global_bounds.y + global_bounds.height) - y};
+ }
+ for (auto r : snap_regions(bounds, area, edge, corner))
+ {
+ r.geometry = r.geometry + origin;
+ wf::json_t region; region["geometry"] = wf::ipc::geometry_to_json(r.geometry);
+ region["slot"] = names[r.slot];
+ region["target"] = wf::ipc::geometry_to_json(wf::grid::get_slot_dimensions(area, r.slot) + origin);
+ monitor["regions"].append(region); render_regions.push_back(r);
+ }
+ reply["monitors"].append(monitor);
+ };
+ for (auto output : wf::get_core().output_layout->get_outputs())
+ {
+ if (std::string(output->handle->name).find("NOOP-") == 0) continue;
+ auto layout = output->get_data<wf::output_stitch_layout_t>();
+ if (selected_scope == "physical" && layout && !layout->zones.empty())
+ for (auto& zone : layout->zones) add(output, zone.name, zone.geometry, wf::physical_zone_workarea(output, zone));
+ else add(output, output->handle->name, output->get_relative_geometry(), output->workarea->get_workarea());
+ }
+ return reply;
+ }
+
+ void hide()
+ {
+ if (overlay) wf::scene::remove_child(overlay);
+ overlay.reset(); displayed.clear(); owner.clear();
+ lease.disconnect();
+ }
+
+ void show(const wf::json_t& state)
+ {
+ auto content = state.serialize();
+ if (content == displayed) return;
+ if (overlay) wf::scene::remove_child(overlay);
+ overlay.reset(); displayed = content;
+ if (render_regions.empty()) return;
+ overlay = std::make_shared<move_snap_map_node_t>(render_regions, render_bounds);
+ wf::scene::add_front(wf::get_core().scene(), overlay);
+ }
+
+ wf::signal::connection_t<wf::output_layout_configuration_changed_signal> layout_changed =
+ [this] (auto) { if (!owner.empty()) show(snapshot(scope)); };
+ wf::signal::connection_t<wf::reload_config_signal> config_changed =
+ [this] (auto) { if (!owner.empty()) show(snapshot(scope)); };
+ wf::signal::connection_t<wf::workarea_changed_signal> workarea_changed =
+ [this] (auto) { if (!owner.empty()) show(snapshot(scope)); };
+ public:
+ void init()
+ {
+ repository->register_method("move/snap-regions", [this] (wf::json_t data)
+ {
+ std::string selected = "physical";
+ if (data.has_member("scope"))
+ {
+ if (!data["scope"].is_string()) return wf::ipc::json_error("scope must be physical or virtual");
+ selected = data["scope"].as_string();
+ if (selected != "physical" && selected != "virtual") return wf::ipc::json_error("scope must be physical or virtual");
+ }
+ if (data.has_member("visible"))
+ {
+ if (!data["visible"].is_bool() || !data.has_member("owner") || !data["owner"].is_string() ||
+ data["owner"].as_string().empty() || data["owner"].as_string().size() > 128)
+ return wf::ipc::json_error("visible requires a boolean and an owner identifier");
+ auto requested = data["owner"].as_string();
+ if (data["visible"].as_bool())
+ {
+ if (!owner.empty() && owner != requested) return wf::ipc::json_error("Snap zones are already displayed by another settings window.");
+ owner = requested; scope = selected;
+ } else if (owner == requested) hide();
+ }
+ auto reply = snapshot(selected);
+ if (data.has_member("visible") && data["visible"].as_bool())
+ {
+ show(reply);
+ lease.set_timeout(2500, [this] { hide(); });
+ }
+ reply["visible"] = bool(overlay);
+ return reply;
+ });
+ wf::get_core().output_layout->connect(&layout_changed);
+ wf::get_core().connect(&config_changed);
+ wf::get_core().connect(&workarea_changed);
+ }
+ void fini() { hide(); repository->unregister_method("move/snap-regions"); }
+};
+}
--- /dev/null
+++ b/plugins/single_plugins/move-snap-geometry.hpp
@@ -0,0 +1,13 @@
+#pragma once
+#include <wayfire/plugins/grid.hpp>
+
+namespace
+{
+// Preserve edge/corner precedence and threshold boundaries, but make the top
+// edge symmetric with the bottom instead of maximizing the window.
+inline wf::grid::slot_t snap_slot(wf::geometry_t area, wf::point_t point, int edge, int corner)
+{
+ auto slot = wf::grid::calc_slot(area, point, edge, corner);
+ return slot == wf::grid::SLOT_CENTER ? wf::grid::SLOT_TOP : slot;
+}
+}
--- /dev/null
+++ b/tests/move-snapping.py
@@ -0,0 +1,376 @@
+#!/usr/bin/env python3
+"""Exercise the display API in a private compositor, never the active desktop."""
+import json, os, socket, struct, subprocess, tempfile, time
+from PIL import Image, ImageChops
+from pathlib import Path
+
+stage=Path(os.environ.get('WCM_TEST_STAGE','/var/tmp/wayfire-move-snap-20261001'))
+runtime=Path(tempfile.mkdtemp(prefix='scope-toggle-test-'))
+env=os.environ.copy()
+for key in ['WAYLAND_DISPLAY','DISPLAY','WAYFIRE_SOCKET','_WAYFIRE_SOCKET','WAYFIRE_CONFIG_FILE','WAYFIRE_DEFAULT_CONFIG_BACKEND']:
+ env.pop(key,None)
+env.update(GIO_USE_VFS='local',GTK_USE_PORTAL='0',XDG_RUNTIME_DIR=str(runtime),WLR_BACKENDS='headless',WLR_HEADLESS_OUTPUTS='4',WLR_RENDERER='gles2',
+ WLR_RENDER_DRM_DEVICE='/dev/dri/renderD128',WAYFIRE_PLUGIN_PATH=str(stage/'plugins'),WAYFIRE_PLUGIN_XML_PATH=str(stage/'metadata'))
+config=runtime/'wayfire.ini'
+config.write_text('''# Preserve this comment and unrelated settings.
+[core]
+plugins = ipc stipc ipc-rules output-control grid place move resize wm-actions wobbly follow-focus simple-tile cube vswitch
+xwayland = false
+stitch_enabled = true
+stitch_outputs = HEADLESS-1 HEADLESS-2 HEADLESS-3
+default_output = VIRTUAL-1
+window_scope = physical
+window_scope_rules = [{"app_id":"tile-wide*","scope":"virtual"},{"app_id":"scope-pinned","scope":"HEADLESS-3"}]
+[simple-tile]
+key_toggle = none
+tile_by_default = none
+float_on_top = false
+inner_gap_size = 10
+outer_horiz_gap_size = 5
+outer_vert_gap_size = 5
+[wm-actions]
+toggle_always_on_top = <super> KEY_T
+[cube]
+rotate_left = <alt> <ctrl> KEY_LEFT
+rotate_right = <alt> <ctrl> KEY_RIGHT
+[autostart]
+autostart_wf_shell = false
+[grid]
+toggle_scope = <super> KEY_ENTER
+type = none
+zone_gap = 20
+[output:HEADLESS-1]
+mode = 640x720@60
+position = 0,0
+[output:HEADLESS-2]
+zone_gap = 20
+mode = 640x720@60
+position = 640,0
+[output:HEADLESS-3]
+mode = 640x720@60
+position = 1280,0
+[output:HEADLESS-4]
+mode = 320x240@60
+position = 1920,0
+masked = true
+''')
+if os.environ.get('MOVE_TEST_UPGRADE'):
+ config.write_text(config.read_text().replace('grid place move',str(stage/'libgrid-old.so')+' place '+str(stage/'libmove-old.so')))
+if os.environ.get('GRID_TEST_UPGRADE'):
+ config.write_text(config.read_text().replace('output-control grid place', 'output-control '+str(stage/'libgrid-r19.so')+' place'))
+if os.environ.get('SCOPE_TEST_ANIMATION'):
+ config.write_text(config.read_text().replace('type = none', 'type = crossfade\nduration = 300ms circle'))
+
+log=(runtime/'wayfire.log').open('w')
+compositor_env=env.copy()
+if os.environ.get('WCM_TEST_ASAN'):
+ compositor_env.update(LD_PRELOAD=os.environ['WCM_TEST_ASAN'],ASAN_OPTIONS='detect_leaks=0:abort_on_error=1',UBSAN_OPTIONS='halt_on_error=1:print_stacktrace=1')
+process=subprocess.Popen([os.environ.get('WCM_TEST_COMPOSITOR',str(stage/'wayfire')),'-c',str(config)],env=compositor_env,stdout=log,stderr=log)
+def wait(fn,timeout=10):
+ deadline=time.monotonic()+timeout
+ while time.monotonic()<deadline:
+ if process.poll() is not None:raise RuntimeError(f'Compositor exited; {runtime}/wayfire.log')
+ result=fn()
+ if result:return result
+ time.sleep(.05)
+ raise TimeoutError(f'Condition timed out; {runtime}/wayfire.log')
+def ipc(method,data=None,fail=False):
+ with socket.socket(socket.AF_UNIX) as s:
+ s.settimeout(8);s.connect(env['WAYFIRE_SOCKET'])
+ b=json.dumps({'method':method,'data':data or {}}).encode();s.sendall(struct.pack('<I',len(b))+b)
+ def read(n):
+ b=b''
+ while len(b)<n:
+ c=s.recv(n-len(b))
+ if not c:raise RuntimeError('IPC disconnected')
+ b+=c
+ return b
+ result=json.loads(read(struct.unpack('<I',read(4))[0]))
+ if fail:assert result.get('error'),result
+ else:assert not isinstance(result,dict) or not result.get('error'),result
+ return result
+def get():return ipc('displays/get')
+def apply(options,fail=False):return ipc('displays/apply',{'revision':get()['revision'],'options':options},fail)
+def revert(t):return ipc('displays/revert',{'token':t['token']})
+def confirm(t,fail=False):return ipc('displays/confirm',{'token':t['token']},fail)
+def names():return [d['name'] for d in get()['desktops']]
+
+clients=[]
+def spawn(app,mode='normal'):
+ f=(runtime/(app+'.log')).open('w')
+ p=subprocess.Popen([str(stage/'scope-client'),app,mode],env=env,stdin=subprocess.PIPE,stdout=f,stderr=f,text=True)
+ clients.append((p,f))
+ if mode=='bar':
+ wait(lambda:any(v.get('app-id')=='scope-bar' and v.get('mapped') for v in ipc('window-rules/list-views')))
+ return p,None
+ v=wait(lambda:next((v for v in ipc('window-rules/list-views') if v.get('app-id')==app and v.get('mapped')),None))
+ return p,v['id']
+def info(vid):return next(v for v in ipc('window-rules/list-views') if v['id']==vid)
+def geometry(vid):return info(vid)['geometry']
+def command(p,cmd):p.stdin.write(cmd+'\n');p.stdin.flush()
+def expect(vid,**wanted):
+ try:return wait(lambda:all(geometry(vid)[k]==v for k,v in wanted.items()))
+ except Exception:
+ print('FAILED expected',wanted,'actual',info(vid),flush=True);raise
+
+def focus(vid):ipc('window-rules/focus-view',{'id':vid})
+def keys(*ks):
+ for k in ks:ipc('stipc/feed_key',{'key':k,'state':True})
+ for k in reversed(ks):ipc('stipc/feed_key',{'key':k,'state':False})
+def layout(monitor,ws=0):return ipc('simple-tile/get-layout',{'wset-index':wset,'workspace':{'x':ws,'y':0},'monitor':monitor})['layout']
+def contains(node,vid):
+ return node.get('view-id')==vid or any(contains(c,vid) for c in node.get('vertical-split',[])+node.get('horizontal-split',[]))
+def tiled(vid):return any(contains(layout(m),vid) for m in ['HEADLESS-1','HEADLESS-2','HEADLESS-3','VIRTUAL-1'])
+def toggle(vid):
+ was=tiled(vid);focus(vid);keys('KEY_LEFTMETA','KEY_ENTER');wait(lambda:tiled(vid)!=was)
+def spawn_at(app,monitor):
+ ipc('stipc/move_cursor',{'x':(monitor-1)*640+200,'y':200})
+ return spawn(app)
+def bounds(vid,x,y,w,h):
+ g=geometry(vid);assert g['x']>=x and g['y']>=y and g['x']+g['width']<=x+w and g['y']+g['height']<=y+h,(vid,g,(x,y,w,h))
+def toggle_scope(vid, keyboard=False):
+ was=info(vid)['window-scope']
+ if keyboard:
+ focus(vid);keys('KEY_LEFTMETA','KEY_ENTER')
+ else:ipc('grid/toggle_scope',{'view-id':vid})
+ wait(lambda:(info(vid)['window-scope']=='virtual') != (was=='virtual'))
+ time.sleep(.4 if os.environ.get('SCOPE_TEST_ANIMATION') else .1)
+
+def same_geometry(vid, before):
+ expect(vid,**before)
+
+def rect(x,y,w,h):return dict(x=x,y=y,width=w,height=h)
+def slot_rect(area,slot):
+ x,y,w,h=(area[k] for k in ('x','y','width','height'))
+ if slot%3==1:w=int(w/2)
+ elif slot%3==0:x+=int(w/2);w=int(w/2)
+ if slot>=7:h=int(h/2)
+ elif slot<=3:y+=int(h/2);h=int(h/2)
+ return rect(x,y,w,h)
+def move(x,y):ipc('stipc/move_cursor',{'x':x,'y':y});time.sleep(.04)
+def button(mode):ipc('stipc/feed_button',{'combo':'S-BTN_LEFT','mode':mode})
+def prepare(vid,monitor=1):
+ ipc('window-rules/set-window-scope',{'id':vid,'scope':'physical'})
+ ipc('grid/restore',{'view-id':vid})
+ g=rect((monitor-1)*640+140,180,300,180)
+ ipc('window-rules/configure-view',{'id':vid,'geometry':g})
+ expect(vid,**g);time.sleep(.4 if os.environ.get("SCOPE_TEST_ANIMATION") else .05);focus(vid)
+def begin(vid,offset=150):
+ g=geometry(vid);move(g['x']+offset,g['y']+60);button('press')
+ move(g['x']+offset+30,g['y']+60)
+def preview(expected):
+ def found():
+ return any(v.get('mapped') and v.get('type')!='toplevel' and v.get('app-id')!='scope-bar' and v.get('geometry')==expected for v in ipc('window-rules/list-views'))
+ try:wait(found,3)
+ except Exception:
+ print('PREVIEW expected',expected,'views',ipc('window-rules/list-views'),flush=True);raise
+
+def end(vid,expected):
+ button('release');expect(vid,**expected);time.sleep(.25)
+import random
+
+def zones(**kw):return ipc('move/snap-regions',kw)
+def hit(g,x,y):return g['x']<=x<g['x']+g['width'] and g['y']<=y<g['y']+g['height']
+def expected(area,x,y,e,q):
+ l=x-area['x']<=e;r=area['x']+area['width']-x<=e
+ t=y-area['y']<e;b=area['y']+area['height']-y<e
+ fl=x-area['x']<=q;fr=area['x']+area['width']-x<=q
+ ft=y-area['y']<q;fb=area['y']+area['height']-y<q
+ if l and ft or fl and t:return 'tl'
+ if r and ft or fr and t:return 'tr'
+ if r and fb or fr and b:return 'br'
+ if l and fb or fl and b:return 'bl'
+ return 'r' if r else 'l' if l else 't' if t else 'b' if b else ''
+def check_partition(state):
+ rng=random.Random(392)
+ for m in state['monitors']:
+ a=m['workarea'];g=m['geometry'];e=state['edge'];q=state['corner']
+ xs={int(g['x']),int(g['x']+g['width']-1)};ys={int(g['y']),int(g['y']+g['height']-1)}
+ for d in [0,e,q]:
+ for delta in [-1,0,1]:
+ xs.update([int(a['x']+d+delta),int(a['x']+a['width']-d+delta)])
+ ys.update([int(a['y']+d+delta),int(a['y']+a['height']-d+delta)])
+ points=[(x,y) for x in xs for y in ys if hit(g,x,y)]
+ points +=[(rng.randrange(int(g['x']),int(g['x']+g['width'])),rng.randrange(int(g['y']),int(g['y']+g['height']))) for _ in range(600)]
+ for x,y in points:
+ found=[r['slot'] for r in m['regions'] if hit(r['geometry'],x,y)]
+ wanted=expected(a,x,y,e,q)
+ assert found==([wanted] if wanted else []),(m['name'],x,y,found,wanted,state)
+
+def shot(name):
+ p=runtime/(name+'.png');subprocess.run(['grim',str(p)],env=env,check=True);return Image.open(p).convert('RGB')
+def status():return ipc('move/snap-status')
+def settled_preview(vid,target,name):
+ # Bounding corners alone do not detect a surface bowed by a live Wobbly
+ # grab. Check the whole solid client texture inside the destination too.
+ def settled():
+ image=shot(name)
+ x,y,w,h=(int(target[k]) for k in ('x','y','width','height'))
+ interior=image.crop((x+3,y+3,x+w-3,y+h-3))
+ color=image.getpixel((x+w//2,y+h//2))
+ bbox=info(vid)['bbox']
+ return color[2]>color[0]+60 and color[2]>color[1]+60 and \
+ ImageChops.difference(interior,Image.new('RGB',interior.size,color)).getbbox() is None and \
+ all(abs(bbox[k]-target[k])<1 for k in target)
+ wait(settled,6)
+ assert status()['ready'] and status()['preview'] and not status()['handoff']
+def options(**kw):ipc('wayfire/set-config-options',{'move/'+k:v for k,v in kw.items()})
+def plugin(name,enabled):
+ current=ipc('wayfire/get-config-option',{'option':'core/plugins'})['value'].split()
+ wanted=[p for p in current if p!=name]
+ if enabled:wanted.append(name)
+ ipc('wayfire/set-config-options',{'core/plugins':' '.join(wanted)})
+ time.sleep(.15)
+def methods():return ipc('list-methods')['methods']
+def destination(m,slot):
+ monitor=next(x for x in zones()['monitors'] if x['name']==f'HEADLESS-{m}')
+ return next(r['target'] for r in monitor['regions'] if r['slot']==slot)
+def arm_at(vid,m,x,y):
+ prepare(vid,m);before=geometry(vid).copy();begin(vid);move((m-1)*640+x,y)
+ wait(lambda:status()['ready']);assert geometry(vid)==before
+ return before
+try:
+ env['WAYFIRE_SOCKET']=str(wait(lambda:next(runtime.glob('wayfire-*.socket'),None)))
+ env['WAYLAND_DISPLAY']=next(p.name for p in runtime.glob('wayland-*') if not p.name.endswith('.lock'))
+ print('Runtime:',runtime,flush=True);wait(lambda:names()==['VIRTUAL-1'])
+ if os.environ.get('MOVE_TEST_UPGRADE'):
+ wait(lambda:'grid/snap-zones' in methods())
+ warm,wid=spawn_at('warm-grid',1);prepare(wid);begin(wid);move(320,350);button('release');time.sleep(.2)
+ ipc('grid/slot_r',{'view-id':wid});time.sleep(.3);saved=geometry(wid)
+ current=ipc('wayfire/get-config-option',{'option':'core/plugins'})['value']
+ current=current.replace(str(stage/'libgrid-old.so'),'grid').replace(str(stage/'libmove-old.so'),'move')
+ ipc('wayfire/set-config-options',{'core/plugins':current})
+ wait(lambda:'move/snap-regions' in methods());assert geometry(wid)==saved
+ ipc('window-rules/close-view',{'id':wid});time.sleep(.2)
+ print('PASS old resident Grid/Move replacement preserves windows and shared drag state',flush=True)
+ wait(lambda:'move/snap-regions' in methods());assert 'grid/snap-zones' not in methods()
+ bar,_=spawn('zone-bar','bar');time.sleep(1.3)
+ for edge,corner in [(10,50),(0,0),(35,90),(90,15),(600,800)]:
+ options(snap_threshold=edge,quarter_snap_threshold=corner)
+ for scope in ['physical','virtual']:check_partition(zones(scope=scope))
+ print('PASS exact physical/VIRTUAL map partitions with top half, corners, gaps and panel reservations',flush=True)
+ options(snap_threshold=10,quarter_snap_threshold=50,snap_delay=500)
+ base=shot('hidden');state=zones(visible=True,owner='test');time.sleep(.15);shown=shot('shown')
+ for m in state['monitors']:
+ for r in m['regions']:
+ g=r['geometry'];p=(int(g['x']+g['width']/2),int(g['y']+g['height']/2))
+ assert base.getpixel(p)!=shown.getpixel(p)
+ ipc('move/snap-regions',{'visible':True,'owner':'other'},fail=True)
+ assert zones(visible=False,owner='other')['visible']
+ zones(visible=False,owner='test');time.sleep(.15)
+ assert shot('hidden-again').tobytes()==base.tobytes()
+ zones(visible=True,owner='test');time.sleep(2.8);assert not zones()['visible']
+ print('PASS map overlay ownership, removal and lease cleanup',flush=True)
+ app,vid=spawn_at('zone-drag',1);prepare(vid);before=geometry(vid).copy();begin(vid);move(320,1)
+ time.sleep(.10);assert not status()['ready'] and not status()['preview'];assert geometry(vid)==before
+ shot('before-delay');wait(lambda:status()['ready']);time.sleep(.8)
+ assert geometry(vid)==before and status()['target']==destination(1,'t')
+ settled_preview(vid,destination(1,'t'),'held-top-preview')
+ move(400,1);time.sleep(.3);settled_preview(vid,destination(1,'t'),'held-top-after-motion')
+ assert geometry(vid)==before
+ print('PASS preview fully settles while button remains down and stays settled during in-zone motion',flush=True)
+ move(360,350);wait(lambda:not status()['preview']);time.sleep(.6)
+ assert geometry(vid)==before
+ move(420,390)
+ # Wobbly rounds the damage box outward, adding up to one pixel to its size.
+ wait(lambda:all(abs(info(vid)['bbox'][k]-v)<=1 for k,v in rect(270,330,300,180).items()))
+ shot('pulled-away');button('release');time.sleep(.3)
+ assert geometry(vid)['width']==300 and geometry(vid)['height']==180
+ print('PASS dwell, held-window preview without client resize, pull-away restoration and free release',flush=True)
+ arm_at(vid,1,320,1);settled_preview(vid,destination(1,'t'),'before-zone-change')
+ move(638,350);assert not status()['ready'];wait(lambda:status()['ready'])
+ settled_preview(vid,destination(1,'r'),'after-zone-change');end(vid,destination(1,'r'))
+ print('PASS moving from a settled preview to another zone restarts dwell and settles again',flush=True)
+ for m in [1,2,3]:
+ for name,x,y in [('t',320,1),('b',320,718),('l',1,350),('r',638,350),('tl',1,1),('tr',638,1),('bl',1,718),('br',638,718)]:
+ before=arm_at(vid,m,x,y)
+ if m==1 or name=='t':
+ settled_preview(vid,destination(m,name),f'held-{m}-{name}')
+ assert geometry(vid)==before
+ end(vid,destination(m,name));wait(lambda:not status()['preview'])
+ assert info(vid)['geometry']==destination(m,name)
+ print(f'PASS all eight delayed destinations commit on physical monitor {m}',flush=True)
+ options(snap_delay=1000);prepare(vid);begin(vid);move(320,1);time.sleep(.1);button('release');time.sleep(.3)
+ assert geometry(vid)['width']==300 and geometry(vid)['height']==180 and not status()['preview']
+ print('PASS release before dwell does not snap',flush=True)
+ options(snap_delay=500);prepare(vid);begin(vid);move(1,350);time.sleep(.25);move(638,350);time.sleep(.2)
+ assert not status()['ready'];move(320,350);time.sleep(.6);assert not status()['preview'];button('release')
+ print('PASS changing zones restarts dwell; leaving cancels the pending preview',flush=True)
+ options(snap_delay=0);arm_at(vid,2,320,1);options(enable_snap=False)
+ assert not zones()['enabled'] and not status()['preview'];button('release');time.sleep(.4)
+ assert geometry(vid)['width']==300 and geometry(vid)['height']==180
+ prepare(vid);begin(vid);move(320,1);time.sleep(.7);button('release');time.sleep(.3)
+ assert geometry(vid)['width']==300 and geometry(vid)['height']==180
+ print('PASS Move Snap checkbox cancels a preview and disables edge snapping',flush=True)
+ ipc('grid/slot_r',{'view-id':vid});expect(vid,**destination(1,'r')) if 'move/snap-regions' in methods() else expect(vid,x=320,y=44,width=300,height=656)
+ ipc('grid/slot_r',{'view-id':vid});expect(vid,x=380,y=109.5,width=240,height=525)
+ print('PASS Grid keyboard placement and size cycling remain independent',flush=True)
+ prepare(vid);plugin('grid',False);options(enable_snap=True);options(snap_delay=100)
+ before=geometry(vid).copy();begin(vid);move(320,1);wait(lambda:status()['ready']);assert geometry(vid)==before
+ end(vid,destination(1,'t'));wait(lambda:not status()['preview'])
+ print('PASS Move snapping works with Grid disabled',flush=True)
+ plugin('grid',True)
+ prepare(vid,2);ipc('window-rules/set-window-scope',{'id':vid,'scope':'virtual'});begin(vid);move(960,1)
+ wait(lambda:status()['ready']);assert status()['target']['width']==1920
+ button('release');expect(vid,x=0,y=24,width=1920,height=348);wait(lambda:not status()['preview'])
+ print('PASS virtual-scope top destination is the upper half of the combined output',flush=True)
+ prepare(vid,2);begin(vid);keys('KEY_LEFTSHIFT')
+ ipc('stipc/feed_key',{'key':'KEY_LEFTSHIFT','state':True});move(960,350);wait(lambda:status()['ready'])
+ assert status()['slot']==5 and status()['target']==rect(660,44,600,656)
+ button('release');ipc('stipc/feed_key',{'key':'KEY_LEFTSHIFT','state':False});expect(vid,x=660,y=44,width=600,height=656)
+ wait(lambda:not status()['preview']);print('PASS explicit Shift monitor-fill stays available',flush=True)
+ plugin('wobbly',False);arm_at(vid,1,320,1);end(vid,destination(1,'t'));wait(lambda:not status()['preview'])
+ plugin('wobbly',True);print('PASS preview and placement also work when Wobbly is disabled',flush=True)
+ # Existing workspace dwell is independent of snap dwell and wraps a row.
+ options(enable_snap=False,workspace_switch_after=350)
+ ipc('wayfire/set-config-options',{'core/vwidth':6,'core/vheight':1})
+ def output_state():return next(o for o in ipc('window-rules/list-outputs') if o['name']=='VIRTUAL-1')
+ def workspace():return output_state()['workspace']['x']
+ prepare(vid,3)
+ ipc('vswitch/set-workspace',{'x':5,'y':0,'output-id':output_state()['id'],'view-id':vid})
+ wait(lambda:workspace()==5);time.sleep(.6)
+ prepare(vid,3);begin(vid);move(1918,350)
+ time.sleep(.1);assert workspace()==5
+ move(1600,350);time.sleep(.5);assert workspace()==5
+ move(1918,350);wait(lambda:workspace()==0);time.sleep(.7)
+ assert workspace()==0 and not status()['preview']
+ button('release');time.sleep(.3)
+ prepare(vid);begin(vid);move(1,350)
+ wait(lambda:workspace()==5);time.sleep(.7);button('release')
+ assert workspace()==5
+ print('PASS delayed workspace switching wraps 6 to 1 and 1 to 6; leaving edge cancels',flush=True)
+ options(enable_snap=True,snap_delay=100)
+ prepare(vid,3);begin(vid);move(1918,350)
+ wait(lambda:workspace()==0);time.sleep(.7)
+ settled_preview(vid,destination(3,'r'),'wrapped-preview-right')
+ end(vid,destination(3,'r'));wait(lambda:not status()['preview'])
+ prepare(vid);begin(vid);move(1,350)
+ wait(lambda:workspace()==5);time.sleep(.7)
+ settled_preview(vid,destination(1,'l'),'wrapped-preview-left')
+ end(vid,destination(1,'l'));wait(lambda:not status()['preview'])
+ print('PASS wrapping in both directions also preserves held previews and drop placement',flush=True)
+ options(enable_snap=False)
+ ipc('vswitch/set-workspace',{'x':0,'y':0,'output-id':output_state()['id'],'view-id':vid})
+ wait(lambda:workspace()==0);time.sleep(.6)
+ ipc('wayfire/set-config-options',{'core/vwidth':1,'core/vheight':1})
+ prepare(vid);begin(vid);move(1,350);time.sleep(.7)
+ assert workspace()==0;button('release')
+ options(enable_snap=True,workspace_switch_after=-1)
+ print('PASS one-workspace grid remains stable at an edge',flush=True)
+ prepare(vid);begin(vid);move(1,350);wait(lambda:status()['ready'])
+ plugin('move',False);assert 'move/snap-regions' not in methods()
+ button('release');time.sleep(.3)
+ assert geometry(vid)['width']==300 and geometry(vid)['height']==180
+ plugin('move',True);wait(lambda:'move/snap-regions' in methods())
+ print('PASS disabling Move during preview cancels safely and reloads cleanly',flush=True)
+ prepare(vid);begin(vid);move(1,350);wait(lambda:status()['ready'])
+ ipc('window-rules/close-view',{'id':vid});wait(lambda:not status()['preview']);button('release')
+ print('PASS closing a held window cancels preview and timer safely',flush=True)
+ assert not any(m.startswith('snap-zones/') for m in methods())
+ for data in [{'scope':'wrong'},{'visible':'true','owner':'x'},{'visible':True}]:ipc('move/snap-regions',data,fail=True)
+ print('ALL PASS',flush=True)
+finally:
+ for p,f in clients:
+ if p.poll() is None:p.terminate()
+ p.wait(timeout=3);f.close()
+ process.terminate();process.wait(timeout=5);log.close()
|