Windows whose class is a respelling of their desktop entry's StartupWMClass (YouTube Music: "youtube-music-desktop-app" vs "YouTube Music Desktop App") showed as separate unknown dock items. Matching now falls back to comparing names with case and space, dash and underscore runs normalized; ambiguous or partial names still never match. Quickshell fills a toplevel's IPC data only at startup, so windows opened later lacked their initial class, mapped/hidden state and floating flag. HyprlandService now runs one `hyprctl -j clients` query per burst of window open/close/move/float/fullscreen/group events (none for title changes, none while idle). Windows with neither IPC data nor a foreign-toplevel handle are treated as unmapped. dock status reports each item's window classes for diagnosis. The Cava helper sets a parent-death signal before exec: Cava writes nothing during silence, so it outlived a killed or crashed shell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.3 KiB
QML
107 lines
4.3 KiB
QML
pragma Singleton
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Hyprland
|
|
import Quickshell.Io
|
|
|
|
Singleton {
|
|
id: root
|
|
readonly property var visibleWorkspaces: Hyprland.workspaces.values.filter(w => w.active).map(w => w.id)
|
|
// Hyprland IPC details by address (no 0x). Quickshell fills lastIpcObject
|
|
// only at startup, and Hyprland.refreshToplevels() can crash 0.3.1, so later
|
|
// windows lacked their initial class (dock matching), mapped/hidden state and
|
|
// floating flag. One query per burst of window events; nothing while idle.
|
|
property var clients: ({})
|
|
readonly property var windows: Hyprland.toplevels.values.map(t => {
|
|
const info = root.clients[String(t.address).replace(/^0x/, "")] || t.lastIpcObject || {};
|
|
return {
|
|
address: t.address,
|
|
handle: t.wayland,
|
|
appId: t.wayland ? t.wayland.appId : info.class || "",
|
|
initialClass: info.initialClass || "",
|
|
title: t.title,
|
|
active: t.activated,
|
|
monitor: t.monitor ? t.monitor.name : "",
|
|
workspace: t.workspace ? t.workspace.id : 0,
|
|
x: info.at ? info.at[0] : 0,
|
|
y: info.at ? info.at[1] : 0,
|
|
width: info.size ? info.size[0] : 0,
|
|
height: info.size ? info.size[1] : 0,
|
|
// Without IPC data, only a foreign-toplevel handle proves the window is mapped.
|
|
hidden: info.hidden === true || info.mapped === false || (!t.wayland && !info.address),
|
|
fullscreen: info.fullscreen === 2,
|
|
floating: info.floating === true
|
|
};
|
|
}).filter(w => !w.hidden)
|
|
// Monitors whose desktop is hidden: a tiled or fullscreen window sits on
|
|
// their active workspace. Desktop widgets pause animation and sampling there.
|
|
readonly property var coveredMonitors: windows.filter(w => visibleWorkspaces.includes(w.workspace) && (!w.floating || w.fullscreen)).map(w => w.monitor)
|
|
readonly property bool needsGeometry: ConfigService.ready && ConfigService.data.dock.enabled && ConfigService.data.dock.visibility === "intelligent"
|
|
function focusWindow(address) {
|
|
const window = windows.find(w => w.address === address);
|
|
if (!window)
|
|
return false;
|
|
if (window.handle)
|
|
window.handle.activate();
|
|
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
|
Hyprland.dispatch("focuswindow address:" + (address.startsWith("0x") ? address : "0x" + address));
|
|
else
|
|
return false;
|
|
return true;
|
|
}
|
|
function closeWindow(address) {
|
|
const window = windows.find(w => w.address === address);
|
|
if (!window)
|
|
return false;
|
|
if (window.handle)
|
|
window.handle.close();
|
|
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
|
Hyprland.dispatch("closewindow address:" + (address.startsWith("0x") ? address : "0x" + address));
|
|
else
|
|
return false;
|
|
return true;
|
|
}
|
|
Process {
|
|
id: clientsQuery
|
|
command: ["hyprctl", "-j", "clients"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
try {
|
|
const next = {};
|
|
for (const c of JSON.parse(text))
|
|
next[String(c.address).replace(/^0x/, "")] = c;
|
|
root.clients = next;
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
}
|
|
Timer {
|
|
id: clientsDebounce
|
|
interval: 150
|
|
onTriggered: {
|
|
if (clientsQuery.running)
|
|
restart();
|
|
else
|
|
clientsQuery.running = true;
|
|
}
|
|
}
|
|
// Title changes (frequent: terminals, browsers) don't affect these fields.
|
|
readonly property var clientEvents: ["openwindow", "closewindow", "movewindowv2", "changefloatingmode", "fullscreen", "togglegroup", "moveintogroup", "moveoutofgroup"]
|
|
Connections {
|
|
target: Hyprland
|
|
function onRawEvent(event) {
|
|
if (root.clientEvents.includes(event.name))
|
|
clientsDebounce.restart();
|
|
}
|
|
}
|
|
Component.onCompleted: clientsDebounce.restart()
|
|
// Native IPC, not subprocess polling. Hyprland emits no continuous resize event.
|
|
Timer {
|
|
interval: 500
|
|
repeat: true
|
|
running: root.needsGeometry
|
|
triggeredOnStart: true
|
|
onTriggered: Hyprland.refreshToplevels()
|
|
}
|
|
}
|