Skip to content

Commit 30e52eb

Browse files
kolayneMozzarella32
authored andcommitted
config: fix multi-argument gesture dispatcher parsing (hyprwm#11721)
* config: Fix multi-argument gesture dispatchers parsing The `dispatcher` gesture handler used to only handle the first argument to the dispatcher, while some dispatchers (e.g., `sendshortcut`) want multiple arguments. This fixes `ConfigManager` to handle all the arguments provided to the dispatcher gesture handler. Fixes hyprwm#11684. * test/gestures: Add a test for a gesture with a multi-argument dispatcher * test/gestures: Factor out `waitForWindowCount` Reduce code duplication in the gestures test.
1 parent dbb14fb commit 30e52eb

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

hyprtester/src/tests/main/gestures.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ using namespace Hyprutils::Memory;
1818
#define UP CUniquePointer
1919
#define SP CSharedPointer
2020

21+
static bool waitForWindowCount(int expectedWindowCnt, std::string_view expectation, int waitMillis = 100, int maxWaitCnt = 50) {
22+
int counter = 0;
23+
while (Tests::windowCount() != expectedWindowCnt) {
24+
counter++;
25+
std::this_thread::sleep_for(std::chrono::milliseconds(waitMillis));
26+
27+
if (counter > maxWaitCnt) {
28+
NLog::log("{}Unmet expectation: {}", Colors::RED, expectation);
29+
return false;
30+
}
31+
}
32+
return true;
33+
}
34+
2135
static bool test() {
2236
NLog::log("{}Testing gestures", Colors::GREEN);
2337

@@ -27,19 +41,21 @@ static bool test() {
2741
NLog::log("{}Switching to workspace 1", Colors::YELLOW);
2842
getFromSocket("/dispatch workspace 1"); // no OK: we might be on 1 already
2943

30-
OK(getFromSocket("/dispatch plugin:test:gesture left,3"));
44+
Tests::spawnKitty();
45+
EXPECT(Tests::windowCount(), 1);
3146

32-
// wait while kitty spawns
33-
int counter = 0;
34-
while (Tests::windowCount() != 1) {
35-
counter++;
36-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
47+
// Give the shell a moment to initialize
48+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
3749

38-
if (counter > 50) {
39-
NLog::log("{}Gesture didnt spawn kitty", Colors::RED);
40-
return false;
41-
}
42-
}
50+
OK(getFromSocket("/dispatch plugin:test:gesture up,4"));
51+
52+
EXPECT(waitForWindowCount(0, "Gesture sent ctrl+d to kitty"), true);
53+
54+
EXPECT(Tests::windowCount(), 0);
55+
56+
OK(getFromSocket("/dispatch plugin:test:gesture left,3"));
57+
58+
EXPECT(waitForWindowCount(1, "Gesture spawned kitty"), true);
4359

4460
EXPECT(Tests::windowCount(), 1);
4561

@@ -126,16 +142,7 @@ static bool test() {
126142

127143
OK(getFromSocket("/dispatch plugin:test:gesture up,3"));
128144

129-
counter = 0;
130-
while (Tests::windowCount() != 0) {
131-
counter++;
132-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
133-
134-
if (counter > 50) {
135-
NLog::log("{}Gesture didnt close kitty", Colors::RED);
136-
return false;
137-
}
138-
}
145+
EXPECT(waitForWindowCount(0, "Gesture closed kitty"), true);
139146

140147
EXPECT(Tests::windowCount(), 0);
141148

hyprtester/test.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,5 @@ gesture = 3, down, mod:ALT, float
332332

333333
gesture = 3, horizontal, mod:ALT, workspace
334334

335+
gesture = 4, up, dispatcher, sendshortcut, ctrl, d, activewindow
336+

src/config/ConfigManager.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,10 +3229,14 @@ std::optional<std::string> CConfigManager::handleGesture(const std::string& comm
32293229

32303230
std::expected<void, std::string> result;
32313231

3232-
if (data[startDataIdx] == "dispatcher")
3233-
result = g_pTrackpadGestures->addGesture(makeUnique<CDispatcherTrackpadGesture>(std::string{data[startDataIdx + 1]}, std::string{data[startDataIdx + 2]}), fingerCount,
3234-
direction, modMask, deltaScale);
3235-
else if (data[startDataIdx] == "workspace")
3232+
if (data[startDataIdx] == "dispatcher") {
3233+
auto dispatcherArgsIt = value.begin();
3234+
for (int i = 0; i < startDataIdx + 2 && dispatcherArgsIt < value.end(); ++i) {
3235+
dispatcherArgsIt = std::find(dispatcherArgsIt, value.end(), ',') + 1;
3236+
}
3237+
result = g_pTrackpadGestures->addGesture(makeUnique<CDispatcherTrackpadGesture>(std::string{data[startDataIdx + 1]}, std::string(dispatcherArgsIt, value.end())),
3238+
fingerCount, direction, modMask, deltaScale);
3239+
} else if (data[startDataIdx] == "workspace")
32363240
result = g_pTrackpadGestures->addGesture(makeUnique<CWorkspaceSwipeGesture>(), fingerCount, direction, modMask, deltaScale);
32373241
else if (data[startDataIdx] == "resize")
32383242
result = g_pTrackpadGestures->addGesture(makeUnique<CResizeTrackpadGesture>(), fingerCount, direction, modMask, deltaScale);

0 commit comments

Comments
 (0)