diff --git a/modules/WindowTitle.qml b/modules/WindowTitle.qml index 78855ce..d4e7dca 100644 --- a/modules/WindowTitle.qml +++ b/modules/WindowTitle.qml @@ -1,12 +1,59 @@ import QtQuick +import Quickshell.Io import "." as M -// Niri window title disabled — Quickshell.Services.Niri not available -Text { - text: "" +M.BarLabel { + id: root + + label: root._title color: M.Theme.base05 - font.pixelSize: M.Theme.fontSize - font.family: M.Theme.fontFamily + tooltip: root._appId ? root._appId + "\n" + root._title : root._title elide: Text.ElideRight - verticalAlignment: Text.AlignVCenter + + 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) {} + } + } + } }