summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-10 16:27:14 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-10 16:27:14 +0100
commitdcb909df0466a8b9fe07ea7c420b840e2e910223 (patch)
tree2fa6680ae1354b7a77b232ca8556467755bae360 /src/managers/KeybindManager.cpp
parent807fc20525e4811dce55f3814fd878e3a140266d (diff)
keybinds: track pressed special binds
Ignore mods only if we're processing a special bind, and only if it's pressed. Otherwise we might shadow normal key releases via ignoring mods. Fixes #3240
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index cf0c573f..98439695 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -71,6 +71,12 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["global"] = global;
m_tScrollTimer.reset();
+
+ g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, std::any param) {
+ // clear cuz realloc'd
+ m_pActiveKeybind = nullptr;
+ m_vPressedSpecialBinds.clear();
+ });
}
void CKeybindManager::addKeybind(SKeybind kb) {
@@ -422,7 +428,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string&
for (auto& k : m_lKeybinds) {
const bool SPECIALDISPATCHER = k.handler == "global" || k.handler == "pass" || k.handler == "mouse";
- const bool IGNOREMODS = SPECIALDISPATCHER && !pressed; // ignore mods. Pass, global dispatchers should be released immediately once the key is released.
+ const bool SPECIALTRIGGERED =
+ std::find_if(m_vPressedSpecialBinds.begin(), m_vPressedSpecialBinds.end(), [&](const auto& other) { return other == &k; }) != m_vPressedSpecialBinds.end();
+ const bool IGNOREMODS = SPECIALDISPATCHER && !pressed && SPECIALTRIGGERED; // ignore mods. Pass, global dispatchers should be released immediately once the key is released.
if ((modmask != k.modmask && !IGNOREMODS) || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || k.shadowed)
continue;
@@ -464,6 +472,11 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string&
const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler);
+ if (SPECIALTRIGGERED && !pressed)
+ std::erase_if(m_vPressedSpecialBinds, [&](const auto& other) { return other == &k; });
+ else if (SPECIALDISPATCHER && pressed)
+ m_vPressedSpecialBinds.push_back(&k);
+
// Should never happen, as we check in the ConfigManager, but oh well
if (DISPATCHER == m_mDispatchers.end()) {
Debug::log(ERR, "Invalid handler in a keybind! (handler {} does not exist)", k.handler);