@@ -18,6 +18,122 @@ using namespace Hyprutils::Memory;
1818#define UP CUniquePointer
1919#define SP CSharedPointer
2020
21+ static void testAnrDialogs () {
22+ NLog::log (" {}Testing anrdialogs" , Colors::YELLOW);
23+
24+ OK (getFromSocket (" /keyword misc:enable_anr_dialog true" ));
25+ OK (getFromSocket (" /keyword misc:anr_missed_pings 1" ));
26+
27+ NLog::log (" {}anrdialogs Should pop up on parent's workspace" , Colors::YELLOW);
28+
29+ NLog::log (" {}anrdialog: regular workspaces" , Colors::YELLOW);
30+ {
31+ OK (getFromSocket (" /dispatch workspace 2" ));
32+
33+ Tests::spawnKitty (" bad_kitty" );
34+
35+ int pid = 0 ;
36+ {
37+ auto str = getFromSocket (" /activewindow" );
38+ EXPECT_CONTAINS (str, " workspace: 2" );
39+ auto pos = str.find (" pid" ) + 4 ;
40+ auto end = str.find (' \n ' , pos);
41+ pid = std::stoi (str.substr (pos, end));
42+ }
43+
44+ OK (getFromSocket (" /dispatch workspace 1" ));
45+
46+ ::kill (pid, SIGSTOP);
47+
48+ Tests::waitUntilWindowsN (2 );
49+
50+ {
51+ auto str = getFromSocket (" /activeworkspace" );
52+ EXPECT_CONTAINS (str, " windows: 0" );
53+ }
54+
55+ {
56+ OK (getFromSocket (" /dispatch focuswindow class:hyprland-dialog" ))
57+ auto str = getFromSocket (" /activewindow" );
58+ EXPECT_CONTAINS (str, " workspace: 2" );
59+ }
60+
61+ Tests::killAllWindows ();
62+ }
63+
64+ NLog::log (" {}anrdialog: named workspaces" , Colors::YELLOW);
65+ {
66+
67+ OK (getFromSocket (" /dispatch workspace name:yummy" ));
68+
69+ Tests::spawnKitty (" bad_kitty" );
70+
71+ int pid = 0 ;
72+ {
73+ auto str = getFromSocket (" /activewindow" );
74+ EXPECT_CONTAINS (str, " yummy" ); // can't predetermined workspace id
75+ auto pos = str.find (" pid" ) + 4 ;
76+ auto end = str.find (' \n ' , pos);
77+ pid = std::stoi (str.substr (pos, end));
78+ }
79+
80+ OK (getFromSocket (" /dispatch workspace 1" ));
81+
82+ ::kill (pid, SIGSTOP);
83+
84+ Tests::waitUntilWindowsN (2 );
85+
86+ {
87+ auto str = getFromSocket (" /activeworkspace" );
88+ EXPECT_CONTAINS (str, " windows: 0" );
89+ }
90+
91+ {
92+ OK (getFromSocket (" /dispatch focuswindow class:hyprland-dialog" ))
93+ auto str = getFromSocket (" /activewindow" );
94+ EXPECT_CONTAINS (str, " yummy" );
95+ }
96+
97+ Tests::killAllWindows ();
98+ }
99+
100+ NLog::log (" {}anrdialog: special workspaces" , Colors::YELLOW);
101+ {
102+
103+ OK (getFromSocket (" /dispatch workspace special:apple" ));
104+
105+ Tests::spawnKitty (" bad_kitty" );
106+
107+ int pid = 0 ;
108+ {
109+ auto str = getFromSocket (" /activewindow" );
110+ EXPECT_CONTAINS (str, " special:apple" );
111+
112+ auto pos = str.find (" pid" ) + 4 ;
113+ auto end = str.find (' \n ' , pos);
114+ pid = std::stoi (str.substr (pos, end));
115+ }
116+
117+ OK (getFromSocket (" /dispatch togglespecialworkspace apple" ));
118+ OK (getFromSocket (" /dispatch workspace 1" ));
119+
120+ ::kill (pid, SIGSTOP);
121+
122+ Tests::waitUntilWindowsN (2 );
123+
124+ {
125+ OK (getFromSocket (" /dispatch focuswindow class:hyprland-dialog" ))
126+ auto str = getFromSocket (" /activewindow" );
127+ EXPECT_CONTAINS (str, " special:apple" );
128+ }
129+
130+ Tests::killAllWindows ();
131+ }
132+
133+ OK (getFromSocket (" /reload" ));
134+ Tests::killAllWindows ();
135+ }
136+
21137static bool test () {
22138 NLog::log (" {}Testing config: misc:" , Colors::GREEN);
23139
@@ -204,6 +320,11 @@ static bool test() {
204320 EXPECT_CONTAINS (str, " fullscreen: 2" );
205321 }
206322
323+ OK (getFromSocket (" /reload" ));
324+ Tests::killAllWindows ();
325+
326+ testAnrDialogs ();
327+
207328 // Ensure that the process autostarted in the config does not
208329 // become a zombie even if it terminates very quickly.
209330 EXPECT (Tests::execAndGet (" pgrep -f 'sleep 0'" ).empty (), true );
0 commit comments