This commit is contained in:
Vaxry 2024-11-09 21:15:35 +00:00
parent 5fd7755b8d
commit 54d51cc2b4
2 changed files with 24 additions and 25 deletions

View file

@ -134,18 +134,13 @@ CKeybindManager::CKeybindManager() {
m_pLongPressTimer = makeShared<CEventLoopTimer>( m_pLongPressTimer = makeShared<CEventLoopTimer>(
std::nullopt, std::nullopt,
[this](SP<CEventLoopTimer> self, void* data) { [this](SP<CEventLoopTimer> self, void* data) {
SKeybind** ppActiveKeybind = (SKeybind**)m_pActiveKeybind; if (!m_pLastLongPressKeybind || g_pSeatManager->keyboard.expired())
return;
if (!m_pActiveKeybind) const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(m_pLastLongPressKeybind->handler);
return 0;
// if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired()) Debug::log(LOG, "Long press timeout passed, calling dispatcher.");
// return 0; DISPATCHER->second(m_pLastLongPressKeybind->arg);
// const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler);
// Debug::log(LOG, "Keybind long press triggered, calling dispatcher.");
// DISPATCHER->second((*ppActiveKeybind)->arg);
}, },
nullptr); nullptr);
@ -154,6 +149,7 @@ CKeybindManager::CKeybindManager() {
static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) {
// clear cuz realloc'd // clear cuz realloc'd
m_pActiveKeybind = nullptr; m_pActiveKeybind = nullptr;
m_pLastLongPressKeybind = nullptr;
m_vPressedSpecialBinds.clear(); m_vPressedSpecialBinds.clear();
}); });
} }
@ -171,6 +167,7 @@ void CKeybindManager::addKeybind(SKeybind kb) {
m_lKeybinds.push_back(kb); m_lKeybinds.push_back(kb);
m_pActiveKeybind = nullptr; m_pActiveKeybind = nullptr;
m_pLastLongPressKeybind = nullptr;
} }
void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) {
@ -184,6 +181,7 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) {
} }
m_pActiveKeybind = nullptr; m_pActiveKeybind = nullptr;
m_pLastLongPressKeybind = nullptr;
} }
uint32_t CKeybindManager::stringToModMask(std::string mods) { uint32_t CKeybindManager::stringToModMask(std::string mods) {
@ -430,6 +428,8 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) {
m_pActiveKeybind = nullptr; m_pActiveKeybind = nullptr;
} }
m_pLastLongPressKeybind = nullptr;
bool suppressEvent = false; bool suppressEvent = false;
if (e.state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (e.state == WL_KEYBOARD_KEY_STATE_PRESSED) {
@ -711,17 +711,6 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
continue; 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) { if (!pressed) {
// Require mods to be matching when the key was first pressed. // Require mods to be matching when the key was first pressed.
if (key.modmaskAtPressTime != modmask && !k.ignoreMods) { if (key.modmaskAtPressTime != modmask && !k.ignoreMods) {
@ -741,6 +730,16 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
continue; continue;
} }
} }
if (k.longPress) {
const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock();
m_pLongPressTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay));
m_pLastLongPressKeybind = &k;
continue;
}
const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler);
if (SPECIALTRIGGERED && !pressed) if (SPECIALTRIGGERED && !pressed)

View file

@ -121,7 +121,7 @@ class CKeybindManager {
inline static std::string m_szCurrentSelectedSubmap = ""; inline static std::string m_szCurrentSelectedSubmap = "";
SKeybind* m_pActiveKeybind = nullptr; SKeybind * m_pActiveKeybind = nullptr, *m_pLastLongPressKeybind = nullptr;
SP<CEventLoopTimer> m_pLongPressTimer; SP<CEventLoopTimer> m_pLongPressTimer;
uint32_t m_uTimeLastMs = 0; uint32_t m_uTimeLastMs = 0;