allow repeating multiple binds

modified:   src/managers/KeybindManager.cpp
modified:   src/managers/KeybindManager.hpp
This commit is contained in:
MightyPlaza 2024-10-29 15:25:11 +00:00
parent d679d20029
commit bbf17b515a
No known key found for this signature in database
GPG key ID: 284C27FD27A6DC0D
2 changed files with 16 additions and 14 deletions

View file

@ -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<IKeyboard> 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<SKeybind*>* ppActiveKeybinds = (std::vector<SKeybind*>*)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();

View file

@ -119,7 +119,7 @@ class CKeybindManager {
inline static std::string m_szCurrentSelectedSubmap = "";
SKeybind* m_pActiveKeybind = nullptr;
std::vector<SKeybind*> m_pActiveKeybinds;
uint32_t m_uTimeLastMs = 0;
uint32_t m_uLastCode = 0;