From bbf17b515ab44283299452c63f653fcddeb2fc8f 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] allow repeating multiple binds modified: src/managers/KeybindManager.cpp modified: src/managers/KeybindManager.hpp --- src/managers/KeybindManager.cpp | 28 +++++++++++++++------------- src/managers/KeybindManager.hpp | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index c2779c58..beefe386 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -132,7 +132,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_pActiveKeybinds.clear(); m_vPressedSpecialBinds.clear(); }); } @@ -145,7 +145,7 @@ CKeybindManager::~CKeybindManager() { void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); } void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { @@ -158,7 +158,7 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { } } - m_pActiveKeybind = nullptr; + m_pActiveKeybinds.clear(); } uint32_t CKeybindManager::stringToModMask(std::string mods) { @@ -402,7 +402,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(); } bool suppressEvent = false; @@ -456,7 +456,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; @@ -499,7 +499,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) { @@ -552,15 +552,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); @@ -732,8 +734,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 24a09836..2b9152e4 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -119,7 +119,7 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; - SKeybind* m_pActiveKeybind = nullptr; + std::vector m_pActiveKeybinds; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0;