Debian Codegraph @

hyprtester/src/tests/main/dwindle.cpp

raw
1 #include "../shared.hpp"
2 #include "../../shared.hpp"
3 #include "../../hyprctlCompat.hpp"
4 #include "tests.hpp"
5
6 TEST_CASE(dwindleFloatClamp) {
7 for (auto const& win : {"a", "b", "c"}) {
8 if (!Tests::spawnKitty(win)) {
9 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
10 }
11 }
12
13 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })"));
14 OK(getFromSocket("/eval hl.monitor({ output = 'HEADLESS-2', reserved = { top = 0, right = 20, bottom = 0, left = 20 } })"));
15 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:c' })"));
16 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:c' })"));
17 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 1200, y = 900, window = 'class:c' })"));
18 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset', window = 'class:c' })"));
19 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:c' })"));
20
21 {
22 auto str = getFromSocket("/clients");
23 EXPECT_CONTAINS(str, "at:");
24 EXPECT_CONTAINS(str, "size: 1200,900");
25 }
26
27 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 0 } })"));
28 }
29
30 TEST_CASE(dwindleIssue13349) {
31
32 // Test if dwindle properly uses a focal point to place a new window.
33 // exposed by #13349 as a regression from #12890
34
35 for (auto const& win : {"a", "b", "c"}) {
36 if (!Tests::spawnKitty(win))
37 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
38 }
39
40 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:c' })"));
41
42 {
43 auto str = getFromSocket("/activewindow");
44 EXPECT_CONTAINS(str, "at: 967,547");
45 EXPECT_CONTAINS(str, "size: 931,511");
46 }
47
48 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'left' })"));
49
50 {
51 auto str = getFromSocket("/activewindow");
52 EXPECT_CONTAINS(str, "at: 22,547");
53 EXPECT_CONTAINS(str, "size: 931,511");
54 }
55
56 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right' })"));
57
58 {
59 auto str = getFromSocket("/activewindow");
60 EXPECT_CONTAINS(str, "at: 967,547");
61 EXPECT_CONTAINS(str, "size: 931,511");
62 }
63 }
64
65 TEST_CASE(dwindleSplit) {
66 // Test various split methods
67
68 Tests::spawnKitty("a");
69
70 // these must not crash
71 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('swapsplit')"), "ok");
72 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio 1 exact')"), "ok");
73
74 Tests::spawnKitty("b");
75
76 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })"));
77 OK(getFromSocket("/dispatch hl.dsp.layout('splitratio -0.2')"));
78
79 {
80 auto str = getFromSocket("/activewindow");
81 EXPECT_CONTAINS(str, "at: 22,22");
82 EXPECT_CONTAINS(str, "size: 743,1036");
83 }
84
85 OK(getFromSocket("/dispatch hl.dsp.layout('splitratio 1.6 exact')"));
86
87 {
88 auto str = getFromSocket("/activewindow");
89 EXPECT_CONTAINS(str, "at: 22,22");
90 EXPECT_CONTAINS(str, "size: 1495,1036");
91 }
92
93 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio fhne exact')"), "ok");
94 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio exact')"), "ok");
95 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio -....9')"), "ok");
96 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio ..9')"), "ok");
97 EXPECT_NOT(getFromSocket("/dispatch hl.dsp.layout('splitratio')"), "ok");
98
99 OK(getFromSocket("/dispatch hl.dsp.layout('togglesplit')"));
100
101 {
102 auto str = getFromSocket("/activewindow");
103 EXPECT_CONTAINS(str, "at: 22,22");
104 EXPECT_CONTAINS(str, "size: 1876,823");
105 }
106
107 OK(getFromSocket("/dispatch hl.dsp.layout('swapsplit')"));
108
109 {
110 auto str = getFromSocket("/activewindow");
111 EXPECT_CONTAINS(str, "at: 22,859");
112 EXPECT_CONTAINS(str, "size: 1876,199");
113 }
114 }
115
116 TEST_CASE(dwindleRotateSplit) {
117 OK(getFromSocket("r/eval hl.config({ general = { gaps_in = 0 } })"));
118 OK(getFromSocket("r/eval hl.config({ general = { gaps_out = 0 } })"));
119 OK(getFromSocket("r/eval hl.config({ general = { border_size = 0 } })"));
120
121 for (auto const& win : {"a", "b"}) {
122 if (!Tests::spawnKitty(win))
123 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
124 }
125
126 {
127 auto str = getFromSocket("/clients");
128 EXPECT_CONTAINS(str, "at: 0,0");
129 EXPECT_CONTAINS(str, "size: 960,1080");
130 }
131
132 // test 4 repeated rotations by 90 degrees
133 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit')"));
134 {
135 auto str = getFromSocket("/clients");
136 EXPECT_CONTAINS(str, "at: 0,0");
137 EXPECT_CONTAINS(str, "size: 1920,540");
138 }
139
140 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit')"));
141 {
142 auto str = getFromSocket("/clients");
143 EXPECT_CONTAINS(str, "at: 960,0");
144 EXPECT_CONTAINS(str, "size: 960,1080");
145 }
146
147 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit')"));
148 {
149 auto str = getFromSocket("/clients");
150 EXPECT_CONTAINS(str, "at: 0,540");
151 EXPECT_CONTAINS(str, "size: 1920,540");
152 }
153
154 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit')"));
155 {
156 auto str = getFromSocket("/clients");
157 EXPECT_CONTAINS(str, "at: 0,0");
158 EXPECT_CONTAINS(str, "size: 960,1080");
159 }
160
161 // test different angles
162 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit 180')"));
163 {
164 auto str = getFromSocket("/clients");
165 EXPECT_CONTAINS(str, "at: 960,0");
166 EXPECT_CONTAINS(str, "size: 960,1080");
167 }
168
169 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit 270')"));
170 {
171 auto str = getFromSocket("/clients");
172 EXPECT_CONTAINS(str, "at: 0,540");
173 EXPECT_CONTAINS(str, "size: 1920,540");
174 }
175
176 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit 360')"));
177 {
178 auto str = getFromSocket("/clients");
179 EXPECT_CONTAINS(str, "at: 0,0");
180 EXPECT_CONTAINS(str, "size: 1920,540");
181 }
182
183 // test negative angles
184 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit -90')"));
185 {
186 auto str = getFromSocket("/clients");
187 EXPECT_CONTAINS(str, "at: 0,0");
188 EXPECT_CONTAINS(str, "size: 960,1080");
189 }
190
191 OK(getFromSocket("/dispatch hl.dsp.layout('rotatesplit -180')"));
192 {
193 auto str = getFromSocket("/clients");
194 EXPECT_CONTAINS(str, "at: 960,0");
195 EXPECT_CONTAINS(str, "size: 960,1080");
196 }
197 }
198
199 TEST_CASE(dwindleForceSplitOnMoveToWorkspace) {
200 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
201 ASSERT(!!Tests::spawnKitty("kitty"), true);
202
203 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
204 ASSERT(!!Tests::spawnKitty("kitty"), true);
205 std::string posBefore = "at: " + Tests::getAttribute(getFromSocket("/activewindow"), "at");
206
207 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })"));
208 OK(getFromSocket("/dispatch hl.dsp.cursor.move_to_corner({ corner = 3 })")); // top left
209 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '2' })"));
210
211 // Should be moved to the right, so the position should change
212 std::string activeWindow = getFromSocket("/activewindow");
213 EXPECT(activeWindow.contains(posBefore), false);
214 }
215
216 TEST_CASE(dwindleMoveAcrossToggledSplit) {
217 // If we have a split whose orientation has been manually toggled (e.g.
218 // vertically stacked, when the split's aspect ratio is such that it would
219 // prefer to be horizontally stacked by default), moving a window across
220 // the split should NOT revert back to the preferred split orientation
221
222 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })"));
223 for (auto const& win : {"a", "b"}) {
224 if (!Tests::spawnKitty(win))
225 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
226 }
227 OK(getFromSocket("/dispatch hl.dsp.layout('togglesplit')"));
228 // Window A, now on top, is to be moved
229
230 auto origWinB = getFromSocket("/activewindow");
231 auto expectPos = "at: " + Tests::getAttribute(origWinB, "at");
232 auto expectSize = "size: " + Tests::getAttribute(origWinB, "size");
233 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })"));
234
235 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'down' })"));
236
237 // Window A should be moved down, so position and size should swap with window B
238 auto newWinA = getFromSocket("/activewindow");
239 EXPECT_CONTAINS(newWinA, std::move(expectPos));
240 EXPECT_CONTAINS(newWinA, std::move(expectSize));
241 }
242
243 TEST_CASE(dwindleMoveSmallWindowAcrossSplit) {
244 // Small windows (<50% of their parent split's area) should be possible to
245 // move across a split. Focal point weirdness has broken this in the past.
246
247 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 1 } })"));
248 OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 1.2 } })"));
249 for (auto const& win : {"a", "b"}) {
250 if (!Tests::spawnKitty(win))
251 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
252 }
253 // Window B, on the left, is the smaller one
254
255 auto posBefore = "at: " + Tests::getAttribute(getFromSocket("/activewindow"), "at");
256
257 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right' })"));
258
259 // Window B should be moved right, so position should change
260 EXPECT_NOT_CONTAINS(getFromSocket("/activewindow"), posBefore);
261 }
262
263 /*
264 Fullscreen Tests
265
266 Tests with `Shared test among all default handled FS` comment are duplicated among all layouts to test each layout individually
267
268 */
269
270 TEST_CASE(dwindleFullscreenMaximiseDispatchers) {
271
272 // Shared test among all default handled FS
273
274 OK(getFromSocket("/eval hl.config({ general = { layout = 'dwindle' } })"));
275
276 Tests::spawnKitty("kitty_A");
277 Tests::spawnKitty("kitty_B");
278
279 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
280 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
281
282 {
283 auto str = getFromSocket("/activewindow");
284 EXPECT_CONTAINS(str, "fullscreen: 2");
285 EXPECT_CONTAINS(str, "fullscreenClient: 2");
286 }
287
288 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'unset' })"));
289
290 {
291 auto str = getFromSocket("/activewindow");
292 EXPECT_CONTAINS(str, "fullscreen: 0");
293 EXPECT_CONTAINS(str, "fullscreenClient: 0");
294 }
295
296 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized', action = 'toggle' })"));
297
298 {
299 auto str = getFromSocket("/activewindow");
300 EXPECT_CONTAINS(str, "fullscreen: 1");
301 EXPECT_CONTAINS(str, "fullscreenClient: 1");
302 }
303
304 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized', action = 'toggle' })"));
305
306 {
307 auto str = getFromSocket("/activewindow");
308 EXPECT_CONTAINS(str, "fullscreen: 0");
309 EXPECT_CONTAINS(str, "fullscreenClient: 0");
310 }
311
312 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 2, client = 2, action = 'set' })"));
313
314 {
315 auto str = getFromSocket("/activewindow");
316 EXPECT_CONTAINS(str, "fullscreen: 2");
317 EXPECT_CONTAINS(str, "fullscreenClient: 2");
318 }
319
320 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 2, client = 2, action = 'set' })"));
321
322 {
323 auto str = getFromSocket("/activewindow");
324 EXPECT_CONTAINS(str, "fullscreen: 2");
325 EXPECT_CONTAINS(str, "fullscreenClient: 2");
326 }
327
328 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 2, client = 2, action = 'toggle' })"));
329
330 {
331 auto str = getFromSocket("/activewindow");
332 EXPECT_CONTAINS(str, "fullscreen: 0");
333 EXPECT_CONTAINS(str, "fullscreenClient: 0");
334 }
335
336 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 2, client = 2, action = 'toggle' })"));
337
338 {
339 auto str = getFromSocket("/activewindow");
340 EXPECT_CONTAINS(str, "fullscreen: 2");
341 EXPECT_CONTAINS(str, "fullscreenClient: 2");
342 }
343 }
344
345 TEST_CASE(dwindleTestFsFocusUnderFSWindow) {
346
347 // Shared test among all default handled FS
348
349 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
350
351 for (auto const& win : {"one", "two", "three"}) {
352 if (!Tests::spawnKitty(win))
353 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
354 }
355
356 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:one' })"));
357 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
358
359 {
360 auto str = getFromSocket("/activewindow");
361 EXPECT_CONTAINS(str, "at: 22,22");
362 EXPECT_CONTAINS(str, "size: 1876,1036");
363 EXPECT_CONTAINS(str, "class: one");
364 }
365
366 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 1 } })"));
367
368 Tests::spawnKitty("four");
369
370 {
371 auto str = getFromSocket("/activewindow");
372 EXPECT_CONTAINS(str, "at: 22,22");
373 EXPECT_CONTAINS(str, "size: 1876,1036");
374 EXPECT_CONTAINS(str, "class: four");
375 EXPECT_CONTAINS(str, "fullscreen: 1");
376 }
377
378 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
379
380 Tests::spawnKitty("ignored");
381
382 {
383 auto str = getFromSocket("/activewindow");
384 EXPECT_CONTAINS(str, "at: 22,22");
385 EXPECT_CONTAINS(str, "size: 1876,1036");
386 EXPECT_CONTAINS(str, "class: four");
387 EXPECT_CONTAINS(str, "fullscreen: 1");
388 }
389
390 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
391
392 Tests::spawnKitty("erstarrwashere");
393
394 {
395 auto str = getFromSocket("/activewindow");
396 EXPECT_CONTAINS(str, "class: erstarrwashere");
397 EXPECT_CONTAINS(str, "fullscreen: 0");
398 }
399 }
400
401 TEST_CASE(dwindleNewWindowTakesOverFullscreen) {
402
403 // Shared test among all default handled FS
404
405 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
406
407 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
408
409 Tests::spawnKitty("kitty_A");
410
411 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
412
413 {
414 auto str = getFromSocket("/activewindow");
415 EXPECT_CONTAINS(str, "fullscreen: 2");
416 EXPECT_CONTAINS(str, "fullscreenClient: 2");
417 EXPECT_CONTAINS(str, "kitty_A");
418 }
419
420 Tests::spawnKitty("kitty_B");
421
422 {
423 auto str = getFromSocket("/activewindow");
424 EXPECT_CONTAINS(str, "fullscreen: 2");
425 EXPECT_CONTAINS(str, "fullscreenClient: 2");
426 EXPECT_CONTAINS(str, "kitty_A");
427 }
428
429 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
430
431 {
432 // should be ignored as per focus_under_fullscreen 0
433 auto str = getFromSocket("/activewindow");
434 EXPECT_CONTAINS(str, "fullscreen: 2");
435 EXPECT_CONTAINS(str, "fullscreenClient: 2");
436 EXPECT_CONTAINS(str, "kitty_A");
437 }
438
439 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 1 } })"));
440
441 Tests::spawnKitty("kitty_C");
442
443 {
444 auto str = getFromSocket("/activewindow");
445 EXPECT_CONTAINS(str, "fullscreen: 2");
446 EXPECT_CONTAINS(str, "fullscreenClient: 2");
447 EXPECT_CONTAINS(str, "kitty_C");
448 }
449
450 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
451
452 Tests::spawnKitty("kitty_D");
453
454 {
455 auto str = getFromSocket("/activewindow");
456 EXPECT_CONTAINS(str, "fullscreen: 0");
457 EXPECT_CONTAINS(str, "fullscreenClient: 0");
458 EXPECT_CONTAINS(str, "kitty_D");
459 }
460
461 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
462
463 Tests::killAllWindows();
464 }
465
466 TEST_CASE(dwindleExitWindowRetainsFullscreen) {
467
468 // Shared test among all default handled FS
469
470 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
471
472 OK(getFromSocket("/eval hl.config({ misc = { exit_window_retains_fullscreen = false } })"));
473
474 Tests::spawnKitty("kitty_A");
475 Tests::spawnKitty("kitty_B");
476
477 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
478
479 {
480 auto str = getFromSocket("/activewindow");
481 EXPECT_CONTAINS(str, "fullscreen: 2");
482 EXPECT_CONTAINS(str, "fullscreenClient: 2");
483 }
484
485 OK(getFromSocket("/dispatch hl.dsp.window.kill({ window = 'activewindow' })"));
486 Tests::waitUntilWindowsN(1);
487
488 {
489 auto str = getFromSocket("/activewindow");
490 EXPECT_CONTAINS(str, "fullscreen: 0");
491 EXPECT_CONTAINS(str, "fullscreenClient: 0");
492 }
493
494 Tests::spawnKitty("kitty_B");
495 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
496 OK(getFromSocket("/eval hl.config({ misc = { exit_window_retains_fullscreen = true } })"));
497
498 OK(getFromSocket("/dispatch hl.dsp.window.kill({ window = 'activewindow' })"));
499 Tests::waitUntilWindowsN(1);
500
501 {
502 auto str = getFromSocket("/activewindow");
503 EXPECT_CONTAINS(str, "fullscreen: 2");
504 EXPECT_CONTAINS(str, "fullscreenClient: 2");
505 }
506
507 Tests::killAllWindows();
508 }
509
510 TEST_CASE(dwindleFullscreenPinnedWindows) {
511
512 // Shared test among all default handled FS
513
514 /*
515
516 allow_pin_fullscreen -> Allow internal FSing a pinned window at all?
517
518 if true: FSed pinned window doesn't behave as pinned while it is FS but continues to behave as pinned when it's unFS
519 if false: doesn't allow FSing it at all (client can be set if de-syncing internal and client)
520
521 */
522
523 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
524
525 Tests::spawnKitty("cake");
526
527 OK(getFromSocket("/dispatch hl.dsp.window.float({action = 'enable', window = 'class:cake'})"));
528
529 // resize to expected floating value: 200 x 200
530 OK(getFromSocket("/dispatch hl.dsp.window.resize({x = 200, y = 200, relative = false, window = 'class:cake'})"));
531
532 // Workspace we are testing on: 1
533 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
534
535 // Pin the window
536 OK(getFromSocket("r/dispatch hl.dsp.window.pin({ window = 'class:cake' })"));
537
538 // set to false, try to FS; expect the cake to be a lie
539 OK(getFromSocket("r/eval hl.config({ binds = { allow_pin_fullscreen = false } })"));
540 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:cake'})"));
541
542 // Try with fullscreen
543 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
544 {
545 auto str = getFromSocket("/activewindow");
546 EXPECT_CONTAINS(str, "class: cake");
547 EXPECT_CONTAINS(str, "pinned: 1");
548 EXPECT_CONTAINS(str, "pinFullscreened: 0");
549 EXPECT_CONTAINS(str, "fullscreen: 0");
550 EXPECT_CONTAINS(str, "fullscreenClient: 0");
551 EXPECT_CONTAINS(str, "size: 200,200");
552 }
553
554 // Try with maximised
555 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
556 {
557 auto str = getFromSocket("/activewindow");
558 EXPECT_CONTAINS(str, "class: cake");
559 EXPECT_CONTAINS(str, "pinned: 1");
560 EXPECT_CONTAINS(str, "pinFullscreened: 0");
561 EXPECT_CONTAINS(str, "fullscreen: 0");
562 EXPECT_CONTAINS(str, "fullscreenClient: 0");
563 EXPECT_CONTAINS(str, "size: 200,200");
564 }
565
566 // Move to another workspace, expect it to follow
567 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
568 {
569 auto str = getFromSocket("/clients");
570 EXPECT_CONTAINS(str, "class: cake");
571 EXPECT_CONTAINS(str, "pinned: 1");
572 EXPECT_CONTAINS(str, "pinFullscreened: 0");
573 EXPECT_CONTAINS(str, "fullscreen: 0");
574 EXPECT_CONTAINS(str, "fullscreenClient: 0");
575 EXPECT_CONTAINS(str, "size: 200,200");
576 EXPECT_CONTAINS(str, "workspace: 2");
577 }
578
579 // Move back to primary testing workspace, assumed it'll follow since the last test passed
580 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
581
582 // While syncing FS state, is not supposed to set either mode. If internal and client are decoupled, client is expected to go through
583 // Try with fullscreen
584 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 2, client = 2, action = 'set', window = 'activewindow' })"));
585 {
586 auto str = getFromSocket("/clients");
587 EXPECT_CONTAINS(str, "class: cake");
588 EXPECT_CONTAINS(str, "pinned: 1");
589 EXPECT_CONTAINS(str, "pinFullscreened: 0");
590 EXPECT_CONTAINS(str, "fullscreen: 0");
591 EXPECT_CONTAINS(str, "fullscreenClient: 2");
592 EXPECT_CONTAINS(str, "size: 200,200");
593 EXPECT_CONTAINS(str, "workspace: 1");
594 }
595
596 // Try with maximised
597 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 1, client = 1, action = 'set', window = 'activewindow' })"));
598 {
599 auto str = getFromSocket("/clients");
600 EXPECT_CONTAINS(str, "class: cake");
601 EXPECT_CONTAINS(str, "pinned: 1");
602 EXPECT_CONTAINS(str, "pinFullscreened: 0");
603 EXPECT_CONTAINS(str, "fullscreen: 0");
604 EXPECT_CONTAINS(str, "fullscreenClient: 1");
605 EXPECT_CONTAINS(str, "size: 200,200");
606 EXPECT_CONTAINS(str, "workspace: 1");
607 }
608
609 // re-set its FS values for the next test
610 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 0, client = 0, action = 'set', window = 'activewindow' })"));
611
612 // set to true, try to FS; expect the cake to be real
613 OK(getFromSocket("r/eval hl.config({ binds = { allow_pin_fullscreen = true } })"));
614 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:cake'})"));
615
616 // Try with fullscreen
617 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
618 {
619 auto str = getFromSocket("/activewindow");
620 EXPECT_CONTAINS(str, "class: cake");
621 EXPECT_CONTAINS(str, "pinned: 0");
622 EXPECT_CONTAINS(str, "pinFullscreened: 1");
623 EXPECT_CONTAINS(str, "fullscreen: 2");
624 EXPECT_CONTAINS(str, "fullscreenClient: 2");
625 EXPECT_CONTAINS(str, "at: 0,0");
626 ASSERT_CONTAINS(str, "size: 1920,1080");
627 }
628
629 // Try with maximised
630 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
631 {
632 auto str = getFromSocket("/activewindow");
633 EXPECT_CONTAINS(str, "class: cake");
634 EXPECT_CONTAINS(str, "pinned: 0");
635 EXPECT_CONTAINS(str, "pinFullscreened: 1");
636 EXPECT_CONTAINS(str, "fullscreen: 1");
637 EXPECT_CONTAINS(str, "fullscreenClient: 1");
638 EXPECT_CONTAINS(str, "at: 2,2");
639 EXPECT_CONTAINS(str, "size: 1916,1076");
640 }
641
642 // unFs it, move to another workspace - expect it to follow
643 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 0, client = 0, action = 'set', window = 'activewindow' })"));
644 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
645 {
646 auto str = getFromSocket("/clients");
647 EXPECT_CONTAINS(str, "class: cake");
648 // After the FSed pinned window is unFSed, expect its pinned value to come back
649 EXPECT_CONTAINS(str, "pinned: 1");
650 EXPECT_CONTAINS(str, "pinFullscreened: 0");
651 EXPECT_CONTAINS(str, "fullscreen: 0");
652 EXPECT_CONTAINS(str, "fullscreenClient: 0");
653 EXPECT_CONTAINS(str, "size: 200,200");
654 EXPECT_CONTAINS(str, "workspace: 2");
655 }
656
657 // set the variable to false, unpin it and expect it to be FS-able
658 OK(getFromSocket("r/eval hl.config({ binds = { allow_pin_fullscreen = false } })"));
659 OK(getFromSocket("r/dispatch hl.dsp.window.pin({ window = 'class:cake' })"));
660
661 // Try with fullscreen
662 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
663 {
664 auto str = getFromSocket("/activewindow");
665 EXPECT_CONTAINS(str, "class: cake");
666 EXPECT_CONTAINS(str, "pinned: 0");
667 EXPECT_CONTAINS(str, "pinFullscreened: 0");
668 EXPECT_CONTAINS(str, "fullscreen: 2");
669 EXPECT_CONTAINS(str, "fullscreenClient: 2");
670 EXPECT_CONTAINS(str, "at: 0,0");
671 ASSERT_CONTAINS(str, "size: 1920,1080");
672 }
673
674 // Try with maximised
675 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
676 {
677 auto str = getFromSocket("/activewindow");
678 EXPECT_CONTAINS(str, "class: cake");
679 EXPECT_CONTAINS(str, "pinned: 0");
680 EXPECT_CONTAINS(str, "pinFullscreened: 0");
681 EXPECT_CONTAINS(str, "fullscreen: 1");
682 EXPECT_CONTAINS(str, "fullscreenClient: 1");
683 EXPECT_CONTAINS(str, "at: 2,2");
684 EXPECT_CONTAINS(str, "size: 1916,1076");
685 }
686 }
687
688 TEST_CASE(dwindleFullscreenNonInterference) {
689
690 // Shared test among all default handled FS
691
692 /*
693
694 When a tiled/floating window is default handled FSed, it must not cause the windows under it to have moved/resized after it is unFSed
695
696 also tests if floating pos/size is properly restored after fS-unfs
697
698 */
699
700 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
701
702 Tests::spawnKitty("red");
703 Tests::spawnKitty("crimson");
704 Tests::spawnKitty("blue");
705 Tests::spawnKitty("cyan");
706 Tests::spawnKitty("azure");
707 Tests::spawnKitty("green");
708
709 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
710
711 // Testing tiled first
712 {
713
714 // save all pos/size inc red
715
716 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
717 auto redPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
718 auto redSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
719
720 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:crimson' })"));
721 auto crimsonPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
722 auto crimsonSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
723
724 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:blue' })"));
725 auto bluePos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
726 auto blueSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
727
728 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:cyan' })"));
729 auto cyanPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
730 auto cyanSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
731
732 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:azure' })"));
733 auto azurePos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
734 auto azureSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
735
736 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:green' })"));
737 auto greenPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
738 auto greenSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
739
740 // FS and unFS red, then check all positions are unchanged
741 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
742 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
743 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
744
745 // red
746 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
747 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), redPos);
748 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), redSize);
749
750 // crimson
751 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:crimson' })"));
752 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), crimsonPos);
753 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), crimsonSize);
754
755 // blue
756 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:blue' })"));
757 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), bluePos);
758 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), blueSize);
759
760 // cyan
761 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:cyan' })"));
762 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), cyanPos);
763 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), cyanSize);
764
765 // azure
766 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:azure' })"));
767 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), azurePos);
768 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), azureSize);
769
770 // green
771 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:green' })"));
772 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), greenPos);
773 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), greenSize);
774 }
775
776 // test floating
777
778 {
779
780 // float red
781 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:red' })"));
782
783 // save all pos/size (red's size will be its floating size)
784 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
785 auto redPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
786 auto redSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
787
788 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:crimson' })"));
789 auto crimsonPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
790 auto crimsonSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
791
792 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:blue' })"));
793 auto bluePos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
794 auto blueSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
795
796 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:cyan' })"));
797 auto cyanPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
798 auto cyanSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
799
800 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:azure' })"));
801 auto azurePos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
802 auto azureSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
803
804 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:green' })"));
805 auto greenPos = Tests::getAttribute(getFromSocket("/activewindow"), "at");
806 auto greenSize = Tests::getAttribute(getFromSocket("/activewindow"), "size");
807
808 // FS and unFS red, then check all positions are unchanged
809 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
810 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
811 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
812
813 // red
814 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:red' })"));
815 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), redPos);
816 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), redSize);
817
818 // crimson
819 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:crimson' })"));
820 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), crimsonPos);
821 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), crimsonSize);
822
823 // blue
824 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:blue' })"));
825 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), bluePos);
826 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), blueSize);
827
828 // cyan
829 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:cyan' })"));
830 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), cyanPos);
831 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), cyanSize);
832
833 // azure
834 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:azure' })"));
835 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), azurePos);
836 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), azureSize);
837
838 // green
839 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:green' })"));
840 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "at"), greenPos);
841 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "size"), greenSize);
842 }
843 }
844
845 TEST_CASE(defaultHandledFsfocusInDirection) {
846
847 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
848
849 /*
850 This test serves as a test for all layouts that use deafult FS behaviour
851 */
852
853 Tests::spawnKitty("normal1");
854 Tests::spawnKitty("fs");
855 Tests::spawnKitty("normal2");
856
857 // if movefocus_cycles_fullscreen = false, all focus({direction}) is disallowed from moving focus from FS window
858 OK(getFromSocket("r/eval hl.config({ binds = { movefocus_cycles_fullscreen = false } })"));
859
860 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:fs' })"));
861 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set', window = 'class:fs' })"));
862
863 // on_focus_under_fullscreen = 0
864 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
865
866 {
867 auto str = getFromSocket("/activewindow");
868 EXPECT_CONTAINS(str, "class: fs");
869 EXPECT_CONTAINS(str, "fullscreen: 2");
870 EXPECT_CONTAINS(str, "fullscreenClient: 2");
871 }
872
873 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
874 {
875 auto str = getFromSocket("/activewindow");
876 EXPECT_CONTAINS(str, "class: fs");
877 EXPECT_CONTAINS(str, "fullscreen: 2");
878 EXPECT_CONTAINS(str, "fullscreenClient: 2");
879 }
880
881 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
882 {
883 auto str = getFromSocket("/activewindow");
884 EXPECT_CONTAINS(str, "class: fs");
885 EXPECT_CONTAINS(str, "fullscreen: 2");
886 EXPECT_CONTAINS(str, "fullscreenClient: 2");
887 }
888
889 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'up' })"));
890 {
891 auto str = getFromSocket("/activewindow");
892 EXPECT_CONTAINS(str, "class: fs");
893 EXPECT_CONTAINS(str, "fullscreen: 2");
894 EXPECT_CONTAINS(str, "fullscreenClient: 2");
895 }
896
897 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'down' })"));
898 {
899 auto str = getFromSocket("/activewindow");
900 EXPECT_CONTAINS(str, "class: fs");
901 EXPECT_CONTAINS(str, "fullscreen: 2");
902 EXPECT_CONTAINS(str, "fullscreenClient: 2");
903 }
904
905 // on_focus_under_fullscreen = 1
906 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 1 } })"));
907
908 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
909 {
910 auto str = getFromSocket("/activewindow");
911 EXPECT_CONTAINS(str, "class: fs");
912 EXPECT_CONTAINS(str, "fullscreen: 2");
913 EXPECT_CONTAINS(str, "fullscreenClient: 2");
914 }
915
916 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
917 {
918 auto str = getFromSocket("/activewindow");
919 EXPECT_CONTAINS(str, "class: fs");
920 EXPECT_CONTAINS(str, "fullscreen: 2");
921 EXPECT_CONTAINS(str, "fullscreenClient: 2");
922 }
923
924 // on_focus_under_fullscreen = 2
925 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
926
927 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
928 {
929 auto str = getFromSocket("/activewindow");
930 EXPECT_CONTAINS(str, "class: fs");
931 EXPECT_CONTAINS(str, "fullscreen: 2");
932 EXPECT_CONTAINS(str, "fullscreenClient: 2");
933 }
934
935 // if movefocus_cycles_fullscreen = true
936
937 OK(getFromSocket("r/eval hl.config({ binds = { movefocus_cycles_fullscreen = true } })"));
938
939 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:fs' })"));
940 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set', window = 'class:fs' })"));
941
942 // on_focus_under_fullscreen = 0
943 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
944
945 {
946 auto str = getFromSocket("/activewindow");
947 EXPECT_CONTAINS(str, "class: fs");
948 EXPECT_CONTAINS(str, "fullscreen: 2");
949 EXPECT_CONTAINS(str, "fullscreenClient: 2");
950 }
951
952 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
953 {
954 auto str = getFromSocket("/activewindow");
955 EXPECT_CONTAINS(str, "class: fs");
956 EXPECT_CONTAINS(str, "fullscreen: 2");
957 EXPECT_CONTAINS(str, "fullscreenClient: 2");
958 }
959
960 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
961 {
962 auto str = getFromSocket("/activewindow");
963 EXPECT_CONTAINS(str, "class: fs");
964 EXPECT_CONTAINS(str, "fullscreen: 2");
965 EXPECT_CONTAINS(str, "fullscreenClient: 2");
966 }
967
968 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'up' })"));
969 {
970 auto str = getFromSocket("/activewindow");
971 EXPECT_CONTAINS(str, "class: fs");
972 EXPECT_CONTAINS(str, "fullscreen: 2");
973 EXPECT_CONTAINS(str, "fullscreenClient: 2");
974 }
975
976 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'down' })"));
977 {
978 auto str = getFromSocket("/activewindow");
979 EXPECT_CONTAINS(str, "class: fs");
980 EXPECT_CONTAINS(str, "fullscreen: 2");
981 EXPECT_CONTAINS(str, "fullscreenClient: 2");
982 }
983
984 // on_focus_under_fullscreen = 1
985 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 1 } })"));
986
987 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
988 {
989 auto str = getFromSocket("/activewindow");
990 EXPECT_CONTAINS(str, "class: normal1");
991 EXPECT_CONTAINS(str, "fullscreen: 2");
992 EXPECT_CONTAINS(str, "fullscreenClient: 2");
993 }
994
995 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
996 {
997 auto str = getFromSocket("/activewindow");
998 EXPECT_CONTAINS(str, "class: fs");
999 EXPECT_CONTAINS(str, "fullscreen: 2");
1000 EXPECT_CONTAINS(str, "fullscreenClient: 2");
1001 }
1002
1003 // on_focus_under_fullscreen = 2
1004 OK(getFromSocket("r/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
1005
1006 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
1007 {
1008 auto str = getFromSocket("/activewindow");
1009 EXPECT_CONTAINS(str, "class: normal1");
1010 EXPECT_CONTAINS(str, "fullscreen: 0");
1011 EXPECT_CONTAINS(str, "fullscreenClient: 0");
1012 }
1013 }