refactor: consolidate niri event-stream into NiriIpc singleton

This commit is contained in:
Damocles 2026-04-15 00:28:40 +02:00
parent cc44bd1c0e
commit 71a843e0f3
4 changed files with 59 additions and 44 deletions

View file

@ -33,24 +33,15 @@ Row {
}
}
// Live updates
Process {
id: eventStream
running: true
command: ["niri", "msg", "--json", "event-stream"]
stdout: SplitParser {
splitMarker: "\n"
onRead: line => {
try {
const ev = JSON.parse(line);
if (ev.WorkspacesChanged !== undefined) {
root._allWorkspaces = ev.WorkspacesChanged.workspaces.sort((a, b) => a.idx - b.idx);
} else if (ev.WorkspaceActivated !== undefined) {
if (ev.WorkspaceActivated.focused)
root._activeId = ev.WorkspaceActivated.id;
}
} catch (e) {}
}
// Live updates via shared NiriIpc singleton
Connections {
target: M.NiriIpc
function onWorkspacesChanged(workspaces) {
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
}
function onWorkspaceActivated(id, focused) {
if (focused)
root._activeId = id;
}
}