From b8952460a703bfb2a7e83d5cdf4f4a0d67717890 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 24 Nov 2026 11:38:50 +0000 Subject: [PATCH] web: open the dock's group stacks on hover (after the pointer rests on a tile for 500 ms; a click opens and pins at once), as a glass panel with a notch at the tile --- .agents/web.md | 19 ++- web/src/components/Dock.tsx | 242 +++++++++++++++++++++++++++---- web/src/components/DockStack.tsx | 114 ++++++++++----- web/src/style.css | 25 ++++ 4 files changed, 331 insertions(+), 69 deletions(-) diff --git a/.agents/web.md b/.agents/web.md index b1cb3b1..0a779cc 100644 --- a/.agents/web.md +++ b/.agents/web.md @@ -589,10 +589,21 @@ deploying the page needs no kernel toolchain. shown. A pinned app's tile stands for its window (`appwindows.ts` `windowApp()`: a page app's own window, a terminal app's Terminal or Wayland window, its installer), which then has no tile of its own; a - pinned group's tile opens its apps in a popover above it (DockStack.tsx, - `#dock-stack`). Tiles magnify under a mouse and show a label above them - at once (`#dock-label`: the name, the state, the key; no native - tooltip), a running dot (busy faint, error red) and an install's bar. A + pinned group's tile opens its apps in a stack above it (DockStack.tsx, + `#dock-stack`: a macOS Grid stack, the group's title over its apps on + a panel of the Dock's glass with a notch pointing at the tile, growing + out of it). A mouse resting on a group's tile (within 5 px) for 500 ms + opens its stack without moving the focus, and with one open, resting on + another group's tile for 130 ms switches to it (500 ms on the way from a + tile to its stack); it closes 300 ms after the pointer has left the tile + and the stack (`OPEN_DELAY`, `SWITCH_DELAY`, `GRACE` in Dock.tsx). A click opens + it pinned (or pins a hovered one) until a click on the tile, a press + elsewhere or Esc; a tap (touch, a pen) and Enter or Space toggle it as a + click does, the keyboard's putting the focus in it. A tile's menu or the + launcher closes it (Dock.tsx's header has the rules). Tiles magnify under + a mouse and show a label above them at once (`#dock-label`: the name, + the state, the key; no native tooltip; a group's tile shows its stack + instead), a running dot (busy faint, error red) and an install's bar. A click shows a window, or minimizes the focused one (not in compact mode); a right click, a long press or Shift-F10 opens the tile's menu (`winmenu.tsx` `windowItems()`, the same items as the top bar's app diff --git a/web/src/components/Dock.tsx b/web/src/components/Dock.tsx index a0f3bbb..952fd9c 100644 --- a/web/src/components/Dock.tsx +++ b/web/src/components/Dock.tsx @@ -8,12 +8,13 @@ // Ctrl-A o; dimmed while the system does not run: data-off, store.ts // isRunning); // - the apps and launcher groups kept in the Dock (pins.ts; by default -// Terminal, Chromium, Thunar, Desktop, Games and Settings; on phones +// Terminal, Browsers, AI, Desktop, Graphics, Games and Settings; on phones // Terminal, glmark2, Galculator, Desktop and Settings), in their order. A // group's tile (#dock-group-, GroupFace: its icon in front of a small -// fan of cards) opens its apps in a popover above it (DockStack.tsx -// #dock-stack; a second click closes it), has a running dot while one of -// its apps runs and the bar of one being installed; dimmed while the +// fan of cards) opens its apps in a stack above it (DockStack.tsx +// #dock-stack; useStackHover below: a mouse resting on the tile opens it, +// a click keeps it open, a second click closes it), has a running dot while +// one of its apps runs and the bar of one being installed; dimmed while the // system does not run (a press says why). An app's tile has its app's // icon, title and key (appwindows.ts // appMeta(): a page app's is its window's). Such a tile stands @@ -60,6 +61,8 @@ // above it at once, as on macOS (#dock-label, useDockLabel: one for the // Dock): its name, then in a quieter tone its state (why it is dimmed, an // install's progress, minimized) and its key; tiles have no native tooltip. +// A group's tile under a mouse has none (its stack, titled, is what shows), +// but while it is dimmed. // System's window has a window tile like any other (#dock-system). The // state, the data disk, memory, Errors, the Control Center and the rest of the // system's commands are in the top bar (TopBar.tsx). @@ -79,9 +82,38 @@ // Open (Show for a tab of a shared window; a group's: its stack), then Move // Left, Move Right (the order of the pins) and Remove from Dock, and keeps // them while it is dimmed. +// +// A group's stack (useStackHover, DockStack.tsx), with a mouse (pointerType +// "mouse"; touch and pens tap, as below): +// - Resting on its tile for OPEN_DELAY ms opens it, unpinned, with no button +// down, no menu open, the system running and the page focused; the focus +// stays where it is. Resting: the wait starts again each time the pointer +// has moved more than REST_SLOP px from where it started, so a pointer +// that crosses the tile, however slowly, opens nothing. With a stack open +// (not one opened from the keyboard), resting on another group's tile for +// SWITCH_DELAY ms switches to that one (unpinned, no growing in), unless +// the pointer is on its way from the open stack's tile to the stack (the +// triangle from where it left the tile to the stack's bottom corners): +// then after OPEN_DELAY ms. +// - Unpinned, it closes GRACE ms after the pointer left its tile, the stack, +// the group tiles and that triangle (or the page), unless its app menu is +// open; back in time, it stays. +// - A click on the tile opens it pinned, or pins it when a hover opened it; +// pinned, a click closes it. Pinned, it stays until a press outside, Esc, a +// pick, the page losing the focus or a resize (DockStack.tsx). Closed with +// the pointer on its tile, a hover does not open it again before the +// pointer leaves the tile. +// - A tap (touch, a pen) toggles it, pinned. Enter or Space on the focused +// tile toggles it, opened from the keyboard (its first app takes the +// focus; a hover-opened one is pinned and takes it); the focus passing over +// a tile opens nothing. +// - A tile's menu, the launcher opening, the system stopping or the group +// leaving the Dock close it. The tile stays pressed (aria-expanded) while +// its stack is open, the Dock's magnification follows the pointer over +// the Dock and holds while it is over the stack. import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, - type KeyboardEvent as RKeyboardEvent, type MouseEvent, type ReactNode, type RefObject, + type Dispatch, type KeyboardEvent as RKeyboardEvent, type MouseEvent, type PointerEvent as RPointerEvent, type ReactNode, type RefObject, type SetStateAction, } from "react"; import { isPageApp, type App, type Group } from "../apps/types.ts"; import { appMeta, appTab, appWindow, WAYLAND, windowApp, windowName } from "../appwindows.ts"; @@ -210,9 +242,10 @@ const notes = (...parts: Array): string => parts.fil * (its label, useDockLabel), `note`: its state after it in the label, both in its accessible name unless * `label` names it; `cmd`: its command (its key shows while the prefix is armed, and in the label; * `shortcut`: another key there instead); `menu`: its context menu; `install`: its app's install (a bar over - * the face); `expanded`: it opens a popover (a group's stack), shown or not. + * the face); `expanded`: it opens a popover (a group's stack), shown or not; `onHover`: the pointer entered, + * moved over or left it. */ -function Tile({ id, win, title, note, label, cmd, shortcut, on, off, keepMenu, dot, badge, install, expanded, colors, menu, onClick, children }: { +function Tile({ id, win, title, note, label, cmd, shortcut, on, off, keepMenu, dot, badge, install, expanded, colors, menu, onHover, onClick, children }: { id?: string; /** An app's own colours (as its launcher tile's): a round disc under its icon, on the Dock's glass face; none: the icon alone. */ colors?: [string, string]; @@ -223,16 +256,24 @@ function Tile({ id, win, title, note, label, cmd, shortcut, on, off, keepMenu, d off?: boolean; /** Its menu stays while it is off (a pinned app's: Remove from Dock). */ keepMenu?: boolean; - badge?: string; install?: Install; expanded?: boolean; menu?: MenuBuild; onClick: (e: MouseEvent) => void; children: ReactNode; + badge?: string; install?: Install; expanded?: boolean; menu?: MenuBuild; + onHover?: (e: RPointerEvent, how: Hover) => void; + onClick: (e: MouseEvent) => void; children: ReactNode; }) { const handlers = useTileMenu(off && !keepMenu ? undefined : menu, onClick); + const long = "onPointerLeave" in handlers ? handlers : undefined; + const hover = onHover && { + onPointerEnter: (e: RPointerEvent) => onHover(e, "enter"), + onPointerMove: (e: RPointerEvent) => { long?.onPointerMove(e); onHover(e, "move"); }, + onPointerLeave: (e: RPointerEvent) => { long?.onPointerLeave(); onHover(e, "leave"); }, + }; const hint = cmd && keyFor(cmd); // The label's text (useDockLabel reads it from the button): the name, then the note and the key. const quiet = [note, shortcut ?? (hint && `${PREFIX_SHORT} ${hint}`)].filter(Boolean).join(" ยท "); return ( ); } -export function DockStack({ group, anchor, kb, inside, onClose }: { +export function DockStack({ group, tile, top, kb, quick, inside, onClose }: { group: Group; - /** The tile's rect when it opened. */ - anchor: DOMRect; + /** Its tile: it is centred on it, and follows it. */ + tile: HTMLElement; + /** The y (viewport px) it stands above: the tile's top. */ + top: number; /** Opened from the keyboard: its first app takes the focus. */ kb: boolean; - /** Presses on these do not close it (its tile: its click toggles it). */ + /** It replaces another stack: no growing in. */ + quick?: boolean; + /** Presses on these do not close it (its tile: its click pins or toggles it). */ inside: (t: EventTarget | null) => boolean; onClose: (how: StackClose) => void; }) { @@ -99,7 +118,8 @@ export function DockStack({ group, anchor, kb, inside, onClose }: { const [menu, setMenu] = useState<{ app: App; at: DOMRect; el: HTMLElement } | null>(null); /** A press while the app menu was open (it closed the menu): its click does nothing else. */ const eat = useRef(false); - const [pos, setPos] = useState<{ left: number; width?: number } | null>(null); + // left: the panel's; width: the sheet's; notch: the notch's middle from the panel's left. + const [pos, setPos] = useState<{ left: number; width?: number; notch: number } | null>(null); const sheet = innerWidth < 640; const cols = columnsFor(apps.length, sheet); @@ -113,13 +133,25 @@ export function DockStack({ group, anchor, kb, inside, onClose }: { }; const tiles = () => [...(box.current?.querySelectorAll("[data-idx]") ?? [])]; - useLayoutEffect(() => { + /** Centred on the tile as it is drawn now (a state change only when it moved). */ + const place = useRef(() => {}); + place.current = () => { const el = box.current; - if (!el) return; - if (sheet) { setPos({ left: EDGE, width: innerWidth - 2 * EDGE }); return; } - const w = el.offsetWidth; - setPos({ left: Math.max(EDGE, Math.min(anchor.left + anchor.width / 2 - w / 2, innerWidth - EDGE - w)) }); - }, [anchor, sheet, apps.length]); + if (!el || !tile.isConnected) return; + const r = tile.getBoundingClientRect(), cx = r.left + r.width / 2; + const w = sheet ? innerWidth - 2 * EDGE : el.offsetWidth; + const left = sheet ? EDGE : Math.round(Math.max(EDGE, Math.min(cx - w / 2, innerWidth - EDGE - w))); + const notch = Math.round(Math.max(NOTCH_EDGE, Math.min(cx - left, w - NOTCH_EDGE))); + setPos((p) => (p && p.left === left && p.notch === notch && p.width === (sheet ? w : undefined) ? p : { left, width: sheet ? w : undefined, notch })); + }; + useLayoutEffect(() => place.current(), [tile, sheet, apps.length]); + useEffect(() => { + let frame = 0, n = 0; + const step = () => { place.current(); frame = ++n < FOLLOW ? requestAnimationFrame(step) : 0; }; + const move = () => { n = 0; if (!frame) frame = requestAnimationFrame(step); }; + document.addEventListener("pointermove", move, { passive: true }); + return () => { cancelAnimationFrame(frame); document.removeEventListener("pointermove", move); }; + }, []); useOutsidePress((t) => !!box.current?.contains(t as Node) || !!(t as Element | null)?.closest?.(`#${MENU_ID}`) || inside(t), () => close.current("away")); useEffect(() => { if (kb) tiles()[0]?.focus({ preventScroll: true }); }, [kb]); useEffect(() => { @@ -199,6 +231,8 @@ export function DockStack({ group, anchor, kb, inside, onClose }: { }; const grid: CSSProperties = { gridTemplateColumns: sheet ? `repeat(${cols}, minmax(0, 1fr))` : `repeat(${cols}, ${CELL}px)` }; + // The notch's middle (both parts grow from its tip: --notch). + const notch = { "--notch": `${pos?.notch ?? 0}px` } as CSSProperties; return ( <> {createPortal( @@ -206,15 +240,21 @@ export function DockStack({ group, anchor, kb, inside, onClose }: { // The focus stays where it is (the terminal), as on the Dock's tiles. onMouseDown={(e) => e.preventDefault()} onClickCapture={(e) => { if (eat.current) { eat.current = false; e.stopPropagation(); e.preventDefault(); } }} - className="popover fixed z-(--z-menu) flex flex-col overflow-y-auto overscroll-contain rounded-2xl p-1.5 select-none" - style={{ left: pos?.left ?? -9999, width: pos?.width, bottom: innerHeight - anchor.top + GAP, maxHeight: Math.max(120, anchor.top - GAP - EDGE) }}> - -
- {apps.map((a, i) => ( - pick(a)} onMenu={(at, el) => openMenu(a, at, el)} onFocus={() => setSel(i)} /> - ))} + data-quick={quick || undefined} + className="dock-stack fixed z-(--z-menu) flex flex-col select-none" + style={{ ...notch, left: pos?.left ?? -9999, width: pos?.width, bottom: innerHeight - top + GAP + NOTCH }}> +
+ +
+ {apps.map((a, i) => ( + pick(a)} onMenu={(at, el) => openMenu(a, at, el)} onFocus={() => setSel(i)} /> + ))} +
+
, document.body, )} diff --git a/web/src/style.css b/web/src/style.css index 5dc799f..1935f4a 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -624,6 +624,31 @@ #dock-label > span:empty { display: none; } #app.compact #dock-label { display: none; } @media (prefers-reduced-motion: reduce) { #dock-label[data-show] { transition: none; } } +/* A group's stack (DockStack.tsx #dock-stack, in ), as a macOS Dock + stack: a rounded panel of the Dock's glass (its edge, sheen, blur and + shadows) under the HUD's darker tint, so the names read over a busy + terminal, and a notch under it pointing at the tile (--notch: its middle + from the panel's left), the same tint and blur of its own, its slanted + edges drawn by its svg. Both grow out of the notch's tip with a short + spring (scale and fade); not when it replaces another stack (data-quick), + nor with reduced motion (the last rule of this file). */ +.dock-stack-panel { + border: 1px solid; border-color: var(--glass-border); border-radius: 18px; + background: var(--glass-sheen), var(--hud-bg); + -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); + box-shadow: var(--glass-shadow); + transform-origin: var(--notch) calc(100% + 8px); +} +.dock-stack-notch { + position: absolute; top: calc(100% - 1px); left: calc(var(--notch) - 9px); width: 18px; + clip-path: polygon(0 0, 100% 0, 50% 100%); + background: var(--hud-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); + transform-origin: 50% 100%; +} +.dock-stack-notch > svg { display: block; width: 100%; height: 100%; fill: none; stroke: rgb(255 255 255 / 11%); stroke-width: 2; } +.dock-stack-panel, .dock-stack-notch { animation: dock-stack-in .26s cubic-bezier(.3, 1.3, .55, 1) both; } +.dock-stack[data-quick] > * { animation: none; } +@keyframes dock-stack-in { from { opacity: 0; transform: scale(.35); } 45% { opacity: 1; } } /* An app being installed (installer.ts): a thin bar over the bottom of its tile's face, the Dock's (Dock.tsx) and the launcher's (Launcher.tsx), as macOS draws a download on its Dock icon; white, red once failed, a