From 1ace5a4ceefc1e1319abfb4d883edce8758a7c36 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 9 Aug 2023 15:47:18 +0200 Subject: [PATCH] input: add special handling for tabbox modifiers modifiersRelevantForTabBox handles modifiers being consumed, which is wrong for the tabbox; all it needs is to ignore capslock. To ensure that happens, this commit adds a separate method for modifiers relevant for the tabbox. BUG: 473099 --- src/input.cpp | 2 +- src/input_event.h | 11 +++++++++++ src/keyboard_input.cpp | 1 + src/xkb.cpp | 21 +++++++++++++++++++++ src/xkb.h | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index 7666084b3b..8a0a3b3ba8 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1623,7 +1623,7 @@ public: passToWaylandServer(event); if (event->type() == QEvent::KeyPress) { - workspace()->tabbox()->keyPress(event->modifiersRelevantForGlobalShortcuts() | event->key()); + workspace()->tabbox()->keyPress(event->modifiersRelevantForTabBox() | event->key()); } else if (static_cast(event)->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) { workspace()->tabbox()->modifiersReleased(); } diff --git a/src/input_event.h b/src/input_event.h index 5389879600..6cdf67dcec 100644 --- a/src/input_event.h +++ b/src/input_event.h @@ -150,11 +150,22 @@ public: m_modifiersRelevantForShortcuts = mods; } + Qt::KeyboardModifiers modifiersRelevantForTabBox() const + { + return m_modifiersRelevantForTabBox; + } + + void setModifiersRelevantForTabBox(const Qt::KeyboardModifiers &mods) + { + m_modifiersRelevantForTabBox = mods; + } + std::chrono::microseconds timestamp() const; private: InputDevice *m_device; Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers(); + Qt::KeyboardModifiers m_modifiersRelevantForTabBox = Qt::KeyboardModifiers(); const std::chrono::microseconds m_timestamp; }; diff --git a/src/keyboard_input.cpp b/src/keyboard_input.cpp index 95139db03c..aff81fd256 100644 --- a/src/keyboard_input.cpp +++ b/src/keyboard_input.cpp @@ -259,6 +259,7 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa time, device); event.setModifiersRelevantForGlobalShortcuts(globalShortcutsModifiers); + event.setModifiersRelevantForTabBox(m_xkb->modifiersRelevantForTabBox()); m_input->processSpies(std::bind(&InputEventSpy::keyEvent, std::placeholders::_1, &event)); if (!m_inited) { diff --git a/src/xkb.cpp b/src/xkb.cpp index 9eb9cd1c59..2ce5d4d94b 100644 --- a/src/xkb.cpp +++ b/src/xkb.cpp @@ -549,6 +549,27 @@ Qt::KeyboardModifiers Xkb::modifiersRelevantForGlobalShortcuts(uint32_t scanCode return mods & ~consumedMods; } +Qt::KeyboardModifiers Xkb::modifiersRelevantForTabBox() const +{ + if (!m_state) { + return Qt::NoModifier; + } + Qt::KeyboardModifiers mods = Qt::NoModifier; + if (xkb_state_mod_index_is_active(m_state, m_shiftModifier, XKB_STATE_MODS_EFFECTIVE) == 1) { + mods |= Qt::ShiftModifier; + } + if (xkb_state_mod_index_is_active(m_state, m_altModifier, XKB_STATE_MODS_EFFECTIVE) == 1) { + mods |= Qt::AltModifier; + } + if (xkb_state_mod_index_is_active(m_state, m_controlModifier, XKB_STATE_MODS_EFFECTIVE) == 1) { + mods |= Qt::ControlModifier; + } + if (xkb_state_mod_index_is_active(m_state, m_metaModifier, XKB_STATE_MODS_EFFECTIVE) == 1) { + mods |= Qt::MetaModifier; + } + return mods; +} + xkb_keysym_t Xkb::toKeysym(uint32_t key) { if (!m_state) { diff --git a/src/xkb.h b/src/xkb.h index 0f2c91f0c5..4966a23567 100644 --- a/src/xkb.h +++ b/src/xkb.h @@ -61,6 +61,7 @@ public: bool superAsMeta = false) const; Qt::KeyboardModifiers modifiers() const; Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts(uint32_t scanCode = 0) const; + Qt::KeyboardModifiers modifiersRelevantForTabBox() const; bool shouldKeyRepeat(quint32 key) const; void switchToNextLayout();