Skip to content

An open-source, self-hosted system for apps built with web technologies.

Release System 0.1.102 with full-Desktop views and immediate window changes

zohayrslileh5dafd38809a4
diff --git a/package.json b/package.json
index 81ce92d..5c2bc21 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.101",
+ "version": "0.1.102",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
diff --git a/source/client/view/components/window-manager/window-geometry.ts b/source/client/view/components/window-manager/window-geometry.ts
index 07fee66..8aa5e8c 100644
--- a/source/client/view/components/window-manager/window-geometry.ts
+++ b/source/client/view/components/window-manager/window-geometry.ts
@@ -20,8 +20,8 @@ export interface WindowSurfaceSize {
export const minimumWindowSize = Object.freeze({ width: 260, height: 160 })
-/** The size the Desktop shows a standard Window at, in each dimension the System records as zero. */
-export const presentedWindowSize = Object.freeze({ width: 520, height: 340 })
+/** The size the Desktop shows a standard Window at, in each dimension the System records as zero: a share of the view, so it suits every screen. */
+export const presentedWindowSize: Size = Object.freeze({ width: "50%", height: "50%" })
const shownSizes = new WeakMap<Size, Size>()
@@ -146,7 +146,7 @@ export function boundedGeometry(position: Position, size: Size, surface: WindowS
return bounded
}
-/** How far this Desktop's view is moved across the plane. Positions it shows are the plane's minus it. */
+/** How far this Desktop's view is moved across the plane, in pixels or in whole views as the context says. */
export interface ViewportOffset {
x: number
@@ -154,25 +154,40 @@ export interface ViewportOffset {
y: number
}
-/** Moves a position by pixels, keeping any share of the surface it names: `"-1/2"` moved by 100 is `"-50% + 100"`. */
-export function shiftPosition(position: Position, by: ViewportOffset): Position {
+/**
+ * Moves a position by views: one view is one share of the surface, so `-1/2` moved by one view is `50%`,
+ * and `120` moved by one view is `100% + 120`. Views stay shares, so each Desktop resolves them against
+ * its own size and a Window stays in its view on every screen.
+ */
+export function shiftPosition(position: Position, views: ViewportOffset): Position {
- if (by.x === 0 && by.y === 0) return position
+ if (views.x === 0 && views.y === 0) return position
- return { x: shiftValue(position.x, by.x), y: shiftValue(position.y, by.y) }
+ return { x: shiftValue(position.x, views.x), y: shiftValue(position.y, views.y) }
}
-function shiftValue(value: Value, by: number): Value {
+/** A point of the plane in pixels, recorded as the view it is in plus pixels within that view, so it keeps to its view on every Desktop. */
+export function recordedPosition(point: { x: number, y: number }, surface: WindowSurfaceSize): Position {
- if (by === 0) return value
+ const views = { x: surface.width ? Math.round(point.x / surface.width) : 0, y: surface.height ? Math.round(point.y / surface.height) : 0 }
+
+ return shiftPosition({ x: Math.round(point.x - views.x * surface.width), y: Math.round(point.y - views.y * surface.height) }, views)
+}
+
+function shiftValue(value: Value, views: number): Value {
+
+ if (views === 0) return value
const { relative: share, pixels } = relative(value)
- const moved = pixels + by
+ // Rounded, so repeated moves do not gather floating-point noise.
+ const percent = Math.round((share + views) * 100 * 10000) / 10000
+
+ if (percent === 0) return pixels
- if (share === 0) return moved
+ if (pixels === 0) return `${percent}%`
- return `${share * 100}% ${moved < 0 ? "-" : "+"} ${Math.abs(moved)}`
+ return `${percent}% ${pixels < 0 ? "-" : "+"} ${Math.abs(pixels)}`
}
/** The inverse at the other end: a painted region's position on the plane, whose zero is the surface's center. */
@@ -194,12 +209,29 @@ export function constrainWindowGeometry(region: WindowRegion, surface: WindowSur
}
}
+/** Space kept on each side of the Desktop when painting what touches it. */
+export interface PaintMargins {
+
+ top: number
+
+ right: number
+
+ bottom: number
+
+ left: number
+}
+
+export const noPaintMargins: PaintMargins = Object.freeze({ top: 0, right: 0, bottom: 0, left: 0 })
+
/**
- * The window's box is its geometry; an ordinary painted surface is inset only
- * on edges that do not touch that box's containing surface. Snap previews use
- * this same function, so preview and final paint cannot disagree.
+ * The window's box is its geometry; what is painted of it is drawn inside. An
+ * edge between two Windows is drawn `inset` inside, so neighbors keep a gap
+ * between them; an edge on the Desktop's own edge is drawn that side's margin
+ * inside, clear of the screen's edge and the Taskbar. Gaps and margins are
+ * 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, current?: WindowRegion) {
+export function windowPaintInsets(position: Position, size: Size, surface: WindowSurfaceSize, inset: number, margins: PaintMargins, current?: WindowRegion) {
const x = current?.x ?? surface.width / 2 + pixels(position.x, surface.width)
@@ -211,13 +243,13 @@ export function windowPaintInsets(position: Position, size: Size, surface: Windo
return {
- top: startsAtBoundary(position.y, y, surface.height) ? 0 : inset,
+ top: startsAtBoundary(position.y, y, surface.height) ? margins.top : inset,
- right: endsAtBoundary(position.x, size.width, x, width, surface.width) ? 0 : inset,
+ right: endsAtBoundary(position.x, size.width, x, width, surface.width) ? margins.right : inset,
- bottom: endsAtBoundary(position.y, size.height, y, height, surface.height) ? 0 : inset,
+ bottom: endsAtBoundary(position.y, size.height, y, height, surface.height) ? margins.bottom : inset,
- left: startsAtBoundary(position.x, x, surface.width) ? 0 : inset
+ left: startsAtBoundary(position.x, x, surface.width) ? margins.left : inset
}
}
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 4e80bdd..a58f4bc 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -1,6 +1,6 @@
import ClientState from "@client/core/link-manager/auth-manager/process-manager/client-state"
import Process from "@client/core/link-manager/auth-manager/process-manager/process"
-import { type Layer, type Position, type Size, type Value } from "@phreshos/core"
+import { type Layer, type Position, type Size, type Value, type WindowGeometry } from "@phreshos/core"
import { useCallback, useLayoutEffect, useRef, useState } from "react"
import { type default as AuthManager } from "@client/core/link-manager/auth-manager/auth-manager"
import WindowPresentations, { type PresentedWindow } from "./window-presentations"
@@ -245,9 +245,14 @@ export default function useWindows(authManager: AuthManager) {
if (window.depth === highest) return
- commit(window.raise())
+ // Shown in front at once; the System's ranking follows when it answers.
+ const request = window.raise()
- }, [commit, summit])
+ presentation.anticipate(process.identity, { front: true }, request)
+
+ commit(request)
+
+ }, [commit, summit, presentation])
const minimize = useCallback(function (process: Process, minimized: boolean) {
@@ -255,9 +260,13 @@ export default function useWindows(authManager: AuthManager) {
if (!window || window.layer !== "window") return
- commit(window.minimize(minimized))
+ const request = window.minimize(minimized)
+
+ presentation.anticipate(process.identity, { minimized }, request)
+
+ commit(request)
- }, [commit])
+ }, [commit, presentation])
const show = useCallback(function (process: Process) {
@@ -314,7 +323,9 @@ export default function useWindows(authManager: AuthManager) {
const window = process.client?.window
if (!window || window.layer !== "window") return Promise.resolve(false)
const maximized = !presentation.projection(process.identity).maximized
- return settle(window.maximize(maximized))
+ const request = window.maximize(maximized)
+ presentation.anticipate(process.identity, { maximized }, request)
+ return settle(request)
}, [presentation, settle])
// Every window on the desktop, in one list and one order.
@@ -399,7 +410,7 @@ export default function useWindows(authManager: AuthManager) {
}, [presentation])
- const commitSharedResize = useCallback(function (geometries: ReadonlyMap<string, WindowRegion>) {
+ const commitSharedResize = useCallback(function (geometries: ReadonlyMap<string, WindowGeometry>) {
for (const [identity, region] of geometries) {
diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.ts
index 0900a0b..1b4e215 100644
--- a/source/client/view/components/window-manager/window-presentations.ts
+++ b/source/client/view/components/window-manager/window-presentations.ts
@@ -38,6 +38,17 @@ export interface PresentedWindow {
minimizeAnimation: PresentationAnimation | null
}
+/**
+ * A change this Desktop shows before the System confirms it: what a person did
+ * here appears at once, and the System's truth replaces it when the request
+ * settles, whether it was accepted or not.
+ */
+export interface AnticipatedWindow {
+ minimized?: boolean
+ maximized?: boolean
+ front?: boolean
+}
+
/** Owns only the local representations of one Desktop. */
export default class WindowPresentations implements WindowPresentationHost {
public windows: ReadonlyMap<string, PresentedWindow>
@@ -47,6 +58,8 @@ export default class WindowPresentations implements WindowPresentationHost {
private readonly representations = new Map<string, PresentationGeometryRepresentation>()
private readonly moveGestureControllers = new Map<string, PresentationMoveGestureController>()
private readonly moveGestures = new Map<string, ActiveMoveGesture>()
+ private readonly anticipated = new Map<string, { change: AnticipatedWindow, pending: number }>()
+ private fronts = 0
private revision = 0
private changed: (windows: ReadonlyMap<string, PresentedWindow>) => void = () => undefined
@@ -72,7 +85,7 @@ export default class WindowPresentations implements WindowPresentationHost {
this.live.set(process, identity)
const existing = next.get(identity)
if (!existing) next.set(identity, initialPresentationState(client))
- else if (existing.layer === "window") next.set(identity, followStandardWindow(existing, client, ++this.revision))
+ else if (existing.layer === "window") next.set(identity, followStandardWindow(existing, client, ++this.revision, this.anticipated.get(identity)?.change))
}
this.publish(next)
@@ -86,6 +99,33 @@ export default class WindowPresentations implements WindowPresentationHost {
this.publish(next)
}
+ /**
+ * Shows a standard Window's change at once, while its request goes to the System. The change holds
+ * until that request settles; then the Window follows the System again, which has either recorded
+ * the same change or kept what it had.
+ */
+ public anticipate(process: string, change: AnticipatedWindow, request: Promise<unknown>) {
+ const identity = this.live.get(process)
+ const state = identity ? this.windows.get(identity) : null
+ const client = this.client(process)
+ if (!identity || !state || !client || state.layer !== "window") return
+ // Changes made together hold together, until the last of their requests settles.
+ const previous = this.anticipated.get(identity)
+ const anticipated = { change: { ...previous?.change, ...change }, pending: (previous?.pending ?? 0) + 1 }
+ // A Window brought forward stays above every Window the System has ranked until it answers.
+ if (change.front) this.fronts++
+ this.anticipated.set(identity, anticipated)
+ this.replace(identity, followStandardWindow(state, client, ++this.revision, anticipated.change, this.fronts))
+ request.catch(() => undefined).finally(() => {
+ const held = this.anticipated.get(identity)
+ if (!held || --held.pending > 0) return
+ this.anticipated.delete(identity)
+ const current = this.windows.get(identity)
+ const live = this.client(process)
+ if (current && live && current.layer === "window") this.replace(identity, followStandardWindow(current, live, ++this.revision))
+ })
+ }
+
public layer(process: string) { return this.existing(process).state.layer }
public projection(process: string) { return this.existing(process).state }
@@ -403,8 +443,20 @@ function initialPresentationState(client: ClientState): PresentedWindow {
}
}
-function followStandardWindow(current: PresentedWindow, client: ClientState, revision: number): PresentedWindow {
- const window = client.window
+/** Anticipated fronts rank above every depth the System assigns. */
+const anticipatedFront = 1_000_000_000
+
+function followStandardWindow(current: PresentedWindow, client: ClientState, revision: number, anticipated?: AnticipatedWindow, fronts = 0): PresentedWindow {
+ const recorded = client.window
+ const window = {
+ position: recorded.position,
+ size: recorded.size,
+ title: recorded.title,
+ header: recorded.header,
+ minimized: anticipated?.minimized ?? recorded.minimized,
+ maximized: anticipated?.maximized ?? recorded.maximized,
+ depth: anticipated?.front ? Math.max(current.depth, anticipatedFront + fronts) : recorded.depth
+ }
const geometryChanged = JSON.stringify([current.position, current.size]) !== JSON.stringify([window.position, window.size])
const maximizedChanged = current.maximized !== window.maximized
const minimizedChanged = current.minimized !== window.minimized
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 3eff738..de2b7f5 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { ApplicationContext, AuthManagerContext, LinkManagerContext } from "../../contexts"
import useClientHost from "../../components/desktop-host/client-host"
-import DesktopLayers from "./layers/desktop-layers"
+import DesktopLayers, { desktopMargins } from "./layers/desktop-layers"
import useDesktopFocus from "./desktop-focus"
import programIcon from "./programs/program-icon"
import ProgramAccessProbe, { type ProgramAccess } from "../../components/program-access"
@@ -18,7 +18,7 @@ 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 { boundedGeometry, planeGeometry, resolveWindowGeometry, shiftPosition, shownSize, type WindowRegion } from "@client/view/components/window-manager/window-geometry"
+import { boundedGeometry, planeGeometry, recordedPosition, resolveWindowGeometry, shiftPosition, shownSize, 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"
import { type Layer, type Position, type Size } from "@phreshos/core"
@@ -75,12 +75,16 @@ export default function Workspace() {
// Standard Windows are shown moved by this Desktop's offset, and what is done to them is recorded
// moved back. Nothing else knows it: a Window works only in what it shows.
- const { offset } = viewport
+ const { offset, views } = viewport
- const back = { x: offset.x, y: offset.y }
+ // Recorded in views, so a Window stays in its view on a Desktop of any size.
+ const back = { x: views.x, y: views.y }
+
+ // Standard Windows measure in the whole Desktop; the space they keep from its edges is painted.
+ const margins = useMemo(() => desktopMargins(appearance.spacing, appearance.taskbar), [appearance.spacing, appearance.taskbar])
// A Window rerenders only when what it shows changes: each position keeps one shown form per offset.
- const shownPositions = useMemo(() => new WeakMap<Position, Position>(), [offset.x, offset.y])
+ const shownPositions = useMemo(() => new WeakMap<Position, Position>(), [views.x, views.y])
function shownPosition(position: Position) {
@@ -88,20 +92,26 @@ export default function Workspace() {
if (cached) return cached
- const shown = shiftPosition(position, { x: -offset.x, y: -offset.y })
+ const shown = shiftPosition(position, { x: -views.x, y: -views.y })
shownPositions.set(position, shown)
return shown
}
- const move = useCallback((record: Process, x: number, y: number) => windows.move(record, x + back.x, y + back.y), [windows.move, back.x, back.y])
+ const move = useCallback(function (record: Process, x: number, y: number) {
+
+ const recorded = shiftPosition({ x, y }, back)
+
+ return windows.move(record, recorded.x, recorded.y)
- const resize = useCallback((record: Process, width: number, height: number, position: { x: number, y: number } | null) => windows.resize(record, width, height, position && { x: position.x + back.x, y: position.y + back.y }), [windows.resize, back.x, back.y])
+ }, [windows.move, back.x, back.y])
+
+ const resize = useCallback((record: Process, width: number, height: number, position: { x: number, y: number } | null) => windows.resize(record, width, height, position && shiftPosition(position, back)), [windows.resize, back.x, back.y])
const snap = useCallback((record: Process, position: Position, size: Size) => windows.snap(record, shiftPosition(position, back), size), [windows.snap, back.x, back.y])
- const commitSharedResize = useCallback((geometries: ReadonlyMap<string, WindowRegion>) => windows.sharedResize.commit(new Map([...geometries].map(([identity, region]) => [identity, { ...region, x: region.x + back.x, y: region.y + back.y }]))), [windows.sharedResize.commit, back.x, back.y])
+ const commitSharedResize = useCallback((geometries: ReadonlyMap<string, WindowRegion>) => windows.sharedResize.commit(new Map([...geometries].map(([identity, region]) => [identity, { ...region, ...shiftPosition(region, back) }]))), [windows.sharedResize.commit, back.x, back.y])
const fileWallpaperLoaded = useCallback(() => {
@@ -191,6 +201,8 @@ export default function Workspace() {
// touch their surface. Positioning is identical in every layer.
paintSurfaceSize={layer === "window" ? windowSurfaceSize : undefined}
+ paintMargins={layer === "window" ? margins : undefined}
+
spacing={appearance.spacing}
depth={presentation.depth}
@@ -261,7 +273,12 @@ export default function Workspace() {
front: fronts.window?.identity === record.identity,
show: () => show(record),
close: () => focus.close(record),
- moveTo: center => void windows.move(record, Math.round(center.x - region.width / 2), Math.round(center.y - region.height / 2))
+ moveTo: center => {
+
+ const recorded = recordedPosition({ x: center.x - region.width / 2, y: center.y - region.height / 2 }, windowSurfaceSize)
+
+ void windows.move(record, recorded.x, recorded.y)
+ }
}
})
: []
@@ -278,7 +295,7 @@ export default function Workspace() {
const step = inView % 8 * appearance.spacing * 2
- return { x: Math.round(offset.x - shown.width / 2 + step), y: Math.round(offset.y - shown.height / 2 + step) }
+ return recordedPosition({ x: offset.x - shown.width / 2 + step, y: offset.y - shown.height / 2 + step }, windowSurfaceSize)
}, [mappedWindows, offset.x, offset.y, windowSurfaceSize, appearance.spacing])
@@ -297,8 +314,8 @@ export default function Workspace() {
const launchPlacement = useMemo<LaunchPlacement>(() => ({ place, reveal }), [place, reveal])
- // Pressing a Window in the Taskbar brings the view to it, so it is in the middle, whether it was
- // minimized or only out of view. A maximized Window fills every view, so the view stays.
+ // Going to a Window brings the view to it, so it is in the middle, whether it was minimized or only
+ // out of view, and brings it to the front. A maximized Window fills every view, so the view stays.
const show = useCallback(function (record: Process) {
const window = windows.presentation.projection(record.identity)
@@ -318,8 +335,8 @@ export default function Workspace() {
>
{/* What a press means is composed here because it is a person's
- expectation, not a system operation: the view goes to the Window,
- which is shown and brought forward. */}
+ expectation, not a system operation: the front window hides;
+ another window is shown and brought forward, wherever it is. */}
{windows.listed.map(record => {
const window = windows.presentation.projection(record.identity)
@@ -346,7 +363,9 @@ export default function Workspace() {
onMinimize={focus.minimize}
- onShow={show}
+ onShow={windows.show}
+
+ onGoTo={show}
onFill={windows.fill}
@@ -387,8 +406,6 @@ export default function Workspace() {
spacing={appearance.spacing}
- taskbar={appearance.taskbar}
-
shell={<>
{shell}
{!wallpaperReady && <Loading />}
diff --git a/source/client/view/structure/desktop/layers/desktop-layers.tsx b/source/client/view/structure/desktop/layers/desktop-layers.tsx
index 5faf8c2..507d805 100644
--- a/source/client/view/structure/desktop/layers/desktop-layers.tsx
+++ b/source/client/view/structure/desktop/layers/desktop-layers.tsx
@@ -1,11 +1,12 @@
import { type CSSProperties, type ReactNode, type Ref } from "react"
import { type AppearanceTaskbar } from "@phreshos/core"
+import { type PaintMargins } from "@client/view/components/window-manager/window-geometry"
/**
* Five coextensive Desktop layers ordered from back to front. No layer owns
* layout space for another; each receives the complete Desktop bounds.
*/
-export default function DesktopLayers({ wallpaper, underWindows, windows, sharedResizeBoundaries, overWindows, shell, windowSurfaceRef, spacing, taskbar }: DesktopLayersProps) {
+export default function DesktopLayers({ wallpaper, underWindows, windows, sharedResizeBoundaries, overWindows, shell, windowSurfaceRef, spacing }: DesktopLayersProps) {
return <div
data-desktop-layers=""
@@ -27,10 +28,9 @@ export default function DesktopLayers({ wallpaper, underWindows, windows, shared
<div data-desktop-layer="window" className="pointer-events-none absolute inset-0 z-2 overflow-hidden">
- {/* This surface defines standard-window geometry, not a paint
- boundary. Windows may leave it and are clipped only by the
- complete Desktop layer. */}
- <div ref={windowSurfaceRef} data-window-surface="" className="absolute" style={windowSurfaceInsets(spacing, taskbar)}>
+ {/* Standard Windows measure in the whole Desktop, like every other
+ layer; the margins around it are painted, not measured. */}
+ <div ref={windowSurfaceRef} data-window-surface="" className="absolute inset-0">
{windows}
@@ -71,13 +71,14 @@ interface DesktopLayersProps {
spacing: number
- taskbar: AppearanceTaskbar
-
shell: ReactNode
}
-/** Reserves the Taskbar edge unless it overlays the standard Window surface. */
-export function windowSurfaceInsets(spacing: number, taskbar: AppearanceTaskbar): CSSProperties {
+/**
+ * The space a standard Window keeps from each edge of the Desktop when it touches it: one spacing,
+ * and on the Taskbar's side the Taskbar too, unless it overlays the Desktop.
+ */
+export function desktopMargins(spacing: number, taskbar: AppearanceTaskbar): PaintMargins {
const inset = {
top: spacing,
right: spacing,
diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx
index 362c81f..dc3c58d 100644
--- a/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx
+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/window-taskbar-item.tsx
@@ -1,17 +1,23 @@
import Process from "@client/core/link-manager/auth-manager/process-manager/process"
import { type TaskbarPosition } from "@phreshos/core"
import { ContextMenu, Menu } from "@phreshos/react-ui"
-import { ArrowDownLeft, ArrowUpRight, Maximize2, Minimize2, X } from "@phreshos/react-ui/icons"
+import { ArrowDownLeft, ArrowUpRight, LocateFixed, Maximize2, Minimize2, X } from "@phreshos/react-ui/icons"
import { useDesktopScaleContainer } from "../../../../desktop-scale"
import TaskbarItem from "./taskbar-item"
import { memo, useCallback } from "react"
/** A taskbar entry rerenders only when what that entry shows changes. */
-export default memo(function ({ record, title, icon, position, active, minimized, maximized, onElement, onMinimize, onShow, onFill, onClose }: WindowTaskbarItemProps) {
+export default memo(function ({ record, title, icon, position, active, minimized, maximized, onElement, onMinimize, onShow, onGoTo, onFill, onClose }: WindowTaskbarItemProps) {
const scaleContainer = useDesktopScaleContainer()
- const press = useCallback(() => onShow(record), [onShow, record])
+ const press = useCallback(function () {
+
+ if (active) onMinimize(record, true)
+
+ else onShow(record)
+
+ }, [active, onMinimize, onShow, record])
const source = useCallback((element: HTMLButtonElement | null) => onElement(record, element), [onElement, record])
const changeVisibility = useCallback(() => {
@@ -39,11 +45,17 @@ export default memo(function ({ record, title, icon, position, active, minimized
<ContextMenu.Content portalContainer={scaleContainer ?? undefined}>
<Menu aria-label={`${title} window actions`} size="small" onAction={action => {
- if (action === "visibility") changeVisibility()
+ if (action === "goTo") onGoTo(record)
+ else if (action === "visibility") changeVisibility()
else if (action === "fill") fill()
else if (action === "close") close()
}}>
+ {/* Where the Window is on the plane is the Map's concern; from here it is one choice away. */}
+ <Menu.Item id="goTo" textValue="Go to"><LocateFixed aria-hidden />Go to</Menu.Item>
+
+ <Menu.Separator />
+
{/* The icons are the Window's own title bar controls. */}
<Menu.Item id="visibility" textValue={minimized ? "Show" : "Minimize"}>{minimized ? <><ArrowUpRight aria-hidden />Show</> : <><ArrowDownLeft aria-hidden />Minimize</>}</Menu.Item>
@@ -82,6 +94,9 @@ interface WindowTaskbarItemProps {
onShow: (record: Process) => void
+ /** Brings the view to the Window and the Window to the front. */
+ onGoTo: (record: Process) => void
+
onFill: (record: Process) => void
onClose: (record: Process) => void
diff --git a/source/client/view/structure/desktop/viewport-offset.ts b/source/client/view/structure/desktop/viewport-offset.ts
index 855c831..8fa089d 100644
--- a/source/client/view/structure/desktop/viewport-offset.ts
+++ b/source/client/view/structure/desktop/viewport-offset.ts
@@ -1,44 +1,48 @@
-import { useCallback, useState } from "react"
+import { useCallback, useMemo, useState } from "react"
import { planeReach, type ViewportOffset, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
/**
* Where this Desktop looks on the plane of standard Windows: the point shown at
* the center of its view. It belongs to this connection alone: it starts at zero
* and is not stored.
+ *
+ * It is kept in views, not pixels, so it means the same place whatever size the
+ * view has: a Desktop that is resized, or rescaled, keeps looking at the same
+ * Windows. Its pixels follow from the current size.
*/
export default function useViewportOffset(surface: WindowSurfaceSize) {
- const [offset, setOffset] = useState<ViewportOffset>(origin)
+ const [views, setViews] = useState<ViewportOffset>(origin)
/** Moves the view to one whole view, counted from the plane's center. */
- const moveTo = useCallback(function (view: ViewportOffset) {
+ const moveTo = useCallback((view: ViewportOffset) => setViews({ x: within(view.x), y: within(view.y) }), [])
+
+ /** 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
- setOffset({ x: within(view.x, planeReach) * surface.width, y: within(view.y, planeReach) * surface.height })
+ setViews({ x: within(point.x / surface.width), y: within(point.y / surface.height) })
}, [surface.width, surface.height])
- /** Places the view at any point of the plane, not only whole views; its center stays over the plane's outer views. */
- const place = useCallback((point: ViewportOffset) => setOffset({
- x: Math.round(within(point.x, planeReach * surface.width)),
- y: Math.round(within(point.y, planeReach * surface.height))
- }), [surface.width, surface.height])
-
/** Returns the view to the plane's center. */
- const home = useCallback(() => setOffset(origin), [])
+ const home = useCallback(() => setViews(origin), [])
+
+ // 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])
// The nearest whole view from the center, which is what a person counts.
- const view = { x: surface.width ? Math.round(offset.x / surface.width) : 0, y: surface.height ? Math.round(offset.y / surface.height) : 0 }
+ const view = { x: Math.round(views.x), y: Math.round(views.y) }
- return { offset, view, surface, moveTo, place, home }
+ return { views, offset, view, surface, moveTo, place, home }
}
export type ViewportControl = ReturnType<typeof useViewportOffset>
-function within(value: number, reach: number) {
+function within(value: number) {
- return Math.min(reach, Math.max(-reach, value))
+ return Math.min(planeReach, Math.max(-planeReach, value))
}
const origin: ViewportOffset = Object.freeze({ x: 0, y: 0 })
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index 7dff5b7..d0fcc9f 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -1,6 +1,6 @@
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 WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
+import { type PaintMargins, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type PresentationAnimation, type PresentationMoveGestureController } from "@client/view/components/desktop-host/window-presentation"
import { type PresentationGeometryRepresentation } from "@client/view/components/window-manager/window-presentations"
import { type Position, type Size, type TaskbarPosition, type Theme, type WindowPresentationSurface, type WindowLayer } from "@phreshos/core"
@@ -24,7 +24,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, spacing, depth, active, minimized, maximized, 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, interactive, closing, stopping, entering, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {
const activate = useCallback(() => onRaise(record), [onRaise, record])
@@ -131,6 +131,8 @@ export default memo(function ({ identity, record, assetId, client, title, header
paintSurfaceSize={paintSurfaceSize}
+ paintMargins={paintMargins}
+
spacing={spacing}
active={active}
@@ -258,6 +260,8 @@ interface ProcessWindowProps {
paintSurfaceSize?: WindowSurfaceSize
+ paintMargins?: PaintMargins
+
spacing: number
depth: number
diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsx
index bfe7b4d..23742e9 100644
--- a/source/client/view/structure/desktop/windows/snap-preview.tsx
+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx
@@ -1,13 +1,13 @@
import { type CSSProperties } from "react"
import { motion } from "motion/react"
-import { windowPaintInsets, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
+import { windowPaintInsets, type PaintMargins, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type Position, type Size } from "@phreshos/core"
import { Surface, useAppearance } from "@phreshos/react-ui"
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, reducedMotion, zIndex }: SnapPreviewProps) {
+export default function SnapPreview({ shown, visible, bare, minimumSize, paintSurfaceSize, paintInset, paintMargins, reducedMotion, zIndex }: SnapPreviewProps) {
const transaction = useAppearance().transaction
@@ -36,7 +36,7 @@ export default function SnapPreview({ shown, visible, bare, minimumSize, paintSu
material={{ opacity: "small" }}
style={{
position: "absolute",
- ...(bare ? { inset: 0 } : windowPaintInsets(shown.position, shown.size, paintSurfaceSize, paintInset))
+ ...(bare ? { inset: 0 } : windowPaintInsets(shown.position, shown.size, paintSurfaceSize, paintInset, paintMargins))
}}
/>
</motion.div>
@@ -55,6 +55,7 @@ interface SnapPreviewProps {
minimumSize?: WindowSurfaceSize
paintSurfaceSize: WindowSurfaceSize
paintInset: number
+ paintMargins: PaintMargins
reducedMotion: boolean
zIndex: CSSProperties["zIndex"]
}
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 6580db9..a75efa2 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -2,7 +2,7 @@ import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useCallba
import { useReducedMotion } from "@libs/react-motion"
import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
import WindowPanel from "./window-panel"
-import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, planeGeometry, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
+import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, noPaintMargins, presentedWindowSize, planeGeometry, resolveWindowGeometry, windowPaintInsets, type PaintMargins, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type BeginWindowMoveGesture, type Position, type Size, type TaskbarPosition, type WindowPresentationSurface as WindowSurfaceDefinition, type WindowLayer } from "@phreshos/core"
import WindowHeader from "./window-header"
import WindowSurface, { windowSurfaceRadius } from "./window-surface"
@@ -66,7 +66,7 @@ export function windowMinimizePose(position: TaskbarPosition) {
}
}
-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, interactive = true, entering = false, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, taskbarPosition = "bottom", surfaceAnimation, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, 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, active = false, closing = false, stopping = false, minimized = false, maximized = false, interactive = true, entering = false, position = { x: 0, y: 0 }, size = presentedWindowSize, 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()
@@ -582,7 +582,7 @@ 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, gesture?.current ?? settlingGeometry ?? undefined)
+ const paintedInsets = windowPaintInsets(presented.current.position, presented.current.size, paintSurfaceSize, paintInset, paintMargins, gesture?.current ?? settlingGeometry ?? undefined)
return <>
@@ -609,6 +609,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
minimumSize={presentationMinimum}
paintSurfaceSize={paintSurfaceSize}
paintInset={paintInset}
+
+ paintMargins={paintMargins}
reducedMotion={reducedMotion}
zIndex={style?.zIndex}
/>}
@@ -809,6 +811,9 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "
/** Surface used only to decide which painted edges receive an inset. */
paintSurfaceSize?: WindowSurfaceSize
+ /** Space kept from each edge of the Desktop when painting an edge that touches it. */
+ paintMargins?: PaintMargins
+
/** Appearance spacing shared by the layer boundary and tiled gaps. */
spacing?: number
diff --git a/tests/desktop-replacements.test.tsx b/tests/desktop-replacements.test.tsx
index e3df08f..e985ee3 100644
--- a/tests/desktop-replacements.test.tsx
+++ b/tests/desktop-replacements.test.tsx
@@ -3,7 +3,7 @@ import { renderToStaticMarkup } from "react-dom/server"
import { UIProvider } from "@phreshos/react-ui"
import type Process from "@client/core/link-manager/auth-manager/process-manager/process"
import Workspace from "@client/view/structure/desktop/desktop"
-import { windowSurfaceInsets } from "@client/view/structure/desktop/layers/desktop-layers"
+import { desktopMargins } from "@client/view/structure/desktop/layers/desktop-layers"
import Taskbar, { taskbarConfigurationChanged, taskbarOverlayTransform, taskbarRegionStyle, taskbarRetentionDistance, taskbarRevealRegionStyle, taskbarStyle, taskbarVisible } from "@client/view/structure/desktop/layers/shell/taskbar/taskbar"
import { startMenuStyle } from "@client/view/structure/desktop/layers/shell/start-menu/start-menu"
import { windowMinimizePose } from "@client/view/structure/desktop/windows/window"
@@ -30,7 +30,7 @@ vi.mock("@the-link/react", () => ({
ReactTunnel: { useFactory: () => ({ useSubscribe() {} }) },
useProperty: (property: { value: unknown }) => property.value
}))
-vi.mock("@client/view/components/desktop-host/client-host", () => ({ default: () => ({ windowSurfaceSize: { width: 0, height: 0 }, viewport: { offset: { x: 0, y: 0 }, view: { x: 0, y: 0 }, surface: { width: 0, height: 0 }, moveTo: () => undefined, place: () => undefined, home: () => undefined } }) }))
+vi.mock("@client/view/components/desktop-host/client-host", () => ({ default: () => ({ windowSurfaceSize: { width: 0, height: 0 }, viewport: { views: { x: 0, y: 0 }, offset: { x: 0, y: 0 }, view: { x: 0, y: 0 }, surface: { width: 0, height: 0 }, moveTo: () => undefined, place: () => undefined, home: () => undefined } }) }))
vi.mock("@client/view/components/program-access", () => ({ default: () => null }))
vi.mock("@libs/readiness", () => ({ useRequirement: () => () => {} }))
vi.mock("@client/view/structure/desktop/layers/shell/default-shell", () => ({
@@ -60,16 +60,14 @@ test("Desktop composes five full-bound stacked layers without a layout track", (
expect(windowLayer).toContain("absolute inset-0")
const windowSurface = markup.match(/<div[^>]*data-window-surface=""[^>]*>/)?.[0]
expect(windowSurface).not.toContain("overflow-hidden")
- expect(windowSurface).toContain(`top:${defaultAppearance.spacing}px`)
- expect(windowSurface).toContain(`right:${defaultAppearance.spacing}px`)
- expect(windowSurface).toContain(`bottom:${defaultAppearance.spacing * 2 + defaultAppearance.taskbar.size}px`)
- expect(windowSurface).toContain(`left:${defaultAppearance.spacing}px`)
+ // Standard Windows measure in the whole Desktop; their margins are painted.
+ expect(windowSurface).toContain("absolute inset-0")
})
-test.each(["top", "right", "bottom", "left"] as const)("standard window surface reserves the %s Taskbar edge", position => {
+test.each(["top", "right", "bottom", "left"] as const)("standard windows keep clear of the %s Taskbar edge when painting", position => {
const spacing = 12
const size = 44
- const insets = windowSurfaceInsets(spacing, { position, size, overlay: false })
+ const insets = desktopMargins(spacing, { position, size, overlay: false })
expect(insets).toEqual({
top: position === "top" ? 68 : 12,
@@ -79,8 +77,8 @@ test.each(["top", "right", "bottom", "left"] as const)("standard window surface
})
})
-test.each(["top", "right", "bottom", "left"] as const)("an overlay Taskbar does not reserve the %s standard-window edge", position => {
- expect(windowSurfaceInsets(12, { position, size: 44, overlay: true })).toEqual({
+test.each(["top", "right", "bottom", "left"] as const)("an overlay Taskbar leaves the %s standard-window margin at one spacing", position => {
+ expect(desktopMargins(12, { position, size: 44, overlay: true })).toEqual({
top: 12,
right: 12,
bottom: 12,
diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.ts
index 0127463..9059202 100644
--- a/tests/window-geometry.test.ts
+++ b/tests/window-geometry.test.ts
@@ -3,7 +3,7 @@ import ClientWindow from "@client/core/link-manager/auth-manager/process-manager
import ClientProcessManager from "@client/core/link-manager/auth-manager/process-manager/process-manager"
import ProcessManager from "@server/core/link-manager/auth-manager/process-manager/process-manager"
import ServerWindow from "@server/core/link-manager/auth-manager/process-manager/window"
-import { boundedGeometry, constrainWindowGeometry, minimumWindowSize, planeGeometry, resolveWindowGeometry, shiftPosition, windowPaintInsets } from "@client/view/components/window-manager/window-geometry"
+import { boundedGeometry, constrainWindowGeometry, minimumWindowSize, noPaintMargins, planeGeometry, recordedPosition, resolveWindowGeometry, shiftPosition, windowPaintInsets } from "@client/view/components/window-manager/window-geometry"
import { defaultAppearance } from "@phreshos/core"
import { TheLink } from "@the-link/core"
import { test } from "vitest"
@@ -22,19 +22,23 @@ test("a position is the top-left corner on a plane whose zero is the surface's c
assert.deepEqual(resolveWindowGeometry(planeGeometry(region, surface), region, surface), region)
})
-test("an offset moves a position by pixels and keeps the share of the surface it names", () => {
- assert.deepEqual(shiftPosition({ x: 120, y: -40 }, { x: 1000, y: 0 }), { x: 1120, y: -40 })
- assert.deepEqual(shiftPosition({ x: "-1/2", y: "0/1" }, { x: 1416, y: -820 }), { x: "-50% + 1416", y: -820 })
- assert.deepEqual(shiftPosition({ x: "-50% + 1416", y: 10 }, { x: -1416, y: 0 }), { x: "-50% + 0", y: 10 })
+test("the view moves a position by whole shares of the surface, so it keeps to its view at any size", () => {
+ assert.deepEqual(shiftPosition({ x: 120, y: -40 }, { x: 1, y: 0 }), { x: "100% + 120", y: -40 })
+ assert.deepEqual(shiftPosition({ x: "-1/2", y: "0/1" }, { x: 1, y: -1 }), { x: "50%", y: "-100%" })
+ assert.deepEqual(shiftPosition({ x: "50%", y: 10 }, { x: -1, y: 0 }), { x: "-50%", y: 10 })
+ assert.deepEqual(shiftPosition({ x: "100% - 30", y: 10 }, { x: -1, y: 0 }), { x: -30, y: 10 })
+
+ // What a Desktop shows two views to the right returns to the plane unchanged, whatever its size.
+ for (const surface of [{ width: 1200, height: 800 }, { width: 1440, height: 900 }]) {
+ const stored = { x: "150%", y: 100 }
+ const shown = resolveWindowGeometry(shiftPosition(stored, { x: -2, y: 0 }), { width: 600, height: 400 }, surface)
+ assert.deepEqual(shown, { x: 0, y: surface.height / 2 + 100, width: 600, height: 400 })
+ const recorded = shiftPosition(planeGeometry(shown, surface), { x: 2, y: 0 })
+ assert.deepEqual(resolveWindowGeometry(recorded, { width: 600, height: 400 }, surface), resolveWindowGeometry(stored, { width: 600, height: 400 }, surface))
+ }
- // What a Desktop shows with its offset returns to the plane unchanged.
- const surface = { width: 1200, height: 800 }
- const stored = { x: "-1/2 + 2400", y: 100 }
- const offset = { x: 2400, y: 0 }
- const shown = resolveWindowGeometry(shiftPosition(stored, { x: -offset.x, y: -offset.y }), { width: 600, height: 400 }, surface)
- assert.deepEqual(shown, { x: 0, y: 500, width: 600, height: 400 })
- const recorded = planeGeometry(shown, surface)
- assert.deepEqual({ x: recorded.x + offset.x, y: recorded.y + offset.y }, { x: 1800, y: 100 })
+ // A point of the plane is recorded as its view and the pixels within it.
+ assert.deepEqual(recordedPosition({ x: 2500, y: -100 }, { width: 1200, height: 800 }), { x: "200% + 100", y: -100 })
})
test("a standard presentation enforces its minimum after resolving authoritative geometry", () => {
@@ -50,14 +54,15 @@ test("a standard presentation enforces its minimum after resolving authoritative
})
})
-test("tiled standard windows share the Appearance gap inside the equally inset surface", () => {
+test("tiled standard windows share the Appearance gap, and keep the Desktop's margins at its edges", () => {
const surface = { width: 1000, height: 600 }
const half = defaultAppearance.spacing / 2
- const left = windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: "1/2", height: "1/1" }, surface, half)
- const right = windowPaintInsets({ x: 0, y: "-1/2" }, { width: "1/2", height: "1/1" }, surface, half)
+ const margins = { top: 12, right: 12, bottom: 68, left: 12 }
+ const left = windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: "1/2", height: "1/1" }, surface, half, margins)
+ const right = windowPaintInsets({ x: 0, y: "-1/2" }, { width: "1/2", height: "1/1" }, surface, half, margins)
- assert.deepEqual(left, { top: 0, right: half, bottom: 0, left: 0 })
- assert.deepEqual(right, { top: 0, right: 0, bottom: 0, left: half })
+ assert.deepEqual(left, { top: 12, right: half, bottom: 68, left: 12 })
+ assert.deepEqual(right, { top: 12, right: 12, bottom: 68, left: half })
assert.equal(left.right + right.left, defaultAppearance.spacing)
})
@@ -65,12 +70,12 @@ test("settling paint follows released geometry instead of its former boundary co
const surface = { width: 1000, height: 600 }
const half = defaultAppearance.spacing / 2
const released = { x: 120, y: 90, width: 500, height: 300 }
- const former = windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: 500, height: 300 }, surface, half)
+ const former = windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: 500, height: 300 }, surface, half, noPaintMargins)
assert.deepEqual(former, { top: 0, right: half, bottom: half, left: 0 })
assert.deepEqual(
- windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: 500, height: 300 }, surface, half, released),
+ windowPaintInsets({ x: "-1/2", y: "-1/2" }, { width: 500, height: 300 }, surface, half, noPaintMargins, released),
{ top: half, right: half, bottom: half, left: half }
)
})
diff --git a/tests/window-presentation-layers.test.ts b/tests/window-presentation-layers.test.ts
index a944cfe..42cc8b8 100644
--- a/tests/window-presentation-layers.test.ts
+++ b/tests/window-presentation-layers.test.ts
@@ -62,3 +62,28 @@ test("standard Window presentation is exclusively Desktop-controlled", () => {
expect(() => presentations.setInteractive("own", false)).toThrow(/does not support raw/)
expect(() => presentations.raise("own")).toThrow(/does not support raw/)
})
+
+test("a standard Window shows a change at once and follows the System once its request settles", async () => {
+ const { client, presentations } = fixture("window")
+ let accept!: () => void
+ let reject!: () => void
+
+ // Shown at once while the System has not answered.
+ presentations.anticipate("own", { minimized: false, front: true }, new Promise<void>(resolve => { accept = resolve }))
+ expect(presentations.projection("own")).toMatchObject({ minimized: false })
+ expect(presentations.projection("own").depth).toBeGreaterThan(5)
+
+ // Accepted: the System's record now says the same, and it is what is shown.
+ client.window.minimized = false
+ client.window.depth = 6
+ accept()
+ await new Promise(resolve => setTimeout(resolve))
+ expect(presentations.projection("own")).toMatchObject({ minimized: false, depth: 6 })
+
+ // Rejected: the System kept what it had, and the Window returns to it.
+ presentations.anticipate("own", { maximized: true }, new Promise<void>((_, fail) => { reject = () => fail(new Error("refused")) }))
+ expect(presentations.projection("own")).toMatchObject({ maximized: true })
+ reject()
+ await new Promise(resolve => setTimeout(resolve))
+ expect(presentations.projection("own")).toMatchObject({ maximized: false })
+})