homescreens/folio: Add options to turn off and lock the phone after a double tap on screen

Linked to issue: https://invent.kde.org/teams/plasma-mobile/issues/-/issues/318
This commit is contained in:
Florian RICHER 2025-06-25 22:39:36 +02:00 committed by Devin Lin
parent 0b8c42193d
commit 2b51e0c30c
8 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: 2025 Florian RICHER <florian.richer@protonmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import org.kde.plasma.private.mobileshell.dpmsplugin as DPMS
import org.kde.plasma.private.mobileshell.state as MobileShellState
Item {
id: root
property real doubleClickInterval: 400
property int tapCount: 0
property bool isSwiping: false
signal doubleTapped()
onDoubleTapped: {
MobileShellState.LockscreenDBusClient.lockScreen()
dpms.turnDpmsOff()
}
DPMS.DPMSUtil {
id: dpms
}
// Workaround for double tap detection without capture events for HomeScreen
Timer {
id: doubleClickTimer
interval: root.doubleClickInterval
onTriggered: {
root.tapCount = 0
}
}
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
onReleased: {
mouse.accepted = false
if (root.isSwiping) {
// Reset the isSwiping flag to re-enable double tap detection
root.isSwiping = false
return
}
root.tapCount++;
if (root.tapCount === 2) {
root.doubleTapped()
}
doubleClickTimer.restart()
}
// If is swiping, we don't want to trigger the double tap
onPositionChanged: {
mouse.accepted = false
doubleClickTimer.stop()
root.tapCount = 0
root.isSwiping = true
}
}
}

View file

@ -33,6 +33,15 @@ bool LockscreenDBusClient::lockscreenActive() const
return m_lockscreenActive;
}
void LockscreenDBusClient::lockScreen()
{
QDBusMessage request = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("Lock"));
QDBusConnection::sessionBus().call(request);
}
void LockscreenDBusClient::slotLockscreenActiveChanged(bool active)
{
if (active != m_lockscreenActive) {

View file

@ -20,6 +20,7 @@ public:
explicit LockscreenDBusClient(QObject *parent = nullptr);
bool lockscreenActive() const;
Q_INVOKABLE void lockScreen();
Q_SIGNALS:
void lockscreenActiveChanged();

View file

@ -19,6 +19,7 @@ const QString CFG_KEY_DELEGATE_ICON_SIZE = QStringLiteral("delegateIconSize");
const QString CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND = QStringLiteral("showFavoritesBarBackground");
const QString CFG_KEY_PAGE_TRANSITION_EFFECT = QStringLiteral("pageTransitionEffect");
const QString CFG_KEY_SHOW_WALLPAPER_BLUR = QStringLiteral("showWallpaperBlur");
const QString CFG_KEY_DOUBLE_TAP_TO_SLEEP = QStringLiteral("doubleTapToSleep");
FolioSettings::FolioSettings(HomeScreen *parent)
: QObject{parent}
@ -153,6 +154,20 @@ void FolioSettings::setShowWallpaperBlur(bool showWallpaperBlur)
}
}
bool FolioSettings::doubleTapToSleep() const
{
return m_doubleTapToSleep;
}
void FolioSettings::setDoubleTapToSleep(bool doubleTapToSleep)
{
if (m_doubleTapToSleep != doubleTapToSleep) {
m_doubleTapToSleep = doubleTapToSleep;
Q_EMIT doubleTapToSleepChanged();
save();
}
}
void FolioSettings::save()
{
if (!m_homeScreen) {
@ -168,6 +183,7 @@ void FolioSettings::save()
m_homeScreen->config().writeEntry(CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND, m_showFavouritesBarBackground);
m_homeScreen->config().writeEntry(CFG_KEY_PAGE_TRANSITION_EFFECT, (int)m_pageTransitionEffect);
m_homeScreen->config().writeEntry(CFG_KEY_SHOW_WALLPAPER_BLUR, m_showWallpaperBlur);
m_homeScreen->config().writeEntry(CFG_KEY_DOUBLE_TAP_TO_SLEEP, m_doubleTapToSleep);
Q_EMIT m_homeScreen->configNeedsSaving();
}
@ -187,6 +203,7 @@ void FolioSettings::load()
m_showFavouritesBarBackground = m_homeScreen->config().readEntry(CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND, true);
m_pageTransitionEffect = static_cast<PageTransitionEffect>(m_homeScreen->config().readEntry(CFG_KEY_PAGE_TRANSITION_EFFECT, (int)SlideTransition));
m_showWallpaperBlur = m_homeScreen->config().readEntry(CFG_KEY_SHOW_WALLPAPER_BLUR, true);
m_doubleTapToSleep = m_homeScreen->config().readEntry(CFG_KEY_DOUBLE_TAP_TO_SLEEP, true);
Q_EMIT homeScreenRowsChanged();
Q_EMIT homeScreenColumnsChanged();
@ -195,6 +212,7 @@ void FolioSettings::load()
Q_EMIT lockLayoutChanged();
Q_EMIT delegateIconSizeChanged();
Q_EMIT showWallpaperBlurChanged();
Q_EMIT doubleTapToSleepChanged();
}
bool FolioSettings::saveLayoutToFile(QString path)

View file

@ -24,6 +24,7 @@ class FolioSettings : public QObject
Q_PROPERTY(
FolioSettings::PageTransitionEffect pageTransitionEffect READ pageTransitionEffect WRITE setPageTransitionEffect NOTIFY pageTransitionEffectChanged)
Q_PROPERTY(bool showWallpaperBlur READ showWallpaperBlur WRITE setShowWallpaperBlur NOTIFY showWallpaperBlurChanged)
Q_PROPERTY(bool doubleTapToSleep READ doubleTapToSleep WRITE setDoubleTapToSleep NOTIFY doubleTapToSleepChanged)
public:
FolioSettings(HomeScreen *parent = nullptr);
@ -68,6 +69,9 @@ public:
bool showWallpaperBlur() const;
void setShowWallpaperBlur(bool showWallpaperBlur);
bool doubleTapToSleep() const;
void setDoubleTapToSleep(bool doubleTapToSleep);
Q_INVOKABLE void load();
Q_INVOKABLE bool saveLayoutToFile(QString path);
@ -83,6 +87,7 @@ Q_SIGNALS:
void showFavouritesBarBackgroundChanged();
void pageTransitionEffectChanged();
void showWallpaperBlurChanged();
void doubleTapToSleepChanged();
private:
void save();
@ -98,4 +103,5 @@ private:
bool m_showFavouritesBarBackground{false};
PageTransitionEffect m_pageTransitionEffect{SlideTransition};
bool m_showWallpaperBlur{false};
bool m_doubleTapToSleep{false};
};

View file

@ -31,6 +31,12 @@ MouseArea {
id: haptics
}
MobileShell.DoubleTapToSleep {
id: doubleTapToSleep
enabled: folio.FolioSettings.doubleTapToSleep
anchors.fill: parent
}
Repeater {
id: repeater
model: folio.FavouritesModel

View file

@ -28,6 +28,12 @@ Item {
id: haptics
}
MobileShell.DoubleTapToSleep {
id: doubleTapToSleep
enabled: folio.FolioSettings.doubleTapToSleep
anchors.fill: parent
}
// background when in settings view (for rearranging pages)
Rectangle {
id: settingsViewBackground

View file

@ -233,6 +233,19 @@ Window {
onCurrentValueChanged: folio.FolioSettings.pageTransitionEffect = currentValue
}
FormCard.FormDelegateSeparator { above: pageTransitionCombobox; below: doubleTapToSleepSwitch }
FormCard.FormSwitchDelegate {
id: doubleTapToSleepSwitch
text: i18n("Double tap to lock device")
checked: folio.FolioSettings.doubleTapToSleep
onCheckedChanged: {
if (checked != folio.FolioSettings.doubleTapToSleep) {
folio.FolioSettings.doubleTapToSleep = checked;
}
}
}
}
FormCard.FormHeader {