An open-source, self-hosted system for apps built with web technologies.
The view glides on a spring and carries its speed into a new move; Windows move on motions derived from their distance; holding a Window or the Map against an edge takes the view there; double-clicking a resize edge extends it; Windows paint margins from their own view; the System icon and the new default Program icon
zohayrslilehe594f9bca55b
diff --git a/assets/default-icon.png b/assets/default-icon.pngindex 7395501..cc45111 100644Binary files a/assets/default-icon.png and b/assets/default-icon.png differdiff --git a/assets/bundled/logo.png b/assets/logo.pngsimilarity index 100%rename from assets/bundled/logo.pngrename to assets/logo.pngdiff --git a/source/client/core/link-manager/auth-manager/auth-manager.ts b/source/client/core/link-manager/auth-manager/auth-manager.tsindex ae8fb47..9d3902f 100644--- a/source/client/core/link-manager/auth-manager/auth-manager.ts+++ b/source/client/core/link-manager/auth-manager/auth-manager.ts@@ -143,6 +143,12 @@ export default class AuthManager extends TheLink {return await this.$outbound.publishFirst("/about")}+ /** The System's own icon as PNG bytes, at one standard size. */+ public async icon(size: unknown) {++ return await this.$outbound.publishFirst("/icon", size)+ }+public async open(process: string, target: unknown) {await this.$outbound.publishFirst("/opening/open", process, target)diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/client/core/link-manager/auth-manager/process-manager/process-manager.tsindex 88c42d7..b87be06 100644--- a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -5,7 +5,7 @@ import { Publish, Subscribe } from "@the-link/core/decorators"import { TheLink } from "@the-link/core"import AuthManager from "../auth-manager"import Process from "./process"-import { type ClientLaunch, type ProgramIconSize, type ServerLaunch } from "@phreshos/core"+import { type ClientLaunch, type IconSize, type ServerLaunch } from "@phreshos/core"import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"import { type ServiceAddress, type WindowLayer } from "@phreshos/core"import { type ServiceScope } from "@server/core/link-manager/auth-manager/process-manager/endpoint-services"@@ -119,7 +119,7 @@ export default class ProcessManager extends TheLink {}}- public async serviceProgramIcon(address: ServiceAddress, iconSize: ProgramIconSize = "medium") {+ public async serviceProgramIcon(address: ServiceAddress, iconSize: IconSize = "medium") {return await this.$outbound.publishFirst("/service/program-icon", address, iconSize) as number[]}diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.tsindex 3a9fd22..11bb435 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -9,7 +9,7 @@ import {type PermissionName,type PermissionRequestInput,type ProgramCommandChunk,- type ProgramIconSize+ type IconSize} from "@phreshos/core"import StreamRelay from "@client/core/link-manager/stream-relay"@@ -160,7 +160,7 @@ export default class ProgramManager extends TheLink {}/** Request one rendered icon from the authoritative server Program. */- public async icon(subject: unknown, size: ProgramIconSize) {+ public async icon(subject: unknown, size: IconSize) {return await this.$outbound.publishFirst("/icon", subject, size) as number[]}diff --git a/source/client/view/appearance/motion.ts b/source/client/view/appearance/motion.tsindex 093818a..9f3a95e 100644--- a/source/client/view/appearance/motion.ts+++ b/source/client/view/appearance/motion.ts@@ -1,7 +1,7 @@-import { type AppearanceTransaction, type Easing, type PresentationTransaction } from "@phreshos/core"+import { progressAt, type AppearanceTransaction, type Easing, type PresentationTransaction } from "@phreshos/core"import { type Transition } from "motion/react"-const easings: Record<Exclude<Easing, readonly number[]>, Transition["ease"]> = {+const easings: Record<Extract<Easing, string>, Transition["ease"]> = {linear: "linear",ease: [0.25, 0.1, 0.25, 1],"ease-in": "easeIn",@@ -15,7 +15,10 @@ export function motionTransition(transaction: AppearanceTransaction, reduced = freturn {type: "tween",duration: reduced ? 0 : transaction.duration / 1_000,- ease: motionEase(transaction.easing)+ // A spring plays through the same function every follower uses, so all of them draw one motion.+ ease: isCurve(transaction.easing)+ ? motionEase(transaction.easing)+ : (t: number) => progressAt(transaction, t * transaction.duration)}}@@ -32,10 +35,28 @@ export function resolveWindowTransaction(transaction: PresentationTransaction |/** Translates the public easing vocabulary into a CSS timing function. */export function cssEasing(easing: Easing) {- return typeof easing === "string" ? easing : "cubic-bezier(" + easing.join(", ") + ")"+ if (typeof easing === "string") return easing++ if (!isCurve(easing)) {++ // A spring in CSS: its path sampled as a linear() curve over a nominal duration.+ const samples = Array.from({ length: 41 }, (_, index) => progressAt({ duration: 1000, easing }, index * 25).toFixed(4))++ return "linear(" + samples.join(", ") + ")"+ }++ return "cubic-bezier(" + (easing as readonly number[]).join(", ") + ")"+}++type Curve = Extract<Easing, string> | readonly [number, number, number, number]++/** Whether an easing is a curve, not a spring. */+function isCurve(easing: Easing): easing is Curve {++ return typeof easing === "string" || Array.isArray(easing)}-function motionEase(easing: Easing): Transition["ease"] {+function motionEase(easing: Curve): Transition["ease"] {return typeof easing === "string" ? easings[easing] : [...easing]}diff --git a/source/client/view/components/desktop-host/client-host.ts b/source/client/view/components/desktop-host/client-host.tsindex 7063685..77ead52 100644--- a/source/client/view/components/desktop-host/client-host.ts+++ b/source/client/view/components/desktop-host/client-host.ts@@ -5,8 +5,9 @@ import useAnnouncements from "./announcements"import ClientProcessBoundary from "./client-process-boundary"import ClientTraffic from "./client-traffic"import { type DesktopViewportHost } from "./host"-import { type RefObject, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"+import { type RefObject, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react"import useViewportOffset from "@client/view/structure/desktop/viewport-offset"+import { useReducedMotion } from "@libs/react-motion"import { type default as AuthManager } from "@client/core/link-manager/auth-manager/auth-manager"import { type PresentationHost } from "./presentation"import messagepack from "@the-link/messagepack"@@ -57,10 +58,13 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObje}), [desktop])- // Every Client following this Desktop hears that its view moved.+ // Every Client following this Desktop hears that its view moved, as it sets off, with the motion+ // it takes; with animations off it is there at once. It is told before the move is drawn, so+ // its own motion starts as close as it can to the Desktop's.+ const reducedMotion = useReducedMotion()const announcedOffset = useRef(viewport.offset)- useEffect(function () {+ useLayoutEffect(function () {if (announcedOffset.current === viewport.offset) return@@ -68,10 +72,10 @@ export default function useClientHost(authManager: AuthManager, desktop: RefObjefor (const identity of sources.keys()) {- traffic.emit(identity, "host-desktop-viewport", "move", viewport.offset).catch(() => undefined)+ traffic.emit(identity, "host-desktop-viewport", "move", { offset: viewport.offset, transaction: reducedMotion ? null : viewport.transaction }).catch(() => undefined)}- }, [viewport.offset, sources, traffic])+ }, [viewport.offset, viewport.transaction, reducedMotion, sources, traffic])useLayoutEffect(function () {diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 7eba6a7..2ea789d 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -22,7 +22,7 @@ import {parseSystemProgramListOptions,parseSystemServiceListOptions,type PermissionRequestInput,- type ProgramIconSize+ type IconSize} from "@phreshos/core"import {presentationSurface,@@ -447,7 +447,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dconst service = await permittedService(args[0])- return [await processManager.serviceProgramIcon(service, args[1] as ProgramIconSize | undefined)]+ return [await processManager.serviceProgramIcon(service, args[1] as IconSize | undefined)]}if (word === "service-follow") {@@ -739,6 +739,8 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "about") return [await authManager.about()]+ if (word === "system-icon") return [await authManager.icon(args[0])]+if (word === "open") {await authManager.open(pane, args[0])@@ -889,7 +891,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "program-definition") return [await programManager.definition(address(await permittedProgram(args[0])))]// Icon bytes are requested only when a concrete Program handle asks.- if (word === "icon") return [await programManager.icon(address(await permittedProgram(args[0])), args[1] as ProgramIconSize)]+ if (word === "icon") return [await programManager.icon(address(await permittedProgram(args[0])), args[1] as IconSize)]// Installation state and lifecycle operations of one held Program.if (word === "installed") {diff --git a/source/client/view/components/system-header.tsx b/source/client/view/components/system-header.tsxindex 6b951e5..faa91ae 100644--- a/source/client/view/components/system-header.tsx+++ b/source/client/view/components/system-header.tsx@@ -1,4 +1,4 @@-import logo from "@/assets/bundled/logo.png"+import logo from "@/assets/logo.png"/*** The System identity shared by System-owned panels. It is content only: thediff --git a/source/client/view/components/window-manager/window-geometry.ts b/source/client/view/components/window-manager/window-geometry.tsindex 2d96c97..6eea294 100644--- a/source/client/view/components/window-manager/window-geometry.ts+++ b/source/client/view/components/window-manager/window-geometry.ts@@ -215,7 +215,13 @@ export const noPaintMargins: PaintMargins = Object.freeze({ top: 0, right: 0, bo* paint, never geometry. Snap previews use this same function, so preview and* final paint cannot disagree.*/-export function windowPaintInsets(position: Position, size: Size, surface: WindowSurfaceSize, inset: number, margins: PaintMargins, current?: WindowRegion) {+/**+ * The space painted around a standard Window: the margins where it meets an edge of its view, the+ * inset elsewhere. The edges are those of the view the Window lives in on the plane, which is+ * `shift` pixels away from what is shown when the Desktop looks between two views; so a Window keeps+ * its margins wherever the view looks from.+ */+export function windowPaintInsets(position: Position, size: Size, surface: WindowSurfaceSize, inset: number, margins: PaintMargins, current?: WindowRegion, shift: Readonly<{ x: number, y: number }> = noShift) {const x = current?.x ?? surface.width / 2 + pixels(position.x, surface.width)@@ -227,13 +233,13 @@ export function windowPaintInsets(position: Position, size: Size, surface: Windoreturn {- top: startsAtBoundary(position.y, y, surface.height) ? margins.top : inset,+ top: startsAtBoundary(position.y, y + shift.y, surface.height) ? margins.top : inset,- right: endsAtBoundary(position.x, size.width, x, width, surface.width) ? margins.right : inset,+ right: endsAtBoundary(position.x, size.width, x + shift.x, width, surface.width) ? margins.right : inset,- bottom: endsAtBoundary(position.y, size.height, y, height, surface.height) ? margins.bottom : inset,+ bottom: endsAtBoundary(position.y, size.height, y + shift.y, height, surface.height) ? margins.bottom : inset,- left: startsAtBoundary(position.x, x, surface.width) ? margins.left : inset+ left: startsAtBoundary(position.x, x + shift.x, surface.width) ? margins.left : inset}}@@ -244,9 +250,19 @@ function pixels(value: Value, span: number) {return resolved.relative * span + resolved.pixels}+const noShift = Object.freeze({ x: 0, y: 0 })++/** Whether a point lies on a line of the grid of views, which repeats every span. */+function onGrid(value: number, span: number) {++ const within = ((value % span) + span) % span++ return closeTo(within, 0) || closeTo(within, span)+}+function startsAtBoundary(value: Value, resolved: number, span: number) {- if (span) return closeTo(resolved, 0)+ if (span) return onGrid(resolved, span)// Without a measured span, the surface's first edge is half of it before the center.return equal(value, -0.5, 0)@@ -254,7 +270,7 @@ function startsAtBoundary(value: Value, resolved: number, span: number) {function endsAtBoundary(position: Value, size: Value, resolvedPosition: number, resolvedSize: number, span: number) {- if (span) return closeTo(resolvedPosition + resolvedSize, span)+ if (span) return onGrid(resolvedPosition + resolvedSize, span)const first = relative(position)diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsxindex 9862712..bf07dd8 100644--- a/source/client/view/structure/authentication/credentials-form.tsx+++ b/source/client/view/structure/authentication/credentials-form.tsx@@ -5,7 +5,7 @@ import { motion } from "motion/react"import { Button, Heading, Input, resolveSpacing, Surface, Text, useAppearance } from "@phreshos/react-ui"import Alert from "../../components/alert"import { useId, useState, type SyntheticEvent } from "react"-import logo from "@/assets/bundled/logo.png"+import logo from "@/assets/logo.png"import { name, version } from "@/source/identity"/** The common username-and-password welcome for sign-up and sign-in: the first thing a System shows. */diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 9f99267..b1a6167 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -18,6 +18,8 @@ import { useProperty } from "@the-link/react"import SharedResizeBoundaries from "./windows/shared-resize-boundaries"import { programsRequirement } from "../readiness-requirements"import { LaunchPlacementContext, type LaunchPlacement } from "./launch-placement"+import { CellShiftStore, PlaneSlide, PlaneSlideContext, ViewCellShift, usePlaneSlide } from "./plane-slide"+import { useViewTravel } from "./edge-hold"import { boundedGeometry, planeGeometry, recordedPosition, resolveWindowGeometry, shiftPosition, viewOfGeometry, type WindowRegion } from "@client/view/components/window-manager/window-geometry"import { type MappedWindow } from "./layers/shell/taskbar/viewport/viewport-control"import type Process from "@client/core/link-manager/auth-manager/process-manager/process"@@ -188,9 +190,51 @@ export default function Workspace() {return found?.assetId ?? knownAssets.current.get(identity) ?? ""}- function renderWindows(layer: Layer) {+ /**+ * Where every other open standard Window stands in this view, for a Window that reaches toward+ * its neighbours. Read when asked, so it is always what is drawn now; the callback itself stays+ * the same, so it does not redraw the Windows it is given to.+ */+ const neighboursNow = useRef<(identity: string) => readonly WindowRegion[]>(() => [])++ neighboursNow.current = identity => windows.panesByLayer.window+ .filter(pane => pane.identity !== identity && !pane.closing && !pane.presentation.minimized)+ .map(pane => {+ const bounded = boundedGeometry(pane.presentation.position, pane.presentation.size, windowSurfaceSize)+ return resolveWindowGeometry(shownPosition(bounded.position), bounded.size, windowSurfaceSize)+ })++ const neighboursOf = useCallback((identity: string) => neighboursNow.current(identity), [])++ // What lives on the plane glides with the view; see usePlaneSlide.+ const slide = usePlaneSlide(viewport.views, viewport.transaction, windowSurfaceSize)++ // How far the shown view is from the grid of whole views: Windows paint their margins at the+ // edges of their own view, wherever the Desktop looks from.+ const [cellShift] = useState(() => new CellShiftStore())++ cellShift.take({+ x: (views.x - Math.round(views.x)) * windowSurfaceSize.width,+ y: (views.y - Math.round(views.y)) * windowSurfaceSize.height+ })- return windows.panesByLayer[layer].map(({ identity, record, client, presentation, closing, entering, stopping }) => {+ useLayoutEffect(() => cellShift.announce(), [cellShift, views.x, views.y, windowSurfaceSize.width, windowSurfaceSize.height])++ // A Window held against an edge takes the view one whole view that way; see useViewTravel.+ const edgeHold = useViewTravel(viewport)++ /** A layer whose drawings may be fixed to the viewport or to the plane: only the second glide with the view. */+ function renderAnchored(layer: "under" | "over") {++ return <>+ {renderWindows(layer, "viewport")}+ <PlaneSlide slide={slide}>{renderWindows(layer, "plane")}</PlaneSlide>+ </>+ }++ function renderWindows(layer: Layer, anchor?: PresentationAnchor) {++ return windows.panesByLayer[layer].filter(({ presentation }) => anchor === undefined || presentation.anchor === anchor).map(({ identity, record, client, presentation, closing, entering, stopping }) => {const bounded = boundedGeometry(presentation.position, presentation.size, windowSurfaceSize)@@ -290,6 +334,10 @@ export default function Workspace() {onSnap={snap}+ onEdgeHold={layer === "window" ? edgeHold : undefined}++ onNeighbours={layer === "window" ? neighboursOf : undefined}+/>})}@@ -480,17 +528,19 @@ export default function Workspace() {<ProgramAccessProbe door={application.doors.program} setAccess={setProgramAccess} />+ <PlaneSlideContext.Provider value={slide}>+ <ViewCellShift.Provider value={cellShift}><DesktopLayerswallpaper={wallpaper}- underWindows={renderWindows("under")}+ underWindows={renderAnchored("under")}- windows={renderWindows("window")}+ windows={<PlaneSlide slide={slide}>{renderWindows("window")}</PlaneSlide>}- sharedResizeBoundaries={<SharedResizeBoundaries {...windows.sharedResize} commit={commitSharedResize} />}+ sharedResizeBoundaries={<PlaneSlide slide={slide}><SharedResizeBoundaries {...windows.sharedResize} commit={commitSharedResize} /></PlaneSlide>}- overWindows={renderWindows("over")}+ overWindows={renderAnchored("over")}windowSurfaceRef={windowSurfaceRef}@@ -502,6 +552,8 @@ export default function Workspace() {</>}/>+ </ViewCellShift.Provider>+ </PlaneSlideContext.Provider>{wallpaperReady && <ReadyWallpaper />}diff --git a/source/client/view/structure/desktop/edge-hold.ts b/source/client/view/structure/desktop/edge-hold.tsnew file mode 100644index 0000000..7702866--- /dev/null+++ b/source/client/view/structure/desktop/edge-hold.ts@@ -0,0 +1,105 @@+import { useCallback } from "react"+import { useReducedMotion } from "@libs/react-motion"+import { planeReach } from "@client/view/components/window-manager/window-geometry"+import motionAcross from "./motion-across"+import { type ViewportControl } from "./viewport-offset"++export type Direction = Readonly<{ x: number, y: number }>++/**+ * Takes the view one whole view in a direction, when the plane goes on there. It answers how long+ * the view takes to get there, so whoever holds it there waits for it, or null when there is nowhere+ * further to go.+ */+export function useViewTravel(viewport: ViewportControl) {++ const reducedMotion = useReducedMotion()++ const { view, moveTo, surface } = viewport++ return useCallback(function (direction: Direction) {++ const next = { x: view.x + direction.x, y: view.y + direction.y }++ if (Math.abs(next.x) > planeReach || Math.abs(next.y) > planeReach || (next.x === view.x && next.y === view.y)) return null++ moveTo(next)++ return reducedMotion ? 0 : motionAcross(Math.hypot(direction.x * surface.width, direction.y * surface.height)).duration++ }, [view.x, view.y, moveTo, reducedMotion, surface.width, surface.height])+}++/** Which edges of a box a point is held against, within 16 pixels: -1, 0 or 1 in each direction. */+export function against(x: number, y: number, width: number, height: number): Direction {++ return {+ x: x <= 16 ? -1 : x >= width - 16 ? 1 : 0,+ y: y <= 16 ? -1 : y >= height - 16 ? 1 : 0+ }+}++/**+ * Something held against an edge of the screen takes the view that way: after 700 milliseconds, one+ * whole view; then, once the view has arrived and a half second has passed, another, for as long as+ * it stays there. Where the plane goes no further, it says so, so the one holding can show it.+ */+export class EdgeHold {++ private direction: Direction = { x: 0, y: 0 }++ private timer = 0++ private blocked = false++ public constructor(+ private readonly travel: (direction: Direction) => number | null | undefined,+ private readonly onBlocked?: (blocked: boolean) => void+ ) {}++ /** Where it is held now; a new edge starts the wait again, and no edge stops it. */+ public update(direction: Direction) {++ if (direction.x === this.direction.x && direction.y === this.direction.y) return++ this.stop()++ this.direction = direction++ if (direction.x || direction.y) this.timer = window.setTimeout(() => this.hold(), 700)+ }++ public stop() {++ if (this.timer) clearTimeout(this.timer)++ this.timer = 0++ this.direction = { x: 0, y: 0 }++ if (this.blocked) {++ this.blocked = false++ this.onBlocked?.(false)+ }+ }++ private hold() {++ const took = this.travel(this.direction)++ if (took === null || took === undefined) {++ this.timer = 0++ this.blocked = true++ this.onBlocked?.(true)++ return+ }++ this.timer = window.setTimeout(() => this.hold(), took + 500)+ }+}diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsxindex 24196dd..fad095d 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu-panel.tsx@@ -1,7 +1,7 @@import { useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react"import { AppLayout, Button, Drawer, Panel, SearchField, SegmentedControl, Text, Tree, useAppearance, useColor, useScale } from "@phreshos/react-ui"import { Activity, LayoutGrid, List, PanelLeft, Settings as SettingsIcon } from "@phreshos/react-ui/icons"-import logo from "@/assets/bundled/logo.png"+import logo from "@/assets/logo.png"import { floatingShadow } from "@client/view/appearance/floating-shadow"import usePrograms from "@client/view/structure/desktop/programs/programs"import Programs, { useLaunch, type ProgramsLayout } from "./programs/programs"diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/viewport/viewport-control.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/viewport/viewport-control.tsxindex a65a1f7..e909e26 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/viewport/viewport-control.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/viewport/viewport-control.tsx@@ -7,7 +7,12 @@ import { planeReach, type WindowRegion } from "@client/view/components/window-maimport { type AppearanceTaskbar } from "@phreshos/core"import { useReducedMotion } from "@libs/react-motion"import { motion } from "motion/react"-import { cssEasing } from "@client/view/appearance/motion"+import { cssEasing, motionTransition } from "@client/view/appearance/motion"+import motionAcross from "../../../../motion-across"+import { EdgeHold, against, useViewTravel } from "../../../../edge-hold"+import { createPortal } from "react-dom"+import SnapPreview, { type SnapTarget } from "../../../../windows/snap-preview"+import { desktopMargins } from "../../../desktop-layers"import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"import { shellSurfaceClassName } from "../../shell-surface"import { floatingShadow } from "@client/view/appearance/floating-shadow"@@ -119,8 +124,122 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, o}, [close])+ // The map's button can be carried: dragged out, it leaves a ghost in the hand, and held against an+ // edge of the screen, the ghost takes the view that way, as a held Window does. It is what the+ // hand holds when there is no Window to carry, and it belongs to the Shell, so no Program under+ // the edge can take the hand from it.+ const travel = useViewTravel(viewport)++ const travelNow = useRef(travel)++ travelNow.current = travel++ // The button as it is lifted: where the hand is, where on the button it holds it, and how large+ // the button is drawn, so the ghost is the button itself; the button left behind is faint.+ const [ghost, setGhost] = useState<{ x: number, y: number, grip: { x: number, y: number }, scale: number } | null>(null)++ const lifted = useRef({ grip: { x: 0, y: 0 }, scale: 1 })++ // A carry that ended over the button is not also a press.+ const carried = useRef(false)++ // Where the ghost is held against the Desktop's edges: the placement a Window would take there,+ // shown as a Window's is, but only as a sign; nothing is placed when the hand lets go. It turns to+ // danger where the plane goes no further.+ const [edge, setEdge] = useState<{ zone: SnapTarget | null, shown: SnapTarget | null, blocked: boolean, surface: HTMLElement | null }>({ zone: null, shown: null, blocked: false, surface: null })++ function carry(event: ReactPointerEvent<HTMLElement>) {++ if (event.button !== 0) return++ const start = { x: event.clientX, y: event.clientY }++ const pointer = event.pointerId++ const held = event.target as Element++ const edges = new EdgeHold(direction => travelNow.current(direction), blocked => setEdge(current => ({ ...current, blocked })))++ const windowSurface = document.querySelector<HTMLElement>("[data-window-surface]")++ const button = trigger.current++ if (button) {++ const bounds = button.getBoundingClientRect()++ lifted.current = { grip: { x: start.x - bounds.left, y: start.y - bounds.top }, scale: button.offsetWidth ? bounds.width / button.offsetWidth : 1 }+ }++ carried.current = false++ function move(motion: PointerEvent) {++ if (motion.pointerId !== pointer) return++ if (!carried.current) {++ if (Math.hypot(motion.clientX - start.x, motion.clientY - start.y) < 6) return++ carried.current = true++ // Held by the Shell from here on, even over a Program's frame.+ try { held.setPointerCapture(pointer) } catch { /* The press already ended. */ }++ close()+ }++ setGhost({ x: motion.clientX, y: motion.clientY, ...lifted.current })++ // Measured as the Desktop measures a Window's drag: in its own pixels, at its scale.+ const bounds = windowSurface?.getBoundingClientRect()++ const scale = bounds && windowSurface?.clientWidth ? bounds.width / windowSurface.clientWidth : 1++ const width = windowSurface?.clientWidth ?? window.innerWidth++ const height = windowSurface?.clientHeight ?? window.innerHeight++ const direction = against((motion.clientX - (bounds?.left ?? 0)) / scale, (motion.clientY - (bounds?.top ?? 0)) / scale, width, height)++ edges.update(direction)++ const zone = direction.x || direction.y ? placementAt(direction) : null++ setEdge(current => ({ ...current, zone, shown: zone ?? current.shown, surface: windowSurface }))+ }++ function end(motion: PointerEvent) {++ if (motion.pointerId !== pointer) return++ edges.stop()++ setGhost(null)++ setEdge(current => ({ ...current, zone: null, blocked: false }))++ removeEventListener("pointermove", move)++ removeEventListener("pointerup", end)++ removeEventListener("pointercancel", end)++ // The press that may follow on this same release is still told it was a carry.+ setTimeout(() => { carried.current = false })+ }++ addEventListener("pointermove", move)++ addEventListener("pointerup", end)++ addEventListener("pointercancel", end)+ }+function toggle() {+ if (carried.current) return+const element = surface.currentif (!element || !trigger.current) return@@ -161,15 +280,37 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, oreturn <>- {/* Showing its icon alone, it names itself on hover and focus. */}+ {/* Showing its icon alone, it names itself on hover and focus; pressed and dragged, it is carried. */}+ <span style={{ display: "contents" }} onPointerDownCapture={carry}><TaskbarTooltip label={centered ? "Map" : `Map, near ${place}`} iconOnly={centered || vertical}><Button ref={trigger} size="small" iconOnly={centered && !vertical} className={vertical ? "px-0" : undefined} color={centered ? undefined : "primary:soft"}+ style={ghost ? { opacity: 0.35 } : undefined}aria-label={centered ? "Map" : `Map, near ${place}`} aria-controls={id} aria-expanded={open} aria-haspopup="dialog"onPressStart={() => { openAtPressStart.current = surface.current?.matches(":popover-open") ?? false }}onPress={toggle}><MapIcon />{!centered && !vertical && <span className="tabular-nums">{place}</span>}</Button></TaskbarTooltip>+ </span>++ {edge.shown && edge.surface && createPortal(<SnapPreview+ shown={edge.shown}+ visible={edge.zone !== null}+ blocked={edge.blocked}+ bare={false}+ paintSurfaceSize={{ width: edge.surface.clientWidth, height: edge.surface.clientHeight }}+ paintInset={spacing / 2}+ paintMargins={desktopMargins(spacing, taskbar)}+ reducedMotion={reducedMotion}+ zIndex={2147483646}+ />, edge.surface)}++ {ghost && createPortal(<div aria-hidden="true" inert className="pointer-events-none fixed"+ style={{ left: ghost.x - ghost.grip.x, top: ghost.y - ghost.grip.y, transform: `scale(${ghost.scale})`, transformOrigin: "0 0", zIndex: 2147483647 }}>+ <Button size="small" iconOnly={centered && !vertical} className={vertical ? "px-0" : undefined} color={centered ? undefined : "primary:soft"}>+ <MapIcon />{!centered && !vertical && <span className="tabular-nums">{place}</span>}+ </Button>+ </div>, document.body)}<motion.divref={surface}@@ -317,11 +458,52 @@ function ViewMap({ labelId, viewport, windows, centered, menus, room }: Readonlyconst transaction = useAppearance().transaction+ // The map is small and the view is large, so every pixel the hand moves is many on the+ // screen. The frame therefore does not jump to the pointer: it follows it, smoothed each+ // frame, which melts the hand's small jolts and keeps its intent.+ const following = useRef<{ target: { x: number, y: number }, shown: { x: number, y: number }, frame: number, last: number } | null>(null)++ const placeView = useRef(viewport.place)++ placeView.current = viewport.place++ function chase(time: number) {++ const state = following.current++ if (!state) return++ const step = state.last ? Math.min(time - state.last, 64) : 16++ state.last = time++ const share = 1 - Math.exp(-step / 60)++ state.shown = { x: state.shown.x + (state.target.x - state.shown.x) * share, y: state.shown.y + (state.target.y - state.shown.y) * share }++ placeView.current(state.shown)++ const near = Math.abs(state.target.x - state.shown.x) < 0.5 && Math.abs(state.target.y - state.shown.y) < 0.5++ state.frame = near && !drag.current ? 0 : requestAnimationFrame(chase)+ }++ function stopFollowing() {++ if (following.current?.frame) cancelAnimationFrame(following.current.frame)++ following.current = null+ }+function grab(event: ReactPointerEvent<HTMLDivElement>) {event.currentTarget.setPointerCapture(event.pointerId)drag.current = { pointer: { x: event.clientX, y: event.clientY }, offset: viewport.offset, scale: shownScale(event.currentTarget) }++ stopFollowing()++ following.current = { target: viewport.offset, shown: viewport.offset, frame: 0, last: 0 }}function follow(event: ReactPointerEvent<HTMLDivElement>) {@@ -336,14 +518,23 @@ function ViewMap({ labelId, viewport, windows, centered, menus, room }: Readonlyy: clamp(started.offset.y + (event.clientY - started.pointer.y) / started.scale / cell.height * surface.height, range.minY * surface.height, range.maxY * surface.height)}- // The frame follows the pointer freely; a nearby whole view is only marked until release.- viewport.place(point)+ // The frame follows the pointer, smoothed; a nearby whole view is only marked until release.+ const state = following.current++ if (state) {++ state.target = point++ if (!state.frame) state.frame = requestAnimationFrame(chase)+ }setSettle(nearView(point, surface))}function release() {+ stopFollowing()+if (drag.current && settle) viewport.moveTo(settle)drag.current = null@@ -397,10 +588,15 @@ function ViewMap({ labelId, viewport, windows, centered, menus, room }: Readonlybackground: `color-mix(in oklab, ${primary} 18%, transparent)`}} />}- {/* The view itself, over the views and dragged anywhere on the map. */}- <Surface aria-hidden="true" color="primary" material={{ opacity: 0.3, backdrop: 0 }} radius="small" className="cursor-grab touch-none active:cursor-grabbing"- style={{ position: "absolute", left: mapX(viewport.offset.x) - cell.width / 2, top: mapY(viewport.offset.y) - cell.height / 2, width: cell.width, height: cell.height }}- onPointerDown={grab} onPointerMove={follow} onPointerUp={release} onPointerCancel={() => { drag.current = null; setSettle(null) }} />+ {/* The view itself, over the views and dragged anywhere on the map. It travels with the+ same motion as the view it stands for; under a dragging hand it follows at once. */}+ <motion.div className="absolute left-0 top-0" style={{ width: cell.width, height: cell.height }} initial={false}+ animate={{ x: mapX(viewport.offset.x) - cell.width / 2, y: mapY(viewport.offset.y) - cell.height / 2 }}+ transition={viewport.transaction && !reducedMotion ? motionTransition(viewport.transaction) : { duration: 0 }}>+ <Surface aria-hidden="true" color="primary" material={{ opacity: 0.3, backdrop: 0 }} radius="small" className="cursor-grab touch-none active:cursor-grabbing"+ style={{ width: "100%", height: "100%" }}+ onPointerDown={grab} onPointerMove={follow} onPointerUp={release} onPointerCancel={() => { drag.current = null; setSettle(null) }} />+ </motion.div>{/* The Windows above everything, since they are dragged too. */}{windows.map(window => <MapWindow key={window.identity} window={window} viewport={viewport} menus={menus} mapX={mapX} mapY={mapY} cell={cell} />)}@@ -451,6 +647,14 @@ function MapWindow({ window, viewport, menus, mapX, mapY, cell }: Readonly<{const shown = dragged ?? center+ // The card travels with the motion its Window takes, chosen from how far it goes; under a+ // dragging hand it follows at once.+ const reducedMotion = useReducedMotion()+ const last = useRef(center)+ const distance = Math.hypot(center.x - last.current.x, center.y - last.current.y)+ useEffect(() => { last.current = center }, [center.x, center.y])+ const cardMotion = dragged || reducedMotion ? { duration: 0 } : motionTransition(motionAcross(distance, "window"))+const icon = space.medium + space.xsmallconst card = icon + space.xsmall * 2@@ -508,8 +712,9 @@ function MapWindow({ window, viewport, menus, mapX, mapY, cell }: Readonly<{addEventListener("pointercancel", end)}- return <div className="absolute touch-none" onPointerDownCapture={down}- style={{ left: mapX(shown.x) - card / 2, top: mapY(shown.y) - card / 2, width: card, height: card }}>+ return <motion.div className="absolute left-0 top-0 touch-none" onPointerDownCapture={down}+ style={{ width: card, height: card }} initial={false}+ animate={{ x: mapX(shown.x) - card / 2, y: mapY(shown.y) - card / 2 }} transition={cardMotion}>{/* Its title shows on hover and focus, above the card; a press, and so a drag, closes it. */}<Tooltip>@@ -546,7 +751,7 @@ function MapWindow({ window, viewport, menus, mapX, mapY, cell }: Readonly<{<Maximize2 style={{ width: mark * 0.6, height: mark * 0.6 }} strokeWidth={2.5} /></Surface>}- </div>+ </motion.div>}/** What sets a Window apart on the map, in words. */@@ -587,3 +792,12 @@ function clamp(value: number, minimum: number, maximum: number) {return Math.min(maximum, Math.max(minimum, value))}++/** The placement a Window takes against edges of the Desktop: a half against a side, a quarter in a corner. */+function placementAt(direction: Readonly<{ x: number, y: number }>): SnapTarget {++ return {+ position: { x: direction.x > 0 ? "0/1" : "-1/2", y: direction.y > 0 ? "0/1" : "-1/2" },+ size: { width: direction.x ? "1/2" : "1/1", height: direction.y ? "1/2" : "1/1" }+ }+}diff --git a/source/client/view/structure/desktop/motion-across.ts b/source/client/view/structure/desktop/motion-across.tsnew file mode 100644index 0000000..e84ba04--- /dev/null+++ b/source/client/view/structure/desktop/motion-across.ts@@ -0,0 +1,50 @@+import { type AppearanceTransaction, type Easing } from "@phreshos/core"++/**+ * The motion of anything the Desktop carries across a distance: the view over the plane, and a+ * standard Window moving, resizing, filling the view, or leaving for the Taskbar. It is chosen for+ * each move from how far it goes, not taken from the Appearance timing: a fixed short time would+ * cross a far distance so fast that frames show as jumps. So the time grows with the distance,+ * gently, as the square root, within bounds, on a curve that starts and ends softly.+ */+export default function motionAcross(distance: number, body: MovingBody = "view", departing = false): AppearanceTransaction {++ const pace = paces[body]++ // Near, the time grows as the square root; a long crossing adds a little more for each pixel+ // past a first stretch, so a far journey is not crossed at a rush.+ const duration = Math.round(Math.min(pace.maximum, Math.max(pace.minimum, pace.base + pace.growth * Math.sqrt(distance) + pace.far * Math.max(0, distance - 1000))))++ // What arrives slows as it lands; what departs, seen only as it sets off, must start softly, or+ // it is gone in the first frames.+ return Object.freeze({ duration, easing: departing ? departure : pace.easing })+}++/**+ * What is moving. The view is a camera crossing a whole scene: it sets off softly and travels+ * slowly. A Window is a light body answering a hand: it sets off at once and settles softly, and+ * the same distance takes it less time.+ */+export type MovingBody = "view" | "window"++/** The curve of something leaving the view: soft to start, gathering speed as it goes. */+const departure = [0.65, 0, 0.35, 1] as const++type Pace = Readonly<{ base: number, growth: number, far: number, minimum: number, maximum: number, easing: Easing }>++const paces: Record<MovingBody, Pace> = {+ // The view moves as a body on a spring: it arrives without passing its place, and a new move+ // taken on the way carries on from how fast it is already going.+ view: { base: 220, growth: 10, far: 0, minimum: 300, maximum: 1000, easing: Object.freeze({ spring: Object.freeze({ bounce: 0 }) }) },+ window: { base: 85, growth: 4, far: 0.05, minimum: 130, maximum: 650, easing: [0.22, 1, 0.36, 1] }+}++/** How far a box travels between two places: its center's path, and half of how much its size changes. */+export function travel(from: Box, to: Box) {++ const moved = Math.hypot(to.x + to.width / 2 - from.x - from.width / 2, to.y + to.height / 2 - from.y - from.height / 2)++ return moved + Math.hypot(to.width - from.width, to.height - from.height) / 2+}++type Box = Readonly<{ x: number, y: number, width: number, height: number }>diff --git a/source/client/view/structure/desktop/plane-slide.tsx b/source/client/view/structure/desktop/plane-slide.tsxnew file mode 100644index 0000000..80a5fd4--- /dev/null+++ b/source/client/view/structure/desktop/plane-slide.tsx@@ -0,0 +1,109 @@+import { createContext, useLayoutEffect, useRef, type ReactNode } from "react"+import { animate, motion, useMotionValue, type MotionValue } from "motion/react"+import { type AppearanceTransaction } from "@phreshos/core"+import { useReducedMotion } from "@libs/react-motion"+import { motionTransition } from "@client/view/appearance/motion"+import { type ViewportOffset, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"++export type PlaneSlideValue = Readonly<{ x: MotionValue<number>, y: MotionValue<number> }>++/**+ * How far the shown view is from the grid of whole views, in pixels: zero on a whole view, and a+ * part of one when the Desktop looks between two, so a Window can find the edges of its own view.+ * It changes on every step of a dragged view, so it is a store a Window reads and follows, not a+ * value that would redraw every Window on each step: a Window redraws only when its own margins do.+ */+export class CellShiftStore {++ private value: Readonly<{ x: number, y: number }> = Object.freeze({ x: 0, y: 0 })++ private readonly listeners = new Set<() => void>()++ public readonly get = () => this.value++ public readonly subscribe = (listener: () => void) => {+ this.listeners.add(listener)+ return () => { this.listeners.delete(listener) }+ }++ /**+ * Takes the new shift while the Desktop draws, before its Windows do, so every Window draws its+ * new place with the shift of the same moment. A Window that paints its margins from a place and a+ * shift of two different moments flips a margin and back, and the Program inside feels both.+ */+ public take(next: Readonly<{ x: number, y: number }>) {+ if (next.x === this.value.x && next.y === this.value.y) return+ this.value = Object.freeze({ ...next })+ }++ /** Tells the Windows that did not draw again, once the Desktop's drawing is done. */+ public announce() {+ for (const listener of this.listeners) listener()+ }+}++export const ViewCellShift = createContext(new CellShiftStore())++/** The plane's current glide, for a Window held by a hand, which stays under the hand instead. */+export const PlaneSlideContext = createContext<PlaneSlideValue | null>(null)++/**+ * When the view moves, what lives on the plane glides there on the motion the move was given instead of+ * jumping. Everything is already drawn where the view now is, and the Desktop announced the new+ * view at once; this only shifts the drawing back to where it was, then lets it go, so one+ * transform moves the whole plane. A resize changes the pixels of the view, not where it looks,+ * so it does not glide, and neither does a view placed under a hand that drags it.+ */+export function usePlaneSlide(views: ViewportOffset, transaction: AppearanceTransaction | null, surface: WindowSurfaceSize): PlaneSlideValue {++ const x = useMotionValue(0)++ const y = useMotionValue(0)++ const reduced = useReducedMotion()++ const previous = useRef(views)++ useLayoutEffect(() => {++ const from = previous.current++ previous.current = views++ const moved = { x: (views.x - from.x) * surface.width, y: (views.y - from.y) * surface.height }++ if (!moved.x && !moved.y) return++ // A view placed under a dragging hand follows it directly; the hand is already smooth.+ if (reduced || !transaction) {++ x.set(0)++ y.set(0)++ return+ }++ // A glide still on its way continues from where it is shown.+ x.set(x.get() + moved.x)++ y.set(y.get() + moved.y)++ const timing = motionTransition(transaction)++ const across = animate(x, 0, timing)++ const down = animate(y, 0, timing)++ return () => { across.stop(); down.stop() }++ }, [views.x, views.y])++ return { x, y }+}++/** Holds what moves with the plane, so the view's glide moves it as one. */+export function PlaneSlide({ slide, children }: Readonly<{ slide: PlaneSlideValue, children: ReactNode }>) {++ return <motion.div data-plane-slide="" className="pointer-events-none absolute inset-0" style={{ x: slide.x, y: slide.y }}>{children}</motion.div>+}diff --git a/source/client/view/structure/desktop/viewport-offset.ts b/source/client/view/structure/desktop/viewport-offset.tsindex 8fa089d..45840aa 100644--- a/source/client/view/structure/desktop/viewport-offset.ts+++ b/source/client/view/structure/desktop/viewport-offset.ts@@ -1,4 +1,6 @@-import { useCallback, useMemo, useState } from "react"+import { useCallback, useMemo, useRef, useState } from "react"+import { progressAt, type AppearanceTransaction } from "@phreshos/core"+import motionAcross from "./motion-across"import { planeReach, type ViewportOffset, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"/**@@ -12,22 +14,78 @@ import { planeReach, type ViewportOffset, type WindowSurfaceSize } from "@client*/export default function useViewportOffset(surface: WindowSurfaceSize) {- const [views, setViews] = useState<ViewportOffset>(origin)+ // How the view gets to where it goes: a move to a whole view takes a motion chosen from how far+ // it goes; placing the view under a hand that drags it follows the hand at once, with none. The+ // motion on its way is kept, so a move taken during it starts from where the view is shown and+ // carries on at the speed it already has.+ const [{ views, transaction }, setState] = useState<ViewportState>({ views: origin, transaction: null, journey: null })++ const size = useRef(surface)++ size.current = surface++ const setViews = useCallback((next: ViewportOffset, glides = true) => setState(current => {++ if (!glides) return { views: next, transaction: null, journey: null }++ const now = performance.now()++ const { width, height } = size.current++ // Where the view is shown now, and how fast it moves there, in pixels a second.+ let from = { x: current.views.x * width, y: current.views.y * height }++ let speed = { x: 0, y: 0 }++ const on = current.journey++ if (on && now - on.start < on.transaction.duration) {++ const elapsed = now - on.start++ const along = progressAt(on.transaction, elapsed)++ const pace = (progressAt(on.transaction, elapsed + 8) - progressAt(on.transaction, Math.max(0, elapsed - 8))) / (elapsed >= 8 ? 16 : elapsed + 8) * 1000++ from = { x: on.from.x + (on.to.x - on.from.x) * along, y: on.from.y + (on.to.y - on.from.y) * along }++ speed = { x: (on.to.x - on.from.x) * pace, y: (on.to.y - on.from.y) * pace }+ }++ const to = { x: next.x * width, y: next.y * height }++ const path = { x: to.x - from.x, y: to.y - from.y }++ const distance = Math.hypot(path.x, path.y)++ if (distance === 0) return { views: next, transaction: null, journey: null }++ const motion = motionAcross(distance)++ // The speed it already has, in lengths of the new journey a second.+ const velocity = (speed.x * path.x + speed.y * path.y) / (distance * distance)++ const transaction: AppearanceTransaction = typeof motion.easing === "object" && "spring" in motion.easing+ ? Object.freeze({ duration: motion.duration, easing: Object.freeze({ spring: Object.freeze({ ...motion.easing.spring, velocity }) }) })+ : motion++ return { views: next, transaction, journey: { from, to, transaction, start: now } }+ }), [])/** Moves the view to one whole view, counted from the plane's center. */- const moveTo = useCallback((view: ViewportOffset) => setViews({ x: within(view.x), y: within(view.y) }), [])+ const moveTo = useCallback((view: ViewportOffset) => setViews({ x: within(view.x), y: within(view.y) }), [setViews])/** Places the view at any point of the plane in pixels, not only whole views; its center stays over the plane's outer views. */const place = useCallback(function (point: ViewportOffset) {if (!surface.width || !surface.height) return- setViews({ x: within(point.x / surface.width), y: within(point.y / surface.height) })+ setViews({ x: within(point.x / surface.width), y: within(point.y / surface.height) }, false)- }, [surface.width, surface.height])+ }, [surface.width, surface.height, setViews])/** Returns the view to the plane's center. */- const home = useCallback(() => setViews(origin), [])+ const home = useCallback(() => setViews(origin), [setViews])// The same place in pixels, at the current size.const offset = useMemo<ViewportOffset>(() => ({ x: Math.round(views.x * surface.width), y: Math.round(views.y * surface.height) }), [views, surface.width, surface.height])@@ -35,11 +93,18 @@ export default function useViewportOffset(surface: WindowSurfaceSize) {// The nearest whole view from the center, which is what a person counts.const view = { x: Math.round(views.x), y: Math.round(views.y) }- return { views, offset, view, surface, moveTo, place, home }+ return { views, transaction, offset, view, surface, moveTo, place, home }}export type ViewportControl = ReturnType<typeof useViewportOffset>+type ViewportState = Readonly<{+ views: ViewportOffset+ transaction: AppearanceTransaction | null+ /** The glide on its way, in pixels of the plane, and when it set off. */+ journey: Readonly<{ from: ViewportOffset, to: ViewportOffset, transaction: AppearanceTransaction, start: number }> | null+}>+function within(value: number) {return Math.min(planeReach, Math.max(-planeReach, value))diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsxindex feec91a..f3d0fdd 100644--- a/source/client/view/structure/desktop/windows/process-window.tsx+++ b/source/client/view/structure/desktop/windows/process-window.tsx@@ -1,3 +1,4 @@+import { type WindowRegion } from "@client/view/components/window-manager/window-geometry"import Process from "@client/core/link-manager/auth-manager/process-manager/process"import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"import { type PaintMargins, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"@@ -25,7 +26,7 @@ export function processWindowProgress(layer: WindowLayer, loading: boolean, stop* props so memoization can see which process actually changed even though* the peer deliberately keeps each Process instance alive and mutates it.*/-export default memo(function ({ identity, record, assetId, client, title, header, surface, layer, icon, position, size, taskbarPosition, surfaceAnimation, geometryAnimation, minimizeAnimation, onPresentationAnimationComplete, onPresentationRepresentation, onPresentationMoveGesture, paintSurfaceSize, paintMargins, spacing, depth, active, minimized, maximized, maximizedPosition, interactive, closing, stopping, entering, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {+export default memo(function ({ identity, record, assetId, client, title, header, surface, layer, icon, position, size, taskbarPosition, surfaceAnimation, geometryAnimation, minimizeAnimation, onPresentationAnimationComplete, onPresentationRepresentation, onPresentationMoveGesture, paintSurfaceSize, paintMargins, spacing, depth, active, minimized, maximized, maximizedPosition, interactive, closing, stopping, entering, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap, onEdgeHold, onNeighbours }: ProcessWindowProps) {const activate = useCallback(() => onRaise(record), [onRaise, record])@@ -47,6 +48,8 @@ export default memo(function ({ identity, record, assetId, client, title, headerconst snap = useCallback((position: Position, size: Size) => onSnap(record, position, size), [onSnap, record])+ const neighbours = useCallback(() => onNeighbours?.(record.identity) ?? [], [onNeighbours, record])+const represent = useCallback((representation: PresentationGeometryRepresentation | null) => onPresentationRepresentation(record.identity, representation), [onPresentationRepresentation, record])const moveGesture = useCallback((controller: DesktopMoveGestureController | null) => onPresentationMoveGesture(record.identity, controller), [onPresentationMoveGesture, record])@@ -176,6 +179,10 @@ export default memo(function ({ identity, record, assetId, client, title, headeronSnap={snap}+ onEdgeHold={onEdgeHold}++ neighbours={onNeighbours ? neighbours : undefined}+>{/* A launch names one of its client half's own pages; joining it@@ -314,6 +321,12 @@ interface ProcessWindowProps {onResize: (record: Process, width: number, height: number, position: { x: number, y: number } | null) => Promise<boolean>onSnap: (record: Process, position: Position, size: Size) => Promise<boolean>++ /** A hand holding the Window against an edge asks the view to go that way; see Window. */+ onEdgeHold?: (direction: Readonly<{ x: number, y: number }>) => number | null++ /** Where the other open standard Windows stand in this view; see Window. */+ onNeighbours?: (identity: string) => readonly WindowRegion[]}interface LoadingState {diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsxindex 23742e9..b8c26ed 100644--- a/source/client/view/structure/desktop/windows/snap-preview.tsx+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx@@ -7,7 +7,7 @@ import { motionTransition } from "@client/view/appearance/motion"import useWindowGeometryMotion from "./window-geometry-motion"/** Preview of the placement currently offered by a drag. */-export default function SnapPreview({ shown, visible, bare, minimumSize, paintSurfaceSize, paintInset, paintMargins, reducedMotion, zIndex }: SnapPreviewProps) {+export default function SnapPreview({ shown, visible, blocked = false, bare, minimumSize, paintSurfaceSize, paintInset, paintMargins, reducedMotion, zIndex }: SnapPreviewProps) {const transaction = useAppearance().transaction@@ -33,6 +33,8 @@ export default function SnapPreview({ shown, visible, bare, minimumSize, paintSu><Surfacedata-snap-preview-frame+ // Held where the plane goes no further, the same surface in a soft danger.+ color={blocked ? "danger:soft" : undefined}material={{ opacity: "small" }}style={{position: "absolute",@@ -51,6 +53,8 @@ export interface SnapTarget {interface SnapPreviewProps {shown: SnapTargetvisible: boolean+ /** The hand holds the Window against the plane's end. */+ blocked?: booleanbare: booleanminimumSize?: WindowSurfaceSizepaintSurfaceSize: WindowSurfaceSizediff --git a/source/client/view/structure/desktop/windows/window-geometry-motion.ts b/source/client/view/structure/desktop/windows/window-geometry-motion.tsindex 000098f..65242bb 100644--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts@@ -5,6 +5,7 @@ import { type AppearanceTransaction, type Position, type Size, type Presentationimport { useMotionValue, useTransform, type MotionStyle } from "motion/react"import { useLayoutEffect, useRef } from "react"import { WindowGeometryAnimation } from "./window-geometry-animation"+import motionAcross, { travel } from "../motion-across"import { useAppearance } from "@phreshos/react-ui"interface WindowGeometryMotionOptions {@@ -13,6 +14,11 @@ interface WindowGeometryMotionOptions {animation?: PresentationAnimation | nulltransaction?: PresentationTransaction | nullimmediate: boolean+ /**+ * A standard Window, which the Desktop moves itself: its motions are chosen from how far it+ * goes, not taken from the Appearance timing. A raw drawing keeps the timing its Program asked.+ */+ standard?: boolean/** Moves visibly only when the person can see where it starts or where it ends; otherwise it is simply there. */seenOnly?: booleanminimumSize?: WindowSurfaceSize@@ -26,7 +32,7 @@ interface WindowGeometryMotionOptions {* visible pixels, including during a pointer gesture, so releasing a drag* cannot hand the transform to another renderer before snapping begins.*/-export default function useWindowGeometryMotion({ position, size, animation, transaction, immediate, seenOnly = false, minimumSize, onComplete }: WindowGeometryMotionOptions) {+export default function useWindowGeometryMotion({ position, size, animation, transaction, immediate, standard = false, seenOnly = false, minimumSize, onComplete }: WindowGeometryMotionOptions) {const appearanceTransaction = useAppearance().transactionconst frame = useRef<HTMLDivElement>(null)@@ -45,9 +51,9 @@ export default function useWindowGeometryMotion({ position, size, animation, traconst gestureRevision = useRef(0)const restoringGesture = useRef(false)const initialized = useRef(false)- const values = useRef({ position, size, animation, transaction, immediate, seenOnly, minimumSize, onComplete })+ const values = useRef({ position, size, animation, transaction, immediate, standard, seenOnly, minimumSize, onComplete })- values.current = { position, size, animation, transaction, immediate, seenOnly, minimumSize, onComplete }+ values.current = { position, size, animation, transaction, immediate, standard, seenOnly, minimumSize, onComplete }function read(): WindowRegion {@@ -90,7 +96,20 @@ export default function useWindowGeometryMotion({ position, size, animation, traset(region)}- function transition(region: WindowRegion, transaction: AppearanceTransaction = appearanceTransaction, complete?: () => void) {+ /**+ * The motion to a place when none was asked for: a standard Window's comes from how far it goes,+ * and from whether it leaves the person's sight on the way.+ */+ function timingTo(region: WindowRegion) {++ if (!values.current.standard) return appearanceTransaction++ const from = read()++ return motionAcross(travel(from, region), "window", seen(from) && !seen(region))+ }++ function transition(region: WindowRegion, transaction: AppearanceTransaction = timingTo(region), complete?: () => void) {if (immediate) {@@ -118,15 +137,20 @@ export default function useWindowGeometryMotion({ position, size, animation, trareturn values.current.minimumSize ? constrainWindowGeometry(region, surface, values.current.minimumSize) : region}- /** Whether the person can see where the box is now or where it is going: either touches the screen. */- function seenAtAnEnd(region: WindowRegion) {+ /** Whether a box on the plane touches the screen. */+ function seen(shown: WindowRegion) {const parent = frame.current?.parentElementif (!parent) return falseconst surface = logicalSize(parent)- const seen = (shown: WindowRegion) => shown.x < surface.width && shown.x + shown.width > 0 && shown.y < surface.height && shown.y + shown.height > 0++ return shown.x < surface.width && shown.x + shown.width > 0 && shown.y < surface.height && shown.y + shown.height > 0+ }++ /** Whether the person can see where the box is now or where it is going. */+ function seenAtAnEnd(region: WindowRegion) {return seen(read()) || seen(region)}@@ -150,7 +174,7 @@ export default function useWindowGeometryMotion({ position, size, animation, tra}const selected = animation- ? resolveWindowTransaction(animation.transaction, appearanceTransaction)+ ? animation.transaction === undefined ? timingTo(region) : resolveWindowTransaction(animation.transaction, appearanceTransaction): transaction === undefined || transaction === null? null: resolveWindowTransaction(transaction, appearanceTransaction)@@ -199,7 +223,7 @@ export default function useWindowGeometryMotion({ position, size, animation, tra}, [])- useLayoutEffect(() => stop, [])+ useLayoutEffect(() => () => { stopChase(); stop() }, [])function beginGesture() {@@ -210,6 +234,7 @@ export default function useWindowGeometryMotion({ position, size, animation, tracompleteGestureRestore()gesturing.current = trueconst revision = ++gestureRevision.current+ stopChase()stop()const physical = parent.getBoundingClientRect()@@ -221,11 +246,65 @@ export default function useWindowGeometryMotion({ position, size, animation, tra}}+ // A dragged box does not jump to each pointer event: it chases the pointer's place each frame,+ // which melts the hand's small jolts and keeps its intent.+ const chase = useRef<{ target: WindowRegion, frame: number, last: number } | null>(null)++ function stopChase() {++ if (chase.current?.frame) cancelAnimationFrame(chase.current.frame)++ chase.current = null+ }++ function follow(time: number) {++ const state = chase.current++ if (!state) return++ const step = state.last ? Math.min(time - state.last, 64) : 16++ state.last = time++ const share = values.current.immediate ? 1 : 1 - Math.exp(-step / 16)++ const shown = read()++ const next = {+ x: shown.x + (state.target.x - shown.x) * share,+ y: shown.y + (state.target.y - shown.y) * share,+ width: shown.width + (state.target.width - shown.width) * share,+ height: shown.height + (state.target.height - shown.height) * share+ }++ if (restoringGesture.current) animator.current!.setPosition(next)++ else set(next)++ const near = Math.abs(state.target.x - next.x) < 0.5 && Math.abs(state.target.y - next.y) < 0.5 && Math.abs(state.target.width - next.width) < 0.5 && Math.abs(state.target.height - next.height) < 0.5++ if (near) {++ if (restoringGesture.current) animator.current!.setPosition(state.target)++ else set(state.target)++ state.frame = 0++ return+ }++ state.frame = requestAnimationFrame(follow)+ }+function updateGesture(region: WindowRegion) {- if (restoringGesture.current) animator.current!.setPosition(region)+ if (!chase.current) chase.current = { target: region, frame: 0, last: 0 }- else set(region)+ chase.current.target = region++ if (!chase.current.frame) chase.current.frame = requestAnimationFrame(follow)}function restoreGesture(region: WindowRegion) {@@ -238,7 +317,7 @@ export default function useWindowGeometryMotion({ position, size, animation, trarestoringGesture.current = truetransformOrigin.set(`${originX}px ${originY}px`)- animator.current!.transitionSize(region, appearanceTransaction, () => {+ animator.current!.transitionSize(region, values.current.standard ? motionAcross(Math.hypot(region.width - shown.width, region.height - shown.height), "window") : appearanceTransaction, () => {completeGestureRestore()})@@ -248,6 +327,8 @@ export default function useWindowGeometryMotion({ position, size, animation, traif (gestureRevision.current !== revision) return false+ stopChase()+completeGestureRestore()transition(region)@@ -258,6 +339,8 @@ export default function useWindowGeometryMotion({ position, size, animation, traif (gestureRevision.current !== revision) return false+ stopChase()+// The authoritative request has now settled. The visible values// already express its result, so ownership can change without// retargeting Motion through an earlier server snapshot.@@ -270,6 +353,8 @@ export default function useWindowGeometryMotion({ position, size, animation, traif (gestureRevision.current !== revision) return false+ stopChase()+gesturing.current = falseif (region) {@@ -285,6 +370,8 @@ export default function useWindowGeometryMotion({ position, size, animation, traif (gestureRevision.current !== revision) return false+ stopChase()+gesturing.current = falsecompleteGestureRestore()diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 066ae33..3e2e90b 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -1,4 +1,4 @@-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"+import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react"import { useReducedMotion } from "@libs/react-motion"import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"import WindowPanel from "./window-panel"@@ -8,11 +8,14 @@ import WindowHeader from "./window-header"import WindowSurface, { windowSurfaceRadius } from "./window-surface"import { type PresentationAnimation, type DesktopMoveGestureController, type DesktopMovePoint } from "@client/view/components/desktop-host/presentation"import { type PresentationGeometryRepresentation } from "@client/view/components/window-manager/presentations"-import { motion } from "motion/react"+import { motion, useMotionValue, type MotionValue } from "motion/react"+import { PlaneSlideContext, ViewCellShift } from "../plane-slide"+import { EdgeHold, against } from "../edge-hold"import { motionTransition, resolveWindowTransaction } from "@client/view/appearance/motion"import { useAppearance, Window as UIWindow } from "@phreshos/react-ui"import SnapPreview, { type SnapTarget } from "./snap-preview"import useWindowGeometryMotion from "./window-geometry-motion"+import motionAcross from "../motion-across"import WindowGestureCommit from "./window-gesture-commit"import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"import { createPortal } from "react-dom"@@ -68,7 +71,7 @@ export function windowMinimizePose(position: TaskbarPosition) {const wholeView: Position = Object.freeze({ x: "-1/2", y: "-1/2" })-export default function ({ title, header = true, surface, layer, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onPresentationAnimationComplete, onPresentationRepresentation, onPresentationMoveGesture, onFocusCapture, active = false, closing = false, stopping = false, minimized = false, maximized = false, maximizedPosition = wholeView, interactive = true, entering = false, position = { x: 0, y: 0 }, size = { width: 0, height: 0 }, taskbarPosition = "bottom", surfaceAnimation, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, paintMargins = noPaintMargins, spacing = 0, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {+export default function ({ title, header = true, surface, layer, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onPresentationAnimationComplete, onPresentationRepresentation, onPresentationMoveGesture, onFocusCapture, onEdgeHold, neighbours, active = false, closing = false, stopping = false, minimized = false, maximized = false, maximizedPosition = wholeView, interactive = true, entering = false, position = { x: 0, y: 0 }, size = { width: 0, height: 0 }, taskbarPosition = "bottom", surfaceAnimation, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, paintMargins = noPaintMargins, spacing = 0, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {const reducedMotion = useReducedMotion()const appearance = useAppearance()@@ -97,6 +100,7 @@ export default function ({ title, header = true, surface, layer, icon, children,size: presented.current.size,animation: geometryAnimation,immediate: reducedMotion,+ standard,// The Desktop moves its own Windows visibly only when the person sees one end or both; a// raw drawing moves the way its Program asked.seenOnly: standard,@@ -106,6 +110,20 @@ export default function ({ title, header = true, surface, layer, icon, children,const frameElement = geometryMotion.frame+ // A drag reads the handlers as they are when it acts, not as they were when it began: the view+ // can move under a held Window, and where the Window lands depends on where the view is then.+ const latest = useRef({ onMove, onResize, onSnap, onEdgeHold, neighbours })++ latest.current = { onMove, onResize, onSnap, onEdgeHold, neighbours }++ // While a hand holds a standard Window, the plane may glide beneath it; the Window stays under+ // the hand by taking that glide back.+ const slide = useContext(PlaneSlideContext)+ const cellShift = useContext(ViewCellShift)+ const held = useMotionValue(0)+ const shownX = useHeldAgainst(geometryMotion.style.x, held, slide?.x)+ const shownY = useHeldAgainst(geometryMotion.style.y, held, slide?.y)+const [gesture, setGesture] = useState<Gesture | null>(null)const [settlingGeometry, setSettlingGeometry] = useState<WindowRegion | null>(null)const [externalMoveActive, setExternalMoveActive] = useState(false)@@ -249,11 +267,18 @@ export default function ({ title, header = true, surface, layer, icon, children,}, [minimizeAnimation?.revision, reducedMotion])- const entryTransaction = standard ? appearanceTransaction : null+ // A standard Window's motions are the Desktop's own, chosen from its size: appearing and leaving+ // happen in place, so they cover little of it; leaving for the Taskbar crosses more.+ const shownBox = geometryMotion.read()+ const reach = Math.hypot(shownBox.width, shownBox.height)+ const presenceMotion = motionAcross(reach * 0.35, "window")+ const entryTransaction = standard ? presenceMotion : nullconst opening = entering && !reducedMotion ? entryTransaction : nullconst [opened, setOpened] = useState(opening === null)const minimizeTransaction = minimizeAnimation- ? resolveWindowTransaction(minimizeAnimation.transaction, appearanceTransaction)+ ? standard && minimizeAnimation.transaction === undefined+ ? motionAcross(reach * 0.75, "window")+ : resolveWindowTransaction(minimizeAnimation.transaction, appearanceTransaction): nullconst initialPresence = standard? opening ? windowSurfaceLifecyclePose.hidden : windowSurfaceLifecyclePose.visible@@ -268,7 +293,7 @@ export default function ({ title, header = true, surface, layer, icon, children,const presenceTransition = reducedMotion? { duration: 0 }: closing && standard- ? motionTransition(appearanceTransaction)+ ? motionTransition(presenceMotion): minimizeTransaction? surfacePresenceTransition(false, minimizeTransaction): !opened && opening@@ -291,6 +316,83 @@ export default function ({ title, header = true, surface, layer, icon, children,}}+ /**+ * A double press on a standard Window's edge takes that edge as far as it can go that way: to+ * the nearest Window facing it there, or to the edge of the view. A corner takes both its edges.+ * The space kept between them is painted, so the edge goes all the way.+ */+ function extendEdge(edge: WindowEdge) {++ if (!standard || maximized) return++ const started = geometryMotion.beginGesture()++ if (!started) return++ const { bounds, revision, region: from } = started++ const others = latest.current.neighbours?.() ?? []++ const acrossY = (other: WindowRegion) => other.y < from.y + from.height && other.y + other.height > from.y++ const acrossX = (other: WindowRegion) => other.x < from.x + from.width && other.x + other.width > from.x++ let { x, y, width, height } = from++ if (edge.includes("e")) {++ const right = Math.min(bounds.width, ...others.filter(other => acrossY(other) && other.x >= from.x + from.width - 1).map(other => other.x))++ if (right > from.x + from.width) width = right - x+ }++ if (edge.includes("w")) {++ const left = Math.max(0, ...others.filter(other => acrossY(other) && other.x + other.width <= from.x + 1).map(other => other.x + other.width))++ if (left < from.x) { width += from.x - left; x = left }+ }++ if (edge.includes("s")) {++ const bottom = Math.min(bounds.height, ...others.filter(other => acrossX(other) && other.y >= from.y + from.height - 1).map(other => other.y))++ if (bottom > from.y + from.height) height = bottom - y+ }++ if (edge.includes("n")) {++ const top = Math.max(0, ...others.filter(other => acrossX(other) && other.y + other.height <= from.y + 1).map(other => other.y + other.height))++ if (top < from.y) { height += from.y - top; y = top }+ }++ const target = { x, y, width, height }++ if (x === from.x && y === from.y && width === from.width && height === from.height) {++ geometryMotion.finishGesture(undefined, revision)++ return+ }++ // Shown on its way at once, and held until the System has recorded it, like a release.+ geometryMotion.targetGesture(revision, target)+ setSettlingGeometry(target)++ const placed = planeGeometry(target, bounds)+ const commit = new WindowGestureCommit()++ commit.request(() => latest.current.onResize?.(width, height, x === from.x && y === from.y ? null : { x: placed.x, y: placed.y }))++ void commit.settle().then(committed => {++ const current = committed ? geometryMotion.settleGesture(revision) : geometryMotion.cancelGesture(revision)++ if (current) setSettlingGeometry(null)+ })+ }+function grab(event: ReactPointerEvent<HTMLElement> | DesktopMovePoint, edge: WindowEdge | null, receive?: (gesture: ActivePointerGesture) => void) {if (maximized && edge !== null) return@@ -339,6 +441,22 @@ export default function ({ title, header = true, surface, layer, icon, children,let renderFrame = 0+ // A hand holding a standard Window against an edge of the screen takes the view that way; see+ // EdgeHold. Where the plane goes no further, the preview of the placement turns to danger.+ let blocked = false++ const edges = new EdgeHold(direction => latest.current.onEdgeHold?.(direction), held => {++ blocked = held++ renderGesture()+ })++ function holdAgainst(motion: DesktopMovePoint) {++ edges.update(against(physicalToDesktopPixels(motion.x - bounds!.left, desktopScale), physicalToDesktopPixels(motion.y - bounds!.top, desktopScale), bounds!.width, bounds!.height))+ }+const commit = new WindowGestureCommit()function request(operation: () => Promise<boolean> | undefined) {@@ -371,7 +489,7 @@ export default function ({ title, header = true, surface, layer, icon, children,renderFrame = 0- setGesture({ origin, current, zone, shown })+ setGesture({ origin, current, zone, shown, blocked })})}@@ -449,12 +567,12 @@ export default function ({ title, header = true, surface, layer, icon, children,const floating = planeGeometry(origin, bounds!)- request(() => onMove?.(floating.x, floating.y))+ request(() => latest.current.onMove?.(floating.x, floating.y))if (restoringMaximized) geometryMotion.restoreGesture(current)else geometryMotion.updateGesture(current)- setGesture({ origin, current, zone, shown })+ setGesture({ origin, current, zone, shown, blocked })return}@@ -466,6 +584,13 @@ export default function ({ title, header = true, surface, layer, icon, children,// Only the Desktop's own Windows snap; a raw drawing goes where it is taken.zone = moved && standard ? snapTerm(motion) : null+ if (moved && standard) {++ held.set(1)++ holdAgainst(motion)+ }+if (zone) shown = zone}@@ -500,6 +625,10 @@ export default function ({ title, header = true, surface, layer, icon, children,function release(motion: DesktopMovePoint, committed: boolean) {+ edges.stop()++ held.set(0)+if (renderFrame) cancelAnimationFrame(renderFrame)// A tiled press that never crossed the threshold changed@@ -522,7 +651,7 @@ export default function ({ title, header = true, surface, layer, icon, children,const target = resolvePresentedGeometry(term.position, term.size, bounds)geometryMotion.targetGesture(revision, target)setSettlingGeometry(target)- request(() => onSnap?.(term.position, term.size))+ request(() => latest.current.onSnap?.(term.position, term.size))settle()}@@ -533,13 +662,13 @@ export default function ({ title, header = true, surface, layer, icon, children,// The Desktop paints from the surface's corner; the System records from its center.const placed = planeGeometry(current, bounds!)- if (edge === null) request(() => onMove?.(placed.x, placed.y))+ if (edge === null) request(() => latest.current.onMove?.(placed.x, placed.y))// Only the west and north edges move the origin. A drag// on any other reports no position, because none was// chosen — and a position nobody chose would replace a// share with the pixels it happened to resolve to.- else request(() => onResize?.(current.width, current.height, current.x === origin.x && current.y === origin.y ? null : { x: placed.x, y: placed.y }))+ else request(() => latest.current.onResize?.(current.width, current.height, current.x === origin.x && current.y === origin.y ? null : { x: placed.x, y: placed.y }))settle()@@ -578,7 +707,7 @@ export default function ({ title, header = true, surface, layer, icon, children,cancel() { release(pointer, false) }})- setGesture({ origin, current, zone, shown })+ setGesture({ origin, current, zone, shown, blocked })}// ------------------------------------------------------------ render@@ -590,7 +719,10 @@ export default function ({ title, header = true, surface, layer, icon, children,// Pointer input may end before its authoritative mutation settles. Paint// follows the same locally owned geometry throughout that interval so an// old boundary contact cannot flash back for one frame.- const paintedInsets = windowPaintInsets(presented.current.position, presented.current.size, paintSurfaceSize, paintInset, paintMargins, gesture?.current ?? settlingGeometry ?? undefined)+ // Follows where the view looks from, but redraws only when this Window's own margins change.+ const insetsNow = () => windowPaintInsets(presented.current.position, presented.current.size, paintSurfaceSize, paintInset, paintMargins, gesture?.current ?? settlingGeometry ?? undefined, cellShift.get())+ const insetsKey = useSyncExternalStore(cellShift.subscribe, () => JSON.stringify(insetsNow()), () => JSON.stringify(insetsNow()))+ const paintedInsets = JSON.parse(insetsKey) as ReturnType<typeof windowPaintInsets>return <>@@ -613,6 +745,7 @@ export default function ({ title, header = true, surface, layer, icon, children,{gesture?.shown && <SnapPreviewshown={gesture.shown}visible={gesture.zone !== null}+ blocked={gesture.blocked === true}bare={!standard}minimumSize={presentationMinimum}paintSurfaceSize={paintSurfaceSize}@@ -649,7 +782,7 @@ export default function ({ title, header = true, surface, layer, icon, children,// Each window keeps its own compositor layer. Moving, raising, or// minimizing one window then only recomposites it, instead of// repainting the windows it shares a layer with.- style={{ ...style, left: 0, top: 0, willChange: "transform", ...geometryMotion.style }}+ style={{ ...style, left: 0, top: 0, willChange: "transform", ...geometryMotion.style, x: shownX, y: shownY }}{...props}@@ -734,6 +867,8 @@ export default function ({ title, header = true, surface, layer, icon, children,onPointerDown={event => grab(event, handle.edge)}+ onDoubleClick={() => extendEdge(handle.edge)}+className={`absolute touch-none ${handle.className}`}/>)}@@ -784,6 +919,16 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "onSnap?: (position: Position, size: Size) => Promise<boolean>+ /**+ * Asks the view to go one whole view toward an edge the Window is held against, as+ * { x, y } of -1, 0 or 1. It answers how long the view takes to get there, or null when the+ * plane does not go on that way.+ */+ onEdgeHold?: (direction: Readonly<{ x: number, y: number }>) => number | null++ /** Where the other open standard Windows stand in this view, for reaching toward them. */+ neighbours?: () => readonly WindowRegion[]+active?: booleanclosing?: boolean@@ -846,6 +991,9 @@ interface Gesture {zone: Snap | null+ /** Held against an edge where the plane goes no further. */+ blocked?: boolean+shown: Snap | null}@@ -860,3 +1008,27 @@ interface ExternalMove {markReady: () => voidfinish: () => void}++/**+ * Where a Window is shown: its own place, less the plane's glide while a hand holds it. It follows+ * every change at once, not on the next frame, so a Window and the plane it lives on are always+ * drawn from the same moment.+ */+function useHeldAgainst(place: MotionValue<number>, held: MotionValue<number>, glide: MotionValue<number> | undefined) {++ const shown = useMotionValue(place.get())++ useLayoutEffect(function () {++ const update = () => shown.set(place.get() - held.get() * (glide ? glide.get() : 0))++ update()++ const stops = [place, held, ...glide ? [glide] : []].map(value => value.on("change", update))++ return () => stops.forEach(stop => stop())++ }, [place, held, glide])++ return shown+}diff --git a/source/client/view/view.tsx b/source/client/view/view.tsxindex c4ba816..dd32395 100644--- a/source/client/view/view.tsx+++ b/source/client/view/view.tsx@@ -3,7 +3,7 @@ import Application, { type Doors } from "@client/core/application"import { ApplicationContext } from "./contexts"import Structure from "./structure/structure"import client from "react-dom/client"-import logo from "@/assets/bundled/logo.png"+import logo from "@/assets/logo.png"import { name, version } from "@/source/identity"export default function (config: Config) {diff --git a/source/server/core/application.ts b/source/server/core/application.tsindex 4f14a83..3dc61f5 100644--- a/source/server/core/application.ts+++ b/source/server/core/application.ts@@ -13,8 +13,8 @@ import SystemLogs from "./logs"export default class Application {- /** Filesystem-owned fallback used by the authoritative Program icon service. */- public readonly defaultProgramIcon: string+ /** The icon files the System renders: its own, and the one for a Program without an icon. */+ public readonly icons: ApplicationIconspublic readonly storage: FileManager@@ -43,7 +43,7 @@ export default class Application {private constructor(payload: ApplicationPayload) {- this.defaultProgramIcon = payload.defaultProgramIcon+ this.icons = payload.iconsthis.storage = payload.storage@@ -66,7 +66,7 @@ export default class Application {this.system = new System(this)}- public static async initialize(homePath: string, defaultProgramIcon: string) {+ public static async initialize(homePath: string, icons: ApplicationIcons) {const storage = new FileManager(homePath)@@ -80,7 +80,7 @@ export default class Application {const appearanceManager = await AppearanceManager.open(store, uploads)- const application = new Application({ defaultProgramIcon, storage, home, store, authentication, appearanceManager, uploads })+ const application = new Application({ icons, storage, home, store, authentication, appearanceManager, uploads })await application.linkManager.authManager.programManager.initialize()@@ -88,9 +88,12 @@ export default class Application {}}+/** Paths of the icon sources: the System's own, and the default for a Program without one. */+export type ApplicationIcons = Readonly<{ system: string, defaultProgram: string }>+interface ApplicationPayload {- defaultProgramIcon: string+ icons: ApplicationIconsstorage: FileManagerdiff --git a/source/server/core/link-manager/auth-manager/auth-manager.ts b/source/server/core/link-manager/auth-manager/auth-manager.tsindex 792f059..0fdaa62 100644--- a/source/server/core/link-manager/auth-manager/auth-manager.ts+++ b/source/server/core/link-manager/auth-manager/auth-manager.ts@@ -235,6 +235,12 @@ export default class AuthManager extends TheLink {return this.linkManager.application.system.about()}+ @Subscribe("/icon")+ protected icon(size: unknown) {++ return this.linkManager.application.system.icon(size)+ }+/** A Client's request to open something, forwarded by the Desktop showing it. */@Subscribe("/opening/open")protected async openForClient(process: unknown, target: unknown) {diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex b66009e..908cab1 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -29,7 +29,7 @@ import {type PermissionName,type PermissionRequestInput,type PermissionValue,- type ProgramIconSize,+ type IconSize,type ServerLaunch,type ServiceAddress,type WindowGeometry,@@ -2178,6 +2178,8 @@ export default class ProcessManager extends TheLink {if (word === "about") return [this.system.about()]+ if (word === "system-icon") return [await this.system.icon(rest[0])]+if (word === "appearance") return [this.system.appearance]if (word === "update-appearance") {@@ -2331,7 +2333,7 @@ export default class ProcessManager extends TheLink {if (word === "service-program-metadata") return [await this.serviceProgramMetadata(heldService(rest[0]))]- if (word === "service-program-icon") return [await this.serviceProgramIcon(heldService(rest[0]), rest[1] as ProgramIconSize | undefined)]+ if (word === "service-program-icon") return [await this.serviceProgramIcon(heldService(rest[0]), rest[1] as IconSize | undefined)]if (word === "service-follow") {diff --git a/source/server/core/link-manager/auth-manager/program-manager/icon.ts b/source/server/core/link-manager/auth-manager/program-manager/icon.tsindex 913d550..ec6db50 100644--- a/source/server/core/link-manager/auth-manager/program-manager/icon.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/icon.ts@@ -1,8 +1,10 @@import { stat } from "node:fs/promises"-import { type ProgramIconSize } from "@phreshos/core"+import { type IconSize } from "@phreshos/core"import type Program from "./program"import sharp from "sharp"+export type { IconSize }+export const iconSizes = {small: 32,@@ -13,7 +15,6 @@ export const iconSizes = {} as const-export type IconSize = ProgramIconSizeexport function isIconSize(value: unknown): value is IconSize {diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.tsindex 127d5cc..7f794ac 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -98,7 +98,7 @@ export default class ProgramManager extends TheLink {this.authManager = authManager- this.icons = new ProgramIcons(authManager.linkManager.application.defaultProgramIcon)+ this.icons = new ProgramIcons(authManager.linkManager.application.icons.defaultProgram)this.connectTo(this.authManager, "/program")}diff --git a/source/server/core/system.ts b/source/server/core/system.tsindex 2e83515..82ee7f4 100644--- a/source/server/core/system.ts+++ b/source/server/core/system.ts@@ -1,5 +1,6 @@import type Application from "./application"import { name, release, version } from "@/source/identity"+import { IconRenderer, isIconSize } from "./link-manager/auth-manager/program-manager/icon"import type Entry from "./link-manager/auth-manager/program-manager/entry"import type Program from "./link-manager/auth-manager/program-manager/program"import type Process from "./link-manager/auth-manager/process-manager/process"@@ -42,6 +43,9 @@ export default class System {/** When this System started: its uptime is counted from here. */private readonly startedAt = new Date()+ /** Renders the System's own icon at each standard size, once. */+ private iconRenderer: IconRenderer | null = null+public constructor(private readonly application: Application) {}public shell(command: string, options: ShellOptions = {}) {@@ -456,6 +460,16 @@ export default class System {return Object.freeze({ name, version, release, startedAt: this.startedAt })}+ /** The System's own icon as PNG bytes at one standard size. Anyone may read it. */+ public async icon(size: unknown = "medium") {++ if (!isIconSize(size)) throw new Error("A System icon size is small, medium, or large")++ this.iconRenderer ??= new IconRenderer(this.application.icons.system)++ return [...await this.iconRenderer.render(size)]+ }+public get appearance() {return this.application.appearanceManager.valuediff --git a/source/server/view/view.ts b/source/server/view/view.tsindex 2e86d66..1ed6846 100644--- a/source/server/view/view.ts+++ b/source/server/view/view.ts@@ -29,7 +29,7 @@ export default async function (config: Config) {font: "simple"})- const application = await Application.initialize(config.home, resolve("assets/default-icon.png"))+ const application = await Application.initialize(config.home, { system: resolve("assets/logo.png"), defaultProgram: resolve("assets/default-icon.png") })// One server, five doors, each at its own name. A program's client// is still not the API — it is files a browser reads, with no link,diff --git a/tests/authentication-domains.test.ts b/tests/authentication-domains.test.tsindex d66ff14..a6e3de6 100644--- a/tests/authentication-domains.test.ts+++ b/tests/authentication-domains.test.ts@@ -9,7 +9,7 @@ test("browser Connections and Sessions form one authoritative lifecycle", asyncconst home = await mkdtemp(join(tmpdir(), "phreshos-authentication-"))const application = await Application.initialize(home,- join(home, "icon.png")+ { system: join(home, "logo.png"), defaultProgram: join(home, "icon.png") })const link = new TheLink()const connection = application.linkManager.addConnection(link)diff --git a/tests/client-permission-boundary.test.ts b/tests/client-permission-boundary.test.tsindex 47f2692..f63c19e 100644--- a/tests/client-permission-boundary.test.ts+++ b/tests/client-permission-boundary.test.ts@@ -342,3 +342,13 @@ test("a Client reads what the System is from the System itself, when it startedawait expect(answer("about")).resolves.toEqual([about])})++test("a Client reads the System's icon from the System itself", async () => {+ const bytes = [137, 80, 78, 71]+ const icon = vi.fn(async () => bytes)+ const auth = { icon } as unknown as AuthManager+ const answer = host(auth, "caller", { state: () => { throw new Error("unused viewport") }, move: () => { throw new Error("unused viewport") } }, () => null, clientFrame(), {} as never)++ await expect(answer("system-icon", "large")).resolves.toEqual([bytes])+ expect(icon).toHaveBeenCalledWith("large")+})diff --git a/tests/distribution.test.mjs b/tests/distribution.test.mjsindex 081d0d6..2365b44 100644--- a/tests/distribution.test.mjs+++ b/tests/distribution.test.mjs@@ -44,7 +44,8 @@ test("distribution contract", async () => {"package.json","server/main.js","client/index.html",- "assets/default-icon.png"+ "assets/default-icon.png",+ "assets/logo.png"]) {assert(paths.has(required), `the distribution has no ${required}`)}diff --git a/tests/link-request-routing.test.ts b/tests/link-request-routing.test.tsindex 85617af..513504a 100644--- a/tests/link-request-routing.test.ts+++ b/tests/link-request-routing.test.ts@@ -11,7 +11,7 @@ import { test } from "vitest"test("an RPC result returns only to its requesting boundary", async () => {const home = await mkdtemp(join(tmpdir(), "phreshos-request-routing-"))- const application = await Application.initialize(home, join(home, "icon.png"))+ const application = await Application.initialize(home, { system: join(home, "logo.png"), defaultProgram: join(home, "icon.png") })const link = new TheLink()const boundary = application.linkManager.addExternalConnection(link)const broadcasts: unknown[][] = []diff --git a/tests/motion-across.test.ts b/tests/motion-across.test.tsnew file mode 100644index 0000000..cbba9eb--- /dev/null+++ b/tests/motion-across.test.ts@@ -0,0 +1,38 @@+import { expect, test } from "vitest"+import motionAcross from "@client/view/structure/desktop/motion-across"++test("the motion across a distance grows with the distance it crosses, gently and within bounds", () => {+ const near = motionAcross(120)+ const oneView = motionAcross(1440)+ const twoViews = motionAcross(2880)+ const across = motionAcross(20_000)++ expect(near.duration).toBe(330)+ expect(oneView.duration).toBeGreaterThan(near.duration)+ expect(twoViews.duration).toBeGreaterThan(oneView.duration)+ // Twice as far does not take twice as long.+ expect(twoViews.duration).toBeLessThan(oneView.duration * 1.5)+ expect(across.duration).toBe(1000)+ expect(motionAcross(1).duration).toBe(300)+ // The view moves as a body on a spring that arrives without passing its place.+ expect(oneView.easing).toEqual({ spring: { bounce: 0 } })+})++test("a Window is a lighter body than the view, so the same distance takes it less time", () => {+ for (const distance of [40, 400, 1440, 5000]) {+ expect(motionAcross(distance, "window").duration).toBeLessThan(motionAcross(distance).duration)+ }+ expect(motionAcross(1, "window").duration).toBe(130)+ expect(motionAcross(20_000, "window").duration).toBe(650)+ // A long crossing takes a little more, so it is not crossed at a rush.+ expect(motionAcross(4000, "window").duration).toBeGreaterThan(450)+ expect(motionAcross(300, "window").duration).toBe(Math.round(85 + 4 * Math.sqrt(300)))+ // A Window answers a hand: it sets off at once.+ expect(motionAcross(400, "window").easing).toEqual([0.22, 1, 0.36, 1])+})++test("what leaves the view starts softly, and what arrives lands softly", () => {+ expect(motionAcross(4000, "window", true).easing).toEqual([0.65, 0, 0.35, 1])+ expect(motionAcross(4000, "window").easing).toEqual([0.22, 1, 0.36, 1])+ expect(motionAcross(4000, "window", true).duration).toBe(motionAcross(4000, "window").duration)+})diff --git a/tests/program-creation.test.ts b/tests/program-creation.test.tsindex 1e3d1b7..686ff7d 100644--- a/tests/program-creation.test.ts+++ b/tests/program-creation.test.ts@@ -19,7 +19,7 @@ function fixture(context: TestContext) {const announceHost = vi.fn()const announceSubject = vi.fn()const auth = Object.assign(new TheLink(), {- linkManager: { application: { storage: new FileManager(directory, "system"), defaultProgramIcon: "" } },+ linkManager: { application: { storage: new FileManager(directory, "system"), icons: { system: "", defaultProgram: "" } } },processManager: { processes: new Map(), exitAll: vi.fn(), announceHost, announceSubject }}) as unknown as AuthManagerconst manager = new ProgramManager(auth)diff --git a/tests/program-installation-lifecycle.test.ts b/tests/program-installation-lifecycle.test.tsindex 9b547d4..930e81c 100644--- a/tests/program-installation-lifecycle.test.ts+++ b/tests/program-installation-lifecycle.test.ts@@ -17,7 +17,7 @@ function fixture(context: TestContext) {const exitAll = vi.fn()const announceHost = vi.fn()const auth = Object.assign(new TheLink(), {- linkManager: { application: { storage: new FileManager(directory, "system"), defaultProgramIcon: "" } },+ linkManager: { application: { storage: new FileManager(directory, "system"), icons: { system: "", defaultProgram: "" } } },processManager: { processes: new Map(), exitAll, announceHost, announceSubject: vi.fn() }}) as unknown as AuthManagerconst manager = new ProgramManager(auth)diff --git a/tests/system-about.test.ts b/tests/system-about.test.tsindex 14dd1f9..b8856a1 100644--- a/tests/system-about.test.ts+++ b/tests/system-about.test.ts@@ -10,7 +10,7 @@ test("the System says what it is from its identity, and when it started", asyncconst home = await mkdtemp(join(tmpdir(), "phreshos-about-"))try {const before = Date.now()- const application = await Application.initialize(home, join(home, "icon.png"))+ const application = await Application.initialize(home, { system: join(home, "logo.png"), defaultProgram: join(home, "icon.png") })const about = application.system.about()assert.deepEqual(about, { name, version, release, startedAt: about.startedAt })diff --git a/tests/system-icon.test.ts b/tests/system-icon.test.tsnew file mode 100644index 0000000..fe6c596--- /dev/null+++ b/tests/system-icon.test.ts@@ -0,0 +1,25 @@+import assert from "node:assert/strict"+import { mkdtemp, rm } from "node:fs/promises"+import { tmpdir } from "node:os"+import { join, resolve } from "node:path"+import sharp from "sharp"+import { test } from "vitest"+import Application from "@server/core/application"++test("the System renders its own icon at each standard size, and only those", async () => {+ const home = await mkdtemp(join(tmpdir(), "phreshos-icon-"))+ try {+ const application = await Application.initialize(home, { system: resolve("assets/logo.png"), defaultProgram: resolve("assets/default-icon.png") })++ for (const [size, length] of [["small", 32], ["medium", 64], ["large", 128]] as const) {+ const metadata = await sharp(Buffer.from(await application.system.icon(size))).metadata()+ assert.equal(metadata.format, "png")+ assert.equal(metadata.width, length)+ assert.equal(metadata.height, length)+ }++ assert.equal((await sharp(Buffer.from(await application.system.icon())).metadata()).width, 64)+ await assert.rejects(application.system.icon("huge"), /small, medium, or large/)+ }+ finally { await rm(home, { recursive: true, force: true }) }+}, 60_000)diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.tsindex b5fe6dc..fc5c418 100644--- a/tests/window-geometry.test.ts+++ b/tests/window-geometry.test.ts@@ -84,6 +84,19 @@ test("settling paint follows released geometry instead of its former boundary co)})+test("a tiled window keeps the margins of its own view while the Desktop looks between two", () => {+ const surface = { width: 1000, height: 600 }+ const half = defaultAppearance.spacing / 2+ const margins = { top: 12, right: 12, bottom: 68, left: 12 }+ // The Desktop looks three tenths of a view to the right: the Window's own view starts 300px left of the screen.+ const shown = { x: -300, y: 0, width: 500, height: 600 }++ assert.deepEqual(+ windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: "1/2", height: "1/1" }, surface, half, margins, shown, { x: 300, y: 0 }),+ { top: 12, right: half, bottom: 68, left: 12 }+ )+})+test("window geometry contract", async () => {const initial = {position: { x: 10, y: 20 },