Debian Codegraph @

hyprtester/src/tests/main/layer.cpp

raw
1 #include "../../Log.hpp"
2 #include "../shared.hpp"
3 #include "tests.hpp"
4 #include "../../shared.hpp"
5 #include "../../hyprctlCompat.hpp"
6 #include <format>
7 #include <hyprutils/os/Process.hpp>
8 #include <hyprutils/memory/WeakPtr.hpp>
9
10 using namespace Hyprutils::OS;
11 using namespace Hyprutils::Memory;
12
13 static bool spawnLayer(const std::string& namespace_, const std::vector<std::string>& args = {}) {
14 NLog::log("{}Spawning kitty layer {}", Colors::YELLOW, namespace_);
15 if (!Tests::spawnLayerKitty(namespace_, args)) {
16 NLog::log("{}Error: {} layer did not spawn", Colors::RED, namespace_);
17 return false;
18 }
19 return true;
20 }
21
22 static std::string getLayerLine(const std::string& layers, const std::string& target) {
23
24 auto pos = layers.find("namespace: " + target);
25 if (pos == std::string::npos)
26 return "";
27
28 auto start = layers.rfind('\n', pos);
29 start = (start == std::string::npos) ? 0 : start + 1;
30
31 auto end = layers.find('\n', pos);
32
33 return layers.substr(start, end - start);
34 }
35
36 TEST_CASE(plugin_layerrules) {
37
38 EXPECT(spawnLayer("rule-layer"), true);
39
40 OK(getFromSocket("/eval hl.plugin.test.add_layer_rule()"));
41 OK(getFromSocket("/reload"));
42
43 OK(getFromSocket("/eval hl.layer_rule({ match = { namespace = 'rule-layer' }, plugin_rule = 'effect' })"));
44
45 EXPECT(spawnLayer("rule-layer"), true);
46
47 EXPECT(spawnLayer("norule-layer"), true);
48
49 OK(getFromSocket("/eval hl.plugin.test.check_layer_rule()"));
50 }
51
52 TEST_CASE(layerPointerFocusPreservedOnKeyboardRefocus) {
53 static constexpr const char* LAYER_NAMESPACE = "pointer-focus-layer";
54
55 OK(getFromSocket("/eval hl.config({ input = { follow_mouse = 0 } })"));
56
57 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
58 ASSERT(!!Tests::spawnKitty("pointer_focus_ws1"), true);
59
60 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
61 ASSERT(!!Tests::spawnKitty("pointer_focus_ws2"), true);
62
63 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
64 OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:pointer_focus_ws1' })"));
65
66 ASSERT(spawnLayer(LAYER_NAMESPACE, {"--edge=top", "--layer=top", "--lines=48px", "--focus-policy=not-allowed"}), true);
67
68 OK(getFromSocket(std::format("/eval hl.plugin.test.set_pointer_focus_layer('{}')", LAYER_NAMESPACE)));
69 OK(getFromSocket(std::format("/eval hl.plugin.test.check_pointer_focus_layer('{}')", LAYER_NAMESPACE)));
70
71 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })"));
72 ASSERT_CONTAINS(getFromSocket("/activewindow"), "class: pointer_focus_ws2\n");
73 OK(getFromSocket(std::format("/eval hl.plugin.test.check_pointer_focus_layer('{}')", LAYER_NAMESPACE)));
74 }
75
76 TEST_CASE(layerVisibilityOnFs) {
77
78 // For default handled fullscreen
79
80 static constexpr const char* LAYER_NAMESPACE = "bar-like-layer";
81
82 ASSERT(spawnLayer(LAYER_NAMESPACE, {"--edge=top", "--layer=top", "--lines=48px", "--focus-policy=not-allowed"}), true);
83
84 Tests::spawnKitty("cat");
85
86 {
87 auto str = getLayerLine(getFromSocket("/layers"), LAYER_NAMESPACE);
88 EXPECT_CONTAINS(str, "a: 1")
89 EXPECT_CONTAINS(getFromSocket("/activewindow"), "fullscreen: 0");
90 }
91
92 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized', action = 'set', window = 'class:cat' })"));
93
94 {
95
96 auto str = getLayerLine(getFromSocket("/layers"), LAYER_NAMESPACE);
97 EXPECT_CONTAINS(str, "a: 1")
98 EXPECT_CONTAINS(getFromSocket("/activewindow"), "fullscreen: 1");
99 }
100
101 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized', action = 'unset', window = 'class:cat' })"));
102
103 {
104 auto str = getLayerLine(getFromSocket("/layers"), LAYER_NAMESPACE);
105 EXPECT_CONTAINS(str, "a: 1")
106 EXPECT_CONTAINS(getFromSocket("/activewindow"), "fullscreen: 0");
107 }
108
109 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set', window = 'class:cat' })"));
110
111 {
112 auto str = getLayerLine(getFromSocket("/layers"), LAYER_NAMESPACE);
113 EXPECT_CONTAINS(str, "a: 0")
114 EXPECT_CONTAINS(getFromSocket("/activewindow"), "fullscreen: 2");
115 }
116
117 OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'unset', window = 'class:cat' })"));
118
119 {
120 auto str = getLayerLine(getFromSocket("/layers"), LAYER_NAMESPACE);
121 EXPECT_CONTAINS(str, "a: 1")
122 EXPECT_CONTAINS(getFromSocket("/activewindow"), "fullscreen: 0");
123 }
124 }
125
126 TEST_CASE(windowRefocusRestoresKeyboardFocusAfterSurfaceFocusCleared) {
127 static constexpr const char* WINDOW_CLASS = "keyboard_refocus_target";
128
129 OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"));
130 ASSERT(!!Tests::spawnKitty(WINDOW_CLASS), true);
131 OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'class:{}' }})", WINDOW_CLASS)));
132 ASSERT_CONTAINS(getFromSocket("/activewindow"), std::format("class: {}\n", WINDOW_CLASS));
133 OK(getFromSocket(std::format("/eval hl.plugin.test.check_keyboard_focus_window('{}')", WINDOW_CLASS)));
134
135 OK(getFromSocket("/eval hl.plugin.test.clear_surface_focus()"));
136 OK(getFromSocket(std::format("/eval hl.plugin.test.window_soft_focus('{}')", WINDOW_CLASS)));
137
138 OK(getFromSocket(std::format("/eval hl.plugin.test.check_keyboard_focus_window('{}')", WINDOW_CLASS)));
139 }