diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 16:34:04 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 16:34:04 +0100 |
| commit | 5a8da8ab392266d5f3bbf3abed61472d6734f31c (patch) | |
| tree | f5c95722e93515d9bcb527345fe8994333ead568 /static | |
| parent | 25c0248a3285c30b12df9d228a13e435786b66f7 (diff) | |
| download | deck-it-5a8da8ab392266d5f3bbf3abed61472d6734f31c.tar.gz deck-it-5a8da8ab392266d5f3bbf3abed61472d6734f31c.zip | |
feat(windows): preview cards and keystone's workspace icons
Each window is a card like the Alt+Tab switcher's: a preview in the
window's shape (grim -T on Hyprland's stableId, also for hidden
workspaces, refreshed every 5 s), the desktop top left, close top right,
the app icon bottom left, each on its own scrim, the title below. Tap
focuses, a long press opens the move menu at the press point (the grid
re-renders under a title that changes every second, so the card itself
may already be gone), and Chrome's image menu is suppressed.
Module.image serves module images at /api/<module>/image/<key>; windows
answers only for a window the last state listed. Workspace tiles, card
markers and the move menu use the icons from keystone's Workspaces.qml,
falling back to the number; the icon route also searches the theme's
places, preferences and categories folders, where two of them live.
The workspaces are centred.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static')
| -rw-r--r-- | static/deck.css | 36 | ||||
| -rw-r--r-- | static/modules/windows.js | 115 |
2 files changed, 104 insertions, 47 deletions
diff --git a/static/deck.css b/static/deck.css index 03b9d43..98a2c2a 100644 --- a/static/deck.css +++ b/static/deck.css @@ -305,20 +305,24 @@ select { .wtile.on { background: var(--udt-accent); color: var(--udt-crust); border-color: var(--udt-accent); } .wtile.launch { min-width: 64px; min-height: 64px; padding: 0 12px; } .laticon { display: block; width: 32px; height: 32px; object-fit: contain; } -.windows .winlist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; } -.wrow { - display: flex; - align-items: center; - gap: 8px; - min-height: 44px; - padding: 0 6px 0 10px; - border-radius: 10px; - background: var(--udt-surface1); -} -.wrow.on { color: var(--udt-accent); } -.wt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; } -.wicon { width: 24px; height: 24px; object-fit: contain; flex: none; } -.wmenu { flex: none; width: 40px; height: 40px; padding: 0; font-size: 1.286rem; line-height: 1; } +.windows .ws { justify-content: center; } +.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 14px; } +.wcard { display: flex; flex-direction: column; gap: 6px; padding: 0; font: inherit; background: none; border: 0; color: inherit; cursor: pointer; min-width: 0; } +.wbox { + position: relative; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; + background: var(--udt-surface0); border: 1px solid var(--udt-surface1); + display: flex; align-items: center; justify-content: center; +} +.wcard.cur .wbox { border-color: var(--udt-accent); box-shadow: 0 0 14px color-mix(in srgb, var(--udt-accent) 45%, transparent); } +.wshot { pointer-events: none; -webkit-touch-callout: none; user-select: none; max-width: calc(100% - 8px); max-height: calc(100% - 8px); object-fit: contain; border-radius: 4px; } +/* Each overlay carries its own scrim: it sits on an arbitrary preview. */ +.wws, .wx, .wbox .wicon { position: absolute; background: color-mix(in srgb, var(--udt-base) 75%, transparent); } +.wws { left: 8px; top: 8px; min-width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; color: var(--udt-accent); font-size: 0.929rem; } +.wx { right: 8px; top: 8px; width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; font-size: 1.6rem; line-height: 1; color: var(--udt-text); } +.wx:active { background: var(--udt-red); } +.wbox .wicon { left: 8px; bottom: 8px; width: 40px; height: 40px; padding: 5px; border-radius: 10px; box-sizing: border-box; } +.wtitle { font-size: 0.929rem; color: var(--udt-subtext0); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.wcard.cur .wtitle { color: var(--udt-text); } .windows .launches { display: flex; flex-wrap: wrap; gap: 8px; } .wpop { @@ -337,7 +341,6 @@ select { } .wpop-title { font-weight: 600; font-size: 0.929rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .wpop-label { font-size: 0.786rem; text-transform: uppercase; letter-spacing: .08em; color: var(--udt-overlay0); } -.wpop-close { text-align: left; } .wpop-ws { display: flex; flex-wrap: wrap; gap: 6px; } .wpop-ws button { min-width: 44px; min-height: 44px; padding: 0; font-size: 1.143rem; font-weight: 600; } @@ -713,3 +716,6 @@ select { margin: 0 0 6px; font: 200 3rem/1.1 system-ui, sans-serif; letter-spacing: -.02em; color: var(--udt-text); } .assistant .as-hello p { margin: 0; font: 300 1.15rem/1.4 system-ui, sans-serif; color: var(--udt-overlay0); } +.windows .ws .wtile img { width: 32px; height: 32px; object-fit: contain; } +.wws img { width: 22px; height: 22px; object-fit: contain; } +.wpop-ws button img { width: 24px; height: 24px; object-fit: contain; } diff --git a/static/modules/windows.js b/static/modules/windows.js index 7404f03..27e966e 100644 --- a/static/modules/windows.js +++ b/static/modules/windows.js @@ -42,24 +42,20 @@ function closePop() { } } -function openMenu(anchor, win, workspaces) { +function openMenu(anchor, win, workspaces, wsIcons) { closePop(); pop = document.createElement("div"); pop.className = "wpop"; pop.innerHTML = ` <div class="wpop-title"></div> - <button class="wpop-close">Close window</button> <div class="wpop-label">Move to desktop</div> <div class="wpop-ws"></div>`; pop.querySelector(".wpop-title").textContent = win.title || win.class; - pop.querySelector(".wpop-close").onclick = () => { - closePop(); - post("close", { address: win.address }); - }; const targets = pop.querySelector(".wpop-ws"); - for (const n of workspaces ?? []) { + for (const n of (workspaces ?? []).filter((n) => n !== win.workspace)) { const b = document.createElement("button"); - b.textContent = String(n); + wsMark(b, n, wsIcons); + b.setAttribute("aria-label", `Desktop ${n}`); b.onclick = () => { closePop(); post("move", { address: win.address, n }); @@ -67,7 +63,9 @@ function openMenu(anchor, win, workspaces) { targets.append(b); } document.body.append(pop); - const r = anchor.getBoundingClientRect(); + // The press point: the card itself may already be rebuilt (a title that + // changes every second re-renders the grid), and a detached one measures 0. + const r = anchor.getBoundingClientRect ? anchor.getBoundingClientRect() : anchor; const width = pop.offsetWidth; const height = pop.offsetHeight; pop.style.top = `${Math.min(r.bottom + 6, window.innerHeight - height - 8)}px`; @@ -75,9 +73,67 @@ function openMenu(anchor, win, workspaces) { } document.addEventListener("pointerdown", (e) => { - if (pop && !pop.contains(e.target) && !e.target.closest(".wmenu")) closePop(); + if (pop && !pop.contains(e.target)) closePop(); }); +// A workspace's icon from keystone's map, the number when it has none or the +// icon theme lacks it. +function wsMark(box, n, icons) { + box.textContent = String(n); + const name = icons?.[String(n)]; + if (!name) return; + const img = document.createElement("img"); + img.alt = String(n); + img.onload = () => { box.textContent = ""; box.append(img); }; + img.src = `/icons/${name}.svg`; +} + +// Previews are re-captured on the PC every PREVIEW ms; the URL carries the +// period, so within one the browser's cache answers and nothing flickers. +const PREVIEW = 5000; +const previewUrl = (w) => `/api/windows/image/${w.id}?t=${Math.floor(Date.now() / PREVIEW)}`; + +// As the Alt+Tab switcher's card (quickshell window-switcher/WindowCard.qml): +// the preview in its window's shape, the desktop top left, close top right, +// the app's icon bottom left, each on its own scrim; the title below. Tap +// focuses, a long press offers the other desktops. +function card(w, workspaces, wsIcons) { + const c = document.createElement("button"); + c.className = `wcard${w.active ? " cur" : ""}`; + c.setAttribute("aria-label", w.title || w.class); + c.innerHTML = `<div class="wbox"><img class="wshot" alt=""><span class="wws"></span> + <span class="wx" role="button" aria-label="Close window">×</span></div><div class="wtitle"></div>`; + const shot = c.querySelector(".wshot"); + shot.src = previewUrl(w); + shot.onerror = () => { shot.hidden = true; }; + wsMark(c.querySelector(".wws"), w.workspace, wsIcons); + c.querySelector(".wtitle").textContent = w.title || w.class; + const icon = appIcon(w); + if (icon) c.querySelector(".wbox").append(icon); + c.querySelector(".wx").addEventListener("click", (e) => { + e.stopPropagation(); + post("close", { address: w.address }); + }); + let timer = null; + let long = false; + c.addEventListener("pointerdown", (e) => { + if (e.target.closest(".wx")) return; + long = false; + const at = { left: e.clientX, bottom: e.clientY }; + timer = setTimeout(() => { long = true; openMenu(at, w, workspaces, wsIcons); }, 600); + }); + // Chrome's own long-press menu (copy or share the image) is not wanted here. + c.addEventListener("contextmenu", (e) => e.preventDefault()); + for (const ev of ["pointerup", "pointercancel", "pointerleave"]) { + c.addEventListener(ev, () => clearTimeout(timer)); + } + c.onclick = () => { + if (long) return; + post("focus", { address: w.address }); + }; + return c; +} + function appIcon(w) { if (!w.icons?.length) return null; const img = document.createElement("img"); @@ -105,7 +161,7 @@ export default { el.innerHTML = `<div class="windows"> <section class="deck-block"><h3>Workspaces</h3><div class="ws"></div></section> <section class="deck-block"><h3>Launches</h3><div class="launches"></div></section> - <section class="deck-block"><h3>Windows</h3><div class="winlist"></div></section> + <section class="deck-block"><h3>Windows</h3><div class="wgrid"></div></section> </div>`; }, @@ -113,12 +169,20 @@ export default { // Polled every second: rebuilding unchanged rows reloads every icon // through its fallbacks, which flickers, so only a change re-renders. const key = JSON.stringify(st); - if (key === el._last) return; + if (key === el._last) { + 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; } + } + return; + } el._last = key; const ws = el.querySelector(".ws"); ws.textContent = ""; for (const id of st.workspaces ?? []) { - const b = tile(String(id), () => post("workspace", { n: id })); + const b = tile("", () => post("workspace", { n: id })); + b.setAttribute("aria-label", `Desktop ${id}`); + wsMark(b, id, st.wsIcons); b.classList.toggle("on", (st.windows ?? []).some((w) => w.workspace === id)); ws.append(b); } @@ -145,25 +209,12 @@ export default { launches.append(b); } - const list = el.querySelector(".winlist"); - list.textContent = ""; - for (const w of (st.windows ?? []).slice(0, 12)) { - const row = document.createElement("div"); - row.className = "wrow"; - row.classList.toggle("on", Boolean(w.active)); - const icon = appIcon(w); - if (icon) row.append(icon); - const title = document.createElement("span"); - title.className = "wt"; - title.textContent = w.title || w.class; - title.onclick = () => post("focus", { address: w.address }); - const menu = document.createElement("button"); - menu.className = "wmenu"; - menu.textContent = "⋮"; - menu.setAttribute("aria-label", "Window actions"); - menu.onclick = () => openMenu(menu, w, st.workspaces); - row.append(title, menu); - list.append(row); + 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); } }, }; |
