From bd58d7792fede7f9b2cf33b85c61e41ce08f3b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 13 Aug 2016 15:25:24 +0200 Subject: [PATCH] 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 --- autotests/integration/modifier_only_shortcut_test.cpp | 5 ----- keyboard_input.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/autotests/integration/modifier_only_shortcut_test.cpp b/autotests/integration/modifier_only_shortcut_test.cpp index b4b1c16b22..dca99aae63 100644 --- a/autotests/integration/modifier_only_shortcut_test.cpp +++ b/autotests/integration/modifier_only_shortcut_test.cpp @@ -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); } diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 3a6880a5d9..7781876888 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -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;