aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gräßlin <[email protected]>2017-02-15 07:00:53 +0100
committerMartin Gräßlin <[email protected]>2017-02-23 16:55:41 +0100
commit4a976d58ec50d6acd22e5cdbff0ca7fbda1367d0 (patch)
tree0e98e22342ed42c7c05db0589ce7d731f796d4f9
parent3fcb19f42fb42359f2d4c7fa2da73539402dc5e1 (diff)
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
-rw-r--r--modifier_only_shortcuts.cpp13
-rw-r--r--modifier_only_shortcuts.h3
2 files changed, 10 insertions, 6 deletions
diff --git a/modifier_only_shortcuts.cpp b/modifier_only_shortcuts.cpp
index e4fd506..cb47df4 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 b75f037..f4b7446 100644
--- a/modifier_only_shortcuts.h
+++ b/modifier_only_shortcuts.h
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwin_export.h>
#include <QObject>
+#include <QSet>
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<quint32> m_pressedKeys;
};
}