diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 81f6f80131..be50cb4daa 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 dca99aae63..50aa49cd41 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 9496f2a94f..7686b43945 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(); +} + } }