Skip to content

Commit

Permalink
input-capture: impl force release
Browse files Browse the repository at this point in the history
  • Loading branch information
3l0w committed Oct 21, 2024
1 parent e0321f7 commit 255db25
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "eventLoop/EventLoopManager.hpp"
#include "debug/Log.hpp"
#include "helpers/varlist/VarList.hpp"
#include "protocols/InputCapture.hpp"

#include <optional>
#include <iterator>
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {};
}
1 change: 1 addition & 0 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
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);

Expand Down
8 changes: 8 additions & 0 deletions src/protocols/InputCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ void CInputCaptureProtocol::sendKeymap(SP<IKeyboard> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/protocols/InputCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 255db25

Please sign in to comment.