From 6b9a9af9a8efc9c4bbdd96931f3845ee575a6c57 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 7 Nov 2024 13:09:25 +0800 Subject: [PATCH] keybindmanager doesnt work and will crash on bindo rn. need fix --- src/managers/KeybindManager.cpp | 62 +++++++++++++++++++++------------ src/managers/KeybindManager.hpp | 2 ++ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 525f124d..22be31b2 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -13,6 +13,7 @@ #include "eventLoop/EventLoopManager.hpp" #include "debug/Log.hpp" #include "helpers/varlist/VarList.hpp" +#include "eventLoop/EventLoopManager.hpp" #include #include @@ -130,6 +131,27 @@ CKeybindManager::CKeybindManager() { m_tScrollTimer.reset(); + m_pLongPressTimer = makeShared( + std::nullopt, + [this](SP self, void* data) { + SKeybind** ppActiveKeybind = (SKeybind**)m_pActiveKeybind; + + if (!m_pActiveKeybind) + return 0; + + // if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired()) + // return 0; + + // const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler); + + // Debug::log(LOG, "Keybind long press triggered, calling dispatcher."); + // DISPATCHER->second((*ppActiveKeybind)->arg); + }, + nullptr + ); + + g_pEventLoopManager->addTimer(m_pLongPressTimer); + static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd m_pActiveKeybind = nullptr; @@ -140,6 +162,10 @@ CKeybindManager::CKeybindManager() { CKeybindManager::~CKeybindManager() { if (m_pXKBTranslationState) xkb_state_unref(m_pXKBTranslationState); + if (m_pLongPressTimer && g_pEventLoopManager) { + g_pEventLoopManager->removeTimer(m_pLongPressTimer); + m_pLongPressTimer.reset(); + } } void CKeybindManager::addKeybind(SKeybind kb) { @@ -567,16 +593,8 @@ int repeatKeyHandler(void* data) { return 0; } -int longPressHandler(void* data) { - SKeybind** ppActiveKeybind = (SKeybind**)data; - - if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired()) - return 0; - - const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler); - - Debug::log(LOG, "Keybind long press triggered, calling dispatcher."); - DISPATCHER->second((*ppActiveKeybind)->arg); +int longPressHandler(SP self, void* data) { + return 0; } @@ -695,6 +713,17 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP continue; } + if (k.longPress) { + m_pActiveKeybind = &k; + + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + + m_pLongPressTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); + // m_pLastLongPressKeybind = &k; + + // continue; + } + if (!pressed) { // Require mods to be matching when the key was first pressed. if (key.modmaskAtPressTime != modmask && !k.ignoreMods) { @@ -714,17 +743,6 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP continue; } } - - if (k.longPress) { - m_pActiveKeybind = &k; - m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, longPressHandler, &m_pActiveKeybind); - - const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - - wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); - continue; - } - const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); if (SPECIALTRIGGERED && !pressed) @@ -753,7 +771,7 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP found = true; // don't process keybinds on submap change. break; } - } + } if (k.repeat) { m_pActiveKeybind = &k; diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index f9ecd79c..2c788590 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -8,6 +8,7 @@ #include #include #include "../devices/IPointer.hpp" +#include "eventLoop/EventLoopTimer.hpp" class CInputManager; class CConfigManager; @@ -121,6 +122,7 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; SKeybind* m_pActiveKeybind = nullptr; + SP m_pLongPressTimer; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0;