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
icc-effect-5.14.5
Martin Gräßlin 2016-10-11 09:47:15 +02:00
parent db95b96854
commit 78a2732a9a
3 changed files with 15 additions and 5 deletions

View File

@ -174,7 +174,7 @@ void GlobalShortcutsTest::testMetaShiftW()
// BUG 370341
QScopedPointer<QAction> 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<QKeySequence>{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++);

View File

@ -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);

View File

@ -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;