lock: resolve session path dynamically, use gdbus monitor (no root needed)
This commit is contained in:
parent
fec5ef4d76
commit
892b2dca48
1 changed files with 32 additions and 12 deletions
|
|
@ -8,6 +8,7 @@ Scope {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property bool _enabled: M.Modules.lock.enable
|
readonly property bool _enabled: M.Modules.lock.enable
|
||||||
|
property string _sessionPath: ""
|
||||||
|
|
||||||
WlSessionLock {
|
WlSessionLock {
|
||||||
id: lock
|
id: lock
|
||||||
|
|
@ -23,21 +24,39 @@ Scope {
|
||||||
lock: lock
|
lock: lock
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for logind Lock/Unlock signals via busctl.
|
// Resolve the actual logind session object path at startup
|
||||||
// TODO: replace with native D-Bus integration when nova-stats becomes a quickshell plugin
|
|
||||||
Process {
|
Process {
|
||||||
id: _logindMonitor
|
id: _sessionResolver
|
||||||
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"]
|
command: ["busctl", "call", "--system", "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "GetSession", "s", "auto"]
|
||||||
running: root._enabled
|
running: root._enabled
|
||||||
|
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
try {
|
// Output: o "/org/freedesktop/login1/session/_32"
|
||||||
const msg = JSON.parse(data);
|
const match = data.match(/"([^"]+)"/);
|
||||||
if (msg.member === "Lock" && root._enabled)
|
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;
|
lock.locked = true;
|
||||||
// Unlock is PAM-driven, ignore logind Unlock signal
|
// Unlock is PAM-driven, ignore logind Unlock signal
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,13 +64,14 @@ Scope {
|
||||||
// Set logind LockedHint when lock state changes
|
// Set logind LockedHint when lock state changes
|
||||||
Process {
|
Process {
|
||||||
id: _lockedHint
|
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 {
|
Connections {
|
||||||
target: lock
|
target: lock
|
||||||
|
|
||||||
function onLockStateChanged() {
|
function onLockStateChanged() {
|
||||||
|
if (root._sessionPath)
|
||||||
_lockedHint.running = true;
|
_lockedHint.running = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue