current window title
This commit is contained in:
parent
7e6ff4bc48
commit
fa7c0106ae
1 changed files with 53 additions and 6 deletions
|
|
@ -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) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue