diff --git a/autotests/integration/keyboard_layout_test.cpp b/autotests/integration/keyboard_layout_test.cpp
index 3a56ea16a8..96cf92c9c6 100644
--- a/autotests/integration/keyboard_layout_test.cpp
+++ b/autotests/integration/keyboard_layout_test.cpp
@@ -24,11 +24,15 @@ along with this program. If not, see .
#include "wayland_server.h"
#include
+#include
+#include
#include
#include
#include
+#include
+
using namespace KWin;
using namespace KWayland::Client;
@@ -44,6 +48,7 @@ private Q_SLOTS:
void testReconfigure();
void testChangeLayoutThroughDBus();
+ void testPerLayoutShortcut();
private:
void reconfigureLayouts();
@@ -184,5 +189,58 @@ void KeyboardLayoutTest::testChangeLayoutThroughDBus()
QVERIFY(layoutChangedSpy.isEmpty());
}
+void KeyboardLayoutTest::testPerLayoutShortcut()
+{
+ // this test verifies that per-layout global shortcuts are working correctly.
+ // first configure layouts
+ KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
+ layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
+ layoutGroup.sync();
+
+ // and create the global shortcuts
+ const QString componentName = QStringLiteral("KDE Keyboard Layout Switcher");
+ QAction *a = new QAction(this);
+ a->setObjectName(QStringLiteral("Switch keyboard layout to English (US)"));
+ a->setProperty("componentName", componentName);
+ KGlobalAccel::self()->setShortcut(a, QList{Qt::CTRL+Qt::ALT+Qt::Key_1}, KGlobalAccel::NoAutoloading);
+ delete a;
+ a = new QAction(this);
+ a->setObjectName(QStringLiteral("Switch keyboard layout to German"));
+ a->setProperty("componentName", componentName);
+ KGlobalAccel::self()->setShortcut(a, QList{Qt::CTRL+Qt::ALT+Qt::Key_2}, KGlobalAccel::NoAutoloading);
+ delete a;
+
+ reconfigureLayouts();
+ // now we should have three layouts
+ auto xkb = input()->keyboard()->xkb();
+ QTRY_COMPARE(xkb->numberOfLayouts(), 3u);
+ // default layout is English
+ xkb->switchToLayout(0);
+ QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
+
+ LayoutChangedSignalWrapper wrapper;
+ QSignalSpy layoutChangedSpy(&wrapper, &LayoutChangedSignalWrapper::layoutChanged);
+ QVERIFY(layoutChangedSpy.isValid());
+
+ // now switch to English through the global shortcut
+ quint32 timestamp = 1;
+ kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
+ kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++);
+ kwinApp()->platform()->keyboardKeyPressed(KEY_2, timestamp++);
+ QVERIFY(layoutChangedSpy.wait());
+ // now layout should be German
+ QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
+ // release keys again
+ kwinApp()->platform()->keyboardKeyReleased(KEY_2, timestamp++);
+ // switch back to English
+ kwinApp()->platform()->keyboardKeyPressed(KEY_1, timestamp++);
+ QVERIFY(layoutChangedSpy.wait());
+ QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
+ // release keys again
+ kwinApp()->platform()->keyboardKeyReleased(KEY_1, timestamp++);
+ kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++);
+ kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTCTRL, timestamp++);
+}
+
WAYLANDTEST_MAIN(KeyboardLayoutTest)
#include "keyboard_layout_test.moc"