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
This commit is contained in:
parent
3fcb19f42f
commit
4a976d58ec
2 changed files with 10 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue