diff options
| author | rfresh2 <89827146+rfresh2@users.noreply.github.com> | 2025-10-06 12:10:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-06 21:10:56 +0200 |
| commit | 73f06434a43c75b3a81e31a6ed7586a14a9c7a48 (patch) | |
| tree | 0bb1a5ace48f8f17859583f59eb39b9787283273 /hyprtester/plugin/src/main.cpp | |
| parent | 17e77e0407bebd5d24521012ee1d04b156d6b9f4 (diff) | |
keybinds: fix repeat and long press keybinds release (#11863)
Diffstat (limited to 'hyprtester/plugin/src/main.cpp')
| -rw-r--r-- | hyprtester/plugin/src/main.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp index 2b1d443a..07f90e9f 100644 --- a/hyprtester/plugin/src/main.cpp +++ b/hyprtester/plugin/src/main.cpp @@ -120,6 +120,7 @@ class CTestMouse : public IPointer { }; SP<CTestMouse> g_mouse; +SP<CTestKeyboard> g_keyboard; static SDispatchResult pressAlt(std::string in) { g_pInputManager->m_lastMods = in == "1" ? HL_MODIFIER_ALT : 0; @@ -220,6 +221,30 @@ static SDispatchResult scroll(std::string in) { return {}; } +static SDispatchResult keybind(std::string in) { + CVarList data(in); + // 0 = release, 1 = press + bool press; + // See src/devices/IKeyboard.hpp : eKeyboardModifiers for modifier bitmasks + // 0 = none, eKeyboardModifiers is shifted to start at 1 + uint32_t modifier; + // keycode + uint32_t key; + try { + press = std::stoul(data[0]) == 1; + modifier = std::stoul(data[1]); + key = std::stoul(data[2]) - 8; // xkb offset + } catch (...) { return {.success = false, .error = "invalid input"}; } + + uint32_t modifierMask = 0; + if (modifier > 0) + modifierMask = 1 << (modifier - 1); + g_pInputManager->m_lastMods = modifierMask; + g_keyboard->sendKey(key, press); + + return {}; +} + APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { PHANDLE = handle; @@ -229,15 +254,22 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:scroll", ::scroll); + HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:keybind", ::keybind); // init mouse g_mouse = CTestMouse::create(false); g_pInputManager->newMouse(g_mouse); + // init keyboard + g_keyboard = CTestKeyboard::create(false); + g_pInputManager->newKeyboard(g_keyboard); + return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"}; } APICALL EXPORT void PLUGIN_EXIT() { g_mouse->destroy(); g_mouse.reset(); -} + g_keyboard->destroy(); + g_keyboard.reset(); +}
\ No newline at end of file |
