config: fix multi-argument gesture dispatcher parsing (#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 #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.
This commit is contained in:
parent
838439080a
commit
41dad38177
3 changed files with 38 additions and 25 deletions
|
|
@ -18,6 +18,20 @@ using namespace Hyprutils::Memory;
|
||||||
#define UP CUniquePointer
|
#define UP CUniquePointer
|
||||||
#define SP CSharedPointer
|
#define SP CSharedPointer
|
||||||
|
|
||||||
|
static bool waitForWindowCount(int expectedWindowCnt, std::string_view expectation, int waitMillis = 100, int maxWaitCnt = 50) {
|
||||||
|
int counter = 0;
|
||||||
|
while (Tests::windowCount() != expectedWindowCnt) {
|
||||||
|
counter++;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(waitMillis));
|
||||||
|
|
||||||
|
if (counter > maxWaitCnt) {
|
||||||
|
NLog::log("{}Unmet expectation: {}", Colors::RED, expectation);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool test() {
|
static bool test() {
|
||||||
NLog::log("{}Testing gestures", Colors::GREEN);
|
NLog::log("{}Testing gestures", Colors::GREEN);
|
||||||
|
|
||||||
|
|
@ -27,19 +41,21 @@ static bool test() {
|
||||||
NLog::log("{}Switching to workspace 1", Colors::YELLOW);
|
NLog::log("{}Switching to workspace 1", Colors::YELLOW);
|
||||||
getFromSocket("/dispatch workspace 1"); // no OK: we might be on 1 already
|
getFromSocket("/dispatch workspace 1"); // no OK: we might be on 1 already
|
||||||
|
|
||||||
|
Tests::spawnKitty();
|
||||||
|
EXPECT(Tests::windowCount(), 1);
|
||||||
|
|
||||||
|
// Give the shell a moment to initialize
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch plugin:test:gesture up,4"));
|
||||||
|
|
||||||
|
EXPECT(waitForWindowCount(0, "Gesture sent ctrl+d to kitty"), true);
|
||||||
|
|
||||||
|
EXPECT(Tests::windowCount(), 0);
|
||||||
|
|
||||||
OK(getFromSocket("/dispatch plugin:test:gesture left,3"));
|
OK(getFromSocket("/dispatch plugin:test:gesture left,3"));
|
||||||
|
|
||||||
// wait while kitty spawns
|
EXPECT(waitForWindowCount(1, "Gesture spawned kitty"), true);
|
||||||
int counter = 0;
|
|
||||||
while (Tests::windowCount() != 1) {
|
|
||||||
counter++;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
||||||
|
|
||||||
if (counter > 50) {
|
|
||||||
NLog::log("{}Gesture didnt spawn kitty", Colors::RED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT(Tests::windowCount(), 1);
|
EXPECT(Tests::windowCount(), 1);
|
||||||
|
|
||||||
|
|
@ -126,16 +142,7 @@ static bool test() {
|
||||||
|
|
||||||
OK(getFromSocket("/dispatch plugin:test:gesture up,3"));
|
OK(getFromSocket("/dispatch plugin:test:gesture up,3"));
|
||||||
|
|
||||||
counter = 0;
|
EXPECT(waitForWindowCount(0, "Gesture closed kitty"), true);
|
||||||
while (Tests::windowCount() != 0) {
|
|
||||||
counter++;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
||||||
|
|
||||||
if (counter > 50) {
|
|
||||||
NLog::log("{}Gesture didnt close kitty", Colors::RED);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT(Tests::windowCount(), 0);
|
EXPECT(Tests::windowCount(), 0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -332,3 +332,5 @@ gesture = 3, down, mod:ALT, float
|
||||||
|
|
||||||
gesture = 3, horizontal, mod:ALT, workspace
|
gesture = 3, horizontal, mod:ALT, workspace
|
||||||
|
|
||||||
|
gesture = 4, up, dispatcher, sendshortcut, ctrl, d, activewindow
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3229,10 +3229,14 @@ std::optional<std::string> CConfigManager::handleGesture(const std::string& comm
|
||||||
|
|
||||||
std::expected<void, std::string> result;
|
std::expected<void, std::string> result;
|
||||||
|
|
||||||
if (data[startDataIdx] == "dispatcher")
|
if (data[startDataIdx] == "dispatcher") {
|
||||||
result = g_pTrackpadGestures->addGesture(makeUnique<CDispatcherTrackpadGesture>(std::string{data[startDataIdx + 1]}, std::string{data[startDataIdx + 2]}), fingerCount,
|
auto dispatcherArgsIt = value.begin();
|
||||||
direction, modMask, deltaScale);
|
for (int i = 0; i < startDataIdx + 2 && dispatcherArgsIt < value.end(); ++i) {
|
||||||
else if (data[startDataIdx] == "workspace")
|
dispatcherArgsIt = std::find(dispatcherArgsIt, value.end(), ',') + 1;
|
||||||
|
}
|
||||||
|
result = g_pTrackpadGestures->addGesture(makeUnique<CDispatcherTrackpadGesture>(std::string{data[startDataIdx + 1]}, std::string(dispatcherArgsIt, value.end())),
|
||||||
|
fingerCount, direction, modMask, deltaScale);
|
||||||
|
} else if (data[startDataIdx] == "workspace")
|
||||||
result = g_pTrackpadGestures->addGesture(makeUnique<CWorkspaceSwipeGesture>(), fingerCount, direction, modMask, deltaScale);
|
result = g_pTrackpadGestures->addGesture(makeUnique<CWorkspaceSwipeGesture>(), fingerCount, direction, modMask, deltaScale);
|
||||||
else if (data[startDataIdx] == "resize")
|
else if (data[startDataIdx] == "resize")
|
||||||
result = g_pTrackpadGestures->addGesture(makeUnique<CResizeTrackpadGesture>(), fingerCount, direction, modMask, deltaScale);
|
result = g_pTrackpadGestures->addGesture(makeUnique<CResizeTrackpadGesture>(), fingerCount, direction, modMask, deltaScale);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue