Debian Codegraph @

hyprtester/src/tests/main/window.cpp

raw
1 #include <unistd.h>
2 #include <cmath>
3 #include <chrono>
4 #include <filesystem>
5 #include <thread>
6 #include <hyprutils/os/Process.hpp>
7 #include <hyprutils/memory/WeakPtr.hpp>
8 #include <hyprutils/string/VarList2.hpp>
9 #include <hyprutils/utils/ScopeGuard.hpp>
10
11 #include "../../shared.hpp"
12 #include "../../hyprctlCompat.hpp"
13 #include "../shared.hpp"
14 #include "tests.hpp"
15
16 using namespace Hyprutils::Utils;
17
18 /// Spawns a kitty and creates a file and returns its name. The removal of the file triggers
19 /// activation of the spawned kitty window.
20 ///
21 /// On failure, returns an empty string, possibly leaving a temporary file.
22 static std::string spawnKittyActivating(const std::string& class_ = "kitty_activating") {
23 // `XXXXXX` is what `mkstemp` expects to find in the string
24 std::string tmpFilename = (std::filesystem::temp_directory_path() / "XXXXXX").string();
25 int fd = mkstemp(tmpFilename.data());
26
27 if (fd < 0) {
28 NLog::red("Error: could not create tmp file: errno {}", errno);
29 return "";
30 }
31
32 (void)close(fd);
33
34 const std::vector<std::string> args = {
35 "-o", "allow_remote_control=yes", "--", "/bin/sh", "-c", "while [ -f \"" + tmpFilename + "\" ]; do :; done; kitten @ focus-window; sleep infinity"};
36
37 if (!Tests::spawnKitty(class_, args)) {
38 NLog::red("Error: failed to spawn kitty");
39 return "";
40 }
41
42 return tmpFilename;
43 }
44
45 static std::string getWindowAddress(const std::string& winInfo) {
46 auto pos = winInfo.find("Window ");
47 auto pos2 = winInfo.find(" -> ");
48 if (pos == std::string::npos || pos2 == std::string::npos) {
49 NLog::log("{}Wrong window info", Colors::RED);
50 return "Wrong window info";
51 }
52 return winInfo.substr(pos + 7, pos2 - pos - 7);
53 }
54
55 TEST_CASE(swapWindow) {
56 // test on workspace "swapwindow"
57 NLog::log("{}Switching to workspace \"swapwindow\"", Colors::YELLOW);
58 getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:swapwindow' })");
59
60 if (!Tests::spawnKitty("kitty_A")) {
61 FAIL_TEST("Could not spawn kitty");
62 }
63
64 if (!Tests::spawnKitty("kitty_B")) {
65 FAIL_TEST("Could not spawn kitty");
66 }
67
68 NLog::log("{}Expecting 2 windows", Colors::YELLOW);
69 ASSERT(Tests::windowCount(), 2);
70
71 // Test swapwindow by direction
72 {
73 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
74 auto pos = "at: " + Tests::getAttribute(getFromSocket("/activewindow"), "at");
75 NLog::log("{}Testing kitty_A {}, swapwindow with direction 'r'", Colors::YELLOW, pos);
76
77 OK(getFromSocket("/dispatch hl.dsp.window.swap({ direction = 'right' })"));
78 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
79
80 EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("{}", pos));
81 }
82
83 // Test swapwindow by class
84 {
85 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
86 auto pos = "at: " + Tests::getAttribute(getFromSocket("/activewindow"), "at");
87 NLog::log("{}Testing kitty_A {}, swapwindow with class:kitty_B", Colors::YELLOW, pos);
88
89 OK(getFromSocket("/dispatch hl.dsp.window.swap({ target = 'class:kitty_B' })"));
90 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
91
92 EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("{}", pos));
93 }
94
95 // Test swapwindow by address
96 {
97 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })");
98 auto addr = getWindowAddress(getFromSocket("/activewindow"));
99 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
100 auto pos = "at: " + Tests::getAttribute(getFromSocket("/activewindow"), "at");
101 NLog::log("{}Testing kitty_A {}, swapwindow with address:0x{}(kitty_B)", Colors::YELLOW, pos, addr);
102
103 OK(getFromSocket(std::format("/dispatch hl.dsp.window.swap({{ target = 'address:0x{}' }})", addr)));
104 OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'address:0x{}' }})", addr)));
105
106 EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("{}", pos));
107 }
108
109 NLog::log("{}Testing swapwindow with fullscreen. Expecting to fail", Colors::YELLOW);
110 {
111 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
112
113 auto str = getFromSocket("/dispatch hl.dsp.window.swap({ direction = 'left' })");
114 EXPECT_CONTAINS(str, "Can't swap fullscreen window");
115
116 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
117 }
118
119 NLog::log("{}Testing swapwindow with different workspace", Colors::YELLOW);
120 {
121 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })");
122 auto addr = getWindowAddress(getFromSocket("/activewindow"));
123 auto ws = "workspace: " + Tests::getAttribute(getFromSocket("/activewindow"), "workspace");
124 NLog::log("{}Sending address:0x{}(kitty_B) to workspace \"swapwindow2\"", Colors::YELLOW, addr);
125
126 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = 'name:swapwindow2', follow = false })"));
127 OK(getFromSocket(std::format("/dispatch hl.dsp.window.swap({{ target = 'address:0x{}' }})", addr)));
128 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })");
129 EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("{}", ws));
130 }
131 }
132
133 TEST_CASE(windowGroupRules) {
134 OK(getFromSocket("/eval hl.config({ general = { border_size = 8 } })"));
135 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'w[tv1]', border_size = 0 })"));
136 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'f[1]', border_size = 0 })"));
137 OK(getFromSocket("/eval hl.window_rule({ match = { workspace = 'w[tv1]' }, border_size = 0 })"));
138 OK(getFromSocket("/eval hl.window_rule({ match = { workspace = 'f[1]' }, border_size = 0 })"));
139
140 if (!Tests::spawnKitty("kitty_A")) {
141 FAIL_TEST("Could not spawn kitty");
142 }
143
144 {
145 auto str = getFromSocket("/getprop active border_size");
146 EXPECT_CONTAINS(str, "0");
147 }
148
149 if (!Tests::spawnKitty("kitty_B")) {
150 FAIL_TEST("Could not spawn kitty");
151 }
152
153 {
154 auto str = getFromSocket("/getprop active border_size");
155 EXPECT_CONTAINS(str, "8");
156 }
157
158 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
159 OK(getFromSocket("/dispatch hl.dsp.group.toggle()"));
160 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
161 OK(getFromSocket("/dispatch hl.dsp.window.move({ into_group = 'left' })"));
162
163 {
164 auto str = getFromSocket("/getprop active border_size");
165 EXPECT_CONTAINS(str, "0");
166 }
167
168 OK(getFromSocket("/dispatch hl.dsp.group.next()"));
169
170 {
171 auto str = getFromSocket("/getprop active border_size");
172 EXPECT_CONTAINS(str, "0");
173 }
174
175 if (!Tests::spawnKitty("kitty_C")) {
176 FAIL_TEST("Could not spawn kitty");
177 }
178
179 OK(getFromSocket("/dispatch hl.dsp.window.move({ out_of_group = 'right' })"));
180
181 {
182 auto str = getFromSocket("/getprop active border_size");
183 EXPECT_CONTAINS(str, "8");
184 }
185 }
186
187 static bool isActiveWindow(const std::string& class_, char fullscreen = '0', bool log = true) {
188 std::string activeWin = getFromSocket("/activewindow");
189 auto winClass = Tests::getAttribute(activeWin, "class");
190 auto winFullscreen = Tests::getAttribute(activeWin, "fullscreen").back();
191 if (winClass == class_ && winFullscreen == fullscreen)
192 return true;
193 else {
194 if (log)
195 NLog::log("{}Wrong active window: expected class {} fullscreen '{}', found class {}, fullscreen '{}'", Colors::RED, class_, fullscreen, winClass, winFullscreen);
196 return false;
197 }
198 }
199
200 static bool waitForActiveWindow(const std::string& class_, char fullscreen = '0', bool logLastCheck = true, int maxTries = 50) {
201 int cnt = 0;
202 while (!isActiveWindow(class_, fullscreen, false)) {
203 ++cnt;
204 std::this_thread::sleep_for(std::chrono::milliseconds(100));
205 if (cnt > maxTries) {
206 return isActiveWindow(class_, fullscreen, logLastCheck);
207 }
208 }
209 return true;
210 }
211
212 /// Tests behavior of a window being focused when on that window's workspace
213 /// another fullscreen window exists.
214 TEST_CASE(windowFocusOnFullscreenConflict) {
215 SPAWN_KITTY("kitty_A");
216 SPAWN_KITTY("kitty_B");
217
218 OK(getFromSocket("/eval hl.config({ misc = { focus_on_activate = true } })"));
219
220 // Unfullscreen on conflict
221 {
222 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
223
224 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
225 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
226 EXPECT(isActiveWindow("kitty_A", '2'), true);
227
228 // Dispatch-focus the same window
229 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
230 EXPECT(isActiveWindow("kitty_A", '2'), true);
231
232 // Dispatch-focus a different window
233 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
234 EXPECT(isActiveWindow("kitty_B", '0'), true);
235
236 // Make a window that will request focus
237 const std::string removeToActivate = spawnKittyActivating();
238 if (removeToActivate.empty())
239 FAIL_TEST("Could not spawn kitty_activating");
240 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
241 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
242 EXPECT(isActiveWindow("kitty_A", '2'), true);
243 std::filesystem::remove(removeToActivate);
244 EXPECT(waitForActiveWindow("kitty_activating", '0'), true);
245 OK(getFromSocket("/dispatch hl.dsp.window.kill()"));
246 Tests::waitUntilWindowsN(2);
247 }
248
249 // Take over on conflict
250 {
251 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 1 } })"));
252
253 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
254 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
255 EXPECT(isActiveWindow("kitty_A", '2'), true);
256
257 // Dispatch-focus the same window
258 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
259 EXPECT(isActiveWindow("kitty_A", '2'), true);
260
261 // Dispatch-focus a different window
262 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
263 EXPECT(isActiveWindow("kitty_B", '2'), true);
264 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen_state({ internal = 0, client = 0, action = 'set' })"));
265
266 // Make a window that will request focus
267 const std::string removeToActivate = spawnKittyActivating();
268 if (removeToActivate.empty())
269 FAIL_TEST("Could not spawn kitty_activating");
270 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
271 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
272 EXPECT(isActiveWindow("kitty_A", '2'), true);
273 std::filesystem::remove(removeToActivate);
274 EXPECT(waitForActiveWindow("kitty_activating", '2'), true);
275 OK(getFromSocket("/dispatch hl.dsp.window.kill()"));
276 Tests::waitUntilWindowsN(2);
277 }
278
279 // Keep the old focus on conflict
280 {
281 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 0 } })"));
282
283 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
284 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
285 EXPECT(isActiveWindow("kitty_A", '2'), true);
286
287 // Dispatch-focus the same window
288 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
289 EXPECT(isActiveWindow("kitty_A", '2'), true);
290
291 // Make a window that will request focus - the setting is treated normally
292 const std::string removeToActivate = spawnKittyActivating();
293 if (removeToActivate.empty())
294 FAIL_TEST("Could not spawn kitty_activating");
295 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
296 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
297 EXPECT(isActiveWindow("kitty_A", '2'), true);
298 std::filesystem::remove(removeToActivate);
299 EXPECT(waitForActiveWindow("kitty_A", '2'), true);
300 }
301 }
302
303 TEST_CASE(focusFloatingOrTilingUnderFullscreen) {
304 OK(getFromSocket("/eval hl.config({ misc = { focus_on_activate = true } })"));
305 OK(getFromSocket("/eval hl.config({ misc = { on_focus_under_fullscreen = 2 } })"));
306
307 ASSERT(!!Tests::spawnKitty("kitty_a"), true);
308 ASSERT(!!Tests::spawnKitty("kitty_b"), true);
309
310 ASSERT(isActiveWindow("kitty_b", '0'), true);
311 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })"));
312
313 // Test 1: focus floating from fullscreen tiled
314
315 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_a' })"));
316 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
317 ASSERT(isActiveWindow("kitty_a", '2'), true);
318
319 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'floating' })"));
320 std::string active = getFromSocket("/activewindow");
321 EXPECT_CONTAINS(Tests::getAttribute(active, "class"), "kitty_b");
322 std::string kitty_a = getFromSocket("/clients");
323 // Assuming clients appear in the same order that they connected in
324 kitty_a = kitty_a.substr(0, kitty_a.size() - active.size());
325 ASSERT_COUNT_STRING(kitty_a, "class:", 1); // Check that the cut is right
326 EXPECT(Tests::getAttribute(kitty_a, "class") == "kitty_a", true);
327 // Remains fullscreen, since we just focused a floating window over it
328 EXPECT(Tests::getAttribute(kitty_a, "fullscreen") == "2", true);
329 EXPECT(Tests::getAttribute(kitty_a, "fullscreenClient") == "2", true);
330
331 // Test 2: focus tiled from fullscreen floating
332
333 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
334 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'tiled' })"));
335 active = getFromSocket("/activewindow");
336 EXPECT_CONTAINS(Tests::getAttribute(active, "class"), "kitty_a");
337 std::string kitty_b = getFromSocket("/clients");
338 // Assuming clients appear in the same order that they connected in
339 kitty_b = kitty_b.substr(active.size());
340 ASSERT_COUNT_STRING(kitty_b, "class:", 1); // Check that the cut is right
341 EXPECT(Tests::getAttribute(kitty_b, "class") == "kitty_b", true);
342 // Exited fullscreen, since we switched focus to a window under it
343 EXPECT(Tests::getAttribute(kitty_b, "fullscreen") == "0", true);
344 EXPECT(Tests::getAttribute(kitty_b, "fullscreen") == "0", true);
345 }
346
347 TEST_CASE(windowMaximizeSize) {
348 SPAWN_KITTY("kitty_A");
349
350 // check kitty properties. Maximizing shouldnt change its size
351 {
352 auto str = getFromSocket("/clients");
353 EXPECT(str.contains("at: 22,22"), true);
354 EXPECT(str.contains("size: 1876,1036"), true);
355 EXPECT(str.contains("fullscreen: 0"), true);
356 }
357
358 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
359
360 {
361 auto str = getFromSocket("/clients");
362 EXPECT(str.contains("at: 22,22"), true);
363 EXPECT(str.contains("size: 1876,1036"), true);
364 EXPECT(str.contains("fullscreen: 1"), true);
365 }
366 }
367
368 TEST_CASE(floatingFocusOnFullscreen) {
369 SPAWN_KITTY("kitty_A");
370 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle' })"));
371
372 SPAWN_KITTY("kitty_B");
373 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })"));
374
375 OK(getFromSocket("/dispatch hl.dsp.window.cycle_next()"));
376
377 OK(getFromSocket("/eval hl.plugin.test.floating_focus_on_fullscreen()"));
378 }
379
380 TEST_CASE(groupFallbackFocus) {
381 SPAWN_KITTY("kitty_A");
382
383 OK(getFromSocket("/dispatch hl.dsp.group.toggle()"));
384
385 SPAWN_KITTY("kitty_B");
386 SPAWN_KITTY("kitty_C");
387 SPAWN_KITTY("kitty_D");
388
389 {
390 auto str = getFromSocket("/activewindow");
391 EXPECT(str.contains("class: kitty_D"), true);
392 }
393
394 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"));
395 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_D' })"));
396 OK(getFromSocket("/dispatch hl.dsp.window.kill()"));
397
398 Tests::waitUntilWindowsN(3);
399
400 // Focus must return to the last focus, in this case B.
401 {
402 auto str = getFromSocket("/activewindow");
403 EXPECT(str.contains("class: kitty_B"), true);
404 }
405 }
406
407 TEST_CASE(bringActiveToTopMouseMovement) {
408 OK(getFromSocket("/eval hl.config({ input = { follow_mouse = 2 } })"));
409 OK(getFromSocket("/eval hl.config({ input = { float_switch_override_focus = 0 } })"));
410
411 SPAWN_KITTY("a");
412 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })"));
413 OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 500, y = 300 })"));
414 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 400, y = 400 })"));
415
416 SPAWN_KITTY("b");
417 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })"));
418 OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 500, y = 300 })"));
419 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 400, y = 400 })"));
420
421 auto getTopWindow = []() -> std::string {
422 auto clients = getFromSocket("/clients");
423 return (clients.rfind("class: a") > clients.rfind("class: b")) ? "a" : "b";
424 };
425
426 ASSERT(getTopWindow(), std::string("b"));
427 OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 700, y = 500 })"));
428
429 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })"));
430 ASSERT_CONTAINS(getFromSocket("/activewindow"), "class: a");
431
432 OK(getFromSocket("/dispatch hl.dsp.window.bring_to_top()"));
433 ASSERT(getTopWindow(), std::string("a"));
434
435 OK(getFromSocket("/eval hl.plugin.test.click(272, 1)"));
436 OK(getFromSocket("/eval hl.plugin.test.click(272, 0)"));
437
438 ASSERT(getTopWindow(), std::string("a"));
439 }
440
441 TEST_CASE(initialFloatSize) {
442 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty' }, float = true })"));
443 OK(getFromSocket("/eval hl.config({ input = { float_switch_override_focus = 0 } })"));
444
445 SPAWN_KITTY("kitty");
446
447 {
448 // Kitty by default opens as 640x400, if this changes this test will break
449 auto str = getFromSocket("/clients");
450 EXPECT(str.contains("size: 640,400"), true);
451 }
452
453 OK(getFromSocket("/reload"));
454
455 Tests::killAllWindows();
456
457 OK(getFromSocket("/dispatch hl.dsp.exec_cmd('kitty', { float = true })"));
458
459 Tests::waitUntilWindowsN(1);
460
461 {
462 // Kitty by default opens as 640x400, if this changes this test will break
463 auto str = getFromSocket("/clients");
464 EXPECT(str.contains("size: 640,400"), true);
465 EXPECT(str.contains("floating: 1"), true);
466 }
467 }
468
469 /// Tests that the `focus_on_activate` effect of window rules always overrides
470 /// the `misc:focus_on_activate` variable.
471 TEST_CASE(windowRuleFocusOnActivate) {
472 SPAWN_KITTY("kitty_default");
473
474 // Do not focus anyone automatically
475 // TODO: this looks like a bug: the following line should not be commented out
476 ///////////OK(getFromSocket("/eval hl.window_rule({ match = { class = '.*' }, no_initial_focus = true })"));
477
478 // `focus_on_activate off` takes over
479 {
480 OK(getFromSocket("/eval hl.config({ misc = { focus_on_activate = true } })"));
481 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_antifocus' }, focus_on_activate = false })"));
482
483 const std::string removeToActivate = spawnKittyActivating("kitty_antifocus");
484 if (removeToActivate.empty()) {
485 FAIL_TEST("Could not spawn kitty_antifocus");
486 }
487 ASSERT(waitForActiveWindow("kitty_antifocus"), true);
488 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_default' })"));
489 ASSERT(isActiveWindow("kitty_default"), true);
490
491 std::filesystem::remove(removeToActivate);
492 // The focus should NOT transition, since the window rule explicitly forbids that
493 ASSERT(waitForActiveWindow("kitty_antifocus", '0', false), false);
494 }
495
496 // `focus_on_activate on` takes over
497 {
498 OK(getFromSocket("/eval hl.config({ misc = { focus_on_activate = false } })"));
499 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_superfocus' }, focus_on_activate = true })"));
500
501 const std::string removeToActivate = spawnKittyActivating("kitty_superfocus");
502 if (removeToActivate.empty()) {
503 FAIL_TEST("Could not spawn kitty_superfocus");
504 }
505 ASSERT(waitForActiveWindow("kitty_superfocus"), true);
506 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_default' })"));
507 ASSERT(isActiveWindow("kitty_default"), true);
508
509 std::filesystem::remove(removeToActivate);
510 // Now that we requested activation, the focus SHOULD transition to kitty_superfocus, according to the window rule
511 ASSERT(waitForActiveWindow("kitty_superfocus"), true);
512 }
513 }
514
515 // tests if a pinned window contains the valid workspace after change
516 TEST_CASE(pinnedWorkspacesValid) {
517 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1337' })");
518
519 SPAWN_KITTY("kitty");
520
521 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:kitty' })"));
522 OK(getFromSocket("/dispatch hl.dsp.window.pin({ action = 'toggle', window = 'class:kitty' })"));
523
524 {
525 auto str = getFromSocket("/activewindow");
526 EXPECT(str.contains("workspace: 1337"), true);
527 EXPECT(str.contains("pinned: 1"), true);
528 }
529
530 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1338' })");
531
532 {
533 auto str = getFromSocket("/activewindow");
534 EXPECT(str.contains("workspace: 1338"), true);
535 EXPECT(str.contains("pinned: 1"), true);
536 }
537
538 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset', window = 'class:kitty' })"));
539
540 {
541 auto str = getFromSocket("/activewindow");
542 EXPECT(str.contains("workspace: 1338"), true);
543 EXPECT(str.contains("pinned: 0"), true);
544 }
545 }
546
547 TEST_CASE(windowruleWorkspaceEmpty) {
548 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_A' }, workspace = 'empty' })"));
549 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_B' }, workspace = 'emptyn' })"));
550
551 getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })");
552
553 SPAWN_KITTY("kitty");
554
555 {
556 auto str = getFromSocket("/activewindow");
557 EXPECT(str.contains("workspace: 3"), true);
558 }
559
560 SPAWN_KITTY("kitty_A");
561
562 {
563 auto str = getFromSocket("/activewindow");
564 EXPECT(str.contains("workspace: 1"), true);
565 }
566
567 getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })");
568 SPAWN_KITTY("kitty_B");
569 {
570 auto str = getFromSocket("/activewindow");
571 EXPECT(str.contains("workspace: 4"), true);
572 }
573 }
574
575 TEST_CASE(contentWindowRules) {
576 // kill me PLEASE
577
578 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_content_string' }, content = 'game' })"));
579 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_content_numbers' }, content = '3' })"));
580 OK(getFromSocket("/eval hl.window_rule({ match = { content = 'game' }, border_size = 10 })"));
581 OK(getFromSocket("/eval hl.window_rule({ match = { content = '3' }, opacity = '0.5' })"));
582
583 #define TEST_PROPS() \
584 EXPECT_CONTAINS(getFromSocket("/getprop active border_size"), "10"); \
585 EXPECT_CONTAINS(getFromSocket("/getprop active opacity"), "0.5");
586
587 SPAWN_KITTY("kitty_content_string");
588 waitForActiveWindow("kitty_content_string");
589 TEST_PROPS();
590
591 Tests::killAllWindows();
592 ASSERT(Tests::windowCount(), 0);
593
594 SPAWN_KITTY("kitty_content_numbers");
595 waitForActiveWindow("kitty_content_numbers");
596 TEST_PROPS();
597
598 Tests::killAllWindows();
599 ASSERT(Tests::windowCount(), 0);
600
601 #undef TEST_PROPS
602 }
603
604 TEST_CASE(issue14038) {
605 SPAWN_KITTY("kitty_14038");
606
607 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = 'special:a', follow = false, window = 'class:kitty_14038' })"));
608 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle', window = 'class:kitty_14038' })"));
609 OK(getFromSocket("/dispatch hl.dsp.window.pin({ action = 'toggle', window = 'class:kitty_14038' })"));
610 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle', window = 'class:kitty_14038' })"));
611
612 // this should not crash hyprland. If we are alive, we good.
613 }
614
615 TEST_CASE(issue14134) {
616 OK(getFromSocket("/output create headless HEADLESS-4"));
617 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-4' })"));
618
619 SPAWN_KITTY("kitty_14134");
620
621 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle', window = 'class:kitty_14134' })"));
622 OK(getFromSocket("/dispatch hl.dsp.window.pin({ action = 'toggle', window = 'class:kitty_14134' })"));
623
624 OK(getFromSocket("/eval hl.monitor({ output = 'HEADLESS-4', disabled = true })"));
625
626 // will return error, should not be OK.
627 getFromSocket("/dispatch hl.dsp.window.pin({ action = 'toggle', window = 'class:kitty_14134' })");
628
629 OK(getFromSocket("/reload"));
630 Tests::killAllWindows();
631 ASSERT(Tests::windowCount(), 0);
632 OK(getFromSocket("/output remove HEADLESS-4"));
633 }
634
635 TEST_CASE(specialFloatRecenters) {
636 SPAWN_KITTY("kitty_special_float_recenter");
637
638 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:kitty_special_float_recenter' })"));
639 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 10, y = 10, window = 'class:kitty_special_float_recenter' })"));
640 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = 'special:recenter', follow = false, window = 'class:kitty_special_float_recenter' })"));
641 OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 50000, y = 50000, window = 'class:kitty_special_float_recenter' })"));
642
643 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('recenter')"));
644 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_special_float_recenter' })"));
645
646 const auto active = getFromSocket("/activewindow");
647 EXPECT_CONTAINS(active, "class: kitty_special_float_recenter");
648 EXPECT_CONTAINS(active, "size: 10,10");
649 EXPECT_CONTAINS(active, "at: 955,535");
650
651 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('recenter')"));
652 Tests::killAllWindows();
653 ASSERT(Tests::windowCount(), 0);
654 }
655
656 TEST_CASE(exactWindowSelectors) {
657 SPAWN_KITTY("kitty_A");
658 SPAWN_KITTY("kitty_B");
659
660 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })");
661 auto target = getFromSocket("/activewindow");
662 auto addr = getWindowAddress(target);
663 auto pid = Tests::getAttribute(target, "pid");
664 auto stable_id = Tests::getAttribute(target, "stableID");
665
666 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
667 // Focus window by address
668 OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'address:0x{}' }})", addr)));
669 EXPECT_CONTAINS(getFromSocket("/activewindow"), "class: kitty_B");
670
671 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
672 // Focus window by PID
673 OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'pid:{}' }})", pid)));
674 EXPECT_CONTAINS(getFromSocket("/activewindow"), "class: kitty_B");
675
676 getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })");
677 // Focus window by stable ID
678 OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'stableid:{}' }})", stable_id)));
679 EXPECT_CONTAINS(getFromSocket("/activewindow"), "class: kitty_B");
680 }
681
682 // TODO: decompose this into multiple test cases
683 TEST_CASE(windows) {
684 // test on workspace "window"
685 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
686 NLog::log("{}Switching to workspace `window`", Colors::YELLOW);
687 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:window' })"));
688
689 SPAWN_KITTY("kitty_A");
690
691 // check kitty properties. One kitty should take the entire screen, as this is smart gaps
692 NLog::log("{}Expecting kitty_A to take up the whole screen", Colors::YELLOW);
693 {
694 auto str = getFromSocket("/clients");
695 EXPECT(str.contains("at: 0,0"), true);
696 EXPECT(str.contains("size: 1920,1080"), true);
697 EXPECT(str.contains("fullscreen: 0"), true);
698 }
699
700 NLog::log("{}Testing window split ratios", Colors::YELLOW);
701 {
702 const double INITIAL_RATIO = 1.25;
703 const int GAPSIN = 5;
704 const int GAPSOUT = 20;
705 const int BORDERSIZE = 2;
706 const int BORDERS = BORDERSIZE * 2;
707 const int MONITOR_W = 1920;
708 const int MONITOR_H = 1080;
709
710 const float totalAvailableHeight = MONITOR_H - (GAPSOUT * 2);
711 const int HEIGHT = std::floor(totalAvailableHeight) - BORDERS;
712 const float availableWidthForSplit = MONITOR_W - (GAPSOUT * 2) - GAPSIN;
713
714 auto calculateFinalWidth = [&](double boxWidth, bool isLeftWindow) {
715 double gapLeft = isLeftWindow ? GAPSOUT : GAPSIN;
716 double gapRight = isLeftWindow ? GAPSIN : GAPSOUT;
717 return std::floor(boxWidth - gapLeft - gapRight - BORDERS);
718 };
719
720 double geomBoxWidthA_R1 = (availableWidthForSplit * INITIAL_RATIO / 2.0) + GAPSOUT + (GAPSIN / 2.0);
721 double geomBoxWidthB_R1 = MONITOR_W - geomBoxWidthA_R1;
722 const int WIDTH1 = calculateFinalWidth(geomBoxWidthB_R1, false);
723
724 const double INVERTED_RATIO = 0.75;
725 double geomBoxWidthA_R2 = (availableWidthForSplit * INVERTED_RATIO / 2.0) + GAPSOUT + (GAPSIN / 2.0);
726 double geomBoxWidthB_R2 = MONITOR_W - geomBoxWidthA_R2;
727 const int WIDTH2 = calculateFinalWidth(geomBoxWidthB_R2, false);
728 const int WIDTH_A_FINAL = calculateFinalWidth(geomBoxWidthA_R2, true);
729
730 OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 1.25 } })"));
731
732 SPAWN_KITTY("kitty_B");
733
734 NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH1, HEIGHT);
735 EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH1, HEIGHT));
736
737 OK(getFromSocket("/dispatch hl.dsp.window.kill({ window = 'activewindow' })"));
738 Tests::waitUntilWindowsN(1);
739
740 NLog::log("{}Inverting the split ratio", Colors::YELLOW);
741 OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 0.75 } })"));
742
743 SPAWN_KITTY("kitty_B");
744
745 try {
746 NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH2, HEIGHT);
747
748 {
749 auto data = getFromSocket("/activewindow");
750 data = data.substr(data.find("size:") + 5);
751 data = data.substr(0, data.find('\n'));
752
753 Hyprutils::String::CVarList2 sizes(std::move(data), 0, ',');
754
755 EXPECT_MAX_DELTA(std::stoi(std::string{sizes[0]}), WIDTH2, 2);
756 EXPECT_MAX_DELTA(std::stoi(std::string{sizes[1]}), HEIGHT, 2);
757 }
758
759 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })"));
760 NLog::log("{}Expecting kitty_A size: {},{}", Colors::YELLOW, WIDTH_A_FINAL, HEIGHT);
761
762 {
763 auto data = getFromSocket("/activewindow");
764 data = data.substr(data.find("size:") + 5);
765 data = data.substr(0, data.find('\n'));
766
767 Hyprutils::String::CVarList2 sizes(std::move(data), 0, ',');
768
769 EXPECT_MAX_DELTA(std::stoi(std::string{sizes[0]}), WIDTH_A_FINAL, 2);
770 EXPECT_MAX_DELTA(std::stoi(std::string{sizes[1]}), HEIGHT, 2);
771 }
772
773 } catch (...) { FAIL_TEST("Exception thrown"); }
774
775 OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 1 } })"));
776 }
777
778 // open xeyes
779 NLog::log("{}Spawning xeyes", Colors::YELLOW);
780 getFromSocket("/dispatch hl.dsp.exec_cmd('xeyes')");
781
782 NLog::log("{}Keep checking if xeyes spawned", Colors::YELLOW);
783 Tests::waitUntilWindowsN(3);
784
785 NLog::log("{}Expecting 3 windows", Colors::YELLOW);
786 ASSERT(Tests::windowCount(), 3);
787
788 NLog::log("{}Checking props of xeyes", Colors::YELLOW);
789 // check some window props of xeyes, try to float it
790 {
791 auto str = getFromSocket("/clients");
792 EXPECT_NOT_CONTAINS(str, "floating: 1");
793 getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:XEyes' })");
794 std::this_thread::sleep_for(std::chrono::milliseconds(200));
795 str = getFromSocket("/clients");
796 EXPECT_CONTAINS(str, "floating: 1");
797 }
798
799 // kill all
800 NLog::log("{}Killing all windows", Colors::YELLOW);
801 Tests::killAllWindows();
802
803 NLog::log("{}Expecting 0 windows", Colors::YELLOW);
804 ASSERT(Tests::windowCount(), 0);
805
806 getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })");
807
808 NLog::log("{}Testing spawning a floating window over a fullscreen window", Colors::YELLOW);
809 {
810 SPAWN_KITTY("kitty_A");
811 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })"));
812 ASSERT(Tests::windowCount(), 1);
813
814 OK(getFromSocket("/dispatch hl.dsp.exec_cmd('kitty', { float = true })"));
815 Tests::waitUntilWindowsN(2);
816
817 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:^kitty$' })"));
818 const auto focused1 = getFromSocket("/activewindow");
819 EXPECT_CONTAINS(focused1, "class: kitty\n");
820
821 OK(getFromSocket("/dispatch hl.dsp.window.kill({ window = 'activewindow' })"));
822 Tests::waitUntilWindowsN(1);
823
824 // The old window should be focused again
825 const auto focused2 = getFromSocket("/activewindow");
826 EXPECT_CONTAINS(focused2, "class: kitty_A\n");
827
828 NLog::log("{}Killing all windows", Colors::YELLOW);
829 Tests::killAllWindows();
830 }
831
832 NLog::log("{}Testing minsize/maxsize rules for tiled windows", Colors::YELLOW);
833 {
834 // Enable the config for testing, test max/minsize for tiled windows and centering
835 OK(getFromSocket("/eval hl.config({ misc = { size_limits_tiled = 1 } })"));
836 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', match = { class = 'kitty_maxsize' } })"));
837 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', max_size = '1500 500' })"));
838 OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })"));
839 SPAWN_KITTY("kitty_maxsize");
840
841 auto dwindle = getFromSocket("/activewindow");
842 EXPECT_CONTAINS(dwindle, "size: 1500,500");
843 EXPECT_CONTAINS(dwindle, "at: 210,290");
844
845 // Fuck this test, it's fucking stupid - vax
846 // if (!spawnKitty("kitty_maxsize"))
847 // return false;
848 // EXPECT_CONTAINS(getFromSocket("/activewindow"), "size: 1200,500");
849
850 Tests::killAllWindows();
851 ASSERT(Tests::windowCount(), 0);
852
853 OK(getFromSocket("r/eval hl.config({ general = { layout = 'master' } })"));
854
855 SPAWN_KITTY("kitty_maxsize");
856
857 auto master = getFromSocket("/activewindow");
858 EXPECT_CONTAINS(master, "size: 1500,500");
859 EXPECT_CONTAINS(master, "at: 210,290");
860
861 SPAWN_KITTY("kitty_maxsize");
862
863 // FIXME: I can't be arsed.
864 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_maxsize' })"));
865 // EXPECT_CONTAINS(getFromSocket("/activewindow"), "size: 1200,500")
866
867 NLog::log("{}Reloading config", Colors::YELLOW);
868 OK(getFromSocket("/reload"));
869 Tests::killAllWindows();
870 ASSERT(Tests::windowCount(), 0);
871 }
872
873 NLog::log("{}Testing minsize/maxsize rules", Colors::YELLOW);
874 {
875 // Disable size limits tiled and check if props are working and not getting skipped
876 OK(getFromSocket("/eval hl.config({ misc = { size_limits_tiled = 0 } })"));
877 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', match = { class = 'kitty_maxsize' } })"));
878 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', max_size = '1500 500' })"));
879 OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })"));
880 SPAWN_KITTY("kitty_maxsize");
881
882 {
883 auto res = getFromSocket("/getprop active max_size");
884 EXPECT_CONTAINS(res, "1500");
885 EXPECT_CONTAINS(res, "500");
886 }
887
888 {
889 auto res = getFromSocket("/getprop active min_size");
890 EXPECT_CONTAINS(res, "1200");
891 EXPECT_CONTAINS(res, "500");
892 }
893
894 NLog::log("{}Reloading config", Colors::YELLOW);
895 OK(getFromSocket("/reload"));
896 Tests::killAllWindows();
897 ASSERT(Tests::windowCount(), 0);
898 }
899
900 {
901 // Set float
902 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', match = { class = 'kitty_maxsize' } })"));
903 OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', max_size = '1200 500' })"));
904 OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })"));
905 OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', float = true })"));
906 SPAWN_KITTY("kitty_maxsize");
907
908 {
909 auto res = getFromSocket("/getprop active max_size");
910 EXPECT_CONTAINS(res, "1200");
911 EXPECT_CONTAINS(res, "500");
912 }
913
914 {
915 auto res = getFromSocket("/getprop active min_size");
916 EXPECT_CONTAINS(res, "1200");
917 EXPECT_CONTAINS(res, "500");
918 }
919
920 {
921 auto res = getFromSocket("/activewindow");
922 EXPECT_CONTAINS(res, "size: 1200,500");
923 }
924
925 NLog::log("{}Reloading config", Colors::YELLOW);
926 OK(getFromSocket("/reload"));
927 Tests::killAllWindows();
928 ASSERT(Tests::windowCount(), 0);
929 }
930
931 NLog::log("{}Testing window rules", Colors::YELLOW);
932 SPAWN_KITTY("wr_kitty");
933 {
934 auto str = getFromSocket("/activewindow");
935 const int SIZE = 200;
936 EXPECT_CONTAINS(str, "floating: 1");
937 EXPECT_CONTAINS(str, std::format("size: {},{}", SIZE, SIZE));
938 EXPECT_NOT_CONTAINS(str, "pinned: 1");
939 }
940
941 OK(getFromSocket("/eval hl.window_rule({ name = 'wr-kitty-stuff', opacity = '0.5 0.5 override' })"));
942
943 {
944 auto str = getFromSocket("/getprop active opacity");
945 EXPECT_CONTAINS(str, "0.5");
946 }
947
948 OK(getFromSocket("/eval hl.window_rule({ name = 'special-magic-kitty', match = { class = 'magic_kitty' } })"));
949 OK(getFromSocket("/eval hl.window_rule({ name = 'special-magic-kitty', workspace = 'special:magic' })"));
950
951 SPAWN_KITTY("magic_kitty");
952
953 {
954 auto str = getFromSocket("/activewindow");
955 EXPECT_CONTAINS(str, "special:magic");
956 EXPECT_NOT_CONTAINS(str, "workspace: 9");
957 }
958
959 if (auto str = getFromSocket("/monitors"); str.contains("magic)")) {
960 OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('magic')"));
961 }
962
963 Tests::killAllWindows();
964
965 OK(getFromSocket("/eval hl.window_rule({ name = 'border-magic-kitty', match = { class = 'border_kitty' } })"));
966 OK(getFromSocket("/eval hl.window_rule({ name = 'border-magic-kitty', border_color = 'rgba(c6ff00ff) rgba(ff0000ee) 45deg' })"));
967
968 SPAWN_KITTY("border_kitty");
969
970 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:border_kitty' })"));
971
972 {
973 auto str = getFromSocket("/getprop active active_border_color");
974 EXPECT_CONTAINS(str, "ffc6ff00");
975 EXPECT_CONTAINS(str, "eeff0000");
976 EXPECT_CONTAINS(str, "45deg");
977 }
978
979 Tests::killAllWindows();
980
981 SPAWN_KITTY("tag_kitty");
982
983 {
984 auto str = getFromSocket("/activewindow");
985 EXPECT_CONTAINS(str, "floating: 1");
986 }
987
988 OK(getFromSocket("/reload"));
989 Tests::killAllWindows();
990
991 // test rules that overlap effects but don't overlap props
992 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'overlap_kitty' }, border_size = 0 })"));
993 OK(getFromSocket("/eval hl.window_rule({ match = { fullscreen = false }, border_size = 10 })"));
994
995 SPAWN_KITTY("overlap_kitty");
996
997 {
998 auto str = getFromSocket("/getprop active border_size");
999 EXPECT_CONTAINS(str, "10");
1000 }
1001
1002 OK(getFromSocket("/reload"));
1003 Tests::killAllWindows();
1004
1005 // test persistent_size between floating window launches
1006 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'persistent_size_kitty' }, persistent_size = true, float = true })"));
1007
1008 SPAWN_KITTY("persistent_size_kitty");
1009
1010 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 600, y = 400 })"));
1011
1012 {
1013 auto str = getFromSocket("/activewindow");
1014 EXPECT_CONTAINS(str, "size: 600,400");
1015 EXPECT_CONTAINS(str, "floating: 1");
1016 }
1017
1018 Tests::killAllWindows();
1019
1020 SPAWN_KITTY("persistent_size_kitty");
1021
1022 {
1023 auto str = getFromSocket("/activewindow");
1024 EXPECT_CONTAINS(str, "size: 600,400");
1025 EXPECT_CONTAINS(str, "floating: 1");
1026 }
1027
1028 OK(getFromSocket("/reload"));
1029 Tests::killAllWindows();
1030
1031 OK(getFromSocket("/eval hl.config({ general = { border_size = 0 } })"));
1032 OK(getFromSocket("/eval hl.window_rule({ match = { float = true }, border_size = 10 })"));
1033
1034 SPAWN_KITTY("border_kitty");
1035
1036 {
1037 auto str = getFromSocket("/getprop active border_size");
1038 EXPECT_CONTAINS(str, "0");
1039 }
1040
1041 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle' })"));
1042
1043 {
1044 auto str = getFromSocket("/getprop active border_size");
1045 EXPECT_CONTAINS(str, "10");
1046 }
1047
1048 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle' })"));
1049
1050 {
1051 auto str = getFromSocket("/getprop active border_size");
1052 EXPECT_CONTAINS(str, "0");
1053 }
1054
1055 OK(getFromSocket("/reload"));
1056 Tests::killAllWindows();
1057
1058 // test expression rules
1059 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'expr_kitty' }, float = true, size = {'monitor_w * 0.5', 'monitor_h * 0.5'}, "
1060 "min_size = {'monitor_w * 0.25', 'monitor_h * 0.25'}, max_size = {'monitor_w * 0.75', 'monitor_h * 0.75'}, "
1061 "move = {'20 + (monitor_w * 0.1)', 'monitor_h * 0.5'} })"));
1062
1063 SPAWN_KITTY("expr_kitty");
1064
1065 {
1066 auto str = getFromSocket("/activewindow");
1067 EXPECT_CONTAINS(str, "floating: 1");
1068 EXPECT_CONTAINS(str, "at: 212,540");
1069 EXPECT_CONTAINS(str, "size: 960,540");
1070
1071 auto min = getFromSocket("/getprop active min_size");
1072 EXPECT_CONTAINS(min, "480");
1073 EXPECT_CONTAINS(min, "270");
1074
1075 auto max = getFromSocket("/getprop active max_size");
1076 EXPECT_CONTAINS(max, "1440");
1077 EXPECT_CONTAINS(max, "810");
1078 }
1079
1080 OK(getFromSocket("/reload"));
1081 Tests::killAllWindows();
1082
1083 OK(getFromSocket("/eval hl.plugin.test.add_window_rule()"));
1084 OK(getFromSocket("/reload"));
1085
1086 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'plugin_kitty' }, plugin_rule = 'effect' })"));
1087
1088 SPAWN_KITTY("plugin_kitty");
1089
1090 OK(getFromSocket("/eval hl.plugin.test.check_window_rule()"));
1091
1092 OK(getFromSocket("/reload"));
1093 Tests::killAllWindows();
1094
1095 OK(getFromSocket("/eval hl.plugin.test.add_window_rule()"));
1096 OK(getFromSocket("/reload"));
1097
1098 OK(getFromSocket("/eval hl.window_rule({ name = 'test-plugin-rule', match = { class = 'plugin_kitty' } })"));
1099 OK(getFromSocket("/eval hl.window_rule({ name = 'test-plugin-rule', plugin_rule = 'effect' })"));
1100
1101 SPAWN_KITTY("plugin_kitty");
1102
1103 OK(getFromSocket("/eval hl.plugin.test.check_window_rule()"));
1104 }
1105
1106 TEST_CASE(cycle_nextTiled) {
1107 // If the user specifically requests a tiled window, give them a tiled window
1108
1109 for (const auto& win : {"a", "b", "c", "d"}) {
1110 SPAWN_KITTY(win);
1111 }
1112
1113 // float the class:a window
1114 OK(getFromSocket("/dispatch hl.dsp.window.float({action = 'enable', window = 'class:a'})"));
1115 // float the class:c window
1116 OK(getFromSocket("/dispatch hl.dsp.window.float({action = 'enable', window = 'class:c'})"));
1117 // float the class:d window
1118 OK(getFromSocket("/dispatch hl.dsp.window.float({action = 'enable', window = 'class:d'})"));
1119
1120 // establish focus history
1121 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:a'})")); // floating
1122 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:b'})")); // tiled <-- What we want to focus on
1123 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:c'})")); // floating
1124 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:d'})")); // floating
1125
1126 // request a tiled window
1127 OK(getFromSocket("/dispatch hl.dsp.window.cycle_next({ next = true, tiled = true, floating = false})"));
1128
1129 ASSERT_CONTAINS(getFromSocket("/activewindow"), "class: b");
1130 }
1131
1132 TEST_CASE(cycle_nextFloating) {
1133 // If the user specifically requests a floating window, give them a floating window
1134
1135 for (const auto& win : {"a", "b", "c", "d"}) {
1136 SPAWN_KITTY(win);
1137 }
1138
1139 // float the class:b window
1140 OK(getFromSocket("/dispatch hl.dsp.window.float({action = 'enable', window = 'class:b'})"));
1141
1142 // establish focus history
1143 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:a'})")); // tiled
1144 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:b'})")); // floating <-- What we want to focus on
1145 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:c'})")); // tiled
1146 OK(getFromSocket("/dispatch hl.dsp.focus({window = 'class:d'})")); // tiled
1147
1148 // request a floating window
1149 OK(getFromSocket("/dispatch hl.dsp.window.cycle_next({ next = true, tiled = false, floating = true})"));
1150
1151 ASSERT_CONTAINS(getFromSocket("/activewindow"), "class: b");
1152 }
1153
1154 TEST_CASE(discussion14233) {
1155 // toggling fullscreen should not mess up workspace state on a 2 window workspace
1156 // with smart gaps
1157
1158 OK(getFromSocket(R"#(/eval hl.workspace_rule({ workspace = "w[tv1]", gaps_out = 0, gaps_in = 0 })
1159 hl.workspace_rule({ workspace = "f[1]", gaps_out = 0, gaps_in = 0 })
1160 hl.window_rule({
1161 name = "no-gaps-wtv1",
1162 match = { float = false, workspace = "w[tv1]" },
1163 border_size = 0,
1164 rounding = 0,
1165 })
1166 hl.window_rule({
1167 name = "no-gaps-f1",
1168 match = { float = false, workspace = "f[1]" },
1169 border_size = 0,
1170 rounding = 0,
1171 })
1172 )#"));
1173
1174 ASSERT(!!Tests::spawnKitty(), true);
1175
1176 // just make sure smart gaps work
1177 {
1178 auto str = getFromSocket("/clients");
1179 ASSERT_CONTAINS(str, "size: 1920,1080");
1180 ASSERT_CONTAINS(str, "at: 0,0");
1181 }
1182
1183 ASSERT(!!Tests::spawnKitty(), true);
1184
1185 {
1186 auto str = getFromSocket("/clients");
1187 ASSERT_COUNT_STRING(str, "size: 931,1036", 2);
1188 ASSERT_CONTAINS(str, "at: 22,22");
1189 ASSERT_CONTAINS(str, "at: 967,22");
1190 }
1191
1192 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1193 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1194
1195 {
1196 auto str = getFromSocket("/clients");
1197 ASSERT_COUNT_STRING(str, "size: 931,1036", 2);
1198 ASSERT_CONTAINS(str, "at: 22,22");
1199 ASSERT_CONTAINS(str, "at: 967,22");
1200 }
1201 }
1202
1203 TEST_CASE(execRulesWorkspaceOverride) {
1204 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_exec_override' }, workspace = '2' })"));
1205
1206 OK(getFromSocket("/dispatch hl.dsp.exec_cmd('[workspace 3] kitty --class kitty_exec_override')"));
1207
1208 Tests::waitUntilWindowsN(1);
1209
1210 auto str = getFromSocket("/activewindow");
1211 EXPECT_CONTAINS(str, "class: kitty_exec_override");
1212 EXPECT_CONTAINS(str, "workspace: 3");
1213
1214 Tests::killAllWindows();
1215 }
1216
1217 TEST_CASE(execRulesTagMutation) {
1218 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_tag_mutate' }, workspace = '2' })"));
1219 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_tag_mutate' }, tag = 'test_tag' })"));
1220
1221 OK(getFromSocket("/dispatch hl.dsp.exec_cmd('[workspace 3] kitty --class kitty_tag_mutate')"));
1222
1223 Tests::waitUntilWindowsN(1);
1224
1225 auto str = getFromSocket("/activewindow");
1226 EXPECT_CONTAINS(str, "class: kitty_tag_mutate");
1227 EXPECT_CONTAINS(str, "workspace: 3");
1228
1229 Tests::killAllWindows();
1230 }
1231
1232 TEST_CASE(execRulesDescendantProcess) {
1233 OK(getFromSocket("/dispatch hl.dsp.exec_cmd('kitty --class kitty_exec_workspace & wait', { workspace = '2 silent' })"));
1234
1235 Tests::waitUntilWindowsN(1);
1236
1237 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_workspace no_focus"), "false");
1238 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_exec_workspace' })"));
1239
1240 {
1241 const auto active = getFromSocket("/activewindow");
1242 EXPECT_CONTAINS(active, "class: kitty_exec_workspace");
1243 EXPECT_CONTAINS(active, "workspace: 2");
1244 }
1245
1246 OK(getFromSocket(
1247 "/dispatch hl.dsp.exec_cmd('[workspace 3; border_size 7] kitty --class kitty_exec_special & wait', { workspace = 'special:exec_rules silent', no_initial_focus = true, "
1248 "no_focus = true })"));
1249
1250 Tests::waitUntilWindowsN(2);
1251
1252 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_special no_focus"), "true");
1253 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_special border_size"), "7");
1254
1255 {
1256 const auto active = getFromSocket("/activewindow");
1257 EXPECT_CONTAINS(active, "class: kitty_exec_workspace");
1258 EXPECT_CONTAINS(active, "workspace: 2");
1259 }
1260
1261 OK(getFromSocket("/dispatch hl.dsp.window.set_prop({ window = 'class:kitty_exec_special', prop = 'no_focus', value = 'false' })"));
1262 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_exec_special' })"));
1263
1264 {
1265 const auto active = getFromSocket("/activewindow");
1266 EXPECT_CONTAINS(active, "class: kitty_exec_special");
1267 EXPECT_CONTAINS(active, "special:exec_rules");
1268 }
1269
1270 Tests::killAllWindows();
1271 }
1272
1273 TEST_CASE(execRulesPendingIsolation) {
1274 OK(getFromSocket(
1275 "/eval do hl.exec_cmd('sleep 1 && kitty --class kitty_exec_first', { workspace = '2 silent' }); "
1276 "hl.exec_cmd('sleep 2 && kitty --class kitty_exec_second', { workspace = 'special:exec_rules_pending silent', no_initial_focus = true, no_focus = true }) end"));
1277
1278 Tests::waitUntilWindowsN(1);
1279
1280 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_first no_focus"), "false");
1281 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_exec_first' })"));
1282
1283 {
1284 const auto active = getFromSocket("/activewindow");
1285 EXPECT_CONTAINS(active, "class: kitty_exec_first");
1286 EXPECT_CONTAINS(active, "workspace: 2");
1287 }
1288
1289 Tests::waitUntilWindowsN(2);
1290
1291 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_first no_focus"), "false");
1292 EXPECT_CONTAINS(getFromSocket("/getprop class:kitty_exec_second no_focus"), "true");
1293
1294 OK(getFromSocket("/dispatch hl.dsp.window.set_prop({ window = 'class:kitty_exec_second', prop = 'no_focus', value = 'false' })"));
1295 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_exec_second' })"));
1296
1297 {
1298 const auto active = getFromSocket("/activewindow");
1299 EXPECT_CONTAINS(active, "class: kitty_exec_second");
1300 EXPECT_CONTAINS(active, "special:exec_rules_pending");
1301 }
1302
1303 Tests::killAllWindows();
1304 }
1305
1306 TEST_CASE(pinnedRetainsPositionOnWorkspaceChange) {
1307 ASSERT(!!Tests::spawnKitty("a"), true);
1308
1309 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1310
1311 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'enable' })"));
1312 OK(getFromSocket("/dispatch hl.dsp.window.pin()"));
1313
1314 {
1315 auto str = getFromSocket("/clients");
1316 ASSERT_CONTAINS(str, "pinned: 1");
1317 }
1318
1319 OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 1900, y = 1000 })"));
1320
1321 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
1322
1323 {
1324 auto str = getFromSocket("/workspaces");
1325 ASSERT_CONTAINS(str, "workspace ID 2");
1326 }
1327
1328 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1329
1330 {
1331 auto str = getFromSocket("/workspaces");
1332 ASSERT_CONTAINS(str, "workspace ID 1");
1333 }
1334
1335 {
1336 auto str = getFromSocket("/clients");
1337 ASSERT_CONTAINS(str, "pinned: 1");
1338 ASSERT_CONTAINS(str, "at: 1900,1000");
1339 }
1340 }
1341
1342 TEST_CASE(monitorrule) {
1343 if (getFromSocket("/monitors all").contains("HEADLESS-3"))
1344 OK(getFromSocket("/output remove HEADLESS-3"));
1345
1346 OK(getFromSocket("/output create headless HEADLESS-3"));
1347 const auto MONALL = getFromSocket("/monitors all");
1348 CScopeGuard guard([&] {
1349 if (MONALL.contains("HEADLESS-3"))
1350 OK(getFromSocket("/output remove HEADLESS-3"));
1351 });
1352
1353 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
1354 OK(getFromSocket("/eval hl.window_rule({ name = 'monitorrule', match = { class = 'monitor_kitty' }, monitor = 'HEADLESS-3' })"));
1355
1356 Tests::spawnKitty("monitor_kitty");
1357 ASSERT(Tests::windowCount(), 1);
1358 const auto MON_SRC_ID = Tests::getAttribute(getFromSocket("/activewindow"), "monitor");
1359 ASSERT_CONTAINS(MONALL, "HEADLESS-3 (ID " + MON_SRC_ID);
1360 EXPECT_CONTAINS(getFromSocket("/activeworkspace"), "HEADLESS-3");
1361
1362 Tests::killAllWindows();
1363 OK(getFromSocket("/reload"));
1364
1365 OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })"));
1366 OK(getFromSocket("/eval hl.window_rule({ name = 'monitorrule', match = { class = 'silent_kitty' }, monitor = 'HEADLESS-3 silent' })"));
1367
1368 Tests::spawnKitty("silent_kitty");
1369 ASSERT(Tests::windowCount(), 1);
1370 const auto SILENT_SRC_ID = Tests::getAttribute(getFromSocket("/clients"), "monitor");
1371 ASSERT_CONTAINS(MONALL, "HEADLESS-3 (ID " + SILENT_SRC_ID);
1372 EXPECT_CONTAINS(getFromSocket("/activeworkspace"), "HEADLESS-2");
1373 }
1374
1375 TEST_CASE(mouseResize) {
1376 #define RESET_WINDOW() \
1377 OK(getFromSocket("r/reload")); \
1378 OK(getFromSocket("r/eval hl.unbind('mouse:273')")); \
1379 OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 640, y = 400, window = 'class:kitty' })")); \
1380 OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 0, y = 0, window = 'class:kitty' })")); \
1381 OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 640, y = 400 })")); \
1382 EXPECT_CONTAINS(getFromSocket("/clients"), "size: 640,400"); \
1383 EXPECT_CONTAINS(getFromSocket("/clients"), "at: 0,0");
1384
1385 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty' }, float = true })"));
1386 Tests::spawnKitty();
1387 ASSERT(Tests::windowCount(), 1);
1388 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty' })"));
1389
1390 RESET_WINDOW();
1391 OK(getFromSocket("r/eval hl.bind('mouse:273', hl.dsp.window.resize(), { mouse = true })"));
1392 OK(getFromSocket("/eval hl.plugin.test.click(273, 1)"));
1393
1394 // Position setting works immediately, but updating window sizes interactively doesn't.
1395 for (size_t i = 0; i < 50; i++) {
1396 OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 700, y = 200 })"));
1397 if (getFromSocket("/clients").contains("size: 700,200")) {
1398 break;
1399 }
1400
1401 std::this_thread::sleep_for(std::chrono::milliseconds(50));
1402 }
1403 OK(getFromSocket("/eval hl.plugin.test.click(273, 0)"));
1404 EXPECT_CONTAINS(getFromSocket("/clients"), "size: 700,200");
1405
1406 RESET_WINDOW();
1407 OK(getFromSocket("r/eval hl.bind('mouse:273', hl.dsp.window.resize({ keep_aspect_ratio = true }), { mouse = true })"));
1408 OK(getFromSocket("/eval hl.plugin.test.click(273, 1)"));
1409 OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 1280, y = 100 })"));
1410 OK(getFromSocket("/eval hl.plugin.test.click(273, 0)"));
1411 EXPECT_CONTAINS(getFromSocket("/clients"), "size: 1280,800");
1412
1413 RESET_WINDOW();
1414 OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty' }, keep_aspect_ratio = true })"));
1415 OK(getFromSocket("r/eval hl.bind('mouse:273', hl.dsp.window.resize({ keep_aspect_ratio = false }), { mouse = true })"));
1416 OK(getFromSocket("/eval hl.plugin.test.click(273, 1)"));
1417 OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 700, y = 200 })"));
1418 OK(getFromSocket("/eval hl.plugin.test.click(273, 0)"));
1419 EXPECT_CONTAINS(getFromSocket("/clients"), "size: 700,200");
1420 #undef RESET_WINDOW
1421 }
1422
1423 TEST_CASE(getFullscreenHandler) {
1424
1425 // Correctly detect the FS handler of a window
1426
1427 // We will use scrolling as it has a layout handled FS
1428
1429 // First test that it's obtained properly in a default FS handled layout - dwindle
1430
1431 OK(getFromSocket("r/eval hl.config({ general = { layout = 'dwindle' } })"));
1432
1433 // Tiled
1434 Tests::spawnKitty("cat");
1435
1436 // FS - check - unFS
1437 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1438 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "fullscreenHandler"), "default");
1439 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1440
1441 // Floating
1442
1443 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })"));
1444
1445 // FS - check - unFS
1446 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1447 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "fullscreenHandler"), "default");
1448 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1449
1450 // switch to scrolling layout
1451
1452 OK(getFromSocket("r/eval hl.config({ general = { layout = 'scrolling' } })"));
1453
1454 // Window still floating. There is no layout handled floating FS behaviour
1455
1456 // FS - check - unFS
1457 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1458 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "fullscreenHandler"), "default");
1459 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1460
1461 // tile the window, and explicitly default handle it
1462 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset' })"));
1463
1464 // FS - check - unFS
1465 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ layout_aware = false })"));
1466 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "fullscreenHandler"), "default");
1467 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ layout_aware = false })"));
1468
1469 // check if layout handler is correctly ontaind
1470
1471 // FS - check - unFS
1472 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1473 EXPECT(Tests::getAttribute(getFromSocket("/activewindow"), "fullscreenHandler"), "scrolling");
1474 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen()"));
1475 }
1476
1477 TEST_CASE(sendFsWindowToAnotherWorkspace) {
1478
1479 /*
1480 If default handled, will be moved as default handled to other workspace.
1481 If layout handled, will be reFSed using target workspace's layout handled if exists
1482
1483 FS sizes are the same for all FS handlers so we share them
1484
1485 */
1486
1487 // Test Default Handled FS
1488
1489 // Establish 5 workspaces with layouts
1490 OK(getFromSocket("/eval hl.workspace_rule({workspace = '1', layout = 'dwindle'})"));
1491 OK(getFromSocket("/eval hl.workspace_rule({workspace = '2', layout = 'master'})"));
1492 OK(getFromSocket("/eval hl.workspace_rule({workspace = '3', layout = 'monocle'})"));
1493 OK(getFromSocket("/eval hl.workspace_rule({workspace = '4', layout = 'scrolling'})"));
1494 OK(getFromSocket("/eval hl.workspace_rule({workspace = '5', layout = 'scrolling'})"));
1495
1496 // set gaps_out to a high value and establish a workspace rule to catch cases where maximised gets the wrong work area size
1497 OK(getFromSocket("/eval hl.config({ general = { gaps_out = 20,}})"));
1498 OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'f[1]', gaps_out = 0, })"));
1499
1500 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1501
1502 Tests::spawnKitty("traveller_1");
1503
1504 // Testing with Tiled window
1505
1506 /*
1507 Test with default handled FS window
1508 */
1509
1510 // Testing Fullscreen
1511
1512 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'fullscreen'})"));
1513
1514 // dwindle
1515 {
1516 const auto str = getFromSocket("/activewindow");
1517 ASSERT_CONTAINS(str, "at: 0,0");
1518 ASSERT_CONTAINS(str, "size: 1920,1080");
1519 ASSERT_CONTAINS(str, "workspace: 1");
1520 ASSERT_CONTAINS(str, "fullscreen: 2");
1521 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1522 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1523 }
1524
1525 // master - try with follow = false
1526 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '2', follow = false })"));
1527 // go to that workspace post move - expect FS window to be in focus
1528 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 2 })"));
1529 {
1530 const auto str = getFromSocket("/activewindow");
1531 ASSERT_CONTAINS(str, "at: 0,0");
1532 ASSERT_CONTAINS(str, "size: 1920,1080");
1533 ASSERT_CONTAINS(str, "workspace: 2");
1534 ASSERT_CONTAINS(str, "fullscreen: 2");
1535 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1536 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1537 }
1538
1539 // monocle
1540 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '3' })"));
1541 {
1542 const auto str = getFromSocket("/activewindow");
1543 ASSERT_CONTAINS(str, "at: 0,0");
1544 ASSERT_CONTAINS(str, "size: 1920,1080");
1545 ASSERT_CONTAINS(str, "workspace: 3");
1546 ASSERT_CONTAINS(str, "fullscreen: 2");
1547 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1548 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1549 }
1550
1551 // scroll
1552 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4' })"));
1553 {
1554 const auto str = getFromSocket("/activewindow");
1555 ASSERT_CONTAINS(str, "at: 0,0");
1556 ASSERT_CONTAINS(str, "size: 1920,1080");
1557 ASSERT_CONTAINS(str, "workspace: 4");
1558 ASSERT_CONTAINS(str, "fullscreen: 2");
1559 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1560 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1561 }
1562
1563 // Try with follow = false for scroll since it's default to layout handled and vice versa and should be tested thoroughly
1564
1565 // monocle
1566 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '3' })"));
1567 {
1568 const auto str = getFromSocket("/activewindow");
1569 ASSERT_CONTAINS(str, "at: 0,0");
1570 ASSERT_CONTAINS(str, "size: 1920,1080");
1571 ASSERT_CONTAINS(str, "workspace: 3");
1572 ASSERT_CONTAINS(str, "fullscreen: 2");
1573 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1574 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1575 }
1576
1577 // scroll - try with follow = false
1578 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4', follow = false })"));
1579 // go to that workspace post move - expect FS window to be in focus
1580 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 4 })"));
1581 {
1582 const auto str = getFromSocket("/activewindow");
1583 ASSERT_CONTAINS(str, "at: 0,0");
1584 ASSERT_CONTAINS(str, "size: 1920,1080");
1585 ASSERT_CONTAINS(str, "workspace: 4");
1586 ASSERT_CONTAINS(str, "fullscreen: 2");
1587 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1588 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1589 }
1590
1591 // before next test kill the window and make a new one on workspace 1 to get a fresh start
1592
1593 Tests::killAllWindows();
1594 Tests::waitUntilWindowsN(0);
1595
1596 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1597 Tests::spawnKitty("traveller_2");
1598
1599 // Testing Maximised
1600
1601 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'maximized'})"));
1602
1603 // dwindle
1604 {
1605 const auto str = getFromSocket("/activewindow");
1606 ASSERT_CONTAINS(str, "at: 2,2");
1607 ASSERT_CONTAINS(str, "size: 1916,1076");
1608 ASSERT_CONTAINS(str, "workspace: 1");
1609 ASSERT_CONTAINS(str, "fullscreen: 1");
1610 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1611 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1612 }
1613
1614 // master - try with follow = false
1615 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '2', follow = false })"));
1616 // go to that workspace post move - expect FS window to be in focus
1617 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 2 })"));
1618 {
1619 const auto str = getFromSocket("/activewindow");
1620 ASSERT_CONTAINS(str, "at: 2,2");
1621 ASSERT_CONTAINS(str, "size: 1916,1076");
1622 ASSERT_CONTAINS(str, "workspace: 2");
1623 ASSERT_CONTAINS(str, "fullscreen: 1");
1624 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1625 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1626 }
1627
1628 // monocle
1629 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '3' })"));
1630 {
1631 const auto str = getFromSocket("/activewindow");
1632 ASSERT_CONTAINS(str, "at: 2,2");
1633 ASSERT_CONTAINS(str, "size: 1916,1076");
1634 ASSERT_CONTAINS(str, "workspace: 3");
1635 ASSERT_CONTAINS(str, "fullscreen: 1");
1636 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1637 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1638 }
1639
1640 // scroll
1641 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4' })"));
1642 {
1643 const auto str = getFromSocket("/activewindow");
1644 ASSERT_CONTAINS(str, "at: 2,2");
1645 ASSERT_CONTAINS(str, "size: 1916,1076");
1646 ASSERT_CONTAINS(str, "workspace: 4");
1647 ASSERT_CONTAINS(str, "fullscreen: 1");
1648 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1649 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1650 }
1651
1652 // Try with follow = false for scroll since it's default to layout handled and vice versa and should be tested thoroughly
1653
1654 // monocle
1655 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '3' })"));
1656 {
1657 const auto str = getFromSocket("/activewindow");
1658 ASSERT_CONTAINS(str, "at: 2,2");
1659 ASSERT_CONTAINS(str, "size: 1916,1076");
1660 ASSERT_CONTAINS(str, "workspace: 3");
1661 ASSERT_CONTAINS(str, "fullscreen: 1");
1662 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1663 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1664 }
1665
1666 // scroll - try with follow = false
1667 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4', follow = false })"));
1668 // go to that workspace post move - expect FS window to be in focus
1669 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 4 })"));
1670 {
1671 const auto str = getFromSocket("/activewindow");
1672 ASSERT_CONTAINS(str, "at: 2,2");
1673 ASSERT_CONTAINS(str, "size: 1916,1076");
1674 ASSERT_CONTAINS(str, "workspace: 4");
1675 ASSERT_CONTAINS(str, "fullscreen: 1");
1676 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1677 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1678 }
1679
1680 // Before next test kill the window and make a new one on workspace 1 to get a fresh start
1681
1682 Tests::killAllWindows();
1683 Tests::waitUntilWindowsN(0);
1684
1685 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1686 Tests::spawnKitty("traveller_3");
1687
1688 /*
1689 Test Layout Handled FS - Move btw scroll-scroll and scroll-dwindle
1690 */
1691
1692 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4' })"));
1693
1694 // fullscreen
1695
1696 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'fullscreen'})"));
1697
1698 // scroll
1699 {
1700 const auto str = getFromSocket("/activewindow");
1701 ASSERT_CONTAINS(str, "at: 0,0");
1702 ASSERT_CONTAINS(str, "size: 1920,1080");
1703 ASSERT_CONTAINS(str, "workspace: 4");
1704 ASSERT_CONTAINS(str, "fullscreen: 2");
1705 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1706 ASSERT_CONTAINS(str, "fullscreenHandler: scrolling");
1707 }
1708
1709 // move to another scrolling workspace
1710 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '5' })"));
1711 {
1712 const auto str = getFromSocket("/activewindow");
1713 ASSERT_CONTAINS(str, "at: 0,0");
1714 ASSERT_CONTAINS(str, "size: 1920,1080");
1715 ASSERT_CONTAINS(str, "workspace: 5");
1716 ASSERT_CONTAINS(str, "fullscreen: 2");
1717 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1718 // both have layout handlers so expected to use that
1719 ASSERT_CONTAINS(str, "fullscreenHandler: scrolling");
1720 }
1721
1722 // dwindle
1723 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '1' })"));
1724 // go to that workspace post move - expect FS window to be in focus
1725 {
1726 const auto str = getFromSocket("/activewindow");
1727 ASSERT_CONTAINS(str, "at: 0,0");
1728 ASSERT_CONTAINS(str, "size: 1920,1080");
1729 ASSERT_CONTAINS(str, "workspace: 1");
1730 ASSERT_CONTAINS(str, "fullscreen: 2");
1731 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1732 // No layout handler in dwindle so expect it to fall back to using the only available handler which is default
1733 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1734 }
1735
1736 // scroll - try with follow = false
1737 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4', follow = false })"));
1738 // go to that workspace post move - expect FS window to be in focus
1739 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 4 })"));
1740 {
1741 const auto str = getFromSocket("/activewindow");
1742 ASSERT_CONTAINS(str, "at: 0,0");
1743 ASSERT_CONTAINS(str, "size: 1920,1080");
1744 ASSERT_CONTAINS(str, "workspace: 4");
1745 ASSERT_CONTAINS(str, "fullscreen: 2");
1746 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1747 // It's not coming from a default handler so expect it to remain as such
1748 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1749 }
1750
1751 // maximised
1752
1753 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'maximized'})"));
1754
1755 // scroll
1756 {
1757 const auto str = getFromSocket("/activewindow");
1758 ASSERT_CONTAINS(str, "at: 2,2");
1759 ASSERT_CONTAINS(str, "size: 1916,1076");
1760 ASSERT_CONTAINS(str, "workspace: 4");
1761 ASSERT_CONTAINS(str, "fullscreen: 1");
1762 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1763 ASSERT_CONTAINS(str, "fullscreenHandler: scrolling");
1764 }
1765
1766 // move to another scrolling workspace
1767 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '5' })"));
1768 {
1769 const auto str = getFromSocket("/activewindow");
1770 ASSERT_CONTAINS(str, "at: 2,2");
1771 ASSERT_CONTAINS(str, "size: 1916,1076");
1772 ASSERT_CONTAINS(str, "workspace: 5");
1773 ASSERT_CONTAINS(str, "fullscreen: 1");
1774 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1775 // both have layout handlers so expected to use that
1776 ASSERT_CONTAINS(str, "fullscreenHandler: scrolling");
1777 }
1778
1779 // dwindle
1780 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '1' })"));
1781 {
1782 const auto str = getFromSocket("/activewindow");
1783 ASSERT_CONTAINS(str, "at: 2,2");
1784 ASSERT_CONTAINS(str, "size: 1916,1076");
1785 ASSERT_CONTAINS(str, "workspace: 1");
1786 ASSERT_CONTAINS(str, "fullscreen: 1");
1787 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1788 // No layout handler in dwindle so expect it to fall back to using the only available handler which is default
1789 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1790 }
1791
1792 // scroll - try with follow = false
1793 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4', follow = false })"));
1794 // go to that workspace post move - expect FS window to be in focus
1795 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 4 })"));
1796 {
1797 const auto str = getFromSocket("/activewindow");
1798 ASSERT_CONTAINS(str, "at: 2,2");
1799 ASSERT_CONTAINS(str, "size: 1916,1076");
1800 ASSERT_CONTAINS(str, "workspace: 4");
1801 ASSERT_CONTAINS(str, "fullscreen: 1");
1802 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1803 // It's coming from a default handler so expect it to remain as such
1804 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1805 }
1806
1807 // Testing the same things but with floating
1808 // floating has no layout handled Fs so just test moving a floating FS window around with maximised and fullscreen values changing between every move
1809
1810 Tests::killAllWindows();
1811 Tests::waitUntilWindowsN(0);
1812
1813 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
1814 Tests::spawnKitty("traveller_float");
1815 OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:traveller_float' })"));
1816
1817 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'fullscreen'})"));
1818
1819 // workspace 1 (dwindle) - fullscreen
1820 {
1821 const auto str = getFromSocket("/activewindow");
1822 ASSERT_CONTAINS(str, "at: 0,0");
1823 ASSERT_CONTAINS(str, "size: 1920,1080");
1824 ASSERT_CONTAINS(str, "workspace: 1");
1825 ASSERT_CONTAINS(str, "fullscreen: 2");
1826 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1827 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1828 ASSERT_CONTAINS(str, "floating: 1");
1829 }
1830
1831 // move to workspace 2 (master) - still fullscreen, then toggle to maximized
1832 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '2' })"));
1833 {
1834 const auto str = getFromSocket("/activewindow");
1835 ASSERT_CONTAINS(str, "at: 0,0");
1836 ASSERT_CONTAINS(str, "size: 1920,1080");
1837 ASSERT_CONTAINS(str, "workspace: 2");
1838 ASSERT_CONTAINS(str, "fullscreen: 2");
1839 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1840 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1841 ASSERT_CONTAINS(str, "floating: 1");
1842 }
1843
1844 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'maximized'})"));
1845 {
1846 const auto str = getFromSocket("/activewindow");
1847 ASSERT_CONTAINS(str, "at: 2,2");
1848 ASSERT_CONTAINS(str, "size: 1916,1076");
1849 ASSERT_CONTAINS(str, "workspace: 2");
1850 ASSERT_CONTAINS(str, "fullscreen: 1");
1851 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1852 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1853 ASSERT_CONTAINS(str, "floating: 1");
1854 }
1855
1856 // move to workspace 3 (monocle) - still maximized, then toggle to fullscreen
1857 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '3' })"));
1858 {
1859 const auto str = getFromSocket("/activewindow");
1860 ASSERT_CONTAINS(str, "at: 2,2");
1861 ASSERT_CONTAINS(str, "size: 1916,1076");
1862 ASSERT_CONTAINS(str, "workspace: 3");
1863 ASSERT_CONTAINS(str, "fullscreen: 1");
1864 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1865 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1866 ASSERT_CONTAINS(str, "floating: 1");
1867 }
1868
1869 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'fullscreen'})"));
1870 {
1871 const auto str = getFromSocket("/activewindow");
1872 ASSERT_CONTAINS(str, "at: 0,0");
1873 ASSERT_CONTAINS(str, "size: 1920,1080");
1874 ASSERT_CONTAINS(str, "workspace: 3");
1875 ASSERT_CONTAINS(str, "fullscreen: 2");
1876 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1877 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1878 ASSERT_CONTAINS(str, "floating: 1");
1879 }
1880
1881 // move to workspace 4 (scrolling) - still fullscreen, then toggle to maximized
1882 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '4' })"));
1883 {
1884 const auto str = getFromSocket("/activewindow");
1885 ASSERT_CONTAINS(str, "at: 0,0");
1886 ASSERT_CONTAINS(str, "size: 1920,1080");
1887 ASSERT_CONTAINS(str, "workspace: 4");
1888 ASSERT_CONTAINS(str, "fullscreen: 2");
1889 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1890 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1891 ASSERT_CONTAINS(str, "floating: 1");
1892 }
1893
1894 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'maximized'})"));
1895 {
1896 const auto str = getFromSocket("/activewindow");
1897 ASSERT_CONTAINS(str, "at: 2,2");
1898 ASSERT_CONTAINS(str, "size: 1916,1076");
1899 ASSERT_CONTAINS(str, "workspace: 4");
1900 ASSERT_CONTAINS(str, "fullscreen: 1");
1901 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1902 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1903 ASSERT_CONTAINS(str, "floating: 1");
1904 }
1905
1906 // move to workspace 5 (scrolling) with follow = false - still maximized, then toggle to fullscreen
1907 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '5', follow = false })"));
1908 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 5 })"));
1909 {
1910 const auto str = getFromSocket("/activewindow");
1911 ASSERT_CONTAINS(str, "at: 2,2");
1912 ASSERT_CONTAINS(str, "size: 1916,1076");
1913 ASSERT_CONTAINS(str, "workspace: 5");
1914 ASSERT_CONTAINS(str, "fullscreen: 1");
1915 ASSERT_CONTAINS(str, "fullscreenClient: 1");
1916 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1917 ASSERT_CONTAINS(str, "floating: 1");
1918 }
1919
1920 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({mode = 'fullscreen'})"));
1921 {
1922 const auto str = getFromSocket("/activewindow");
1923 ASSERT_CONTAINS(str, "at: 0,0");
1924 ASSERT_CONTAINS(str, "size: 1920,1080");
1925 ASSERT_CONTAINS(str, "workspace: 5");
1926 ASSERT_CONTAINS(str, "fullscreen: 2");
1927 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1928 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1929 ASSERT_CONTAINS(str, "floating: 1");
1930 }
1931
1932 // move back to workspace 1 (dwindle) with follow = false - still fullscreen
1933 OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = '1', follow = false })"));
1934 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 1 })"));
1935 {
1936 const auto str = getFromSocket("/activewindow");
1937 ASSERT_CONTAINS(str, "at: 0,0");
1938 ASSERT_CONTAINS(str, "size: 1920,1080");
1939 ASSERT_CONTAINS(str, "workspace: 1");
1940 ASSERT_CONTAINS(str, "fullscreen: 2");
1941 ASSERT_CONTAINS(str, "fullscreenClient: 2");
1942 ASSERT_CONTAINS(str, "fullscreenHandler: default");
1943 ASSERT_CONTAINS(str, "floating: 1");
1944 }
1945 }