summaryrefslogtreecommitdiff
path: root/hyprtester/src/tests/main/workspaces.cpp
blob: 8cde4914b4678f82cedbc904f31546df0ce556a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
#include "tests.hpp"
#include "../../shared.hpp"
#include "../../hyprctlCompat.hpp"
#include <print>
#include <thread>
#include <chrono>
#include <hyprutils/os/Process.hpp>
#include <hyprutils/memory/WeakPtr.hpp>
#include <hyprutils/utils/ScopeGuard.hpp>
#include <csignal>
#include <cerrno>
#include "../shared.hpp"

using namespace Hyprutils::OS;
using namespace Hyprutils::Memory;
using namespace Hyprutils::Utils;

#define UP CUniquePointer
#define SP CSharedPointer

// All the `SUBTEST`s below are supposed to be independent `TEST_CASE`s.
// But if isolated trivially, some of them fail.
// TODO: investigate and isolate tests by turning `SUBTEST`s into `TEST_CASE`s.

SUBTEST(specialWorkspaceFullscreen) {
    NLog::log("{}Testing special workspace fullscreen detection", Colors::YELLOW);

    CScopeGuard guard = {[&]() {
        NLog::log("{}Cleaning up special workspace fullscreen test", Colors::YELLOW);
        // Close special workspace if open
        auto monitors = getFromSocket("/monitors");
        if (monitors.contains("(special:test_fs_special)") && !monitors.contains("special workspace: 0 ()"))
            getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')");
        Tests::killAllWindows();
        OK(getFromSocket("/reload"));
    }};

    getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");
    ASSERT(Tests::windowCount(), 0);

    NLog::log("{}Test 1: Fullscreen detection on special workspace", Colors::YELLOW);

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:test_fs_special' })"));

    if (!Tests::spawnKitty("kitty_special"))
        FAIL_TEST("Could not spawn kitty");

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: kitty_special");
        EXPECT_CONTAINS(str, "(special:test_fs_special)");
    }

    OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "fullscreen: 2");
    }

    {
        auto str = getFromSocket("/monitors");
        EXPECT_CONTAINS(str, "(special:test_fs_special)");
    }

    NLog::log("{}Test 2: Special workspace fullscreen precedence", Colors::YELLOW);

    // Close special workspace before spawning on regular workspace
    OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
    getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");

    if (!Tests::spawnKitty("kitty_regular"))
        FAIL_TEST("Could not spawn kitty");

    OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: kitty_regular");
        EXPECT_CONTAINS(str, "fullscreen: 2");
    }

    OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_special' })"));

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: kitty_special");
    }

    NLog::log("{}Test 3: Toggle special workspace hides it", Colors::YELLOW);

    OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('test_fs_special')"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_regular' })"));

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: kitty_regular");
        EXPECT_CONTAINS(str, "fullscreen: 2");
    }

    {
        auto str = getFromSocket("/monitors");
        EXPECT_CONTAINS(str, "special workspace: 0 ()");
    }
}

SUBTEST(asymmetricGaps) {
    NLog::log("{}Testing asymmetric gap splits", Colors::YELLOW);

    ASSERT(Tests::windowCount(), 0);
    getFromSocket("/dispatch workspace 1");
    getFromSocket("/reload");

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:gap_split_test' })"));
    OK(getFromSocket("r/eval hl.config({ general = { gaps_in = 0 } })"));
    OK(getFromSocket("r/eval hl.config({ general = { border_size = 0 } })"));
    OK(getFromSocket("r/eval hl.config({ dwindle = { split_width_multiplier = 1.0 } })"));
    OK(getFromSocket("r/eval hl.workspace_rule({ workspace = 'name:gap_split_test', gaps_out = { top = 0, right = 1000, bottom = 0, left = 0 } })"));

    NLog::log("{}Testing default split (force_split = 0)", Colors::YELLOW);
    OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 0 } })"));

    if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
        FAIL_TEST("Could not spawn kitty");

    NLog::log("{}Expecting vertical split (B below A)", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");

    Tests::killAllWindows();
    ASSERT(Tests::windowCount(), 0);

    NLog::log("{}Testing force_split = 1", Colors::YELLOW);
    OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 1 } })"));

    if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
        FAIL_TEST("Could not spawn kitty");

    NLog::log("{}Expecting vertical split (B above A)", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");

    NLog::log("{}Expecting horizontal split (C left of B)", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));

    if (!Tests::spawnKitty("gaps_kitty_C"))
        FAIL_TEST("Could not spawn kitty");

    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_C' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 460,0");

    Tests::killAllWindows();
    ASSERT(Tests::windowCount(), 0);

    NLog::log("{}Testing force_split = 2", Colors::YELLOW);
    OK(getFromSocket("r/eval hl.config({ dwindle = { force_split = 2 } })"));

    if (!Tests::spawnKitty("gaps_kitty_A") || !Tests::spawnKitty("gaps_kitty_B"))
        FAIL_TEST("Could not spawn kitty");

    NLog::log("{}Expecting vertical split (B below A)", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_B' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,540");

    NLog::log("{}Expecting horizontal split (C right of A)", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));

    if (!Tests::spawnKitty("gaps_kitty_C"))
        FAIL_TEST("Could not spawn kitty");

    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_A' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 0,0");
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:gaps_kitty_C' })"));
    EXPECT_CONTAINS(getFromSocket("/activewindow"), "at: 460,0");

    // kill all
    NLog::log("{}Killing all windows", Colors::YELLOW);
    Tests::killAllWindows();
}

SUBTEST(workspaceHistoryMultiMon) {
    NLog::log("{}Testing multimon workspace history tracker", Colors::YELLOW);

    // Initial state:
    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '10' })"));
    Tests::spawnKitty();
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '11' })"));
    Tests::spawnKitty();

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '12' })"));
    Tests::spawnKitty();

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 11");
    }
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous_per_monitor' })"));
    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 10");
    }

    NLog::log("{}Killing all windows", Colors::YELLOW);
    Tests::killAllWindows();
}

SUBTEST(multimonBAF) {
    NLog::log("{}Testing multimon back and forth", Colors::YELLOW);

    OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = 1 } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    Tests::spawnKitty();

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));

    Tests::spawnKitty();

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));

    Tests::spawnKitty();

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 2 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '4' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '4' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 2 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 4 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 4 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 3 ");
    }

    Tests::killAllWindows();
}

SUBTEST(multimonFocus) {
    NLog::log("{}Testing multimon focus and move", Colors::YELLOW);

    OK(getFromSocket("/eval hl.config({ input = { follow_mouse = 0 } })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '8' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '7' })"));

    for (auto const& win : {"a", "b"}) {
        if (!Tests::spawnKitty(win)) {
            FAIL_TEST("Could not spawn kitty with win class `{}`", win);
        }
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 7 ");
    }

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: b");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 8 ");
    }

    Tests::spawnKitty("c");

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: c");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 8 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));

    {
        auto str = getFromSocket("/activewindow");
        EXPECT_CONTAINS(str, "class: b");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        EXPECT_CONTAINS(str, "workspace ID 7 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: b");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_CONTAINS(str, "workspace ID 8 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: c");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_CONTAINS(str, "workspace ID 8 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"));

    OK(getFromSocket("/eval hl.config({ general = { no_focus_fallback = true } })"));
    OK(getFromSocket("/eval hl.config({ binds = { window_direction_monitor_fallback = false } })"));

    ASSERT_NOT(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })"), "ok");

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: b");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_CONTAINS(str, "workspace ID 8 ");
    }

    OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'left' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: b");
    }

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_CONTAINS(str, "workspace ID 8 ");
    }

    OK(getFromSocket("/reload"));

    Tests::killAllWindows();
}

SUBTEST(dynamicWsEffects) {
    // test dynamic workspace effects, they shouldn't lag

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '69' })"));

    Tests::spawnKitty("bitch");

    OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '69', border_size = 20 })"));
    OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '69', no_rounding = true })"));

    ASSERT(getFromSocket("/getprop class:bitch border_size"), "20");
    ASSERT(getFromSocket("/getprop class:bitch rounding"), "0");

    OK(getFromSocket("/reload"));

    Tests::killAllWindows();
}

// TODO: decompose this into multiple test cases
TEST_CASE(workspacesCombined) {
    NLog::log("{}Checking persistent no-mon", Colors::YELLOW);
    OK(getFromSocket("r/eval hl.workspace_rule({ workspace = '966', persistent = true })"));

    {
        auto str = getFromSocket("/workspaces");
        ASSERT_CONTAINS(str, "workspace ID 966 (966)");
    }

    OK(getFromSocket("/reload"));

    NLog::log("{}Spawning kittyProc on ws 1", Colors::YELLOW);
    auto kittyProcA = Tests::spawnKitty();

    if (!kittyProcA)
        FAIL_TEST("Could not spawn kitty");

    NLog::log("{}Switching to workspace 3", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));

    NLog::log("{}Spawning kittyProc on ws 3", Colors::YELLOW);
    auto kittyProcB = Tests::spawnKitty();

    if (!kittyProcB)
        FAIL_TEST("Could not spawn kitty");

    NLog::log("{}Switching to workspace 1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    NLog::log("{}Switching to workspace +1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
    }

    // check if the other workspaces are alive
    {
        auto str = getFromSocket("/workspaces");
        ASSERT_CONTAINS(str, "workspace ID 3 (3)");
        ASSERT_CONTAINS(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Switching to workspace 1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    {
        auto str = getFromSocket("/workspaces");
        ASSERT_NOT_CONTAINS(str, "workspace ID 2 (2)");
    }

    NLog::log("{}Switching to workspace m+1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'm+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    NLog::log("{}Switching to workspace -1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '-1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
    }

    NLog::log("{}Switching to workspace 1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
    }

    NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    NLog::log("{}Switching to workspace r~1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r~1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Switching to workspace empty", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'empty' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 2 (2)");
    }

    NLog::log("{}Switching to workspace previous", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Switching to workspace name:TEST_WORKSPACE_NULL", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:TEST_WORKSPACE_NULL' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID -1337 (TEST_WORKSPACE_NULL)");
    }

    NLog::log("{}Switching to workspace 1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    // add a new monitor
    NLog::log("{}Adding a new monitor", Colors::YELLOW);
    ASSERT(getFromSocket("/output create headless"), "ok");

    // should take workspace 2
    {
        auto str = getFromSocket("/monitors");
        ASSERT_CONTAINS(str, "active workspace: 2 (2)");
        ASSERT_CONTAINS(str, "active workspace: 1 (1)");
        ASSERT_CONTAINS(str, "HEADLESS-3");
    }

    // focus the first monitor
    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Switching to workspace r+1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    NLog::log("{}Switching to workspace r~2", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'r~2' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    NLog::log("{}Switching to workspace m+1", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'm+1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Switching to workspace 1", Colors::YELLOW);
    // no OK: this will throw an error as it should
    getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    NLog::log("{}Testing back_and_forth", Colors::YELLOW);
    OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = true } })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    OK(getFromSocket("/eval hl.config({ binds = { workspace_back_and_forth = false } })"));

    NLog::log("{}Testing hide_special_on_workspace_change", Colors::YELLOW);
    OK(getFromSocket("/eval hl.config({ binds = { hide_special_on_workspace_change = true } })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:HELLO' })"));

    {
        auto str = getFromSocket("/monitors");
        ASSERT_CONTAINS(str, "special workspace: -");
        ASSERT_CONTAINS(str, "special:HELLO");
    }

    // no OK: will err (it shouldn't prolly but oh well)
    getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })");

    {
        auto str = getFromSocket("/monitors");
        ASSERT_COUNT_STRING(str, "special workspace: 0 ()", 2);
    }

    OK(getFromSocket("/eval hl.config({ binds = { hide_special_on_workspace_change = false } })"));

    NLog::log("{}Testing allow_workspace_cycles", Colors::YELLOW);
    OK(getFromSocket("/eval hl.config({ binds = { allow_workspace_cycles = true } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 1 (1)");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'previous' })"));

    {
        auto str = getFromSocket("/activeworkspace");
        ASSERT_STARTS_WITH(str, "workspace ID 3 (3)");
    }

    OK(getFromSocket("/eval hl.config({ binds = { allow_workspace_cycles = false } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));

    NLog::log("{}Killing all windows", Colors::YELLOW);
    Tests::killAllWindows();

    // spawn 3 kitties
    NLog::log("{}Testing focus_preferred_method", Colors::YELLOW);
    OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })"));
    Tests::spawnKitty("kitty_A");
    Tests::spawnKitty("kitty_B");
    Tests::spawnKitty("kitty_C");
    OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 0 } })"));

    // focus kitty 2: will be top right (dwindle)
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));

    // resize it to be a bit taller
    OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 20, y = 20, relative = true })"));

    // now we test focus methods.
    OK(getFromSocket("/eval hl.config({ binds = { focus_preferred_method = 0 } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_C' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_C");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));

    OK(getFromSocket("/eval hl.config({ binds = { focus_preferred_method = 1 } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_B");
    }

    NLog::log("{}Testing movefocus_cycles_fullscreen", Colors::YELLOW);
    OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-3' })"));
    Tests::spawnKitty("kitty_D");
    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_D");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'l' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_A");
    }

    OK(getFromSocket("/eval hl.config({ binds = { movefocus_cycles_fullscreen = false } })"));
    OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen' })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_D");
    }

    OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'l' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_A");
    }

    OK(getFromSocket("/eval hl.config({ binds = { movefocus_cycles_fullscreen = true } })"));

    OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'right' })"));

    {
        auto str = getFromSocket("/activewindow");
        ASSERT_CONTAINS(str, "class: kitty_B");
    }

    // kill all
    NLog::log("{}Killing all windows", Colors::YELLOW);
    Tests::killAllWindows();

    CALL_SUBTEST(multimonBAF);
    CALL_SUBTEST(multimonFocus);
    CALL_SUBTEST(workspaceHistoryMultiMon);

    // destroy the headless output
    OK(getFromSocket("/output remove HEADLESS-3"));

    CALL_SUBTEST(specialWorkspaceFullscreen);
    CALL_SUBTEST(asymmetricGaps);
    CALL_SUBTEST(dynamicWsEffects);

    NLog::log("{}Expecting 0 windows", Colors::YELLOW);
    ASSERT(Tests::windowCount(), 0);
}