From 6496d0660abf781ff2a76f97f9a5c03034d6cf45 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 26 Nov 2026 10:42:40 +0100 Subject: feat(windows): horizontal strips grouped by workspace or app The window grid becomes horizontal strips with All, Workspace and App filters. Grouped views get one strip per workspace or app class, headed by its icon; the choice is kept in localStorage. A strip is not rebuilt while touched or within a second of scrolling, and keeps its scroll. Co-Authored-By: Claude Opus 5.5 --- static/modules/windows.js | 78 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) (limited to 'static/modules') diff --git a/static/modules/windows.js b/static/modules/windows.js index fdd9ec8..ada6e61 100644 --- a/static/modules/windows.js +++ b/static/modules/windows.js @@ -136,7 +136,8 @@ function card(w, workspaces, wsIcons) { return c; } -function appIcon(w) { +// gone() runs when no icon name resolves. +function appIcon(w, gone) { if (!w.icons?.length) return null; const img = document.createElement("img"); img.className = "wicon"; @@ -145,6 +146,7 @@ function appIcon(w) { const next = () => { if (i >= w.icons.length) { img.remove(); + gone?.(); return; } img.src = `/icons/${w.icons[i++]}.svg`; @@ -154,6 +156,52 @@ function appIcon(w) { return img; } +// The window list is one horizontal strip, or one per workspace or app. +const GROUPS = { all: () => "", ws: (w) => w.workspace, app: (w) => w.class }; +const MODE_KEY = "deckit.windows.group"; +const saved = globalThis.localStorage?.getItem(MODE_KEY); +let mode = GROUPS[saved] ? saved : "all"; + +function rows(el) { + // A rebuild under a swiping finger kills the swipe: wait until the strips + // have been still for a second, the next poll catches up. + el._stale = el._touch || Date.now() - (el._held ?? 0) < 1000; + if (el._stale) return; + const st = el._st; + for (const b of el.querySelectorAll(".wfilter .wtile")) b.classList.toggle("on", b.dataset.k === mode); + const box = el.querySelector(".wrows"); + const scrolled = {}; + for (const r of box.children) scrolled[r.dataset.k] = r.querySelector(".wstrip").scrollLeft; + box.textContent = ""; + for (const [k, wins] of Map.groupBy(st.windows ?? [], GROUPS[mode])) { + const row = document.createElement("div"); + row.className = "wrow"; + row.dataset.k = k; + if (mode !== "all") { + const head = document.createElement("div"); + head.className = "wlabel"; + head.title = String(k); + if (mode === "ws") wsMark(head, k, st.wsIcons); + else { + const icon = appIcon(wins[0], () => { head.textContent = k; }); + if (icon) head.append(icon); + else head.textContent = k; + } + row.append(head); + } + const strip = document.createElement("div"); + strip.className = "wstrip"; + for (const w of wins) { + const c = card(w, st.workspaces, st.wsIcons); + c.dataset.id = w.id; + strip.append(c); + } + row.append(strip); + box.append(row); + strip.scrollLeft = scrolled[k] ?? 0; + } +} + export default { title: "Windows", tab: "Windows", @@ -163,8 +211,24 @@ export default { el.innerHTML = `

Workspaces

Applications

-

Windows

+

Windows

+
`; + const filter = el.querySelector(".wfilter"); + for (const [k, label] of [["all", "All"], ["ws", "Workspace"], ["app", "App"]]) { + const b = tile(label, () => { + mode = k; + localStorage.setItem(MODE_KEY, k); + if (el._st) rows(el); + }); + b.dataset.k = k; + filter.append(b); + } + const box = el.querySelector(".wrows"); + const held = () => { el._held = Date.now(); }; + box.addEventListener("touchstart", () => { el._touch = true; held(); }, { passive: true }); + for (const ev of ["touchend", "touchcancel"]) box.addEventListener(ev, () => { el._touch = false; held(); }); + box.addEventListener("scroll", held, true); }, // A window that was not there on the last poll brings the tab forward for @@ -180,8 +244,10 @@ export default { update(st, el) { // Polled every second: rebuilding unchanged rows reloads every icon // through its fallbacks, which flickers, so only a change re-renders. + el._st = st; const key = JSON.stringify(st); if (key === el._last) { + if (el._stale) rows(el); for (const img of el.querySelectorAll(".wshot")) { const url = previewUrl({ id: img.closest(".wcard").dataset.id }); if (!img.src.endsWith(url)) { img.hidden = false; img.src = url; } @@ -221,12 +287,6 @@ export default { launches.append(b); } - const grid = el.querySelector(".wgrid"); - grid.textContent = ""; - for (const w of st.windows ?? []) { - const c = card(w, st.workspaces, st.wsIcons); - c.dataset.id = w.id; - grid.append(c); - } + rows(el); }, }; -- cgit v1.2.3