Commit 70bc9524 authored by Martin Flöser's avatar Martin Flöser

Send QKeyEvent with Qt::Key as expected by Qt to internal windows

KWin passes the current keysym converted to a Qt::Key in the QKeyEvent.
The current keysym does not always change when a key gets released, so
when pressing a shortcut the release carry a Qt::Key which could be
considered as wrong.

QtWayland transforms the actual pressed/released key into a keysym and
passes that through the QKeyEvent. This change does the same for the
internal windows. A new QKeyEvent is created and adjusted in a way that
it matches what Qt expects.

Why not change everything to how Qt expects it? The key is used at
various places and in KWin internally we expect the behavior how it is
currently implemented. So it's better to use Qt's expectation only when
interacting with Qt.

Also the change carries a workaround for a bug in QKeySequenceEdit
(see QTBUG-62102) and transforms Super to Meta. As this adjustment only
makes sense for the internal windows we need to send in an adjusted
QKeyEvent anyway, so another argument for using the Qt behavior only in
this place.

Test Plan:
Can set a shortcut on Wayland and it can be used to activate
the window.

Reviewers: #kwin, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision:
parent f88c322a
......@@ -57,6 +57,7 @@ private Q_SLOTS:
void testMetaShiftW();
void testX11ClientShortcut();
void testWaylandClientShortcut();
void testSetupWindowShortcut();
void GlobalShortcutsTest::initTestCase()
......@@ -314,6 +315,47 @@ void GlobalShortcutsTest::testWaylandClientShortcut()
void GlobalShortcutsTest::testSetupWindowShortcut()
QScopedPointer<Surface> surface(Test::createSurface());
QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(;
auto client = Test::renderAndWaitForShown(, QSize(100, 50), Qt::blue);
QCOMPARE(workspace()->activeClient(), client);
QCOMPARE(client->shortcut(), QKeySequence());
QSignalSpy shortcutDialogAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QTRY_COMPARE(shortcutDialogAddedSpy.count(), 1);
auto dialog = shortcutDialogAddedSpy.first().first().value<ShellClient*>();
auto sequenceEdit = workspace()->shortcutDialog()->findChild<QKeySequenceEdit*>();
// the QKeySequenceEdit field does not get focus, we need to pass it focus manually
QEXPECT_FAIL("", "Edit does not have focus", Continue);
quint32 timestamp = 0;
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
kwinApp()->platform()->keyboardKeyPressed(KEY_Y, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_Y, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
// the sequence gets accepted after one second, so wait a bit longer
// now send in enter
kwinApp()->platform()->keyboardKeyPressed(KEY_ENTER, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_ENTER, timestamp++);
QTRY_COMPARE(client->shortcut(), QKeySequence(Qt::META + Qt::SHIFT + Qt::Key_Y));
#include "globalshortcuts_test.moc"
......@@ -826,8 +826,17 @@ class InternalWindowEventFilter : public InputEventFilter {
if (!found) {
return false;
if (QCoreApplication::sendEvent(found, event)) {
auto xkb = input()->keyboard()->xkb();
Qt::Key key = xkb->toQtKey(xkb->toKeysym(event->nativeScanCode()));
if (key == Qt::Key_Super_L || key == Qt::Key_Super_R) {
// workaround for QTBUG-62102
key = Qt::Key_Meta;
QKeyEvent internalEvent(event->type(), key,
event->modifiers(), event->nativeScanCode(), event->nativeVirtualKey(),
event->nativeModifiers(), event->text());
if (QCoreApplication::sendEvent(found, &internalEvent)) {
return true;
......@@ -379,6 +379,10 @@ public:
void switchWindow(Direction direction);
ShortcutDialog *shortcutDialog() const {
return client_keys_dialog;
public Q_SLOTS:
void performWindowOperation(KWin::AbstractClient* c, Options::WindowOperation op);
// Keybindings
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment