From 90e65ea031d7b89cec70088ca9cc16acb449ac88 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Thu, 4 Apr 2024 14:56:30 -0400 Subject: [PATCH] lockscreen: Reset state when screen is off Wipe a partially entered password, and the open state of the lockscreen when the screen is off. Addresses https://invent.kde.org/plasma/plasma-mobile/-/issues/110 --- components/CMakeLists.txt | 1 + components/dpmsplugin/CMakeLists.txt | 16 ++++++++++ components/dpmsplugin/dpmsutil.cpp | 35 ++++++++++++++++++++++ components/dpmsplugin/dpmsutil.h | 37 ++++++++++++++++++++++++ shell/contents/lockscreen/LockScreen.qml | 14 +++++++++ 5 files changed, 103 insertions(+) create mode 100644 components/dpmsplugin/CMakeLists.txt create mode 100644 components/dpmsplugin/dpmsutil.cpp create mode 100644 components/dpmsplugin/dpmsutil.h diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8bdcbb76..03cc57cd 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -10,3 +10,4 @@ add_subdirectory(quicksettingsplugin) add_subdirectory(windowplugin) add_subdirectory(shellsettingsplugin) add_subdirectory(wallpaperimageplugin) +add_subdirectory(dpmsplugin) diff --git a/components/dpmsplugin/CMakeLists.txt b/components/dpmsplugin/CMakeLists.txt new file mode 100644 index 00000000..55bf1748 --- /dev/null +++ b/components/dpmsplugin/CMakeLists.txt @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2024 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +ecm_add_qml_module(dpmsplugin URI org.kde.plasma.private.mobileshell.dpmsplugin GENERATE_PLUGIN_SOURCE) + +target_sources(dpmsplugin PRIVATE dpmsutil.cpp) + +target_link_libraries(dpmsplugin PRIVATE + Qt::Qml + Qt::DBus + Qt::Gui + Qt::Quick + KF6::ScreenDpms +) + +ecm_finalize_qml_module(dpmsplugin) diff --git a/components/dpmsplugin/dpmsutil.cpp b/components/dpmsplugin/dpmsutil.cpp new file mode 100644 index 00000000..1c4b4b1b --- /dev/null +++ b/components/dpmsplugin/dpmsutil.cpp @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "dpmsutil.h" + +#include + +DPMSUtil::DPMSUtil(QObject *parent) + : QObject{parent} + , m_dpms(new KScreen::Dpms) +{ + connect(m_dpms.get(), &KScreen::Dpms::modeChanged, this, [this](auto mode, auto screen) { + switch (mode) { + case KScreen::Dpms::On: + Q_EMIT dpmsTurnedOn(screen); + break; + case KScreen::Dpms::Off: + case KScreen::Dpms::Standby: + case KScreen::Dpms::Suspend: + default: + Q_EMIT dpmsTurnedOff(screen); + break; + } + }); +} + +void DPMSUtil::turnDpmsOn() +{ + m_dpms->switchMode(KScreen::Dpms::On); +} + +void DPMSUtil::turnDpmsOff() +{ + m_dpms->switchMode(KScreen::Dpms::Off); +} diff --git a/components/dpmsplugin/dpmsutil.h b/components/dpmsplugin/dpmsutil.h new file mode 100644 index 00000000..35e8897b --- /dev/null +++ b/components/dpmsplugin/dpmsutil.h @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2024 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +/** + * Utility class that provides useful functions related to dpms. + * + * @author Devin Lin + **/ +class DPMSUtil : public QObject +{ + Q_OBJECT + QML_ELEMENT + +public: + DPMSUtil(QObject *parent = nullptr); + + Q_INVOKABLE void turnDpmsOn(); + Q_INVOKABLE void turnDpmsOff(); + +Q_SIGNALS: + void dpmsTurnedOn(QScreen *screen); + void dpmsTurnedOff(QScreen *screen); + +private: + QScopedPointer m_dpms; +}; diff --git a/shell/contents/lockscreen/LockScreen.qml b/shell/contents/lockscreen/LockScreen.qml index 8e3a988b..fc36c6a5 100644 --- a/shell/contents/lockscreen/LockScreen.qml +++ b/shell/contents/lockscreen/LockScreen.qml @@ -8,6 +8,8 @@ import QtQuick.Layouts import org.kde.plasma.core as PlasmaCore import org.kde.notificationmanager as Notifications +import org.kde.plasma.private.mobileshell.dpmsplugin as DPMS + import org.kde.kirigami 2.12 as Kirigami @@ -64,6 +66,18 @@ Item { } } + // when screen turns off, reset state + DPMS.DPMSUtil { + id: dpms + + onDpmsTurnedOff: (screen) => { + if (screen.name === Screen.name) { + flickable.goToClosePosition(); + lockScreenState.resetPassword(); + } + } + } + Item { id: lockscreenContainer anchors.fill: parent