From 255db256648c9747122faf45dfd9c9937cbb9d1f Mon Sep 17 00:00:00 2001 From: Gwilherm Folliot Date: Mon, 21 Oct 2024 10:27:03 +0200 Subject: [PATCH] input-capture: impl force release --- src/managers/KeybindManager.cpp | 15 +++++++++++++++ src/managers/KeybindManager.hpp | 1 + src/managers/input/InputManager.cpp | 2 +- src/protocols/InputCapture.cpp | 8 ++++++++ src/protocols/InputCapture.hpp | 2 ++ subprojects/hyprland-protocols | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9c22fb93..ddff64e3 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -13,6 +13,7 @@ #include "eventLoop/EventLoopManager.hpp" #include "debug/Log.hpp" #include "helpers/varlist/VarList.hpp" +#include "protocols/InputCapture.hpp" #include #include @@ -126,6 +127,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["denywindowfromgroup"] = denyWindowFromGroup; m_mDispatchers["event"] = event; m_mDispatchers["global"] = global; + m_mDispatchers["releaseinputcapture"] = releaseInputCapture; m_tScrollTimer.reset(); @@ -716,6 +718,14 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP m_iPassPressed = (int)pressed; + // We only process the releaseinputcapture dispatcher when input capture is active + if (PROTO::inputCapture->isCaptured()) { + if (k.handler == "releaseinputcapture") + res = DISPATCHER->second(k.arg); + else + break; + } + // if the dispatchers says to pass event then we will if (k.handler == "mouse") res = DISPATCHER->second((pressed ? "1" : "0") + k.arg); @@ -2891,3 +2901,8 @@ SDispatchResult CKeybindManager::event(std::string args) { g_pEventManager->postEvent(SHyprIPCEvent{"custom", args}); return {}; } + +SDispatchResult CKeybindManager::releaseInputCapture(std::string args) { + PROTO::inputCapture->forceRelease(); + return {}; +} diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 8981dcaf..4abb1d6b 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -217,6 +217,7 @@ class CKeybindManager { static SDispatchResult denyWindowFromGroup(std::string); static SDispatchResult global(std::string); static SDispatchResult event(std::string); + static SDispatchResult releaseInputCapture(std::string); friend class CCompositor; friend class CInputManager; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 47f712c8..579cf1fd 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1316,7 +1316,7 @@ void CInputManager::onKeyboardKey(std::any event, SP pKeyboard) { const auto EMAP = std::unordered_map{{"keyboard", pKeyboard}, {"event", event}}; EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); - bool passEvent = !PROTO::inputCapture->isCaptured() && (DISALLOWACTION || g_pKeybindManager->onKeyEvent(event, pKeyboard)); + bool passEvent = (DISALLOWACTION || g_pKeybindManager->onKeyEvent(event, pKeyboard)) && !PROTO::inputCapture->isCaptured(); auto e = std::any_cast(event); diff --git a/src/protocols/InputCapture.cpp b/src/protocols/InputCapture.cpp index 0381d63c..b305827e 100644 --- a/src/protocols/InputCapture.cpp +++ b/src/protocols/InputCapture.cpp @@ -67,6 +67,14 @@ void CInputCaptureProtocol::sendKeymap(SP keyboard, const std::unique close(fd); } +void CInputCaptureProtocol::forceRelease() { + Debug::log(LOG, "[input-capture] Force Input released"); + active = false; + + for (const auto& manager : m_vManagers) + manager->sendForceRelease(); +} + void CInputCaptureProtocol::sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state) { for (const auto& manager : m_vManagers) manager->sendKey(keyCode, state); diff --git a/src/protocols/InputCapture.hpp b/src/protocols/InputCapture.hpp index 3f174448..90dd74e5 100644 --- a/src/protocols/InputCapture.hpp +++ b/src/protocols/InputCapture.hpp @@ -13,6 +13,8 @@ class CInputCaptureProtocol : public IWaylandProtocol { bool isCaptured(); void updateKeymap(); + void forceRelease(); + void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta); void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state); void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state); diff --git a/subprojects/hyprland-protocols b/subprojects/hyprland-protocols index d3674e1f..0c7cf263 160000 --- a/subprojects/hyprland-protocols +++ b/subprojects/hyprland-protocols @@ -1 +1 @@ -Subproject commit d3674e1f4eac730efc01c08e794a988be31ec73e +Subproject commit 0c7cf263faeae9429942c6ffbc1e9b5dfd709bf4