From dd604c8e42a559b4ad3f97bd8bb6bf9ee28a0770 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Mon, 8 May 2023 13:24:51 +0200 Subject: [PATCH] [plugins/stickykeys] Unlatch keys when deactivating sticky keys Otherwise when deactivating sticky keys while a modifier is latched it will stay latched forever with no way to unlatch --- src/plugins/stickykeys/stickykeys.cpp | 28 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/plugins/stickykeys/stickykeys.cpp b/src/plugins/stickykeys/stickykeys.cpp index 2d7b8e651f..c4bc1370d7 100644 --- a/src/plugins/stickykeys/stickykeys.cpp +++ b/src/plugins/stickykeys/stickykeys.cpp @@ -24,15 +24,6 @@ StickyKeysFilter::StickyKeysFilter() } } -void StickyKeysFilter::loadConfig(const KConfigGroup &group) -{ - KWin::input()->uninstallInputEventFilter(this); - - if (group.readEntry("StickyKeys", false)) { - KWin::input()->prependInputEventFilter(this); - } -} - Qt::KeyboardModifier keyToModifier(Qt::Key key) { if (key == Qt::Key_Shift) { @@ -50,6 +41,23 @@ Qt::KeyboardModifier keyToModifier(Qt::Key key) return Qt::NoModifier; } +void StickyKeysFilter::loadConfig(const KConfigGroup &group) +{ + KWin::input()->uninstallInputEventFilter(this); + + if (group.readEntry("StickyKeys", false)) { + KWin::input()->prependInputEventFilter(this); + } else { + // sticky keys are deactivated, unlatch all latched keys + for (auto it = m_keyStates.keyValueBegin(); it != m_keyStates.keyValueEnd(); ++it) { + if (it->second != KeyState::None) { + it->second = KeyState::None; + KWin::input()->keyboard()->xkb()->setModifierLatched(keyToModifier((Qt::Key)it->first), false); + } + } + } +} + bool StickyKeysFilter::keyEvent(KWin::KeyEvent *event) { if (m_modifiers.contains(event->key())) { @@ -65,7 +73,7 @@ bool StickyKeysFilter::keyEvent(KWin::KeyEvent *event) for (auto it = m_keyStates.keyValueBegin(); it != m_keyStates.keyValueEnd(); ++it) { it->second = KeyState::None; - KWin::input()->keyboard()->xkb()->setModifierLatched(keyToModifier((Qt::Key)it->first), false); + KWin::input()->keyboard()->xkb()->setModifierLatched(keyToModifier(static_cast(it->first)), false); } }