Fix stray dock items and orphaned Cava
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>
This commit is contained in:
1 parent
508b18c7de
commit
9aa61559eb
5 files changed
+75
-4
No files matched your search
@@ -81,7 +81,9 @@ Singleton {
|
|||||||
pinned: i.pinned,
|
pinned: i.pinned,
|
||||||
running: i.windows.length,
|
running: i.windows.length,
|
||||||
focused: i.focused,
|
focused: i.focused,
|
||||||
matched: !!i.entry
|
matched: !!i.entry,
|
||||||
|
// Diagnoses unmatched items: what each window reported.
|
||||||
|
classes: i.windows.map(w => w.appId + (w.initialClass && w.initialClass !== w.appId ? " (" + w.initialClass + ")" : ""))
|
||||||
})),
|
})),
|
||||||
opened: root.opened,
|
opened: root.opened,
|
||||||
chooser: root.chooser,
|
chooser: root.chooser,
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Exec the optional visualizer; report an absent executable without a QML warning."""
|
"""Exec the optional visualizer; report an absent executable without a QML warning."""
|
||||||
|
import ctypes
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# Cava writes nothing during silence, so it never hits a broken pipe: without a
|
||||||
|
# parent-death signal it outlived a killed or crashed shell, capturing audio.
|
||||||
|
# The setting survives exec.
|
||||||
|
try:
|
||||||
|
ctypes.CDLL(None, use_errno=True).prctl(1, signal.SIGTERM) # PR_SET_PDEATHSIG
|
||||||
|
except (OSError, AttributeError):
|
||||||
|
pass
|
||||||
|
if os.getppid() == 1:
|
||||||
|
sys.exit(0) # The shell already exited before the signal was armed.
|
||||||
try:
|
try:
|
||||||
os.execvp('cava', ['cava', '-p', sys.argv[1]])
|
os.execvp('cava', ['cava', '-p', sys.argv[1]])
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
function canonical(id) { return String(id || "").replace(/\.desktop$/i, ""); }
|
function canonical(id) { return String(id || "").replace(/\.desktop$/i, ""); }
|
||||||
function normalized(id) { return canonical(id).toLowerCase(); }
|
function normalized(id) { return canonical(id).toLowerCase(); }
|
||||||
|
// Same name in another spelling: "YouTube Music Desktop App" (StartupWMClass)
|
||||||
|
// and "youtube-music-desktop-app" (window class). Case and space/dash/underscore
|
||||||
|
// runs only; never substrings.
|
||||||
|
function spelled(id) { return normalized(id).replace(/[\s_-]+/g, "-"); }
|
||||||
// Lookup tables for one catalog array. Hyprland emits events (title changes)
|
// Lookup tables for one catalog array. Hyprland emits events (title changes)
|
||||||
// several times a second; scanning every entry per window per event dominated
|
// several times a second; scanning every entry per window per event dominated
|
||||||
// idle JavaScript time. The catalog array is replaced, not mutated, on change.
|
// idle JavaScript time. The catalog array is replaced, not mutated, on change.
|
||||||
@@ -7,11 +11,13 @@ let indexedEntries = null, index = null;
|
|||||||
function lookup(entries) {
|
function lookup(entries) {
|
||||||
if (entries === indexedEntries) return index;
|
if (entries === indexedEntries) return index;
|
||||||
const add = (map, key, entry) => { if (!map.has(key)) map.set(key, []); map.get(key).push(entry); };
|
const add = (map, key, entry) => { if (!map.has(key)) map.set(key, []); map.get(key).push(entry); };
|
||||||
index = {canonical: new Map(), normalized: new Map(), startup: new Map()};
|
index = {canonical: new Map(), normalized: new Map(), startup: new Map(), spelled: new Map()};
|
||||||
for (const e of entries) {
|
for (const e of entries) {
|
||||||
if (!index.canonical.has(canonical(e.id))) index.canonical.set(canonical(e.id), e);
|
if (!index.canonical.has(canonical(e.id))) index.canonical.set(canonical(e.id), e);
|
||||||
add(index.normalized, normalized(e.id), e);
|
add(index.normalized, normalized(e.id), e);
|
||||||
if (e.startupClass) add(index.startup, e.startupClass.toLowerCase(), e);
|
if (e.startupClass) add(index.startup, e.startupClass.toLowerCase(), e);
|
||||||
|
const names = new Set([spelled(e.id)].concat(e.startupClass ? [spelled(e.startupClass)] : []));
|
||||||
|
for (const name of names) add(index.spelled, name, e);
|
||||||
}
|
}
|
||||||
indexedEntries = entries;
|
indexedEntries = entries;
|
||||||
return index;
|
return index;
|
||||||
@@ -29,6 +35,10 @@ function match(appId, initialClass, entries, overrides) {
|
|||||||
const startup = table.startup.get(key.toLowerCase()) || [];
|
const startup = table.startup.get(key.toLowerCase()) || [];
|
||||||
if (startup.length === 1) return startup[0];
|
if (startup.length === 1) return startup[0];
|
||||||
}
|
}
|
||||||
|
for (const key of candidates) {
|
||||||
|
const respelled = table.spelled.get(spelled(key)) || [];
|
||||||
|
if (respelled.length === 1) return respelled[0];
|
||||||
|
}
|
||||||
return null; // Never guess from titles, substrings, or an ambiguous class.
|
return null; // Never guess from titles, substrings, or an ambiguous class.
|
||||||
}
|
}
|
||||||
function group(entries, windows, pinned, overrides, showRunning) {
|
function group(entries, windows, pinned, overrides, showRunning) {
|
||||||
|
|||||||
@@ -2,12 +2,18 @@ pragma Singleton
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
import Quickshell.Io
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
readonly property var visibleWorkspaces: Hyprland.workspaces.values.filter(w => w.active).map(w => w.id)
|
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 => {
|
readonly property var windows: Hyprland.toplevels.values.map(t => {
|
||||||
const info = t.lastIpcObject || {};
|
const info = root.clients[String(t.address).replace(/^0x/, "")] || t.lastIpcObject || {};
|
||||||
return {
|
return {
|
||||||
address: t.address,
|
address: t.address,
|
||||||
handle: t.wayland,
|
handle: t.wayland,
|
||||||
@@ -21,7 +27,8 @@ Singleton {
|
|||||||
y: info.at ? info.at[1] : 0,
|
y: info.at ? info.at[1] : 0,
|
||||||
width: info.size ? info.size[0] : 0,
|
width: info.size ? info.size[0] : 0,
|
||||||
height: info.size ? info.size[1] : 0,
|
height: info.size ? info.size[1] : 0,
|
||||||
hidden: info.hidden === true || info.mapped === false,
|
// 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,
|
fullscreen: info.fullscreen === 2,
|
||||||
floating: info.floating === true
|
floating: info.floating === true
|
||||||
};
|
};
|
||||||
@@ -54,6 +61,40 @@ Singleton {
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
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.
|
// Native IPC, not subprocess polling. Hyprland emits no continuous resize event.
|
||||||
Timer {
|
Timer {
|
||||||
interval: 500
|
interval: 500
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ assert.equal(app.match('EDITOR','',entries,{}),entries[0]);
|
|||||||
assert.equal(app.match('web','',entries,{}),null); // ambiguous StartupWMClass is not guessed
|
assert.equal(app.match('web','',entries,{}),null); // ambiguous StartupWMClass is not guessed
|
||||||
assert.equal(app.match('browser-helper','',entries,{}),null);
|
assert.equal(app.match('browser-helper','',entries,{}),null);
|
||||||
assert.equal(app.match('web','',entries,{web:'browser.desktop'}),entries[1]);
|
assert.equal(app.match('web','',entries,{web:'browser.desktop'}),entries[1]);
|
||||||
|
// The same name spelled differently matches; substrings and ambiguous spellings do not.
|
||||||
|
const ytm=[{id:'ytmdesktop',name:'YouTube Music Desktop App',startupClass:'YouTube Music Desktop App'},{id:'player_one',name:'One'},{id:'player-one',name:'One Dash'}];
|
||||||
|
assert.equal(app.match('youtube-music-desktop-app','',ytm,{}),ytm[0]);
|
||||||
|
assert.equal(app.match('youtube_music_desktop_app','',ytm,{}),ytm[0]);
|
||||||
|
assert.equal(app.match('youtube-music','',ytm,{}),null);
|
||||||
|
assert.equal(app.match('Player One','',ytm,{}),null);
|
||||||
const windows=[{address:'1',appId:'editor',active:false},{address:'2',appId:'editor',active:true},{address:'3',appId:'unknown',active:false}];
|
const windows=[{address:'1',appId:'editor',active:false},{address:'2',appId:'editor',active:true},{address:'3',appId:'unknown',active:false}];
|
||||||
const groups=app.group(entries,windows,['missing.desktop','org.example.Editor.desktop'],{},true);
|
const groups=app.group(entries,windows,['missing.desktop','org.example.Editor.desktop'],{},true);
|
||||||
assert.equal(groups.length,3);assert.equal(groups[0].entry,null);assert.equal(groups[1].windows.length,2);assert.equal(groups[1].focused,true);assert.equal(groups[2].pinned,false);
|
assert.equal(groups.length,3);assert.equal(groups[0].entry,null);assert.equal(groups[1].windows.length,2);assert.equal(groups[1].focused,true);assert.equal(groups[2].pinned,false);
|
||||||
|
|||||||
Reference in new issue
Block a user