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>
71 lines
3.6 KiB
JavaScript
71 lines
3.6 KiB
JavaScript
function canonical(id) { return String(id || "").replace(/\.desktop$/i, ""); }
|
|
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)
|
|
// several times a second; scanning every entry per window per event dominated
|
|
// idle JavaScript time. The catalog array is replaced, not mutated, on change.
|
|
let indexedEntries = null, index = null;
|
|
function lookup(entries) {
|
|
if (entries === indexedEntries) return index;
|
|
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(), spelled: new Map()};
|
|
for (const e of entries) {
|
|
if (!index.canonical.has(canonical(e.id))) index.canonical.set(canonical(e.id), e);
|
|
add(index.normalized, normalized(e.id), 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;
|
|
return index;
|
|
}
|
|
function match(appId, initialClass, entries, overrides) {
|
|
const candidates = [appId, initialClass].filter(Boolean);
|
|
const table = lookup(entries);
|
|
for (const key of candidates) {
|
|
const override = overrides[key];
|
|
if (override) return table.canonical.get(canonical(override)) || null;
|
|
}
|
|
for (const key of candidates) {
|
|
const exact = table.normalized.get(normalized(key)) || [];
|
|
if (exact.length === 1) return exact[0];
|
|
const startup = table.startup.get(key.toLowerCase()) || [];
|
|
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.
|
|
}
|
|
function group(entries, windows, pinned, overrides, showRunning) {
|
|
const result = [], byId = new Map();
|
|
function add(id, entry, isPinned, label) {
|
|
const row = {id:id, entry:entry, pinned:isPinned, name:entry ? entry.name : label || id, windows:[], focused:false};
|
|
byId.set(id, row); result.push(row); return row;
|
|
}
|
|
for (const id of pinned) {
|
|
const key = canonical(id);
|
|
if (!byId.has(key)) add(key, lookup(entries).canonical.get(key) || null, true);
|
|
}
|
|
for (const window of windows) {
|
|
const entry = match(window.appId, window.initialClass, entries, overrides);
|
|
const id = entry ? canonical(entry.id) : "window:" + (window.appId || window.initialClass || window.address);
|
|
let row = byId.get(id);
|
|
if (!row && showRunning) row = add(id, entry, false, window.appId || window.title);
|
|
if (row) { row.windows.push(window); row.focused = row.focused || window.active; }
|
|
}
|
|
return result;
|
|
}
|
|
function reorder(pinned, source, target) {
|
|
const result = pinned.slice();
|
|
const from = result.findIndex(id => canonical(id) === canonical(source));
|
|
const to = result.findIndex(id => canonical(id) === canonical(target));
|
|
if (from < 0 || to < 0 || from === to) return result;
|
|
result.splice(to, 0, result.splice(from, 1)[0]);
|
|
return result;
|
|
}
|