diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 81f6f80131e4708379c632775d2a4f8f00e71f05..be50cb4daaa3968fd0d1ff192052dac9d33aa47a 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -143,6 +143,18 @@ ShellClient *renderAndWaitForShown(KWayland::Client::Surface *surface, const QSi * Waits for the @p client to be destroyed. **/ bool waitForWindowDestroyed(AbstractClient *client); + +/** + * Locks the screen and waits till the screen is locked. + * @returns @c true if the screen could be locked, @c false otherwise + **/ +bool lockScreen(); + +/** + * Unlocks the screen and waits till the screen is unlocked. + * @returns @c true if the screen could be unlocked, @c false otherwise + **/ +bool unlockScreen(); } } diff --git a/autotests/integration/modifier_only_shortcut_test.cpp b/autotests/integration/modifier_only_shortcut_test.cpp index dca99aae63233eb60ca83a5003ccf06262d4e172..50aa49cd41a52c64bc8c48f7c6882f003b20c051 100644 --- a/autotests/integration/modifier_only_shortcut_test.cpp +++ b/autotests/integration/modifier_only_shortcut_test.cpp @@ -228,6 +228,21 @@ void ModifierOnlyShortcutTest::testTrigger() kwinApp()->platform()->pointerAxisHorizontal(5.0, timestamp++); kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++); QCOMPARE(triggeredSpy.count(), 2); + + // now try to lock the screen while modifier key is pressed + kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++); + QVERIFY(Test::lockScreen()); + kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++); + QEXPECT_FAIL("", "Screen locking does not quit trigger yet", Continue); + QCOMPARE(triggeredSpy.count(), 2); + + // now trigger while screen is locked, should also not work + kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++); + kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++); + QEXPECT_FAIL("", "Screen locking does not prevent trigger yet", Continue); + QCOMPARE(triggeredSpy.count(), 2); + + QVERIFY(Test::unlockScreen()); } WAYLANDTEST_MAIN(ModifierOnlyShortcutTest) diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 9496f2a94f2e7602477c2213081db1472aac8e83..7686b439456194ff0c60df4d0a3c81281e712ae3 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -34,6 +34,9 @@ along with this program. If not, see . #include #include +//screenlocker +#include + #include using namespace KWayland::Client; @@ -362,5 +365,42 @@ bool waitForWindowDestroyed(AbstractClient *client) return destroyedSpy.wait(); } +bool lockScreen() +{ + if (waylandServer()->isScreenLocked()) { + return false; + } + QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged); + if (!lockStateChangedSpy.isValid()) { + return false; + } + ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate); + if (lockStateChangedSpy.count() != 1) { + return false; + } + return waylandServer()->isScreenLocked(); +} + +bool unlockScreen() +{ + QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged); + if (!lockStateChangedSpy.isValid()) { + return false; + } + using namespace ScreenLocker; + const auto children = KSldApp::self()->children(); + for (auto it = children.begin(); it != children.end(); ++it) { + if (qstrcmp((*it)->metaObject()->className(), "LogindIntegration") != 0) { + continue; + } + QMetaObject::invokeMethod(*it, "requestUnlock"); + break; + } + if (waylandServer()->isScreenLocked()) { + lockStateChangedSpy.wait(); + } + return !waylandServer()->isScreenLocked(); +} + } }