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

@ -39,32 +39,21 @@ M.BarSection {
}
}
// Live updates via event stream
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.WindowFocusChanged !== undefined) {
// WindowFocusChanged only gives id, re-query for full info
if (ev.WindowFocusChanged.id !== null)
initProc.running = true;
else {
root._title = "";
root._appId = "";
}
} else if (ev.WindowOpenedOrChanged !== undefined) {
const w = ev.WindowOpenedOrChanged.window;
if (w.is_focused) {
root._title = w.title || "";
root._appId = w.app_id || "";
}
}
} catch (e) {}
// Live updates via shared NiriIpc singleton
Connections {
target: M.NiriIpc
function onWindowFocusChanged(windowId) {
if (windowId !== null)
initProc.running = true;
else {
root._title = "";
root._appId = "";
}
}
function onWindowOpenedOrChanged(window) {
if (window.is_focused) {
root._title = window.title || "";
root._appId = window.app_id || "";
}
}
}