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
This commit is contained in:
Devin Lin 2024-04-04 14:56:30 -04:00
parent 29f014ad04
commit 90e65ea031
5 changed files with 103 additions and 0 deletions

View file

@ -10,3 +10,4 @@ add_subdirectory(quicksettingsplugin)
add_subdirectory(windowplugin) add_subdirectory(windowplugin)
add_subdirectory(shellsettingsplugin) add_subdirectory(shellsettingsplugin)
add_subdirectory(wallpaperimageplugin) add_subdirectory(wallpaperimageplugin)
add_subdirectory(dpmsplugin)

View file

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 Devin Lin <devin@kde.org>
# 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)

View file

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2024 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "dpmsutil.h"
#include <QGuiApplication>
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);
}

View file

@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2024 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QObject>
#include <QPointer>
#include <QQuickItem>
#include <QQuickWindow>
#include <QTimer>
#include <qqmlregistration.h>
#include <KScreenDpms/Dpms>
/**
* Utility class that provides useful functions related to dpms.
*
* @author Devin Lin <devin@kde.org>
**/
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<KScreen::Dpms> m_dpms;
};

View file

@ -8,6 +8,8 @@ import QtQuick.Layouts
import org.kde.plasma.core as PlasmaCore import org.kde.plasma.core as PlasmaCore
import org.kde.notificationmanager as Notifications import org.kde.notificationmanager as Notifications
import org.kde.plasma.private.mobileshell.dpmsplugin as DPMS
import org.kde.kirigami 2.12 as Kirigami 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 { Item {
id: lockscreenContainer id: lockscreenContainer
anchors.fill: parent anchors.fill: parent