config: fix gesture dispatcher parsing with whitespaces (#11784)
* config: fix gesture dispatcher parsing with whitespaces Some dispatcher functions (e.g., `moveFocusTo`) expect the given string to be stripped of whitepsaces. This fixes `gesture` line parsing: rather than calling dispatcher functions with the original string, we reuse words parsed by `CConstVarList` and join them with a comma. * tests/gestures: Add a test for `movecursortocorner`
This commit is contained in:
parent
d8f615751a
commit
4f3dd1ddb4
3 changed files with 15 additions and 8 deletions
|
|
@ -146,6 +146,16 @@ static bool test() {
|
||||||
|
|
||||||
EXPECT(Tests::windowCount(), 0);
|
EXPECT(Tests::windowCount(), 0);
|
||||||
|
|
||||||
|
// This test ensures that `movecursortocorner`, which expects
|
||||||
|
// a single-character direction argument, is parsed correctly.
|
||||||
|
Tests::spawnKitty();
|
||||||
|
OK(getFromSocket("/dispatch movecursortocorner 0"));
|
||||||
|
const std::string cursorPos1 = getFromSocket("/cursorpos");
|
||||||
|
OK(getFromSocket("/dispatch plugin:test:gesture left,4"));
|
||||||
|
const std::string cursorPos2 = getFromSocket("/cursorpos");
|
||||||
|
// The cursor should have moved because of the gesture
|
||||||
|
EXPECT(cursorPos1 != cursorPos2, true);
|
||||||
|
|
||||||
// kill all
|
// kill all
|
||||||
NLog::log("{}Killing all windows", Colors::YELLOW);
|
NLog::log("{}Killing all windows", Colors::YELLOW);
|
||||||
Tests::killAllWindows();
|
Tests::killAllWindows();
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,7 @@ 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
|
gesture = 4, up, dispatcher, sendshortcut, ctrl, d, activewindow
|
||||||
|
gesture = 4, left, dispatcher, movecursortocorner, 1
|
||||||
|
|
||||||
windowrule = float, pin, class:wr_kitty
|
windowrule = float, pin, class:wr_kitty
|
||||||
windowrule = size 200 200, class:wr_kitty
|
windowrule = size 200 200, class:wr_kitty
|
||||||
|
|
|
||||||
|
|
@ -3163,14 +3163,10 @@ 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")
|
||||||
auto dispatcherArgsIt = value.begin();
|
result = g_pTrackpadGestures->addGesture(makeUnique<CDispatcherTrackpadGesture>(std::string{data[startDataIdx + 1]}, data.join(",", startDataIdx + 2)), fingerCount,
|
||||||
for (int i = 0; i < startDataIdx + 2 && dispatcherArgsIt < value.end(); ++i) {
|
direction, modMask, deltaScale);
|
||||||
dispatcherArgsIt = std::find(dispatcherArgsIt, value.end(), ',') + 1;
|
else if (data[startDataIdx] == "workspace")
|
||||||
}
|
|
||||||
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