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

This commit is contained in:
Pooya Parsa
2026-11-24 11:38:50 +00:00
parent 4f932073de
commit b8952460a7
4 changed files with 331 additions and 69 deletions

View File

@@ -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

View File

@@ -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-<id>, 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 | false | undefined>): 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<HTMLButtonElement>) => void; children: ReactNode;
badge?: string; install?: Install; expanded?: boolean; menu?: MenuBuild;
onHover?: (e: RPointerEvent<HTMLButtonElement>, how: Hover) => void;
onClick: (e: MouseEvent<HTMLButtonElement>) => void; children: ReactNode;
}) {
const handlers = useTileMenu(off && !keepMenu ? undefined : menu, onClick);
const long = "onPointerLeave" in handlers ? handlers : undefined;
const hover = onHover && {
onPointerEnter: (e: RPointerEvent<HTMLButtonElement>) => onHover(e, "enter"),
onPointerMove: (e: RPointerEvent<HTMLButtonElement>) => { long?.onPointerMove(e); onHover(e, "move"); },
onPointerLeave: (e: RPointerEvent<HTMLButtonElement>) => { 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 (
<button id={id} type="button" aria-label={label ?? notes(title, note)} data-label={title} data-label-note={quiet || undefined} aria-pressed={on}
aria-haspopup={expanded === undefined ? undefined : "dialog"} aria-expanded={expanded}
aria-disabled={off || undefined} data-off={off || undefined} data-win={win} className="dock-tile group relative flex-none" {...handlers}>
aria-disabled={off || undefined} data-off={off || undefined} data-win={win} className="dock-tile group relative flex-none" {...handlers} {...hover}>
<span className="dock-face">
{colors ? <span className="dock-disc" style={{ backgroundImage: `linear-gradient(135deg, ${colors[0]}, ${colors[1]})` }}>{children}</span> : children}
</span>
@@ -347,14 +388,19 @@ const magnifies = () => !!FINE?.matches && !reducedMotion();
* not change). Not on touch, with reduced motion, or while the window tiles
* scroll (the strip clips then: tiles magnified when they start to go back
* at once, held or not); not over an open menu. `held` (a tile's
* menu is open): it stays as it is, so the tile does not shrink away under
* its menu, and lets go once the menu closes with the pointer elsewhere.
* menu or a pinned stack is open): it stays as it is, so the tile does not
* shrink away under its menu, and lets go once the menu closes with the
* pointer elsewhere. `keep` (a stack the mouse opened): it follows the
* pointer over the Dock but stays as it is when the pointer leaves the Dock
* (for the stack above its tile), and lets go likewise.
*/
function useMagnify(dock: RefObject<HTMLElement | null>, strip: RefObject<HTMLElement | null>, held: boolean): void {
function useMagnify(dock: RefObject<HTMLElement | null>, strip: RefObject<HTMLElement | null>, held: boolean, keep: boolean): void {
const hold = useRef(held);
hold.current = held;
const stay = useRef(keep);
stay.current = keep;
const release = useRef<() => void>(() => {});
useEffect(() => { if (!held) release.current(); }, [held]);
useEffect(() => { if (!held && !keep) release.current(); }, [held, keep]);
useEffect(() => {
const nav = dock.current;
if (!nav) return;
@@ -401,7 +447,7 @@ function useMagnify(dock: RefObject<HTMLElement | null>, strip: RefObject<HTMLEl
x = e.clientX - nav.getBoundingClientRect().left - nav.clientLeft;
if (!frame) frame = requestAnimationFrame(apply);
};
const leave = () => { inside = false; if (!hold.current) clear(); };
const leave = () => { inside = false; if (!hold.current && !stay.current) clear(); };
release.current = () => { if (!inside) clear(); };
// The tiles start to scroll (useScrollFlag): the strip would clip a magnified tile, held or not.
const scrolls = new MutationObserver(() => { if (strip.current?.hasAttribute("data-scroll")) clear(); });
@@ -456,7 +502,8 @@ const LABEL_STILL = 8;
* goes when the pointer leaves the Dock, on a press or Enter (until another
* tile), when the tiles scroll, and while `off` (a tile's menu or a group's
* stack is open, the prefix is armed, compact mode); never for touch or a
* pen, so a tap leaves none.
* pen, so a tap leaves none, nor for a group's tile under the mouse (its
* stack shows instead) unless it is dimmed.
*/
function useDockLabel(dock: RefObject<HTMLElement | null>, nav: RefObject<HTMLElement | null>, strip: RefObject<HTMLElement | null>, label: RefObject<HTMLElement | null>, off: boolean): void {
const off$ = useRef(off);
@@ -515,7 +562,13 @@ function useDockLabel(dock: RefObject<HTMLElement | null>, nav: RefObject<HTMLEl
const move = (e: PointerEvent) => {
if (e.pointerType !== "mouse" || e.buttons) return;
const t = tileOf(e.target);
if (t && t !== pressed) { pressed = null; tile = t; focus = false; }
if (t && t !== pressed) {
pressed = null;
focus = false;
// A group's tile opens its stack under the mouse instead (but dimmed).
if (t.getAttribute("aria-haspopup") === "dialog" && !t.hasAttribute("data-off")) { hide(); return; }
tile = t;
}
follow();
};
const leave = () => {
@@ -559,6 +612,127 @@ function useDockLabel(dock: RefObject<HTMLElement | null>, nav: RefObject<HTMLEl
}, [dock, nav, strip, label]);
}
/**
* The open group stack (DockStack.tsx): its group, its tile, the y it stands above (stackTop()), opened from
* the keyboard, opened by a hover and not pinned, it replaced another (no growing in).
*/
interface Stack { group: Group; el: HTMLElement; top: number; kb: boolean; hover: boolean; quick: boolean }
/** What the pointer did on a group's tile (Tile onHover). */
type Hover = "enter" | "move" | "leave";
/**
* A mouse resting on a group's tile this long opens its stack; with another stack open, this long switches to
* it; one a hover opened closes this long after the pointer left (ms).
*/
const OPEN_DELAY = 500, SWITCH_DELAY = 130, GRACE = 300;
/** The pointer rests while it stays this close to where the wait started (px); further, the wait starts again. */
const REST_SLOP = 5;
/** How far the triangle toward the stack reaches past its bottom corners (px). */
const AIM_SLACK = 12;
/**
* The y a stack stands above: its tile's top, or with magnification the top
* of the tile fully magnified, so the stack does not move up and down as the
* tile under it grows, nor when it switches to another tile.
*/
function stackTop(el: HTMLElement): number {
const r = el.getBoundingClientRect(), pill = el.closest(".dock-pill")?.getBoundingClientRect();
if (!pill || !magnifies() || el.closest("[data-scroll]")) return r.top;
return Math.min(r.top, pill.top + el.offsetTop - (MAG_MAX - 1) * el.offsetHeight);
}
/** Point (x, y) is in the triangle a, b, c (its edges included). */
function inTriangle(x: number, y: number, ax: number, ay: number, bx: number, by: number, cx: number, cy: number): boolean {
const side = (px: number, py: number, qx: number, qy: number) => (x - qx) * (py - qy) - (px - qx) * (y - qy);
const d1 = side(ax, ay, bx, by), d2 = side(bx, by, cx, cy), d3 = side(cx, cy, ax, ay);
return !((d1 < 0 || d2 < 0 || d3 < 0) && (d1 > 0 || d2 > 0 || d3 > 0));
}
/**
* A group's stack under the mouse (the header's list: OPEN_DELAY,
* SWITCH_DELAY, REST_SLOP, GRACE, the triangle toward the stack). Returns
* `tile` (a group tile's pointer entered, moved or left it), `cancel` (a pending open goes: a press, a menu, a click) and
* `closed` (a stack closed: with the pointer on its tile, no hover opens it
* again before the pointer leaves). A stable object; it reads the stack from
* a ref.
*/
function useStackHover(stack: Stack | null, setStack: Dispatch<SetStateAction<Stack | null>>) {
const now = useRef(stack);
now.current = stack;
// intent: the open pending (its tile, where the wait started, its timer); exit: where the pointer left the open stack's tile; quiet: a tile the
// pointer is on whose stack just closed.
const intent = useRef<{ el: HTMLElement; x: number; y: number; t: ReturnType<typeof setTimeout> } | null>(null);
const exit = useRef<{ x: number; y: number } | null>(null);
const quiet = useRef<HTMLElement | null>(null);
const [api] = useState(() => {
const cancel = () => { if (intent.current) { clearTimeout(intent.current.t); intent.current = null; } };
/** On the way from the open stack's tile to the stack: above the tile, or in the triangle from where it left the tile to the stack's bottom corners. */
const aiming = (x: number, y: number): boolean => {
const s = now.current, from = exit.current, box = document.getElementById("dock-stack")?.getBoundingClientRect();
if (!s || !box?.width) return false;
const r = s.el.getBoundingClientRect();
if (x >= r.left && x <= r.right && y >= box.bottom && y <= r.bottom) return true;
return !!from && inTriangle(x, y, from.x, from.y, box.left - AIM_SLACK, box.bottom, box.right + AIM_SLACK, box.bottom);
};
/** A hover may open one: the page has the focus, the system runs, no menu is open. */
const may = () => document.hasFocus() && isRunning(ui$().get()) && !document.querySelector('[role="menu"]');
const open = (g: Group, el: HTMLElement) => setStack((s) => (s?.kb || s?.group.id === g.id || !el.isConnected ? s
: { group: g, el, top: stackTop(el), kb: false, hover: true, quick: !!s }));
const tile = (g: Group, e: RPointerEvent<HTMLButtonElement>, how: Hover) => {
const el = e.currentTarget, s = now.current, p = intent.current;
if (how === "leave") {
if (p?.el === el) cancel();
if (quiet.current === el) quiet.current = null;
if (s?.el === el) exit.current = { x: e.clientX, y: e.clientY };
return;
}
if (s?.el === el) { exit.current = null; return; }
if (e.pointerType !== "mouse" || e.buttons || quiet.current === el || s?.kb || !may()) { if (p?.el === el) cancel(); return; }
// Resting where the wait started: it goes on. Else it starts (again) from here.
if (p?.el === el && Math.hypot(e.clientX - p.x, e.clientY - p.y) <= REST_SLOP) return;
cancel();
// Another stack is open: this one after SWITCH_DELAY, unless the pointer is on its way to that stack.
const ms = s && !aiming(e.clientX, e.clientY) ? SWITCH_DELAY : OPEN_DELAY;
intent.current = { el, x: e.clientX, y: e.clientY, t: setTimeout(() => { intent.current = null; if (el.matches(":hover") && may()) open(g, el); }, ms) };
};
const closed = (el: HTMLElement | undefined) => { if (el?.matches(":hover")) quiet.current = el; };
return { tile, cancel, closed, aiming };
});
// A press anywhere: no hover opens one now.
useEffect(() => {
document.addEventListener("pointerdown", api.cancel, true);
return () => { document.removeEventListener("pointerdown", api.cancel, true); api.cancel(); };
}, [api]);
// One a hover opened: it goes GRACE ms after the pointer left its tile, the stack (and its app menu), the group
// tiles (another's hover switches) and the way to it, or left the page; back in time, it stays.
useEffect(() => {
exit.current = null;
if (!stack?.hover) return;
let t: ReturnType<typeof setTimeout> | undefined;
const keep = () => { clearTimeout(t); t = undefined; };
const away = () => {
if (document.getElementById("dock-stack-menu")) return;
t ??= setTimeout(() => setStack((s) => (s?.hover ? null : s)), GRACE);
};
const move = (e: PointerEvent) => {
if (e.pointerType !== "mouse") return;
const at = e.target instanceof Element ? e.target : null;
if (at?.closest("#dock-stack, #dock-stack-menu")) { exit.current = null; keep(); }
else if ((at && stack.el.contains(at)) || at?.closest('.dock-tile[aria-haspopup="dialog"]:not([data-off])') || api.aiming(e.clientX, e.clientY)) keep();
else away();
};
const out = (e: globalThis.MouseEvent) => { if (!e.relatedTarget) away(); };
document.addEventListener("pointermove", move, true);
document.addEventListener("mouseout", out, true);
return () => {
keep();
document.removeEventListener("pointermove", move, true);
document.removeEventListener("mouseout", out, true);
};
}, [stack, setStack, api]);
return api;
}
export function Dock() {
const wayland = useStore((s) => s.wayland);
const wlFocused = useWaylandFocused();
@@ -581,30 +755,42 @@ export function Dock() {
const label = useRef<HTMLDivElement>(null);
const prefix = useStore((s) => s.prefix);
const compact = useWm((s) => s.compact);
// The open group stack (DockStack.tsx): its group, its tile and where the tile was, opened from the keyboard or not.
const [stack, setStack] = useState<{ group: Group; el: HTMLElement; rect: DOMRect; kb: boolean } | null>(null);
// The open group stack (DockStack.tsx) and its hover controller (useStackHover).
const [stack, setStack] = useState<Stack | null>(null);
const hover = useStackHover(stack, setStack);
// A tile's context menu (useTileMenu), built again on each render so it follows its window.
const [menu, setMenu] = useState<{ el: HTMLElement; rect: DOMRect; build: MenuBuild } | null>(null);
const openMenu = useCallback((el: HTMLElement, build: MenuBuild) => {
hover.cancel();
setStack(null);
setMenu((m) => (m?.el === el ? m : { el, rect: el.getBoundingClientRect(), build }));
}, []);
/** A group tile's click: its stack, toggled (once the system runs; before, why not). */
}, [hover]);
/**
* A group tile's click (or Enter, `kb`): its stack, opened pinned; one a hover opened is pinned (from the
* keyboard its first app takes the focus); a pinned one closes. Once the system runs; before, why not.
*/
const toggleStack = (g: Group, el: HTMLElement | null, kb: boolean) => {
hover.cancel();
if (!isRunning(ui$().get())) { KW.ui?.toast(`${g.title}: opens once the system is running`); return; }
if (!el || stack?.group.id === g.id) { setStack(null); return; }
if (!el) { setStack(null); return; }
if (stack?.group.id === g.id) {
if (stack.hover) setStack({ ...stack, hover: false, kb: stack.kb || kb });
else { hover.closed(el); setStack(null); }
return;
}
if (strip.current) reveal(strip.current, el);
setStack({ group: g, el, rect: el.getBoundingClientRect(), kb });
setStack({ group: g, el, top: stackTop(el), kb, hover: false, quick: false });
};
const closeStack = (how: StackClose) => {
const el = stack?.el;
hover.closed(el);
setStack(null);
if (how === "key" && el?.isConnected) el.focus({ preventScroll: true });
};
// Its group was taken out of the Dock, or the system stopped: it goes.
// Its group was taken out of the Dock, the system stopped or the launcher opened: it goes.
useEffect(() => {
if (stack && (!running || !pins.some((p) => p.group?.id === stack.group.id) || !stack.el.isConnected)) setStack(null);
}, [stack, running, pins]);
if (stack && (!running || launcher || !pins.some((p) => p.group?.id === stack.group.id) || !stack.el.isConnected)) setStack(null);
}, [stack, running, launcher, pins]);
const spec = menu?.build() ?? null;
useEffect(() => { if (menu && !spec) setMenu(null); }, [menu, spec]);
/** Esc or Tab gives the focus back to the tile; a pick leaves it where the pick put it. */
@@ -614,7 +800,7 @@ export function Dock() {
if (how === "key" && el?.isConnected) el.focus({ preventScroll: true });
};
useScrollFlag(strip);
useMagnify(nav, strip, !!menu || !!stack);
useMagnify(nav, strip, !!menu || (!!stack && !stack.hover), !!stack?.hover);
// No label over an open menu or stack, the shortcuts HUD and the tiles' key hints (the prefix), or on a phone.
useDockLabel(root, nav, strip, label, !!menu || !!stack || prefix || compact);
// Keep the focused window's tile in view when the tiles scroll (phones).
@@ -629,7 +815,7 @@ export function Dock() {
<footer id="dock" ref={root} aria-label="Dock" className="relative flex flex-none items-center justify-center select-none">
<div id="dock-label" ref={label} aria-hidden="true"><span /><span /></div>
{menu && spec && <Menu id="dock-tile-menu" label={spec.header} header={spec.header} items={spec.items} anchor={menu.rect} onClose={closeMenu} />}
{stack && <DockStack key={stack.group.id} group={stack.group} anchor={stack.rect} kb={stack.kb} inside={(t) => !!stack.el.contains(t as Node)} onClose={closeStack} />}
{stack && <DockStack key={stack.group.id} group={stack.group} tile={stack.el} top={stack.top} kb={stack.kb} quick={stack.quick} inside={(t) => !!stack.el.contains(t as Node)} onClose={closeStack} />}
<DockMenu.Provider value={openMenu}>
<nav ref={nav} aria-label="Windows and system" className="dock-pill">
<Tile id="dock-launcher" title="Apps" label="unkernel: Apps" cmd="launcher" shortcut={directKeys(command("launcher"))[0]} on={launcher} off={!running} onClick={toggleLauncher}
@@ -647,7 +833,7 @@ export function Dock() {
note={instApp ? notes(instApp.title, installNote(inst)) : !running ? "opens once the system is running" : undefined}
off={!running} keepMenu expanded={open} install={inst} dot={groupLive(g, terms) ? "on" : undefined}
menu={() => ({ header: g.title, items: [{ label: "Open", run: () => toggleStack(g, document.getElementById(`dock-group-${g.id}`), true) }, null, ...dockItems({ group: g })] })}
onClick={(e) => toggleStack(g, e.currentTarget, e.detail === 0)}>
onHover={(e, how) => hover.tile(g, e, how)} onClick={(e) => toggleStack(g, e.currentTarget, e.detail === 0)}>
<GroupFace g={g} />
</Tile>
);

View File

@@ -1,13 +1,21 @@
// SPDX-License-Identifier: MIT
// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
// The Dock's stack (#dock-stack): the popover a pinned group's tile opens
// (Dock.tsx, pins.ts), as a macOS Dock folder: the group's title, small, over
// a compact grid of its apps' tiles (the launcher's look, smaller: the app's
// gradient and glyph, its name, a running dot, an install's bar), in a plain
// black popover (style.css .popover) above the tile, centred on it and kept
// EDGE px inside the viewport; under sm (phones) a sheet across the page above
// the Dock. Portaled to <body> at the menus' layer (--z-menu); taller than
// the room above the tile, it scrolls.
// (Dock.tsx, pins.ts), as a macOS Dock stack in its Grid view: the group's
// title centred at the top over a grid of its apps' tiles (the launcher's
// look, smaller: the app's gradient and glyph, its name, a running dot, an
// install's bar), on a rounded panel of the Dock's material, translucent and
// blurring what is behind it (style.css .dock-stack: the --glass-* tokens,
// the HUD's darker tint), with a notch under it pointing at the tile. It
// stands `top` px from the top of the viewport (the tile's top, as high as
// the tile magnifies: Dock.tsx stackTop()), centred on the tile and kept EDGE
// px inside the viewport, and follows the tile sideways while it moves (the
// Dock's magnification, a frame per pointer move and a few after); under sm
// (phones) a sheet across the page above the Dock. It grows out of the tile
// with a short spring (scale and fade from the notch's tip), at once when it
// replaces another stack (`quick`) or with reduced motion. Portaled to <body>
// at the menus' layer (--z-menu); taller than the room above the tile, its
// panel scrolls.
//
// - A click on an app runs it (launcher.ts launch(): a running one is shown)
// and closes the stack; one that cannot run now (unavailable(), or the
@@ -16,12 +24,14 @@
// a long press on touch, the ContextMenu key or Shift-F10. Open, then Keep
// in Dock or Remove from Dock (the app). A press in the stack that closes
// that menu does nothing else.
// - A press outside it (but on its tile, whose click toggles it), Esc, a
// pick, a resize or the page losing the focus close it. Esc closes it
// wherever the focus is (opened with the mouse, the terminal keeps the
// focus: presses in it never take it; the guest does not get that Esc).
// Opened from the keyboard its first app takes the focus; the arrows move
// it through the grid (up and down by a row), Home and End, Enter or
// - A press outside it (but on its tile, whose click pins or toggles it), Esc,
// a pick, a resize or the page losing the focus close it; Dock.tsx also
// closes one the mouse opened once the pointer has left the tile and the
// stack. Esc closes it wherever the focus is (opened with the mouse, by a
// hover or a click, the terminal keeps the focus: presses in it never take
// it; the guest does not get that Esc). Opened from the keyboard (`kb`, also
// when it turns true while open) its first app takes the focus; the arrows
// move it through the grid (up and down by a row), Home and End, Enter or
// Space runs it, Esc or Tab closes the stack and the opener puts the focus
// back on the tile (onClose "key").
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type MouseEvent } from "react";
@@ -42,9 +52,14 @@ import { Menu, type MenuClose, type MenuEntry } from "./Menu.tsx";
/** How it closed: Esc or Tab in it (the focus goes back to the tile), a press elsewhere (Esc elsewhere, a resize), an app picked. */
export type StackClose = "key" | "away" | "pick";
const EDGE = 8, GAP = 8;
/** Its least distance from the viewport's sides; the gap between the notch's tip and `top`; the notch's height (px). */
const EDGE = 8, GAP = 4, NOTCH = 8;
/** How far the notch stays from the panel's sides (its round corners), px. */
const NOTCH_EDGE = 22;
/** A tile's width on wide screens (px). */
const CELL = 76;
const CELL = 80;
/** Frames it keeps following the tile after a pointer move (the magnification's transition is .14 s). */
const FOLLOW = 10;
const GRAY: [string, string] = ["#52525b", "#18181b"];
const MENU_ID = "dock-stack-menu";
@@ -65,25 +80,29 @@ function StackTile({ app, idx, sel, why, running, onPick, onMenu, onFocus }: {
onClick={() => { if (!long.consumed()) onPick(); }} onFocus={onFocus}
onContextMenu={(e: MouseEvent<HTMLButtonElement>) => { e.preventDefault(); long.context(); onMenu(new DOMRect(e.clientX, e.clientY, 0, 0), e.currentTarget); }}
{...long.handlers}
className={`group flex min-w-0 flex-col items-center gap-1 rounded-lg px-1 pt-2 pb-1 outline-none transition-colors hover:bg-white/10 focus-visible:bg-white/10 [-webkit-touch-callout:none] ${why ? "opacity-45" : ""}`}>
className={`group flex min-w-0 flex-col items-center gap-1 rounded-xl px-1 pt-2 pb-1 outline-none transition-colors hover:bg-white/10 focus-visible:bg-white/12 [-webkit-touch-callout:none] ${why ? "opacity-45" : ""}`}>
<span aria-hidden="true" style={face}
className={`relative grid size-11 place-items-center rounded-[22%] text-[22px] leading-none text-white shadow-[0_2px_6px_rgba(0,0,0,.45)] transition-transform group-active:scale-95 ${why ? "grayscale" : ""}`}>
className={`relative grid size-12 place-items-center rounded-[22%] text-[24px] leading-none text-white shadow-[0_2px_6px_rgba(0,0,0,.45)] transition-transform group-active:scale-95 ${why ? "grayscale" : ""}`}>
<AppGlyph icon={app.icon ?? app.title[0]!.toUpperCase()} className="size-[58%]" />
<TileProgress inst={inst} className="right-[16%] bottom-[12%] left-[16%]" />
</span>
<span className="max-w-full truncate font-sans text-[11px] leading-tight text-muted group-hover:text-fg">{app.title}</span>
<span className="max-w-full truncate font-sans text-[11.5px] leading-tight text-fg/85 [text-shadow:0_1px_2px_rgb(0_0_0/50%)] group-hover:text-fg">{app.title}</span>
<span aria-hidden="true" className={`size-1 flex-none rounded-full ${running ? "bg-white/80" : "bg-transparent"}`} />
</button>
);
}
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<HTMLButtonElement>("[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) }}>
<div aria-hidden="true" className="truncate px-1.5 pt-1 pb-0.5 font-sans text-[11.5px] font-medium text-faint">{group.title}</div>
<div className="grid gap-0.5" style={grid}>
{apps.map((a, i) => (
<StackTile key={a.id} app={a} idx={i} sel={i === sel} why={whyOf(a)} running={runningOf(a)}
onPick={() => 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 }}>
<div className="dock-stack-panel flex flex-col overflow-y-auto overscroll-contain p-2 pt-1.5" style={{ maxHeight: Math.max(120, top - GAP - NOTCH - EDGE) }}>
<div aria-hidden="true" className="truncate px-2 pt-0.5 pb-1 text-center font-sans text-[12.5px] font-semibold text-fg/90 [text-shadow:0_1px_2px_rgb(0_0_0/50%)]">{group.title}</div>
<div className="grid gap-0.5" style={grid}>
{apps.map((a, i) => (
<StackTile key={a.id} app={a} idx={i} sel={i === sel} why={whyOf(a)} running={runningOf(a)}
onPick={() => pick(a)} onMenu={(at, el) => openMenu(a, at, el)} onFocus={() => setSel(i)} />
))}
</div>
</div>
<span aria-hidden="true" className="dock-stack-notch" style={{ height: NOTCH + 1 }}>
<svg viewBox="0 0 18 9" preserveAspectRatio="none"><path d="M0 0L9 9L18 0" /></svg>
</span>
</div>,
document.body,
)}

View File

@@ -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 <body>), 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