diff options
| author | JS Deck <jsdeckerido@gmail.com> | 2025-08-04 16:29:39 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-04 21:29:39 +0200 |
| commit | 2be309de1df5e4262175fbcc58e6dd8de4e0e6d3 (patch) | |
| tree | 866629ba5a4b9b45d8720383e4332726444f3566 /hyprtester/plugin/src/main.cpp | |
| parent | 6491bb4fb7c7e86d9168a104d5b87ace4e1b978d (diff) | |
virtualkeyboard: Add options to skip releasing pressed keys on close and to skip sharing key states (#11214)
Diffstat (limited to 'hyprtester/plugin/src/main.cpp')
| -rw-r--r-- | hyprtester/plugin/src/main.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp index 17b1e02a..01ec7b38 100644 --- a/hyprtester/plugin/src/main.cpp +++ b/hyprtester/plugin/src/main.cpp @@ -8,9 +8,13 @@ #include <src/config/ConfigDescriptions.hpp> #include <src/layout/IHyprLayout.hpp> #include <src/managers/LayoutManager.hpp> +#include <src/managers/input/InputManager.hpp> #include <src/Compositor.hpp> #undef private +#include <hyprutils/utils/ScopeGuard.hpp> +using namespace Hyprutils::Utils; + #include "globals.hpp" // Do NOT change this function. @@ -48,11 +52,95 @@ static SDispatchResult snapMove(std::string in) { return {}; } +class CTestKeyboard : public IKeyboard { + public: + static SP<CTestKeyboard> create(bool isVirtual) { + auto keeb = SP<CTestKeyboard>(new CTestKeyboard()); + keeb->m_self = keeb; + keeb->m_isVirtual = isVirtual; + keeb->m_shareStates = !isVirtual; + return keeb; + } + + virtual bool isVirtual() { + return m_isVirtual; + } + + virtual SP<Aquamarine::IKeyboard> aq() { + return nullptr; + } + + void sendKey(uint32_t key, bool pressed) { + auto event = IKeyboard::SKeyEvent{ + .timeMs = static_cast<uint32_t>(Time::millis(Time::steadyNow())), + .keycode = key, + .state = pressed ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED, + }; + updatePressed(event.keycode, pressed); + m_keyboardEvents.key.emit(event); + } + + void destroy() { + m_events.destroy.emit(); + } + + private: + bool m_isVirtual; +}; + +static SDispatchResult vkb(std::string in) { + auto tkb0 = CTestKeyboard::create(false); + auto tkb1 = CTestKeyboard::create(false); + auto vkb0 = CTestKeyboard::create(true); + + g_pInputManager->newKeyboard(tkb0); + g_pInputManager->newKeyboard(tkb1); + g_pInputManager->newKeyboard(vkb0); + + CScopeGuard x([&] { + tkb0->destroy(); + tkb1->destroy(); + vkb0->destroy(); + }); + + const auto& PRESSED = g_pInputManager->getKeysFromAllKBs(); + const uint32_t TESTKEY = 1; + + tkb0->sendKey(TESTKEY, true); + if (!std::ranges::contains(PRESSED, TESTKEY)) { + return { + .success = false, + .error = "Expected pressed key not found", + }; + } + + tkb1->sendKey(TESTKEY, true); + tkb0->sendKey(TESTKEY, false); + if (!std::ranges::contains(PRESSED, TESTKEY)) { + return { + .success = false, + .error = "Expected pressed key not found (kb share state)", + }; + } + + vkb0->sendKey(TESTKEY, true); + tkb1->sendKey(TESTKEY, false); + if (std::ranges::contains(PRESSED, TESTKEY)) { + return { + .success = false, + .error = "Expected released key found in pressed (vkb no share state)", + }; + } + + return {}; +} + APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { PHANDLE = handle; HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:test", ::test); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:snapmove", ::snapMove); + HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:vkb", ::vkb); return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"}; } |
