aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/windows.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/modules/windows.js')
-rw-r--r--static/modules/windows.js78
1 files changed, 69 insertions, 9 deletions
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 = `<div class="windows">
<section class="deck-block"><h3>Workspaces</h3><div class="ws"></div></section>
<section class="deck-block"><h3>Applications</h3><div class="launches"></div></section>
- <section class="deck-block"><h3>Windows</h3><div class="wgrid"></div></section>
+ <section class="deck-block"><div class="whead"><h3>Windows</h3><div class="wfilter"></div></div>
+ <div class="wrows"></div></section>
</div>`;
+ 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);
},
};