keybinds: fix tracking of sent key states

This commit is contained in:
Vaxry 2024-01-10 18:06:38 +01:00
parent b240704bee
commit d484506600
2 changed files with 26 additions and 20 deletions

View file

@ -313,9 +313,10 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
.keysym = keysym, .keysym = keysym,
.keycode = KEYCODE, .keycode = KEYCODE,
.modmaskAtPressTime = MODS, .modmaskAtPressTime = MODS,
.sent = true,
}; };
bool found = false; bool suppressEvent = false;
if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
// clean repeat // clean repeat
if (m_pActiveKeybindEventSource) { if (m_pActiveKeybindEventSource) {
@ -326,10 +327,12 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
m_dPressedKeys.push_back(KEY); m_dPressedKeys.push_back(KEY);
found = handleKeybinds(MODS, KEY, true); suppressEvent = handleKeybinds(MODS, KEY, true);
if (found) if (suppressEvent)
shadowKeybinds(keysym, KEYCODE); shadowKeybinds(keysym, KEYCODE);
m_dPressedKeys.back().sent = !suppressEvent;
} else { // key release } else { // key release
// clean repeat // clean repeat
if (m_pActiveKeybindEventSource) { if (m_pActiveKeybindEventSource) {
@ -341,11 +344,11 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
bool foundInPressedKeys = false; bool foundInPressedKeys = false;
for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) { for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) {
if (it->keycode == KEYCODE) { if (it->keycode == KEYCODE) {
if (!foundInPressedKeys) { suppressEvent = handleKeybinds(MODS, *it, false);
found = handleKeybinds(MODS, *it, false);
foundInPressedKeys = true; foundInPressedKeys = true;
} suppressEvent = !it->sent;
it = m_dPressedKeys.erase(it); it = m_dPressedKeys.erase(it);
break;
} else { } else {
++it; ++it;
} }
@ -353,13 +356,13 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
if (!foundInPressedKeys) { if (!foundInPressedKeys) {
Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys"); Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys");
// fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy
found = handleKeybinds(MODS, KEY, false); suppressEvent = handleKeybinds(MODS, KEY, false);
} }
shadowKeybinds(); shadowKeybinds();
} }
return !found && !mouseBindWasActive; return !suppressEvent && !mouseBindWasActive;
} }
bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) {
@ -396,7 +399,7 @@ bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) {
bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) { bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) {
const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
bool found = false; bool suppressEvent = false;
m_uLastMouseCode = e->button; m_uLastMouseCode = e->button;
m_uLastCode = 0; m_uLastCode = 0;
@ -414,19 +417,21 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) {
if (e->state == WLR_BUTTON_PRESSED) { if (e->state == WLR_BUTTON_PRESSED) {
m_dPressedKeys.push_back(KEY); m_dPressedKeys.push_back(KEY);
found = handleKeybinds(MODS, KEY, true); suppressEvent = handleKeybinds(MODS, KEY, true);
if (found) if (suppressEvent)
shadowKeybinds(); shadowKeybinds();
m_dPressedKeys.back().sent = !suppressEvent;
} else { } else {
bool foundInPressedKeys = false; bool foundInPressedKeys = false;
for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) { for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) {
if (it->keyName == KEY_NAME) { if (it->keyName == KEY_NAME) {
if (!foundInPressedKeys) { suppressEvent = handleKeybinds(MODS, *it, false);
found = handleKeybinds(MODS, *it, false);
foundInPressedKeys = true; foundInPressedKeys = true;
} suppressEvent = !it->sent;
it = m_dPressedKeys.erase(it); it = m_dPressedKeys.erase(it);
break;
} else { } else {
++it; ++it;
} }
@ -434,13 +439,13 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) {
if (!foundInPressedKeys) { if (!foundInPressedKeys) {
Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys (2)"); Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys (2)");
// fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy
found = handleKeybinds(MODS, KEY, false); suppressEvent = handleKeybinds(MODS, KEY, false);
} }
shadowKeybinds(); shadowKeybinds();
} }
return !found && !mouseBindWasActive; return !suppressEvent && !mouseBindWasActive;
} }
void CKeybindManager::resizeWithBorder(wlr_pointer_button_event* e) { void CKeybindManager::resizeWithBorder(wlr_pointer_button_event* e) {

View file

@ -41,6 +41,7 @@ struct SPressedKeyWithMods {
xkb_keysym_t keysym = 0; xkb_keysym_t keysym = 0;
uint32_t keycode = 0; uint32_t keycode = 0;
uint32_t modmaskAtPressTime = 0; uint32_t modmaskAtPressTime = 0;
bool sent = false;
}; };
class CKeybindManager { class CKeybindManager {