lockscreen: Add DoubleTap to Lock in Lockscreen

Thx @devinlin to help me fix the MouseArea ^^

Can fix https://invent.kde.org/teams/plasma-mobile/issues/-/issues/90
This commit is contained in:
Florian RICHER 2025-07-01 17:03:26 +02:00 committed by Devin Lin
parent 975b6bd3bb
commit a329099b83
5 changed files with 113 additions and 1 deletions

View file

@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later
ecm_add_qml_module(shellsettingsplugin URI org.kde.plasma.private.mobileshell.shellsettingsplugin GENERATE_PLUGIN_SOURCE)
target_sources(shellsettingsplugin PRIVATE mobileshellsettings.cpp)
target_sources(shellsettingsplugin PRIVATE kwinsettings.cpp mobileshellsettings.cpp)
target_link_libraries(shellsettingsplugin PRIVATE
Qt::Qml

View file

@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: 2025 Florian RICHER <florian.richer@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwinsettings.h"
const QString CONFIG_FILE = QStringLiteral("kwinrc");
const QString WAYLAND_CONFIG_GROUP = QStringLiteral("Wayland");
KWinSettings::KWinSettings(QObject *parent)
: QObject{parent}
, m_config{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)}
{
m_configWatcher = KConfigWatcher::create(m_config);
connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
Q_UNUSED(names)
if (group.name() == WAYLAND_CONFIG_GROUP) {
Q_EMIT doubleTapWakeupChanged();
}
});
}
bool KWinSettings::doubleTapWakeup() const
{
auto group = KConfigGroup{m_config, WAYLAND_CONFIG_GROUP};
return group.readEntry("DoubleTapWakeup", true);
}
void KWinSettings::setDoubleTapWakeup(bool enabled)
{
auto group = KConfigGroup{m_config, WAYLAND_CONFIG_GROUP};
group.writeEntry("DoubleTapWakeup", enabled, KConfigGroup::Notify);
m_config->sync();
}

View file

@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2025 Florian RICHER <florian.richer@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <KConfigGroup>
#include <KConfigWatcher>
#include <KSharedConfig>
#include <qobject.h>
#include <qqmlintegration.h>
class KWinSettings : public QObject
{
Q_OBJECT
QML_NAMED_ELEMENT(KWinSettings)
QML_SINGLETON
Q_PROPERTY(bool doubleTapWakeup READ doubleTapWakeup WRITE setDoubleTapWakeup NOTIFY doubleTapWakeupChanged)
public:
KWinSettings(QObject *parent = nullptr);
/**
* Whether Double Tap to Wakeup is enabled.
*/
bool doubleTapWakeup() const;
/**
* Set whether Double Tap to Wakeup is enabled.
*
* @param enabled
*/
void setDoubleTapWakeup(bool enabled);
Q_SIGNALS:
void doubleTapWakeupChanged();
private:
KConfigWatcher::Ptr m_configWatcher;
KSharedConfig::Ptr m_config;
};

View file

@ -61,6 +61,20 @@ KCM.SimpleKCM {
}
}
}
FormCard.FormDelegateSeparator { above: autoHidePanels; below: doubleTapWakeup }
FormCard.FormSwitchDelegate {
id: doubleTapWakeup
text: i18n("Double Tap to Wakeup")
description: i18n("When active, it allow to wakeup the device just with double tap when the screen is off.")
checked: ShellSettings.KWinSettings.doubleTapWakeup
onCheckedChanged: {
if (checked != ShellSettings.KWinSettings.doubleTapWakeup) {
ShellSettings.KWinSettings.doubleTapWakeup = checked;
}
}
}
}
FormCard.FormHeader {

View file

@ -11,6 +11,7 @@ import org.kde.notificationmanager as Notifications
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.dpmsplugin as DPMS
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
import org.kde.kirigami 2.12 as Kirigami
@ -207,6 +208,23 @@ Item {
color: Qt.rgba(0, 0, 0, 0.5)
}
MouseArea {
// Disable "double tap to lock" to avoid accidental locking
// when the keypad is open, and the user is typing their password.
enabled: flickable.openFactor < 0.1
anchors.fill: parent
onDoubleClicked: (mouse) => {
if (ShellSettings.KWinSettings.doubleTapWakeup) {
deviceLock.triggerLock();
}
}
MobileShell.DeviceLock {
id: deviceLock
}
}
Keypad {
id: keypad
visible: !root.lockScreenState.canBeUnlocked // don't show for passwordless login