added keybinds on key up

This commit is contained in:
vaxerski
2022-07-20 22:45:06 +02:00
parent fc33cae70c
commit fa2bd3b1a8
5 changed files with 47 additions and 26 deletions

View File

@@ -82,7 +82,31 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) {
return modMask;
}
bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode) {
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
const xkb_keysym_t* keysyms;
int syms = xkb_state_key_get_syms(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE, &keysyms);
const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
bool found = false;
if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
for (int i = 0; i < syms; ++i)
found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, true) || found;
found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true) || found;
} else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
for (int i = 0; i < syms; ++i)
found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, false) || found;
found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false) || found;
}
return !found;
}
bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed) {
bool found = false;
if (handleInternalKeybinds(key))
@@ -92,10 +116,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
Debug::log(LOG, "Keybind handling only locked (inhibitor)");
for (auto& k : m_lKeybinds) {
if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap)
if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release))
continue;
if (k.keycode != -1) {
if (keycode != k.keycode)
continue;
@@ -114,6 +137,11 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
continue;
}
if (pressed && k.release) {
// suppress down event
return true;
}
const auto DISPATCHER = m_mDispatchers.find(k.handler);
// Should never happen, as we check in the ConfigManager, but oh well