diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index c1d2da2db1..432a1baf4c 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -49,6 +49,7 @@ private Q_SLOTS: void testUserActionsMenu(); void testMetaShiftW(); void testComponseKey(); + void testKeypad(); void testX11WindowShortcut(); void testWaylandWindowShortcut(); void testSetupWindowShortcut(); @@ -275,6 +276,44 @@ void GlobalShortcutsTest::testComponseKey() QTRY_COMPARE(triggeredSpy.count(), 0); } +void GlobalShortcutsTest::testKeypad() +{ + auto zeroAction = std::make_unique(); + zeroAction->setProperty("componentName", QStringLiteral("kwin")); + zeroAction->setObjectName(QStringLiteral("globalshortcuts-test-keypad-0")); + QSignalSpy zeroActionTriggeredSpy(zeroAction.get(), &QAction::triggered); + KGlobalAccel::self()->setShortcut(zeroAction.get(), QList{Qt::MetaModifier | Qt::KeypadModifier | Qt::Key_0}, KGlobalAccel::NoAutoloading); + + auto insertAction = std::make_unique(); + insertAction->setProperty("componentName", QStringLiteral("kwin")); + insertAction->setObjectName(QStringLiteral("globalshortcuts-test-keypad-ins")); + QSignalSpy insertActionTriggeredSpy(insertAction.get(), &QAction::triggered); + KGlobalAccel::self()->setShortcut(insertAction.get(), QList{Qt::MetaModifier | Qt::KeypadModifier | Qt::Key_Insert}, KGlobalAccel::NoAutoloading); + + // Turn on numlock + quint32 timestamp = 0; + Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++); + Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++); + + Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++); + Test::keyboardKeyPressed(KEY_KP0, timestamp++); + Test::keyboardKeyReleased(KEY_KP0, timestamp++); + Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); + QTRY_COMPARE(zeroActionTriggeredSpy.count(), 1); + QCOMPARE(insertActionTriggeredSpy.count(), 0); + + // Turn off numlock + Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++); + Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++); + + Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++); + Test::keyboardKeyPressed(KEY_KP0, timestamp++); + Test::keyboardKeyReleased(KEY_KP0, timestamp++); + Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); + QTRY_COMPARE(insertActionTriggeredSpy.count(), 1); + QCOMPARE(zeroActionTriggeredSpy.count(), 1); +} + void GlobalShortcutsTest::testX11WindowShortcut() { // create an X11 window