import QtQuick import Quickshell.Io import "." as M M.BarLabel { id: root label: root._title color: M.Theme.base05 tooltip: root._appId ? root._appId + "\n" + root._title : root._title elide: Text.ElideRight property string _title: "" property string _appId: "" // Initial state — niri event-stream doesn't replay current focus Process { id: initProc running: true command: ["niri", "msg", "--json", "focused-window"] stdout: StdioCollector { onStreamFinished: { try { const w = JSON.parse(text); if (w) { root._title = w.title || ""; root._appId = w.app_id || ""; } } catch (e) {} } } } // 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) { const w = ev.WindowFocusChanged.window; root._title = w ? (w.title || "") : ""; root._appId = w ? (w.app_id || "") : ""; } 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) {} } } } }