@@ -18,6 +18,20 @@ using namespace Hyprutils::Memory;
1818#define UP CUniquePointer
1919#define SP CSharedPointer
2020
21+ static bool waitForWindowCount (int expected_window_cnt, std::string_view expectation, int wait_millis = 100 , int max_wait_cnt = 50 ) {
22+ int counter = 0 ;
23+ while (Tests::windowCount () != expected_window_cnt) {
24+ counter++;
25+ std::this_thread::sleep_for (std::chrono::milliseconds (wait_millis));
26+
27+ if (counter > max_wait_cnt) {
28+ NLog::log (" {}Unmet expectation: {}" , Colors::RED, expectation);
29+ return false ;
30+ }
31+ }
32+ return true ;
33+ }
34+
2135static bool test () {
2236 NLog::log (" {}Testing gestures" , Colors::GREEN);
2337
@@ -34,32 +48,14 @@ static bool test() {
3448 std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
3549
3650 OK (getFromSocket (" /dispatch plugin:test:gesture up,4" ));
37- int counter = 0 ;
38- while (Tests::windowCount () != 0 ) {
39- counter++;
40- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
4151
42- if (counter > 50 ) {
43- NLog::log (" {}Gesture didnt send ctrl+d to kitty" , Colors::RED);
44- return false ;
45- }
46- }
52+ EXPECT (waitForWindowCount (0 , " Gesture sent ctrl+d to kitty" ), true );
4753
4854 EXPECT (Tests::windowCount (), 0 );
4955
5056 OK (getFromSocket (" /dispatch plugin:test:gesture left,3" ));
5157
52- // wait while kitty spawns
53- counter = 0 ;
54- while (Tests::windowCount () != 1 ) {
55- counter++;
56- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
57-
58- if (counter > 50 ) {
59- NLog::log (" {}Gesture didnt spawn kitty" , Colors::RED);
60- return false ;
61- }
62- }
58+ EXPECT (waitForWindowCount (1 , " Gesture spawned kitty" ), true );
6359
6460 EXPECT (Tests::windowCount (), 1 );
6561
@@ -146,16 +142,7 @@ static bool test() {
146142
147143 OK (getFromSocket (" /dispatch plugin:test:gesture up,3" ));
148144
149- counter = 0 ;
150- while (Tests::windowCount () != 0 ) {
151- counter++;
152- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
153-
154- if (counter > 50 ) {
155- NLog::log (" {}Gesture didnt close kitty" , Colors::RED);
156- return false ;
157- }
158- }
145+ EXPECT (waitForWindowCount (0 , " Gesture closed kitty" ), true );
159146
160147 EXPECT (Tests::windowCount (), 0 );
161148
0 commit comments