Don't trigger modifier only shortcuts if pointer interaction

Summary:
If the user clicked a pointer button or scrolled a pointer axis the
held modifier was most likely intended to modify the pointer event.
Thus the modifier only shortcut should not be triggered.

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D2435
This commit is contained in:
Martin Gräßlin 2016-08-13 15:25:24 +02:00
parent 3a730fa51e
commit bd58d7792f
2 changed files with 8 additions and 6 deletions

View file

@ -197,7 +197,6 @@ void ModifierOnlyShortcutTest::testTrigger()
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
QEXPECT_FAIL("", "Button not yet handled", Continue);
QCOMPARE(triggeredSpy.count(), 2);
// mouse button press before mod press, release before mod release
@ -207,7 +206,6 @@ void ModifierOnlyShortcutTest::testTrigger()
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
QEXPECT_FAIL("", "Button not yet handled", Continue);
QCOMPARE(triggeredSpy.count(), 2);
// mouse button click while mod is pressed
@ -217,21 +215,18 @@ void ModifierOnlyShortcutTest::testTrigger()
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
QEXPECT_FAIL("", "Button not yet handled", Continue);
QCOMPARE(triggeredSpy.count(), 2);
// scroll while mod is pressed
kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++);
kwinApp()->platform()->pointerAxisVertical(5.0, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QEXPECT_FAIL("", "Axis not yet handled", Continue);
QCOMPARE(triggeredSpy.count(), 2);
// same for horizontal
kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++);
kwinApp()->platform()->pointerAxisHorizontal(5.0, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QEXPECT_FAIL("", "Axis not yet handled", Continue);
QCOMPARE(triggeredSpy.count(), 2);
}

View file

@ -95,6 +95,12 @@ Xkb::Xkb(InputRedirection *input)
xkb_context_set_log_level(m_context, XKB_LOG_LEVEL_DEBUG);
xkb_context_set_log_fn(m_context, &xkbLogHandler);
}
auto resetModOnlyShortcut = [this] {
m_modOnlyShortcut.modifier = Qt::NoModifier;
};
QObject::connect(m_input, &InputRedirection::pointerButtonStateChanged, resetModOnlyShortcut);
QObject::connect(m_input, &InputRedirection::pointerAxisChanged, resetModOnlyShortcut);
}
Xkb::~Xkb()
@ -243,7 +249,8 @@ void Xkb::updateKey(uint32_t key, InputRedirection::KeyboardKeyState state)
updateModifiers();
if (state == InputRedirection::KeyboardKeyPressed) {
m_modOnlyShortcut.pressCount++;
if (m_modOnlyShortcut.pressCount == 1) {
if (m_modOnlyShortcut.pressCount == 1 &&
m_input->qtButtonStates() == Qt::NoButton) {
m_modOnlyShortcut.modifier = Qt::KeyboardModifier(int(m_modifiers));
} else {
m_modOnlyShortcut.modifier = Qt::NoModifier;