From 892b2dca48414e6d3c880a16824c2e911c8b795d Mon Sep 17 00:00:00 2001 From: Damocles Date: Fri, 17 Apr 2026 14:01:07 +0200 Subject: [PATCH] lock: resolve session path dynamically, use gdbus monitor (no root needed) --- modules/lock/Lock.qml | 44 +++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/modules/lock/Lock.qml b/modules/lock/Lock.qml index f1e63d5..fd6821d 100644 --- a/modules/lock/Lock.qml +++ b/modules/lock/Lock.qml @@ -8,6 +8,7 @@ Scope { id: root readonly property bool _enabled: M.Modules.lock.enable + property string _sessionPath: "" WlSessionLock { id: lock @@ -23,21 +24,39 @@ Scope { lock: lock } - // Listen for logind Lock/Unlock signals via busctl. - // TODO: replace with native D-Bus integration when nova-stats becomes a quickshell plugin + // Resolve the actual logind session object path at startup Process { - id: _logindMonitor - command: ["busctl", "monitor", "--system", "--match", "type='signal',interface='org.freedesktop.login1.Session',member='Lock'", "--match", "type='signal',interface='org.freedesktop.login1.Session',member='Unlock'", "--json=short"] + id: _sessionResolver + command: ["busctl", "call", "--system", "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "GetSession", "s", "auto"] running: root._enabled stdout: SplitParser { onRead: data => { - try { - const msg = JSON.parse(data); - if (msg.member === "Lock" && root._enabled) - lock.locked = true; - // Unlock is PAM-driven, ignore logind Unlock signal - } catch (e) {} + // Output: o "/org/freedesktop/login1/session/_32" + const match = data.match(/"([^"]+)"/); + if (match) + root._sessionPath = match[1]; + } + } + + onExited: { + if (root._sessionPath) + _logindMonitor.running = true; + } + } + + // Listen for logind Lock/Unlock signals via gdbus monitor. + // TODO: replace with native D-Bus integration when nova-stats becomes a quickshell plugin + Process { + id: _logindMonitor + command: ["gdbus", "monitor", "--system", "--dest", "org.freedesktop.login1", "--object-path", root._sessionPath] + running: false + + stdout: SplitParser { + onRead: data => { + if (data.indexOf(".Lock ()") !== -1 && root._enabled) + lock.locked = true; + // Unlock is PAM-driven, ignore logind Unlock signal } } } @@ -45,14 +64,15 @@ Scope { // Set logind LockedHint when lock state changes Process { id: _lockedHint - command: ["busctl", "call", "--system", "org.freedesktop.login1", "/org/freedesktop/login1/session/auto", "org.freedesktop.login1.Session", "SetLockedHint", "b", lock.locked ? "true" : "false"] + command: ["busctl", "call", "--system", "org.freedesktop.login1", root._sessionPath || "/org/freedesktop/login1/session/auto", "org.freedesktop.login1.Session", "SetLockedHint", "b", lock.locked ? "true" : "false"] } Connections { target: lock function onLockStateChanged() { - _lockedHint.running = true; + if (root._sessionPath) + _lockedHint.running = true; } } }