From 87af4fc3256461c710bb2871d8190af304c96df5 Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 12 Aug 2025 12:00:56 -0400 Subject: [PATCH] monitor logind dbus events --- Modules/Lock/Lock.qml | 85 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/Modules/Lock/Lock.qml b/Modules/Lock/Lock.qml index b5a71f8b..c4e30103 100644 --- a/Modules/Lock/Lock.qml +++ b/Modules/Lock/Lock.qml @@ -8,40 +8,95 @@ import qs.Common Item { id: root + property string sid: Quickshell.env("XDG_SESSION_ID") || "self" + property string sessionPath: "" function activate() { loader.activeAsync = true } - function checkLockedOnStartup() { - lockStateChecker.running = true - } - Component.onCompleted: { - checkLockedOnStartup() + getSessionPath.running = true } Process { - id: lockStateChecker - command: ["loginctl", "show-session", Quickshell.env("XDG_SESSION_ID"), "--property=LockedHint"] + id: getSessionPath + command: ["gdbus", "call", "--system", "--dest", "org.freedesktop.login1", "--object-path", "/org/freedesktop/login1", "--method", "org.freedesktop.login1.Manager.GetSession", sid] running: false - - onExited: (exitCode, exitStatus) => { - if (exitCode !== 0) { - console.warn("Failed to check session lock state, exit code:", exitCode) - } - } - + stdout: StdioCollector { onStreamFinished: { - if (text.trim() === "LockedHint=yes") { + const match = text.match(/objectpath '([^']+)'/) + if (match) { + root.sessionPath = match[1] + console.log("Found session path:", root.sessionPath) + checkCurrentLockState.running = true + lockStateMonitor.running = true + } else { + console.warn("Could not determine session path") + } + } + } + + onExited: (exitCode, exitStatus) => { + if (exitCode !== 0) { + console.warn("Failed to get session path, exit code:", exitCode) + } + } + } + + Process { + id: checkCurrentLockState + command: root.sessionPath ? ["gdbus", "call", "--system", "--dest", "org.freedesktop.login1", "--object-path", root.sessionPath, "--method", "org.freedesktop.DBus.Properties.Get", "org.freedesktop.login1.Session", "LockedHint"] : [] + running: false + + stdout: StdioCollector { + onStreamFinished: { + if (text.includes("true")) { console.log("Session is locked on startup, activating lock screen") loader.activeAsync = true } } } + + onExited: (exitCode, exitStatus) => { + if (exitCode !== 0) { + console.warn("Failed to check initial lock state, exit code:", exitCode) + } + } } + Process { + id: lockStateMonitor + command: root.sessionPath ? ["gdbus", "monitor", "--system", "--dest", "org.freedesktop.login1", "--object-path", root.sessionPath] : [] + running: false + + stdout: StdioCollector { + onRead: (chunk) => { + if (chunk.includes("LockedHint") && chunk.includes("true")) { + console.log("login1: LockedHint=true -> show lock") + loader.activeAsync = true + } else if (chunk.includes("LockedHint") && chunk.includes("false")) { + console.log("login1: LockedHint=false -> hide lock") + loader.active = false + } + } + onStreamFinished: { + console.warn("gdbus monitor ended, restarting...") + Qt.callLater(() => { + if (root.sessionPath) lockStateMonitor.running = true + }) + } + } + + onExited: (exitCode, exitStatus) => { + if (exitCode !== 0) { + console.warn("gdbus monitor failed, exit code:", exitCode) + } + } + } + + LazyLoader { id: loader