fix: track focused window in NiriIpc singleton to fix window title always hidden
This commit is contained in:
parent
30b9e5c479
commit
d7ca7e405f
2 changed files with 41 additions and 47 deletions
|
|
@ -1,63 +1,23 @@
|
|||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Widgets
|
||||
import "." as M
|
||||
|
||||
M.BarSection {
|
||||
id: root
|
||||
spacing: M.Theme.moduleSpacing
|
||||
visible: M.Modules.windowTitle.enable && root._title !== ""
|
||||
visible: M.Modules.windowTitle.enable && M.NiriIpc.focusedTitle !== ""
|
||||
|
||||
tooltip: root._appId ? root._appId + "\n" + root._title : root._title
|
||||
tooltip: M.NiriIpc.focusedAppId ? M.NiriIpc.focusedAppId + "\n" + M.NiriIpc.focusedTitle : M.NiriIpc.focusedTitle
|
||||
|
||||
property string _title: ""
|
||||
property string _appId: ""
|
||||
readonly property string _iconSource: {
|
||||
if (!root._appId)
|
||||
if (!M.NiriIpc.focusedAppId)
|
||||
return "";
|
||||
const entry = DesktopEntries.heuristicLookup(root._appId);
|
||||
const entry = DesktopEntries.heuristicLookup(M.NiriIpc.focusedAppId);
|
||||
return entry ? Quickshell.iconPath(entry.icon) : "";
|
||||
}
|
||||
|
||||
// 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 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 || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IconImage {
|
||||
visible: root._iconSource !== ""
|
||||
source: root._iconSource
|
||||
|
|
@ -71,7 +31,7 @@ M.BarSection {
|
|||
}
|
||||
|
||||
M.BarLabel {
|
||||
label: root._title
|
||||
label: M.NiriIpc.focusedTitle
|
||||
color: root.accentColor
|
||||
elide: Text.ElideRight
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue