diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-08-28 11:20:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-28 11:20:29 +0200 |
| commit | 81bf4eccba449bfe2b6adfb51260108aec710d4f (patch) | |
| tree | 215c5b536cbcf1df9888081aadd3de16eb4b3ebe /hyprtester | |
| parent | 378e130f1426648d8d734049800128f9882805bf (diff) | |
input: Add fully configurable trackpad gestures (#11490)
Adds configurable trackpad gestures
Diffstat (limited to 'hyprtester')
| -rw-r--r-- | hyprtester/plugin/src/main.cpp | 40 | ||||
| -rw-r--r-- | hyprtester/src/tests/main/gestures.cpp | 155 | ||||
| -rw-r--r-- | hyprtester/test.conf | 12 |
3 files changed, 206 insertions, 1 deletions
diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp index 7eeb2eea..03035918 100644 --- a/hyprtester/plugin/src/main.cpp +++ b/hyprtester/plugin/src/main.cpp @@ -9,11 +9,14 @@ #include <src/layout/IHyprLayout.hpp> #include <src/managers/LayoutManager.hpp> #include <src/managers/input/InputManager.hpp> +#include <src/managers/input/trackpad/TrackpadGestures.hpp> #include <src/Compositor.hpp> #undef private #include <hyprutils/utils/ScopeGuard.hpp> +#include <hyprutils/string/VarList.hpp> using namespace Hyprutils::Utils; +using namespace Hyprutils::String; #include "globals.hpp" @@ -88,6 +91,41 @@ class CTestKeyboard : public IKeyboard { bool m_isVirtual; }; +static SDispatchResult pressAlt(std::string in) { + g_pInputManager->m_lastMods = in == "1" ? HL_MODIFIER_ALT : 0; + + return {.success = true}; +} + +static SDispatchResult simulateGesture(std::string in) { + CVarList data(in); + + uint32_t fingers = 3; + try { + fingers = std::stoul(data[1]); + } catch (...) { return {.success = false}; } + + if (data[0] == "down") { + g_pTrackpadGestures->gestureBegin(IPointer::SSwipeBeginEvent{}); + g_pTrackpadGestures->gestureUpdate(IPointer::SSwipeUpdateEvent{.fingers = fingers, .delta = {0, 300}}); + g_pTrackpadGestures->gestureEnd(IPointer::SSwipeEndEvent{}); + } else if (data[0] == "up") { + g_pTrackpadGestures->gestureBegin(IPointer::SSwipeBeginEvent{}); + g_pTrackpadGestures->gestureUpdate(IPointer::SSwipeUpdateEvent{.fingers = fingers, .delta = {0, -300}}); + g_pTrackpadGestures->gestureEnd(IPointer::SSwipeEndEvent{}); + } else if (data[0] == "left") { + g_pTrackpadGestures->gestureBegin(IPointer::SSwipeBeginEvent{}); + g_pTrackpadGestures->gestureUpdate(IPointer::SSwipeUpdateEvent{.fingers = fingers, .delta = {-300, 0}}); + g_pTrackpadGestures->gestureEnd(IPointer::SSwipeEndEvent{}); + } else { + g_pTrackpadGestures->gestureBegin(IPointer::SSwipeBeginEvent{}); + g_pTrackpadGestures->gestureUpdate(IPointer::SSwipeUpdateEvent{.fingers = fingers, .delta = {300, 0}}); + g_pTrackpadGestures->gestureEnd(IPointer::SSwipeEndEvent{}); + } + + return {.success = true}; +} + static SDispatchResult vkb(std::string in) { auto tkb0 = CTestKeyboard::create(false); auto tkb1 = CTestKeyboard::create(false); @@ -141,6 +179,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:test", ::test); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:snapmove", ::snapMove); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:vkb", ::vkb); + HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt); + HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture); return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"}; } diff --git a/hyprtester/src/tests/main/gestures.cpp b/hyprtester/src/tests/main/gestures.cpp new file mode 100644 index 00000000..37d367d2 --- /dev/null +++ b/hyprtester/src/tests/main/gestures.cpp @@ -0,0 +1,155 @@ +#include "tests.hpp" +#include "../../shared.hpp" +#include "../../hyprctlCompat.hpp" +#include <print> +#include <thread> +#include <chrono> +#include <hyprutils/os/Process.hpp> +#include <hyprutils/memory/WeakPtr.hpp> +#include <csignal> +#include <cerrno> +#include "../shared.hpp" + +static int ret = 0; + +using namespace Hyprutils::OS; +using namespace Hyprutils::Memory; + +#define UP CUniquePointer +#define SP CSharedPointer + +static bool test() { + NLog::log("{}Testing gestures", Colors::GREEN); + + EXPECT(Tests::windowCount(), 0); + + // test on workspace "window" + NLog::log("{}Switching to workspace 1", Colors::YELLOW); + getFromSocket("/dispatch workspace 1"); // no OK: we might be on 1 already + + OK(getFromSocket("/dispatch plugin:test:gesture left,3")); + + // wait while kitty spawns + 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); + + OK(getFromSocket("/dispatch plugin:test:gesture right,3")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "floating: 1"); + } + + OK(getFromSocket("/dispatch plugin:test:gesture down,3")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "fullscreen: 2"); + } + + OK(getFromSocket("/dispatch plugin:test:gesture down,3")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "fullscreen: 0"); + } + + OK(getFromSocket("/dispatch plugin:test:alt 1")); + + OK(getFromSocket("/dispatch plugin:test:gesture left,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_CONTAINS(str, "ID 2 (2)"); + } + + OK(getFromSocket("/dispatch plugin:test:gesture right,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_NOT_CONTAINS(str, "ID 2 (2)"); + } + + // check for crashes + OK(getFromSocket("/dispatch plugin:test:gesture right,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_NOT_CONTAINS(str, "ID 2 (2)"); + } + + OK(getFromSocket("/keyword gestures:workspace_swipe_invert 0")); + + OK(getFromSocket("/dispatch plugin:test:gesture right,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_CONTAINS(str, "ID 2 (2)"); + } + + OK(getFromSocket("/dispatch plugin:test:gesture left,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_NOT_CONTAINS(str, "ID 2 (2)"); + } + + OK(getFromSocket("/keyword gestures:workspace_swipe_invert 1")); + OK(getFromSocket("/keyword gestures:workspace_swipe_create_new 0")); + + OK(getFromSocket("/dispatch plugin:test:gesture left,3")); + + { + auto str = getFromSocket("/workspaces"); + EXPECT_NOT_CONTAINS(str, "ID 2 (2)"); + EXPECT_CONTAINS(str, "ID 1 (1)"); + } + + OK(getFromSocket("/dispatch plugin:test:gesture down,3")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "floating: 0"); + } + + OK(getFromSocket("/dispatch plugin:test:alt 0")); + + OK(getFromSocket("/dispatch plugin:test:gesture up,3")); + + counter = 0; + 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); + + // kill all + NLog::log("{}Killing all windows", Colors::YELLOW); + Tests::killAllWindows(); + + NLog::log("{}Expecting 0 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 0); + + // reload cfg + OK(getFromSocket("/reload")); + + return !ret; +} + +REGISTER_TEST_FN(test) diff --git a/hyprtester/test.conf b/hyprtester/test.conf index 3d55b7ae..3e042ae6 100644 --- a/hyprtester/test.conf +++ b/hyprtester/test.conf @@ -203,7 +203,7 @@ input { # https://wiki.hyprland.org/Configuring/Variables/#gestures gestures { - workspace_swipe = false + } # Example per-device config @@ -313,3 +313,13 @@ windowrulev2 = bordersize 0, floating:0, onworkspace:n[s:window] w[tv1] windowrulev2 = rounding 0, floating:0, onworkspace:n[s:window] w[tv1] windowrulev2 = bordersize 0, floating:0, onworkspace:n[s:window] f[1] windowrulev2 = rounding 0, floating:0, onworkspace:n[s:window] f[1] + +gesture = 3, left, dispatcher, exec, kitty +gesture = 3, right, float +gesture = 3, up, close +gesture = 3, down, fullscreen + +gesture = 3, down, mod:ALT, float + +gesture = 3, horizontal, mod:ALT, workspace + |
