input-capture: impl force release

This commit is contained in:
Gwilherm Folliot 2024-10-21 10:27:03 +02:00
parent e0321f721e
commit 255db25664
No known key found for this signature in database
GPG key ID: 90236D3623DCD660
6 changed files with 28 additions and 2 deletions

View file

@ -13,6 +13,7 @@
#include "eventLoop/EventLoopManager.hpp" #include "eventLoop/EventLoopManager.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "helpers/varlist/VarList.hpp" #include "helpers/varlist/VarList.hpp"
#include "protocols/InputCapture.hpp"
#include <optional> #include <optional>
#include <iterator> #include <iterator>
@ -126,6 +127,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["denywindowfromgroup"] = denyWindowFromGroup; m_mDispatchers["denywindowfromgroup"] = denyWindowFromGroup;
m_mDispatchers["event"] = event; m_mDispatchers["event"] = event;
m_mDispatchers["global"] = global; m_mDispatchers["global"] = global;
m_mDispatchers["releaseinputcapture"] = releaseInputCapture;
m_tScrollTimer.reset(); m_tScrollTimer.reset();
@ -716,6 +718,14 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
m_iPassPressed = (int)pressed; 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 the dispatchers says to pass event then we will
if (k.handler == "mouse") if (k.handler == "mouse")
res = DISPATCHER->second((pressed ? "1" : "0") + k.arg); res = DISPATCHER->second((pressed ? "1" : "0") + k.arg);
@ -2891,3 +2901,8 @@ SDispatchResult CKeybindManager::event(std::string args) {
g_pEventManager->postEvent(SHyprIPCEvent{"custom", args}); g_pEventManager->postEvent(SHyprIPCEvent{"custom", args});
return {}; return {};
} }
SDispatchResult CKeybindManager::releaseInputCapture(std::string args) {
PROTO::inputCapture->forceRelease();
return {};
}

View file

@ -217,6 +217,7 @@ class CKeybindManager {
static SDispatchResult denyWindowFromGroup(std::string); static SDispatchResult denyWindowFromGroup(std::string);
static SDispatchResult global(std::string); static SDispatchResult global(std::string);
static SDispatchResult event(std::string); static SDispatchResult event(std::string);
static SDispatchResult releaseInputCapture(std::string);
friend class CCompositor; friend class CCompositor;
friend class CInputManager; friend class CInputManager;

View file

@ -1316,7 +1316,7 @@ void CInputManager::onKeyboardKey(std::any event, SP<IKeyboard> pKeyboard) {
const auto EMAP = std::unordered_map<std::string, std::any>{{"keyboard", pKeyboard}, {"event", event}}; const auto EMAP = std::unordered_map<std::string, std::any>{{"keyboard", pKeyboard}, {"event", event}};
EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); 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<IKeyboard::SKeyEvent>(event); auto e = std::any_cast<IKeyboard::SKeyEvent>(event);

View file

@ -67,6 +67,14 @@ void CInputCaptureProtocol::sendKeymap(SP<IKeyboard> keyboard, const std::unique
close(fd); 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) { void CInputCaptureProtocol::sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state) {
for (const auto& manager : m_vManagers) for (const auto& manager : m_vManagers)
manager->sendKey(keyCode, state); manager->sendKey(keyCode, state);

View file

@ -13,6 +13,8 @@ class CInputCaptureProtocol : public IWaylandProtocol {
bool isCaptured(); bool isCaptured();
void updateKeymap(); void updateKeymap();
void forceRelease();
void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta); void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta);
void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state); void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state);
void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state); void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state);

@ -1 +1 @@
Subproject commit d3674e1f4eac730efc01c08e794a988be31ec73e Subproject commit 0c7cf263faeae9429942c6ffbc1e9b5dfd709bf4