From 4a976d58ec50d6acd22e5cdbff0ca7fbda1367d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 15 Feb 2017 07:00:53 +0100 Subject: [PATCH] Track the actual pressed keys in ModifierOnlyShortcuts Summary: With this change the ModifierOnlyShortcut starts to track the actual pressed keys instead using a counter of combined pressed keys. This should help for the cases that we get unsynced key codes. E.g. if we get two key presses for the same key and only one release we don't get out of sync. Similar if we get a key release for a key which wasn't pressed, we don't go out of sync. Test Plan: Auto test still passes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D4617 --- modifier_only_shortcuts.cpp | 13 ++++++++----- modifier_only_shortcuts.h | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modifier_only_shortcuts.cpp b/modifier_only_shortcuts.cpp index e4fd50644f..cb47df4471 100644 --- a/modifier_only_shortcuts.cpp +++ b/modifier_only_shortcuts.cpp @@ -45,8 +45,9 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event) return; } if (event->type() == QEvent::KeyPress) { - m_pressCount++; - if (m_pressCount == 1 && + const bool wasEmpty = m_pressedKeys.isEmpty(); + m_pressedKeys.insert(event->nativeScanCode()); + if (wasEmpty && m_pressedKeys.size() == 1 && !ScreenLockerWatcher::self()->isLocked() && m_buttonPressCount == 0 && m_cachedMods == Qt::NoModifier) { @@ -54,9 +55,9 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event) } else { m_modifier = Qt::NoModifier; } - } else { - m_pressCount--; - if (m_pressCount == 0 && + } else if (!m_pressedKeys.isEmpty()) { + m_pressedKeys.remove(event->nativeScanCode()); + if (m_pressedKeys.isEmpty() && event->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier && !workspace()->globalShortcutsDisabled()) { if (m_modifier != Qt::NoModifier) { @@ -73,6 +74,8 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event) } } m_modifier = Qt::NoModifier; + } else { + m_modifier = Qt::NoModifier; } m_cachedMods = event->modifiersRelevantForGlobalShortcuts(); } diff --git a/modifier_only_shortcuts.h b/modifier_only_shortcuts.h index b75f037261..f4b7446ce7 100644 --- a/modifier_only_shortcuts.h +++ b/modifier_only_shortcuts.h @@ -24,6 +24,7 @@ along with this program. If not, see . #include #include +#include namespace KWin { @@ -44,10 +45,10 @@ public: } private: - uint m_pressCount = 0; Qt::KeyboardModifier m_modifier = Qt::NoModifier; Qt::KeyboardModifiers m_cachedMods; uint m_buttonPressCount = 0; + QSet m_pressedKeys; }; }