From 78a2732a9a421b8554022ec5edcca30d95b45d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 11 Oct 2016 09:47:15 +0200 Subject: [PATCH] Fix shortcut triggering with shift+letter Summary: A shortcut with e.g. shift+w could not be triggered as shift is considered as consumed. It transforms the keysym to an uppercase variant thus it is consumed. This change checks for the condition that shift is pressed and is the only consumed modifier. If the current keysym is a letter the shift is removed from the consumed modifier again to still support the shortcut. BUG: 370341 FIXED-IN: 5.8.2 Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3015 --- autotests/integration/globalshortcuts_test.cpp | 3 +-- keyboard_input.cpp | 15 +++++++++++++-- keyboard_input.h | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index f3968369cb..441822e27d 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -174,7 +174,7 @@ void GlobalShortcutsTest::testMetaShiftW() // BUG 370341 QScopedPointer action(new QAction(nullptr)); action->setProperty("componentName", QStringLiteral(KWIN_NAME)); - action->setObjectName(QStringLiteral("globalshortcuts-test-consumed-shift")); + action->setObjectName(QStringLiteral("globalshortcuts-test-meta-shift-w")); QSignalSpy triggeredSpy(action.data(), &QAction::triggered); QVERIFY(triggeredSpy.isValid()); KGlobalAccel::self()->setShortcut(action.data(), QList{Qt::META + Qt::SHIFT + Qt::Key_W}, KGlobalAccel::NoAutoloading); @@ -187,7 +187,6 @@ void GlobalShortcutsTest::testMetaShiftW() kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++); QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier | Qt::MetaModifier); kwinApp()->platform()->keyboardKeyPressed(KEY_W, timestamp++); - QEXPECT_FAIL("", "BUG 370341", Continue); QTRY_COMPARE(triggeredSpy.count(), 1); kwinApp()->platform()->keyboardKeyReleased(KEY_W, timestamp++); diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 52c50df46e..bb6b37739e 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -449,7 +449,18 @@ Qt::KeyboardModifiers Xkb::modifiersRelevantForGlobalShortcuts() const return mods; } - return mods & ~m_consumedModifiers; + Qt::KeyboardModifiers consumedMods = m_consumedModifiers; + if ((mods & Qt::ShiftModifier) && (consumedMods == Qt::ShiftModifier)) { + // test whether current keysym is a letter + // in that case the shift should be removed from the consumed modifiers again + // otherwise it would not be possible to trigger e.g. Shift+W as a shortcut + // see BUG: 370341 + if (QChar(toQtKey(m_keysym)).isLetter()) { + consumedMods = Qt::KeyboardModifiers(); + } + } + + return mods & ~consumedMods; } xkb_keysym_t Xkb::toKeysym(uint32_t key) @@ -473,7 +484,7 @@ QString Xkb::toString(xkb_keysym_t keysym) return QString::fromUtf8(byteArray.constData()); } -Qt::Key Xkb::toQtKey(xkb_keysym_t keysym) +Qt::Key Xkb::toQtKey(xkb_keysym_t keysym) const { int key = Qt::Key_unknown; KKeyServer::symXToKeyQt(keysym, &key); diff --git a/keyboard_input.h b/keyboard_input.h index 69b35b5592..5b3e6d074e 100644 --- a/keyboard_input.h +++ b/keyboard_input.h @@ -65,7 +65,7 @@ public: return m_keysym; } QString toString(xkb_keysym_t keysym); - Qt::Key toQtKey(xkb_keysym_t keysym); + Qt::Key toQtKey(xkb_keysym_t keysym) const; Qt::KeyboardModifiers modifiers() const; Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const; bool shouldKeyRepeat(quint32 key) const;