diff --git a/Common/SessionData.qml b/Common/SessionData.qml index 9848a998..54c564a6 100644 --- a/Common/SessionData.qml +++ b/Common/SessionData.qml @@ -58,6 +58,8 @@ Singleton { property int batterySuspendTimeout: 0 // Never property int batteryHibernateTimeout: 0 // Never + property bool lockBeforeSuspend: false + Component.onCompleted: { loadSettings() } @@ -121,6 +123,7 @@ Singleton { batteryLockTimeout = settings.batteryLockTimeout !== undefined ? settings.batteryLockTimeout : 0 batterySuspendTimeout = settings.batterySuspendTimeout !== undefined ? settings.batterySuspendTimeout : 0 batteryHibernateTimeout = settings.batteryHibernateTimeout !== undefined ? settings.batteryHibernateTimeout : 0 + lockBeforeSuspend = settings.lockBeforeSuspend !== undefined ? settings.lockBeforeSuspend : false // Generate system themes but don't override user's theme choice if (typeof Theme !== "undefined") { @@ -170,7 +173,8 @@ Singleton { "batteryMonitorTimeout": batteryMonitorTimeout, "batteryLockTimeout": batteryLockTimeout, "batterySuspendTimeout": batterySuspendTimeout, - "batteryHibernateTimeout": batteryHibernateTimeout + "batteryHibernateTimeout": batteryHibernateTimeout, + "lockBeforeSuspend": lockBeforeSuspend }, null, 2)) } @@ -457,6 +461,11 @@ Singleton { saveSettings() } + function setLockBeforeSuspend(enabled) { + lockBeforeSuspend = enabled + saveSettings() + } + FileView { id: settingsFile diff --git a/Modals/Settings/PowerSettings.qml b/Modals/Settings/PowerSettings.qml index f608da47..1c07a5d6 100644 --- a/Modals/Settings/PowerSettings.qml +++ b/Modals/Settings/PowerSettings.qml @@ -223,6 +223,14 @@ Item { } } + DankToggle { + width: parent.width + text: "Lock before suspend" + description: "Automatically lock the screen when the system prepares to suspend" + checked: SessionData.lockBeforeSuspend + onToggled: checked => SessionData.setLockBeforeSuspend(checked) + } + StyledText { text: "Idle monitoring not supported - requires newer Quickshell version" font.pixelSize: Theme.fontSizeSmall diff --git a/Modules/Lock/Lock.qml b/Modules/Lock/Lock.qml index 18913a5b..b1aca204 100644 --- a/Modules/Lock/Lock.qml +++ b/Modules/Lock/Lock.qml @@ -79,25 +79,39 @@ Item { Process { id: lockStateMonitor - command: root.sessionPath ? ["gdbus", "monitor", "--system", "--dest", "org.freedesktop.login1", "--object-path", root.sessionPath] : [] + command: root.sessionPath ? ["gdbus", "monitor", "--system", "--dest", "org.freedesktop.login1"] : [] running: false stdout: SplitParser { splitMarker: "\n" onRead: line => { - if (line.includes("org.freedesktop.login1.Session.Lock")) { - console.log("login1: Lock signal received -> show lock") + if (line.includes(root.sessionPath)) { + if (line.includes("org.freedesktop.login1.Session.Lock")) { + console.log("login1: Lock signal received -> show lock") + loader.activeAsync = true + return + } + if (line.includes("org.freedesktop.login1.Session.Unlock")) { + console.log("login1: Unlock signal received -> hide lock") + loader.active = false + return + } + if (line.includes("LockedHint") && line.includes("true")) { + console.log("login1: LockedHint=true -> show lock") + loader.activeAsync = true + return + } + if (line.includes("LockedHint") && line.includes("false")) { + console.log("login1: LockedHint=false -> hide lock") + loader.active = false + return + } + } + if (line.includes("PrepareForSleep") && + line.includes("true") && + SessionData.lockBeforeSuspend) { loader.activeAsync = true - } else if (line.includes("org.freedesktop.login1.Session.Unlock")) { - console.log("login1: Unlock signal received -> hide lock") - loader.active = false - } else if (line.includes("LockedHint") && line.includes("true")) { - console.log("login1: LockedHint=true -> show lock") - loader.activeAsync = true - } else if (line.includes("LockedHint") && line.includes("false")) { - console.log("login1: LockedHint=false -> hide lock") - loader.active = false } } }