Debian Codegraph @

hyprtester/src/tests/main/workspaces.cpp

raw
1 #include "tests.hpp"
2 #include "../../shared.hpp"
3 #include "../../hyprctlCompat.hpp"
4 #include <hyprutils/os/Process.hpp>
5 #include <hyprutils/memory/WeakPtr.hpp>
6 #include <hyprutils/utils/ScopeGuard.hpp>
7 #include "../shared.hpp"
8
9 #include <chrono>
10 #include <string>
11 #include <thread>
12
13 using namespace Hyprutils::OS;
14 using namespace Hyprutils::Memory;
15 using namespace Hyprutils::Utils;
16
17 #define UP CUniquePointer
18 #define SP CSharedPointer
19
20 static bool waitForMonitorListed(const char* name, bool listed) {
21 for (int i = 0; i < 50; ++i) {
22 if (getFromSocket("/monitors").contains(name) == listed)
23 return true;
24
25 std::this_thread::sleep_for(std::chrono::milliseconds(100));
26 }
27
28 return false;
29 }
30
31 // All the `SUBTEST`s below are supposed to be independent `TEST_CASE`s.
32 // But if isolated trivially, some of them fail.
33 // TODO: investigate and isolate tests by turning `SUBTEST`s into `TEST_CASE`s.
34
35 SUBTEST(specialWorkspaceFullscreen) {
36 NLog::log("{}Testing special workspace fullscreen detection", Colors::YELLOW);
37
38 CScopeGuard guard = {[&]() {
39 NLog::log("{}Cleaning up special workspace fullscreen test", Colors::YELLOW);
40 // Close special workspace if open
41 auto monitors = getFromSocket("/monitors");
42 if (monitors.contains("(special:test_fs_special)") && !monitors.contains("special workspace: 0 ()"))
43 getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')");
44 Tests::killAllWindows();
45 OK(getFromSocket("/reload"));
46 }};
47
48 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");
49 ASSERT(Tests::windowCount(), 0);
50
51 NLog::log("{}Test 1: Fullscreen detection on special workspace", Colors::YELLOW);
52
53 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:test_fs_special' })"));
54
55 if (!Tests::spawnKitty("kitty_special"))
56 FAIL_TEST("Could not spawn kitty");
57
58 {
59 auto str = getFromSocket("/activewindow");
60 EXPECT_CONTAINS(str, "class: kitty_special");
61 EXPECT_CONTAINS(str, "(special:test_fs_special)");
62 }
63
64 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
65
66 {
67 auto str = getFromSocket("/activewindow");
68 EXPECT_CONTAINS(str, "fullscreen: 2");
69 }
70
71 {
72 auto str = getFromSocket("/monitors");
73 EXPECT_CONTAINS(str, "(special:test_fs_special)");
74 }
75
76 NLog::log("{}Test 2: Special workspace fullscreen precedence", Colors::YELLOW);
77
78 // Close special workspace before spawning on regular workspace
79 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
80 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");
81
82 if (!Tests::spawnKitty("kitty_regular"))
83 FAIL_TEST("Could not spawn kitty");
84
85 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
86
87 {
88 auto str = getFromSocket("/activewindow");
89 EXPECT_CONTAINS(str, "class: kitty_regular");
90 EXPECT_CONTAINS(str, "fullscreen: 2");
91 }
92
93 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
94 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_special' })"));
95
96 {
97 auto str = getFromSocket("/activewindow");
98 EXPECT_CONTAINS(str, "class: kitty_special");
99 }
100
101 NLog::log("{}Test 3: Toggle special workspace hides it", Colors::YELLOW);
102
103 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
104 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_regular' })"));
105
106 {
107 auto str = getFromSocket("/activewindow");
108 EXPECT_CONTAINS(str, "class: kitty_regular");
109 EXPECT_CONTAINS(str, "fullscreen: 2");
110 }
111
112 {
113 auto str = getFromSocket("/monitors");
114 EXPECT_CONTAINS(str, "special workspace: 0 ()");
115 }
116 }
117
118 SUBTEST(asymmetricGaps) {
119 NLog::log("{}Testing asymmetric gap splits", Colors::YELLOW);
120
121 ASSERT(Tests::windowCount(), 0);
122 getFromSocket("/dispatch workspace 1");
123 getFromSocket("/reload");
124
125 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:gap_split_test' })"));
126 OK(getFromSocket("r/eval hl.config({ general = { gaps_in = 0 } })"));
127 OK(getFromSocket("r/eval hl.config({ general = { border_size = 0 } })"));
128 OK(getFromSocket("r/eval hl.config({ dwindle = { split_width_multiplier = 1.0 } })"));
129 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = 'name:gap_split_test', gaps_out = { top = 0, right = 1000, bottom = 0, left = 0 } })"));
130
131 NLog::log("{}Testing default split (force_split = 0)", Colors::YELLOW);
132 OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 0 } })"));
133
134 if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
135 FAIL_TEST("Could not spawn kitty");
136
137 NLog::log("{}Expecting vertical split (B below A)", Colors::YELLOW);
138 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
139 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
140 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
141 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");
142
143 Tests::killAllWindows();
144 ASSERT(Tests::windowCount(), 0);
145
146 NLog::log("{}Testing force_split = 1", Colors::YELLOW);
147 OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 1 } })"));
148
149 if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
150 FAIL_TEST("Could not spawn kitty");
151
152 NLog::log("{}Expecting vertical split (B above A)", Colors::YELLOW);
153 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
154 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
155 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
156 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");
157
158 NLog::log("{}Expecting horizontal split (C left of B)", Colors::YELLOW);
159 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
160
161 if (!Tests::spawnKitty("gaps_kitty_C"))
162 FAIL_TEST("Could not spawn kitty");
163
164 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_C' })"));
165 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
166 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
167 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 460,0");
168
169 Tests::killAllWindows();
170 ASSERT(Tests::windowCount(), 0);
171
172 NLog::log("{}Testing force_split = 2", Colors::YELLOW);
173 OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 2 } })"));
174
175 if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
176 FAIL_TEST("Could not spawn kitty");
177
178 NLog::log("{}Expecting vertical split (B below A)", Colors::YELLOW);
179 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
180 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
181 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
182 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");
183
184 NLog::log("{}Expecting horizontal split (C right of A)", Colors::YELLOW);
185 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
186
187 if (!Tests::spawnKitty("gaps_kitty_C"))
188 FAIL_TEST("Could not spawn kitty");
189
190 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
191 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
192 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_C' })"));
193 EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 460,0");
194
195 // kill all
196 NLog::log("{}Killing all windows", Colors::YELLOW);
197 Tests::killAllWindows();
198 }
199
200 SUBTEST(workspaceHistoryMultiMon) {
201 NLog::log("{}Testing multimon workspace history tracker", Colors::YELLOW);
202
203 // Initial state:
204 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
205 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '10' })"));
206 Tests::spawnKitty();
207 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '11' })"));
208 Tests::spawnKitty();
209
210 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
211 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '12' })"));
212 Tests::spawnKitty();
213
214 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
215 {
216 auto str = getFromSocket("/activeworkspace");
217 EXPECT_CONTAINS(str, "workspace ID 11");
218 }
219 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous_per_monitor' })"));
220 {
221 auto str = getFromSocket("/activeworkspace");
222 EXPECT_CONTAINS(str, "workspace ID 10");
223 }
224
225 NLog::log("{}Killing all windows", Colors::YELLOW);
226 Tests::killAllWindows();
227 }
228
229 SUBTEST(multimonBAF) {
230 NLog::log("{}Testing multimon back and forth", Colors::YELLOW);
231
232 OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = 1 } })"));
233
234 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
235 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
236
237 Tests::spawnKitty();
238
239 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
240
241 Tests::spawnKitty();
242
243 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
244 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
245
246 Tests::spawnKitty();
247
248 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
249
250 {
251 auto str = getFromSocket("/activeworkspace");
252 EXPECT_CONTAINS(str, "workspace ID 2 ");
253 }
254
255 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '4' })"));
256 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '4' })"));
257
258 {
259 auto str = getFromSocket("/activeworkspace");
260 EXPECT_CONTAINS(str, "workspace ID 2 ");
261 }
262
263 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
264
265 {
266 auto str = getFromSocket("/activeworkspace");
267 EXPECT_CONTAINS(str, "workspace ID 4 ");
268 }
269
270 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
271 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
272
273 {
274 auto str = getFromSocket("/activeworkspace");
275 EXPECT_CONTAINS(str, "workspace ID 4 ");
276 }
277
278 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
279 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
280 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
281 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
282
283 {
284 auto str = getFromSocket("/activeworkspace");
285 EXPECT_CONTAINS(str, "workspace ID 3 ");
286 }
287
288 Tests::killAllWindows();
289 }
290
291 SUBTEST(multimonFocus) {
292 NLog::log("{}Testing multimon focus and move", Colors::YELLOW);
293
294 OK(getFromSocket("/eval hl.config({ input = { follow_mouse = 0 } })"));
295 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
296 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '8' })"));
297 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
298 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '7' })"));
299
300 for (auto const& win : {"a", "b"}) {
301 if (!Tests::spawnKitty(win))
302 FAIL_TEST("Could not spawn kitty with win class `{}`", win);
303 }
304
305 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })"));
306 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
307
308 {
309 auto str = getFromSocket("/activeworkspace");
310 EXPECT_CONTAINS(str, "workspace ID 7 ");
311 }
312
313 {
314 auto str = getFromSocket("/activewindow");
315 EXPECT_CONTAINS(str, "class: b");
316 }
317
318 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
319
320 {
321 auto str = getFromSocket("/activeworkspace");
322 EXPECT_CONTAINS(str, "workspace ID 8 ");
323 }
324
325 Tests::spawnKitty("c");
326
327 {
328 auto str = getFromSocket("/activewindow");
329 EXPECT_CONTAINS(str, "class: c");
330 }
331
332 {
333 auto str = getFromSocket("/activeworkspace");
334 EXPECT_CONTAINS(str, "workspace ID 8 ");
335 }
336
337 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
338
339 {
340 auto str = getFromSocket("/activewindow");
341 EXPECT_CONTAINS(str, "class: b");
342 }
343
344 {
345 auto str = getFromSocket("/activeworkspace");
346 EXPECT_CONTAINS(str, "workspace ID 7 ");
347 }
348
349 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right' })"));
350
351 {
352 auto str = getFromSocket("/activewindow");
353 ASSERT_CONTAINS(str, "class: b");
354 }
355
356 {
357 auto str = getFromSocket("/activeworkspace");
358 ASSERT_CONTAINS(str, "workspace ID 8 ");
359 }
360
361 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
362
363 {
364 auto str = getFromSocket("/activewindow");
365 ASSERT_CONTAINS(str, "class: c");
366 }
367
368 {
369 auto str = getFromSocket("/activeworkspace");
370 ASSERT_CONTAINS(str, "workspace ID 8 ");
371 }
372
373 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));
374
375 OK(getFromSocket("/eval hl.config({ general = { no_focus_fallback = true } })"));
376 OK(getFromSocket("/eval hl.config({ binds = { window_direction_monitor_fallback = false } })"));
377
378 ASSERT_NOT(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"), "ok");
379
380 {
381 auto str = getFromSocket("/activewindow");
382 ASSERT_CONTAINS(str, "class: b");
383 }
384
385 {
386 auto str = getFromSocket("/activeworkspace");
387 ASSERT_CONTAINS(str, "workspace ID 8 ");
388 }
389
390 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'left' })"));
391
392 {
393 auto str = getFromSocket("/activewindow");
394 ASSERT_CONTAINS(str, "class: b");
395 }
396
397 {
398 auto str = getFromSocket("/activeworkspace");
399 ASSERT_CONTAINS(str, "workspace ID 8 ");
400 }
401
402 OK(getFromSocket("/reload"));
403
404 Tests::killAllWindows();
405 }
406
407 SUBTEST(dynamicWsEffects) {
408 // test dynamic workspace effects, they shouldn't lag
409
410 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '69' })"));
411
412 Tests::spawnKitty("bitch");
413
414 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '69', border_size = 20 })"));
415 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '69', no_rounding = true })"));
416
417 ASSERT(getFromSocket("/getprop class:bitch border_size"), "20");
418 ASSERT(getFromSocket("/getprop class:bitch rounding"), "0");
419
420 OK(getFromSocket("/reload"));
421
422 Tests::killAllWindows();
423 }
424
425 // TODO: decompose this into multiple test cases
426 TEST_CASE(workspacesCombined) {
427 NLog::log("{}Checking persistent no-mon", Colors::YELLOW);
428 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '966', persistent = true })"));
429
430 {
431 auto str = getFromSocket("/workspaces");
432 ASSERT_CONTAINS(str, "workspace ID 966 (966)");
433 }
434
435 OK(getFromSocket("/reload"));
436
437 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
438
439 NLog::log("{}Spawning kittyProc on ws 1", Colors::YELLOW);
440 auto kittyProcA = Tests::spawnKitty();
441
442 if (!kittyProcA)
443 FAIL_TEST("Could not spawn kitty");
444
445 NLog::log("{}Switching to workspace 3", Colors::YELLOW);
446 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
447
448 NLog::log("{}Spawning kittyProc on ws 3", Colors::YELLOW);
449 auto kittyProcB = Tests::spawnKitty();
450
451 if (!kittyProcB)
452 FAIL_TEST("Could not spawn kitty");
453
454 NLog::log("{}Switching to workspace 1", Colors::YELLOW);
455 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
456
457 NLog::log("{}Switching to workspace +1", Colors::YELLOW);
458 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '+1' })"));
459
460 {
461 auto str = getFromSocket("/activeworkspace");
462 ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
463 }
464
465 // check if the other workspaces are alive
466 {
467 auto str = getFromSocket("/workspaces");
468 ASSERT_CONTAINS(str, "workspace ID 3 (3)");
469 ASSERT_CONTAINS(str, "workspace ID 1 (1)");
470 }
471
472 NLog::log("{}Switching to workspace 1", Colors::YELLOW);
473 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
474
475 {
476 auto str = getFromSocket("/workspaces");
477 ASSERT_NOT_CONTAINS(str, "workspace ID 2 (2)");
478 }
479
480 NLog::log("{}Switching to workspace m+1", Colors::YELLOW);
481 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'm+1' })"));
482
483 {
484 auto str = getFromSocket("/activeworkspace");
485 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
486 }
487
488 NLog::log("{}Switching to workspace -1", Colors::YELLOW);
489 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '-1' })"));
490
491 {
492 auto str = getFromSocket("/activeworkspace");
493 ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
494 }
495
496 NLog::log("{}Switching to workspace 1", Colors::YELLOW);
497 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
498
499 NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
500 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));
501
502 {
503 auto str = getFromSocket("/activeworkspace");
504 ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
505 }
506
507 NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
508 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));
509
510 {
511 auto str = getFromSocket("/activeworkspace");
512 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
513 }
514
515 NLog::log("{}Switching to workspace r~1", Colors::YELLOW);
516 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r~1' })"));
517
518 {
519 auto str = getFromSocket("/activeworkspace");
520 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
521 }
522
523 NLog::log("{}Switching to workspace empty", Colors::YELLOW);
524 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'empty' })"));
525
526 {
527 auto str = getFromSocket("/activeworkspace");
528 ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
529 }
530
531 NLog::log("{}Switching to workspace previous", Colors::YELLOW);
532 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));
533
534 {
535 auto str = getFromSocket("/activeworkspace");
536 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
537 }
538
539 NLog::log("{}Switching to workspace name:TEST_WORKSPACE_NULL", Colors::YELLOW);
540 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:TEST_WORKSPACE_NULL' })"));
541
542 {
543 auto str = getFromSocket("/activeworkspace");
544 ASSERT_STARTS_WITH(str, "workspace ID -1337 (TEST_WORKSPACE_NULL)");
545 }
546
547 NLog::log("{}Switching to workspace 1", Colors::YELLOW);
548 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
549
550 // add a new monitor
551 NLog::log("{}Adding a new monitor", Colors::YELLOW);
552 ASSERT(getFromSocket("/output create headless HEADLESS-3"), "ok");
553
554 // should take workspace 2
555 {
556 auto str = getFromSocket("/monitors");
557 ASSERT_CONTAINS(str, "active workspace: 2 (2)");
558 ASSERT_CONTAINS(str, "active workspace: 1 (1)");
559 ASSERT_CONTAINS(str, "HEADLESS-3");
560 }
561
562 // focus the first monitor
563 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
564
565 {
566 auto str = getFromSocket("/activeworkspace");
567 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
568 }
569
570 NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
571 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));
572
573 {
574 auto str = getFromSocket("/activeworkspace");
575 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
576 }
577
578 NLog::log("{}Switching to workspace r~2", Colors::YELLOW);
579 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
580 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r~2' })"));
581
582 {
583 auto str = getFromSocket("/activeworkspace");
584 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
585 }
586
587 NLog::log("{}Switching to workspace m+1", Colors::YELLOW);
588 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'm+1' })"));
589
590 {
591 auto str = getFromSocket("/activeworkspace");
592 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
593 }
594
595 NLog::log("{}Switching to workspace 1", Colors::YELLOW);
596 // no OK: this will throw an error as it should
597 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");
598
599 {
600 auto str = getFromSocket("/activeworkspace");
601 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
602 }
603
604 NLog::log("{}Testing back_and_forth", Colors::YELLOW);
605 OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = true } })"));
606 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
607
608 {
609 auto str = getFromSocket("/activeworkspace");
610 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
611 }
612
613 OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = false } })"));
614
615 NLog::log("{}Testing hide_special_on_workspace_change", Colors::YELLOW);
616 OK(getFromSocket("/eval hl.config({ binds = { hide_special_on_workspace_change = true } })"));
617 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:HELLO' })"));
618
619 {
620 auto str = getFromSocket("/monitors");
621 ASSERT_CONTAINS(str, "special workspace: -");
622 ASSERT_CONTAINS(str, "special:HELLO");
623 }
624
625 // no OK: will err (it shouldn't prolly but oh well)
626 getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })");
627
628 {
629 auto str = getFromSocket("/monitors");
630 ASSERT_COUNT_STRING(str, "special workspace: 0 ()", 2);
631 }
632
633 OK(getFromSocket("/eval hl.config({ binds = { hide_special_on_workspace_change = false } })"));
634
635 NLog::log("{}Testing allow_workspace_cycles", Colors::YELLOW);
636 OK(getFromSocket("/eval hl.config({ binds = { allow_workspace_cycles = true } })"));
637
638 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
639 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
640 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
641
642 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));
643
644 {
645 auto str = getFromSocket("/activeworkspace");
646 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
647 }
648
649 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));
650
651 {
652 auto str = getFromSocket("/activeworkspace");
653 ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
654 }
655
656 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));
657
658 {
659 auto str = getFromSocket("/activeworkspace");
660 ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
661 }
662
663 OK(getFromSocket("/eval hl.config({ binds = { allow_workspace_cycles = false } })"));
664
665 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
666
667 NLog::log("{}Killing all windows", Colors::YELLOW);
668 Tests::killAllWindows();
669
670 // spawn 3 kitties
671 NLog::log("{}Testing focus_preferred_method", Colors::YELLOW);
672 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })"));
673 Tests::spawnKitty("kitty_A");
674 Tests::spawnKitty("kitty_B");
675 Tests::spawnKitty("kitty_C");
676 OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 0 } })"));
677
678 // focus kitty 2: will be top right (dwindle)
679 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
680
681 // resize it to be a bit taller
682 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 20, y = 20, relative = true })"));
683
684 // now we test focus methods.
685 OK(getFromSocket("/eval hl.config({ binds = { focus_preferred_method = 0 } })"));
686
687 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_C' })"));
688 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
689
690 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
691
692 {
693 auto str = getFromSocket("/activewindow");
694 ASSERT_CONTAINS(str, "class: kitty_C");
695 }
696
697 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
698
699 OK(getFromSocket("/eval hl.config({ binds = { focus_preferred_method = 1 } })"));
700
701 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
702
703 {
704 auto str = getFromSocket("/activewindow");
705 ASSERT_CONTAINS(str, "class: kitty_B");
706 }
707
708 NLog::log("{}Testing movefocus_cycles_fullscreen", Colors::YELLOW);
709 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
710 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
711 Tests::spawnKitty("kitty_D");
712 {
713 auto str = getFromSocket("/activewindow");
714 ASSERT_CONTAINS(str, "class: kitty_D");
715 }
716
717 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'l' })"));
718
719 {
720 auto str = getFromSocket("/activewindow");
721 ASSERT_CONTAINS(str, "class: kitty_A");
722 }
723
724 OK(getFromSocket("/eval hl.config({ binds = { movefocus_cycles_fullscreen = false } })"));
725 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));
726
727 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
728
729 {
730 auto str = getFromSocket("/activewindow");
731 ASSERT_CONTAINS(str, "class: kitty_D");
732 }
733
734 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'l' })"));
735
736 {
737 auto str = getFromSocket("/activewindow");
738 ASSERT_CONTAINS(str, "class: kitty_A");
739 }
740
741 OK(getFromSocket("/eval hl.config({ binds = { movefocus_cycles_fullscreen = true } })"));
742
743 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));
744
745 {
746 auto str = getFromSocket("/activewindow");
747 ASSERT_CONTAINS(str, "class: kitty_B");
748 }
749
750 // kill all
751 NLog::log("{}Killing all windows", Colors::YELLOW);
752 Tests::killAllWindows();
753
754 CALL_SUBTEST(multimonBAF);
755 CALL_SUBTEST(multimonFocus);
756 CALL_SUBTEST(workspaceHistoryMultiMon);
757
758 // destroy the headless output
759 OK(getFromSocket("/output remove HEADLESS-3"));
760
761 CALL_SUBTEST(specialWorkspaceFullscreen);
762 CALL_SUBTEST(asymmetricGaps);
763 CALL_SUBTEST(dynamicWsEffects);
764
765 NLog::log("{}Expecting 0 windows", Colors::YELLOW);
766 ASSERT(Tests::windowCount(), 0);
767 }
768
769 TEST_CASE(workspacesFollowProperNoGaps) {
770 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"100\" })"));
771 OK(getFromSocket(R"#(/eval hl.workspace_rule({ workspace = "w[tv1]", gaps_out = 0, gaps_in = 0 })
772 hl.workspace_rule({ workspace = "f[1]", gaps_out = 0, gaps_in = 0 })
773 hl.window_rule({
774 name = "no-gaps-wtv1",
775 match = { float = false, workspace = "w[tv1]" },
776 border_size = 0,
777 rounding = 0,
778 })
779 hl.window_rule({
780 name = "no-gaps-f1",
781 match = { float = false, workspace = "f[1]" },
782 border_size = 0,
783 rounding = 0,
784 })
785 )#"));
786
787 ASSERT(!!Tests::spawnKitty(), true);
788
789 {
790 auto str = getFromSocket("/activewindow");
791 ASSERT_CONTAINS(str, "size: 1920,1080");
792 }
793
794 ASSERT(!!Tests::spawnKitty(), true);
795
796 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = \"101\" })"));
797
798 {
799 auto str = getFromSocket("/activewindow");
800 ASSERT_CONTAINS(str, "size: 1920,1080");
801 }
802
803 {
804 auto str = getFromSocket("/activeworkspace");
805 ASSERT_CONTAINS(str, "workspace ID 101 (101)");
806 }
807 }
808
809 TEST_CASE(workspacesSmartGapsDirectionalMoveAcrossMonitors) {
810 static constexpr const char* LEFT_OUTPUT = "HSG-L";
811 static constexpr const char* RIGHT_OUTPUT = "HSG-R";
812
813 CScopeGuard guard = {[&]() {
814 Tests::killAllWindows();
815 getFromSocket(std::string("/output remove ") + RIGHT_OUTPUT);
816 getFromSocket(std::string("/output remove ") + LEFT_OUTPUT);
817 OK(getFromSocket("/reload"));
818 }};
819
820 getFromSocket(std::string("/output remove ") + RIGHT_OUTPUT);
821 ASSERT(waitForMonitorListed(RIGHT_OUTPUT, false), true);
822 getFromSocket(std::string("/output remove ") + LEFT_OUTPUT);
823 ASSERT(waitForMonitorListed(LEFT_OUTPUT, false), true);
824
825 OK(getFromSocket(R"#(/eval hl.monitor({ output = "HSG-L", mode = "1920x1080@60", position = "20000x0", scale = "1" })
826 hl.monitor({ output = "HSG-R", mode = "1920x1080@60", position = "21920x0", scale = "1" })
827 )#"));
828
829 OK(getFromSocket(std::string("/output create headless ") + LEFT_OUTPUT));
830 ASSERT(waitForMonitorListed(LEFT_OUTPUT, true), true);
831 OK(getFromSocket(std::string("/output create headless ") + RIGHT_OUTPUT));
832 ASSERT(waitForMonitorListed(RIGHT_OUTPUT, true), true);
833
834 OK(getFromSocket(R"#(/eval hl.config({
835 general = { layout = "dwindle", gaps_out = 20, gaps_in = 5, border_size = 2 },
836 binds = { window_direction_monitor_fallback = true },
837 })
838 hl.workspace_rule({ workspace = "w[tv1]", gaps_out = 0, gaps_in = 0 })
839 hl.window_rule({
840 name = "smart-gaps-single-tiled-no-border",
841 match = { float = false, workspace = "w[tv1]" },
842 border_size = 0,
843 rounding = 0,
844 })
845 )#"));
846
847 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HSG-L' })"));
848 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '230' })"));
849 ASSERT(!!Tests::spawnKitty("smart_gaps_src_a"), true);
850 ASSERT(!!Tests::spawnKitty("smart_gaps_src_b"), true);
851
852 {
853 auto str = getFromSocket("/activewindow");
854 ASSERT_CONTAINS(str, "class: smart_gaps_src_b");
855 ASSERT_CONTAINS(str, "size: 931,1036");
856 }
857
858 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HSG-R' })"));
859 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '231' })"));
860 ASSERT(!!Tests::spawnKitty("smart_gaps_dst"), true);
861
862 {
863 auto str = getFromSocket("/activewindow");
864 ASSERT_CONTAINS(str, "class: smart_gaps_dst");
865 ASSERT_CONTAINS(str, "size: 1920,1080");
866 }
867
868 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:smart_gaps_src_b' })"));
869 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right' })"));
870
871 {
872 auto str = getFromSocket("/activewindow");
873 ASSERT_CONTAINS(str, "class: smart_gaps_src_b");
874 ASSERT_CONTAINS(str, "size: 931,1036");
875 }
876
877 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HSG-L' })"));
878 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:smart_gaps_src_a' })"));
879
880 {
881 auto str = getFromSocket("/activewindow");
882 ASSERT_CONTAINS(str, "class: smart_gaps_src_a");
883 ASSERT_CONTAINS(str, "size: 1920,1080");
884 }
885 }
886
887 TEST_CASE(workspaceRenameChangeID) {
888 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"150\" })"));
889 Tests::spawnKitty();
890
891 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"name:coce\" })"));
892 Tests::spawnKitty();
893
894 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"100\" })"));
895
896 {
897 auto str = getFromSocket("/activeworkspace");
898 ASSERT_CONTAINS(str, "workspace ID 100 (100)");
899 }
900
901 OK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"100\", id = 101 })"));
902
903 {
904 auto str = getFromSocket("/activeworkspace");
905 ASSERT_CONTAINS(str, "workspace ID 101 (101)");
906 }
907
908 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"101\", id = -1 })")); // bad id
909 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"101\", id = \"abc\" })")); // bad id
910 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"101\" })")); // no target
911 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"102\", id = 200 })")); // source doesn't exist
912 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"101\", id = 150 })")); // occupied
913 NOK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"name:coce\", id = 105 })")); // bad source
914
915 {
916 auto str = getFromSocket("/activeworkspace");
917 ASSERT_CONTAINS(str, "workspace ID 101 (101)");
918 }
919
920 OK(getFromSocket("/dispatch hl.dsp.workspace.rename({ workspace = \"101\", name = \"vaxry_was_here\" })"));
921
922 {
923 auto str = getFromSocket("/activeworkspace");
924 ASSERT_CONTAINS(str, "workspace ID 101 (vaxry_was_here)");
925 }
926
927 OK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"101\", id = 102 })"));
928
929 {
930 auto str = getFromSocket("/activeworkspace");
931 ASSERT_CONTAINS(str, "workspace ID 102 (vaxry_was_here)");
932 }
933 }
934
935 TEST_CASE(workspaceChangeIDUpdatesRules) {
936 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"200\" })"));
937
938 {
939 auto str = getFromSocket("/activeworkspace");
940 ASSERT_CONTAINS(str, "workspace ID 200 (200)");
941 }
942
943 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '201', gaps_out = { top = 40, right = 40, bottom = 40, left = 40 } })"));
944
945 Tests::spawnKitty();
946
947 {
948 auto str = getFromSocket("/activewindow");
949 ASSERT_CONTAINS(str, "at: 22,22");
950 }
951
952 OK(getFromSocket("/dispatch hl.dsp.workspace.change_id({ workspace = \"200\", id = 201 })"));
953
954 Tests::sync();
955
956 {
957 auto str = getFromSocket("/activewindow");
958 ASSERT_CONTAINS(str, "at: 42,42");
959 }
960 }
961
962 TEST_CASE(workspaceRenameUpdatesRules) {
963 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = \"200\" })"));
964
965 {
966 auto str = getFromSocket("/activeworkspace");
967 ASSERT_CONTAINS(str, "workspace ID 200 (200)");
968 }
969
970 OK(getFromSocket("r/eval hl.workspace_rule({ workspace = 'name:vaxry', gaps_out = { top = 40, right = 40, bottom = 40, left = 40 } })"));
971
972 Tests::spawnKitty();
973
974 {
975 auto str = getFromSocket("/activewindow");
976 ASSERT_CONTAINS(str, "at: 22,22");
977 }
978
979 OK(getFromSocket("/dispatch hl.dsp.workspace.rename({ workspace = \"200\", name = \"vaxry\" })"));
980
981 Tests::sync();
982
983 {
984 auto str = getFromSocket("/activewindow");
985 ASSERT_CONTAINS(str, "at: 42,42");
986 }
987 }
988
989 TEST_CASE(workspacesDistinctTiledAndFloatGaps) {
990 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'name:workspacesDistinctTiledAndFloatGaps', gaps_out = 200, float_gaps = 10, no_border = true })"));
991 OK(getFromSocket("/eval hl.window_rule({ match = { workspace = 'name:workspacesDistinctTiledAndFloatGaps', class = 'workspacesDistinctTiledAndFloatGaps' }, float = true })"));
992 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:workspacesDistinctTiledAndFloatGaps' })"));
993 ASSERT(!!Tests::spawnKitty(), true);
994 ASSERT(getFromSocket("r/repl hl.get_active_window().at.x == 200"), "true");
995 ASSERT(!!Tests::spawnKitty("workspacesDistinctTiledAndFloatGaps"), true);
996 OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'l' })"));
997 ASSERT(getFromSocket("r/repl hl.get_active_window().at.x == 10"), "true");
998 }