Debian Codegraph @

hyprtester/src/tests/main/moveintoorcreategroup.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 "../shared.hpp"
7
8 using namespace Hyprutils::OS;
9 using namespace Hyprutils::Memory;
10
11 #define UP CUniquePointer
12 #define SP CSharedPointer
13
14 TEST_CASE(moveIntoOrCreateGroup) {
15 NLog::log("{}Dispatching workspace `moveintoorcreategroup`", Colors::YELLOW);
16 getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:moveintoorcreategroup' })");
17
18 OK(getFromSocket("/eval hl.config({ group = { auto_group = false } })"));
19
20 NLog::log("{}Spawning kittyA", Colors::YELLOW);
21 auto kittyA = Tests::spawnKitty("kitty_A");
22 if (!kittyA) {
23 FAIL_TEST("Could not spawn kitty_A");
24 }
25
26 NLog::log("{}Spawning kittyB", Colors::YELLOW);
27 auto kittyB = Tests::spawnKitty("kitty_B");
28 if (!kittyB) {
29 FAIL_TEST("Could not spawn kitty_B");
30 }
31
32 NLog::log("{}Expecting 2 windows", Colors::YELLOW);
33 ASSERT(Tests::windowCount(), 2);
34
35 {
36 auto str = getFromSocket("/clients");
37 EXPECT_CONTAINS(str, "grouped: 0");
38 }
39
40 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
41
42 NLog::log("{}Move kittyA into group with kittyB (creates group)", Colors::YELLOW);
43 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_or_create_group = 'right' })"));
44
45 {
46 auto str = getFromSocket("/clients");
47 EXPECT_CONTAINS(str, "grouped:");
48 }
49
50 NLog::log("{}Verify active window is kitty_A (the moved window)", Colors::YELLOW);
51 {
52 auto str = getFromSocket("/activewindow");
53 EXPECT_CONTAINS(str, "kitty_A");
54 }
55
56 NLog::log("{}Kill windows", Colors::YELLOW);
57 Tests::killAllWindows();
58
59 NLog::log("{}Expecting 0 windows", Colors::YELLOW);
60 ASSERT(Tests::windowCount(), 0);
61
62 NLog::log("{}Testing moveintoorcreategroup into existing group", Colors::YELLOW);
63
64 NLog::log("{}Spawning kittyC", Colors::YELLOW);
65 auto kittyC = Tests::spawnKitty("kitty_C");
66 NLog::log("{}Spawning kittyD", Colors::YELLOW);
67 auto kittyD = Tests::spawnKitty("kitty_D");
68 NLog::log("{}Spawning kittyE", Colors::YELLOW);
69 auto kittyE = Tests::spawnKitty("kitty_E");
70
71 NLog::log("{}Expecting 3 windows", Colors::YELLOW);
72 ASSERT(Tests::windowCount(), 3);
73
74 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_D' })"));
75 OK(getFromSocket("/dispatch hl.dsp.group.toggle()"));
76
77 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_E' })"));
78
79 NLog::log("{}Move kittyE into existing group with kittyD", Colors::YELLOW);
80 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_or_create_group = 'left' })"));
81
82 {
83 auto str = getFromSocket("/clients");
84 EXPECT_CONTAINS(str, "grouped:");
85 }
86
87 NLog::log("{}Verify active window is kitty_E (the moved window)", Colors::YELLOW);
88 {
89 auto str = getFromSocket("/activewindow");
90 EXPECT_CONTAINS(str, "kitty_E");
91 }
92 }
93
94 // Moving a window from a group on one monitor into a group on another monitor
95 // must leave the moved window's monitor field set to the destination.
96 TEST_CASE(crossMonitorGroupJoin) {
97 // We merge windows ourselves, suppress auto-grouping on spawn for predictability
98 OK(getFromSocket("/eval hl.config({ group = { auto_group = false } })"));
99
100 // Create a destination monitor to the right of the default one and pin the
101 // destination workspace to it
102 OK(getFromSocket("/eval hl.monitor({ output = 'HYPRTEST-CROSSGROUP', mode = '1920x1080@60', position = 'auto-right', scale = '1' })"));
103 OK(getFromSocket("/output create headless HYPRTEST-CROSSGROUP"));
104 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'name:groupcross-dst', monitor = 'HYPRTEST-CROSSGROUP' })"));
105
106 // Source group: 2 kittys on the default monitor, merged into one group
107 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groupcross-src' })"));
108 auto srcA = Tests::spawnKitty("groupcross_srcA");
109 auto srcB = Tests::spawnKitty("groupcross_srcB");
110 if (!srcA || !srcB)
111 FAIL_TEST("Could not spawn source kittys");
112 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:groupcross_srcB' })"));
113 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_or_create_group = 'left' })"));
114 const auto MON_SRC_ID = Tests::getAttribute(getFromSocket("/activewindow"), "monitor");
115
116 // Destination group: 2 kittys on the new monitor, merged into one group
117 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groupcross-dst' })"));
118 auto dstA = Tests::spawnKitty("groupcross_dstA");
119 auto dstB = Tests::spawnKitty("groupcross_dstB");
120 if (!dstA || !dstB)
121 FAIL_TEST("Could not spawn destination kittys");
122 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:groupcross_dstB' })"));
123 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_or_create_group = 'right' })"));
124 const auto MON_DST_ID = Tests::getAttribute(getFromSocket("/activewindow"), "monitor");
125
126 // Sanity check: the two groups really do live on different monitors
127 ASSERT_NOT(MON_SRC_ID, MON_DST_ID);
128
129 // move srcA out of the source group rightward into the destination group on
130 // the other monitor
131 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:groupcross_srcA' })"));
132 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_or_create_group = 'right' })"));
133
134 const auto active = getFromSocket("/activewindow");
135 // moved window becomes active
136 EXPECT_CONTAINS(active, "class: groupcross_srcA");
137 // and it now lives on the destination monitor
138 EXPECT(Tests::getAttribute(active, "monitor"), MON_DST_ID);
139
140 Tests::killAllWindows();
141 OK(getFromSocket("/output remove HYPRTEST-CROSSGROUP"));
142 }