From 05229f83cfd5ab028bd80077d569f73b49da681c Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:25:11 +0000 Subject: [PATCH 1/4] allow repeating multiple binds modified: src/managers/KeybindManager.cpp modified: src/managers/KeybindManager.hpp --- src/managers/KeybindManager.cpp | 27 +++++++++++++++------------ src/managers/KeybindManager.hpp | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 4d2f4dcce04..796415d31d7 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -148,7 +148,7 @@ CKeybindManager::CKeybindManager() { static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd - m_pActiveKeybind = nullptr; + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; m_vPressedSpecialBinds.clear(); }); @@ -166,7 +166,7 @@ CKeybindManager::~CKeybindManager() { void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; } @@ -180,6 +180,7 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { } } + m_vActiveKeybinds.clear(); m_pActiveKeybind = nullptr; m_pLastLongPressKeybind = nullptr; } @@ -429,7 +430,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { if (m_pActiveKeybindEventSource) { wl_event_source_remove(m_pActiveKeybindEventSource); m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); } m_pLastLongPressKeybind = nullptr; @@ -485,7 +486,7 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { if (m_pActiveKeybindEventSource) { wl_event_source_remove(m_pActiveKeybindEventSource); m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); } bool found = false; @@ -528,7 +529,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { if (m_pActiveKeybindEventSource) { wl_event_source_remove(m_pActiveKeybindEventSource); m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); } if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) { @@ -581,15 +582,17 @@ void CKeybindManager::onSwitchOffEvent(const std::string& switchName) { } int repeatKeyHandler(void* data) { - SKeybind** ppActiveKeybind = (SKeybind**)data; + std::vector* ppActiveKeybinds = (std::vector*)data; - if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired()) + if (ppActiveKeybinds->size() == 0 || g_pSeatManager->keyboard.expired()) return 0; - const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler); + for (SKeybind* k : *ppActiveKeybinds) { + const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); - Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); - DISPATCHER->second((*ppActiveKeybind)->arg); + Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); + DISPATCHER->second(k->arg); + } wl_event_source_timer_update(g_pKeybindManager->m_pActiveKeybindEventSource, 1000 / g_pSeatManager->keyboard->repeatRate); @@ -770,8 +773,8 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP } if (k.repeat) { - m_pActiveKeybind = &k; - m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybind); + m_pActiveKeybinds.push_back(&k); + m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybinds); const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 4a0af6e9318..0fb8bbbe0e9 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -121,7 +121,8 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; - SKeybind * m_pActiveKeybind = nullptr, *m_pLastLongPressKeybind = nullptr; + std::vector m_vActiveKeybinds; + SKeybind * m_pLastLongPressKeybind = nullptr; SP m_pLongPressTimer; uint32_t m_uTimeLastMs = 0; From 75d2ac1f5664ec869317dbff13ff4a12d3121631 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:15:20 +0000 Subject: [PATCH 2/4] only add timer once modified: src/managers/KeybindManager.cpp --- src/managers/KeybindManager.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 796415d31d7..e698b9d21e7 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -774,11 +774,13 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP if (k.repeat) { m_pActiveKeybinds.push_back(&k); - m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybinds); + if (!m_pActiveKeybindEventSource) { + m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybinds); - const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); + wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); + } } if (!k.nonConsuming) From afc45a5fb1be36220516bfb9d0c236a0bb0c5e0c Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:17:10 +0000 Subject: [PATCH 3/4] rebase modified: src/managers/KeybindManager.cpp modified: src/managers/KeybindManager.hpp --- src/managers/KeybindManager.cpp | 73 ++++++++++++++------------------- src/managers/KeybindManager.hpp | 4 +- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index e698b9d21e7..a4a81dc3ebe 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -144,7 +144,27 @@ CKeybindManager::CKeybindManager() { }, nullptr); + m_pRepeatKeyTimer = makeShared( + std::nullopt, + [this](SP self, void* data) { + + if (m_vActiveKeybinds.size() == 0 || g_pSeatManager->keyboard.expired()) + return; + + for (SKeybind* k : m_vActiveKeybinds) { + const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); + + Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); + DISPATCHER->second(k->arg); + } + + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + self->updateTimeout(std::chrono::milliseconds(1000 / PACTIVEKEEB->repeatRate)); + }, + nullptr); + g_pEventLoopManager->addTimer(m_pLongPressTimer); + g_pEventLoopManager->addTimer(m_pRepeatKeyTimer); static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd @@ -161,12 +181,16 @@ CKeybindManager::~CKeybindManager() { g_pEventLoopManager->removeTimer(m_pLongPressTimer); m_pLongPressTimer.reset(); } + if (m_pRepeatKeyTimer && g_pEventLoopManager) { + g_pEventLoopManager->removeTimer(m_pRepeatKeyTimer); + m_pRepeatKeyTimer.reset(); + } } void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); - m_pActiveKeybinds.clear(); + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; } @@ -181,7 +205,6 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { } m_vActiveKeybinds.clear(); - m_pActiveKeybind = nullptr; m_pLastLongPressKeybind = nullptr; } @@ -427,11 +450,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { .submapAtPress = m_szCurrentSelectedSubmap, }; - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybinds.clear(); - } + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; @@ -483,11 +502,7 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { m_tScrollTimer.reset(); - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybinds.clear(); - } + m_vActiveKeybinds.clear(); bool found = false; if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { @@ -526,11 +541,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { .modmaskAtPressTime = MODS, }; - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybinds.clear(); - } + m_vActiveKeybinds.clear(); if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) { m_dPressedKeys.push_back(KEY); @@ -581,24 +592,6 @@ void CKeybindManager::onSwitchOffEvent(const std::string& switchName) { handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:off:" + switchName}, true); } -int repeatKeyHandler(void* data) { - std::vector* ppActiveKeybinds = (std::vector*)data; - - if (ppActiveKeybinds->size() == 0 || g_pSeatManager->keyboard.expired()) - return 0; - - for (SKeybind* k : *ppActiveKeybinds) { - const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); - - Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); - DISPATCHER->second(k->arg); - } - - wl_event_source_timer_update(g_pKeybindManager->m_pActiveKeybindEventSource, 1000 / g_pSeatManager->keyboard->repeatRate); - - return 0; -} - eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set keybindKeysyms, const std::set pressedKeysyms) { // Returns whether two sets of keysyms are equal, partially equal, or not // matching. (Partially matching means that pressed is a subset of bound) @@ -773,14 +766,10 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP } if (k.repeat) { - m_pActiveKeybinds.push_back(&k); - if (!m_pActiveKeybindEventSource) { - m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybinds); - - const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); - } + m_vActiveKeybinds.push_back(&k); + m_pRepeatKeyTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); } if (!k.nonConsuming) diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 0fb8bbbe0e9..ccbbce6c6af 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -102,8 +102,6 @@ class CKeybindManager { std::unordered_map> m_mDispatchers; - wl_event_source* m_pActiveKeybindEventSource = nullptr; - bool m_bGroupsLocked = false; std::list m_lKeybinds; @@ -123,7 +121,7 @@ class CKeybindManager { std::vector m_vActiveKeybinds; SKeybind * m_pLastLongPressKeybind = nullptr; - SP m_pLongPressTimer; + SP m_pLongPressTimer, m_pRepeatKeyTimer; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0; From 361ae19835b15eb49682eacd9eeb27843bd3617a Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:34:49 +0000 Subject: [PATCH 4/4] format modified: src/managers/KeybindManager.cpp modified: src/managers/KeybindManager.hpp --- src/managers/KeybindManager.cpp | 19 +++++++++---------- src/managers/KeybindManager.hpp | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index a4a81dc3ebe..a0cd01a9135 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -147,19 +147,18 @@ CKeybindManager::CKeybindManager() { m_pRepeatKeyTimer = makeShared( std::nullopt, [this](SP self, void* data) { + if (m_vActiveKeybinds.size() == 0 || g_pSeatManager->keyboard.expired()) + return; - if (m_vActiveKeybinds.size() == 0 || g_pSeatManager->keyboard.expired()) - return; - - for (SKeybind* k : m_vActiveKeybinds) { - const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); + for (SKeybind* k : m_vActiveKeybinds) { + const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); - Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); - DISPATCHER->second(k->arg); - } + Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); + DISPATCHER->second(k->arg); + } - const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - self->updateTimeout(std::chrono::milliseconds(1000 / PACTIVEKEEB->repeatRate)); + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + self->updateTimeout(std::chrono::milliseconds(1000 / PACTIVEKEEB->repeatRate)); }, nullptr); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index ccbbce6c6af..d375db0fd68 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -120,7 +120,7 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; std::vector m_vActiveKeybinds; - SKeybind * m_pLastLongPressKeybind = nullptr; + SKeybind* m_pLastLongPressKeybind = nullptr; SP m_pLongPressTimer, m_pRepeatKeyTimer; uint32_t m_uTimeLastMs = 0;