Debian Codegraph @

hyprtester/src/tests/main/focus.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 using namespace Hyprutils::OS;
10 using namespace Hyprutils::Memory;
11 using namespace Hyprutils::Utils;
12
13 #define UP CUniquePointer
14 #define SP CSharedPointer
15
16 TEST_CASE(crossMonitorFullscreenFocus) {
17 // Create a destination monitor to the right of the default one and pin the
18 // destination workspace to it
19 OK(getFromSocket("/eval hl.monitor({ output = 'HYPRTEST-2', mode = '1920x1080@60', position = 'auto-right', scale = '1' })"));
20 OK(getFromSocket("/output create headless HYPRTEST-2"));
21 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'name:workspace2', monitor = 'HYPRTEST-2' })"));
22
23 // 1 window on the left monitor
24 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:workspace1' })"));
25 auto src = Tests::spawnKitty("1A");
26 if (!src)
27 FAIL_TEST("Could not spawn kitty");
28 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:1A' })"));
29 const auto MON_SRC_ID = Tests::getAttribute(getFromSocket("/activewindow"), "monitor");
30
31 // 2 windows on the right monitor
32 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:workspace2' })"));
33 auto dstA = Tests::spawnKitty("2A");
34 auto dstB = Tests::spawnKitty("2B");
35 if (!dstA || !dstB)
36 FAIL_TEST("Could not spawn destination kittys");
37 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:2B' })"));
38 const auto MON_DST_ID = Tests::getAttribute(getFromSocket("/activewindow"), "monitor");
39
40 // Sanity check: the two windows really do live on different monitors
41 ASSERT_NOT(MON_SRC_ID, MON_DST_ID);
42
43 // float and fullscreen 2B
44 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:2B' })"));
45 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle' })"));
46 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'toggle' })"));
47
48 // focus 1A and focus to the right
49 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:1A' })"));
50 OK(getFromSocket("/dispatch hl.dsp.focus({ direction = \"right\" })"));
51
52 const auto active = getFromSocket("/activewindow");
53 EXPECT_CONTAINS(active, "class: 2B");
54
55 Tests::killAllWindows();
56 OK(getFromSocket("/output remove HYPRTEST-2"));
57 }
58
59 TEST_CASE(crossMonitorEmptyWorkspaceUnfocusesWindow) {
60 getFromSocket("/output remove HYPRTEST-UNFOCUS");
61 OK(getFromSocket("/eval hl.monitor({ output = 'HEADLESS-2', mode = '1920x1080@60', position = '0x0', scale = '1' })"));
62 OK(getFromSocket("/eval hl.monitor({ output = 'HYPRTEST-UNFOCUS', mode = '1920x1080@60', position = '1920x0', scale = '1' })"));
63 OK(getFromSocket("/output create headless HYPRTEST-UNFOCUS"));
64
65 CScopeGuard guard = {[&]() {
66 Tests::killAllWindows();
67 OK(getFromSocket("/output remove HYPRTEST-UNFOCUS"));
68 }};
69
70 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
71 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
72 ASSERT(Tests::windowCount(), 0);
73
74 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HYPRTEST-UNFOCUS' })"));
75 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
76
77 auto kittyProc = Tests::spawnKitty("cross_monitor_ws2");
78 if (!kittyProc)
79 FAIL_TEST("Could not spawn kitty");
80
81 {
82 auto str = getFromSocket("/activewindow");
83 ASSERT_CONTAINS(str, "class: cross_monitor_ws2");
84 }
85
86 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
87
88 {
89 auto str = getFromSocket("/activeworkspace");
90 ASSERT_CONTAINS(str, "workspace ID 1 ");
91 }
92
93 ASSERT(getFromSocket("/activewindow"), "Invalid");
94 }