An open-source, self-hosted system for apps built with web technologies.
Refine Desktop viewport and Window placement
zohayrslileh284575729ef5
diff --git a/bun.lock b/bun.lockindex e6b4a75..c1249ae 100644--- a/bun.lock+++ b/bun.lock@@ -8,7 +8,7 @@"@fontsource/roboto": "^5.3.0","@hono/node-server": "^2.1.1","@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",- "@phreshos/core": "^0.1.64",+ "@phreshos/core": "^0.1.65","@phreshos/react-ui": "^0.1.46","@the-link/core": "^0.3.1","@the-link/http": "^0.1.1",@@ -200,7 +200,7 @@"@oxc-project/types": ["@oxc-project/[email protected]", "", {}, "sha512-rDS5/31E9HfPl/CIzGrn0DOlvBbXFseQ5URJ9sYMfstbKLD/c6Gm9vmRzRGDdAXyOIL4zmO37lc9RIwYqVruZw=="],- "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-c3wBWBHpDtTRCqrpsk1Iac1cQfUBeWm9xLlSBv1i4tJ0d1xQ5hIbOEq+a2qoO3kV3eOHYtBpYWUAeob+cMRsIA=="],+ "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-MhKB8aKZJri8ICxuGwHmMD9TGCv2rerbORiWtB5YuZGtQ0Pza+MrPQ8QSlrOKjkoOIUdPKKr2qpgHIK2dNwVug=="],"@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.63", "colorjs.io": "^0.7.1", "lucide-react": "^1.48.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-AF36/07KX4IyES3ong/IhscPccILOLC9m5vxC4O4VbTHZud14UXKRUsoxNPM6F9twYVFjLE+iEzo4ZJTzfig7A=="],diff --git a/package.json b/package.jsonindex 7603898..ba61239 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "phreshos","displayName": "PhreshOS",- "version": "0.1.103",+ "version": "0.1.104","description": "The PhreshOS server, desktop, and authoritative system runtime.","type": "module","private": true,@@ -37,7 +37,7 @@"@fontsource/roboto": "^5.3.0","@hono/node-server": "^2.1.1","@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",- "@phreshos/core": "^0.1.64",+ "@phreshos/core": "^0.1.65","@phreshos/react-ui": "^0.1.46","@the-link/core": "^0.3.1","@the-link/http": "^0.1.1",diff --git a/source/client/view/components/window-manager/window-geometry.ts b/source/client/view/components/window-manager/window-geometry.tsindex 4fe34a4..6596a53 100644--- a/source/client/view/components/window-manager/window-geometry.ts+++ b/source/client/view/components/window-manager/window-geometry.ts@@ -20,41 +20,6 @@ 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: 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>()--/**- * A zero dimension is no size at all: the System records zero when nobody chose one. The Desktop shows its- * own size there instead, and records nothing until the Window is resized.- */-export function shownSize(size: Size): Size {-- const width = isZero(size.width) ? presentedWindowSize.width : size.width-- const height = isZero(size.height) ? presentedWindowSize.height : size.height-- if (width === size.width && height === size.height) return size-- const cached = shownSizes.get(size)-- if (cached) return cached-- const shown = { width, height }-- shownSizes.set(size, shown)-- return shown-}--function isZero(value: Value) {-- const { relative: share, pixels } = relative(value)-- return share === 0 && pixels === 0-}-/*** Every window type uses this same calculation inside the CSS containing* block supplied by its layer. Every expression is one relative coefficientdiff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex e6f15c4..dcd92b6 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -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, recordedPosition, resolveWindowGeometry, shiftPosition, shownSize, viewOfGeometry, type WindowRegion } from "@client/view/components/window-manager/window-geometry"+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"import { type Layer, type Position, type Size } from "@phreshos/core"@@ -155,23 +155,27 @@ export default function Workspace() {function icon(record: { program: string }) {- return programIcon(application.doors.program, program(record.program).assetId)+ return programIcon(application.doors.program, assetOf(record.program))}- function program(identity: string) {+ // A Program can leave while one of its Windows is still leaving, as when `phresh start` ends and its+ // attached Program is forgotten at once. The leaving Window keeps what it showed.+ const knownAssets = useRef(new Map<string, string>())++ function assetOf(identity: string) {const found = authManager.programManager.programs.get(identity)- if (!found) throw new Error(`The Program "${identity}" does not exist`)+ if (found) knownAssets.current.set(identity, found.assetId)- return found+ return found?.assetId ?? knownAssets.current.get(identity) ?? ""}function renderWindows(layer: Layer) {return windows.panesByLayer[layer].map(({ identity, record, client, presentation, closing, entering, stopping }) => {- const bounded = boundedGeometry(presentation.position, shownSize(presentation.size), windowSurfaceSize)+ const bounded = boundedGeometry(presentation.position, presentation.size, windowSurfaceSize)return <ProcessWindow@@ -181,7 +185,7 @@ export default function Workspace() {record={record}- assetId={program(record.program).assetId}+ assetId={assetOf(record.program)}client={client}@@ -279,7 +283,7 @@ export default function Workspace() {const mappedWindows: MappedWindow[] = windowSurfaceSize.width && windowSurfaceSize.height? windows.panesByLayer.window.filter(pane => !pane.closing).map(({ identity, record, presentation }) => {- const shown = boundedGeometry(presentation.position, shownSize(presentation.size), windowSurfaceSize)+ const shown = boundedGeometry(presentation.position, presentation.size, windowSurfaceSize)const region = planeGeometry(resolveWindowGeometry(shown.position, shown.size, windowSurfaceSize), windowSurfaceSize)@@ -306,11 +310,22 @@ export default function Workspace() {}): []+ // A Window launched from this Desktop without a size of its own gets a square: three fifths of the+ // view's shorter side. Shares of the view would stretch it with the screen's own proportions.+ function launchSize(): Size {++ const side = Math.round(Math.min(windowSurfaceSize.width, windowSurfaceSize.height) * 0.6)++ return { width: side, height: side }+ }+// A Window launched from this Desktop opens centered in what it shows, each one stepped a little from// the Windows already in view, so none lands exactly on another.- const place = useCallback(function (size: Size | null): Position {+ const place = useCallback(function (declared: Size | null) {++ const size = declared ?? launchSize()- const shown = resolveWindowGeometry({ x: 0, y: 0 }, shownSize(size ?? { width: 0, height: 0 }), windowSurfaceSize)+ const shown = resolveWindowGeometry({ x: 0, y: 0 }, size, windowSurfaceSize)const inView = mappedWindows.filter(({ region }) =>Math.abs(region.x + region.width / 2 - offset.x) < windowSurfaceSize.width / 2 &&@@ -318,43 +333,40 @@ export default function Workspace() {const step = inView % 8 * appearance.spacing * 2- return recordedPosition({ x: offset.x - shown.width / 2 + step, y: offset.y - shown.height / 2 + step }, windowSurfaceSize)+ const position = recordedPosition({ x: offset.x - shown.width / 2 + step, y: offset.y - shown.height / 2 + step }, windowSurfaceSize)++ return declared ? { position } : { position, size }}, [mappedWindows, offset.x, offset.y, windowSurfaceSize, appearance.spacing])- /** Centers the view on a Window at this position and size, as the Desktop shows it. */+ /**+ * Moves the view to the whole view a Window at this position and size is in. It never centers on the+ * Window itself: a view resting between two would put a maximized Window, which fills its own view,+ * off the screen's edges. Moving within or between views stays the person's choice.+ */const reveal = useCallback(function (position: Position, size: Size | null) {if (!windowSurfaceSize.width || !windowSurfaceSize.height) return- const shown = boundedGeometry(position, shownSize(size ?? { width: 0, height: 0 }), windowSurfaceSize)-- const region = planeGeometry(resolveWindowGeometry(shown.position, shown.size, windowSurfaceSize), windowSurfaceSize)+ const shown = boundedGeometry(position, size ?? { width: 0, height: 0 }, windowSurfaceSize)- viewport.place({ x: region.x + region.width / 2, y: region.y + region.height / 2 })+ viewport.moveTo(viewOfGeometry(shown.position, shown.size, windowSurfaceSize))- }, [windowSurfaceSize, viewport.place])+ }, [windowSurfaceSize, viewport.moveTo])const launchPlacement = useMemo<LaunchPlacement>(() => ({ place, reveal }), [place, reveal])- // 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 its view, so the view goes there.+ // Going to a Window brings the view to the view it is in, whether it was minimized or only out of+ // view, and brings it to the front.const show = useCallback(function (record: Process) {const window = windows.presentation.projection(record.identity)- if (window.layer === "window") {-- const shown = boundedGeometry(window.position, shownSize(window.size), windowSurfaceSize)-- if (window.maximized) viewport.moveTo(viewOfGeometry(shown.position, shown.size, windowSurfaceSize))-- else reveal(window.position, window.size)- }+ if (window.layer === "window") reveal(window.position, window.size)windows.show(record)- }, [windows.presentation, windows.show, reveal, viewport.moveTo, windowSurfaceSize])+ }, [windows.presentation, windows.show, reveal])// Bringing a Window here moves it by whole views into the view on screen, so it keeps its place// within a view: a Window on the left half arrives on the left half, a maximized one fills this view.@@ -364,7 +376,7 @@ export default function Workspace() {if (window.layer !== "window") return- const shown = boundedGeometry(window.position, shownSize(window.size), windowSurfaceSize)+ const shown = boundedGeometry(window.position, window.size, windowSurfaceSize)const from = viewOfGeometry(shown.position, shown.size, windowSurfaceSize)diff --git a/source/client/view/structure/desktop/launch-placement.ts b/source/client/view/structure/desktop/launch-placement.tsindex ef8a992..043f792 100644--- a/source/client/view/structure/desktop/launch-placement.ts+++ b/source/client/view/structure/desktop/launch-placement.ts@@ -7,14 +7,17 @@ import { type Position, type Size } from "@phreshos/core"*/export interface LaunchPlacement {- /** Where a new Window should appear, given the size its Program declares, or `null` without one. */- place(size: Size | null): Position+ /**+ * Where a new Window should appear, given the size its Program declares; without one, the size it+ * should have as well.+ */+ place(size: Size | null): Readonly<{ position: Position, size?: Size }>- /** Moves the view so a Window at this position and size is at its center. */+ /** Moves the view to the whole view a Window at this position and size is in. */reveal(position: Position, size: Size | null): void}-export const LaunchPlacementContext = createContext<LaunchPlacement>({ place: () => ({ x: 0, y: 0 }), reveal: () => undefined })+export const LaunchPlacementContext = createContext<LaunchPlacement>({ place: () => ({ position: { x: 0, y: 0 } }), reveal: () => undefined })export function useLaunchPlacement() {diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsxindex a16f73c..4f40fb9 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/processes/process-item.tsx@@ -59,7 +59,7 @@ export default function ProcessRow({ process, program, server, client }: Readonlpending={ending.isPending}aria-label={`End process ${label}`}onPress={() => void ending.safeExecute()}- ><X style={{ color: danger }} /></Button>+ >{/* Quiet until it is needed: the danger color, softened. */}<X style={{ color: `color-mix(in oklab, ${danger} 55%, transparent)` }} /></Button></Table.Cell></Table.Row>diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsxindex 47a4a55..370f790 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/processes/processes.tsx@@ -29,8 +29,8 @@ export default function Processes({ terms }: Readonly<{ terms: readonly string[]return <Section label="Processes" count={matching.length} empty={terms.length ? "No matching Processes" : "No Processes"}>{/* A fixed layout keeps the table in its well: a long Process name is cut short instead of widening it. */}- {/* Without a heading, the first row has nothing above it to be set apart from. */}- <Table aria-label="Processes" size="small" className="[&_tbody>tr:first-child>*]:!border-t-0" style={{ minWidth: 0, tableLayout: "fixed" }}>+ {/* Without a heading, the first row has nothing above it to be set apart from; the lines between rows stay faint. */}+ <Table aria-label="Processes" size="small" className="[&_tbody>tr:first-child>*]:!border-t-0 [&_tbody>tr>*]:![border-top-color:color-mix(in_oklab,currentColor_6%,transparent)]" style={{ minWidth: 0, tableLayout: "fixed" }}>{/* The columns stay for their widths and names, but the rows need no heading: each row says what it is. */}<Table.Header style={{ visibility: "collapse" }}>diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsxindex f47f577..e8c9c8a 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/programs/programs.tsx@@ -57,7 +57,8 @@ function ProgramItem({ icon, record, onChoose }: { icon: string, record: Programplacement.current = currentPlacement- // A Program that declares where its Window goes keeps it; otherwise the Window opens where this Desktop looks.+ // A Program that declares where its Window goes keeps it; otherwise the Window opens where this Desktop+ // looks, with a square size of this Desktop's choosing when the Program declares none.const launch = usePromise(async function () {onChoose()@@ -66,10 +67,12 @@ function ProgramItem({ icon, record, onChoose }: { icon: string, record: Programconst size = record.client?.size ?? null+ const placed = placement.current.place(size)+// A Window that opens where its Program declares is brought into view.- if (declared) placement.current.reveal(declared, size)+ if (declared) placement.current.reveal(declared, placed.size ?? size)- await record.createProcess(declared ? {} : { client: { position: placement.current.place(size) } })+ await record.createProcess({ client: declared ? (placed.size ? { size: placed.size } : {}) : placed })})return <>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 ecd2a28..0e2f0ed 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@@ -9,13 +9,15 @@ import SystemHeader from "@client/view/components/system-header"* is the Appearance spacing, the same as the header's side padding, so the wells* line up with the header's content.*/-export default function StartMenuPanel({ labelId, name, version, left, right, footer }: Readonly<{+export default function StartMenuPanel({ labelId, name, version, left, right, footer, stacked = false }: Readonly<{labelId: stringname: stringversion: stringleft: ReactNoderight: ReactNodefooter: ReactNode+ /** On a tall menu, the Programs sit above the Processes instead of beside them. */+ stacked?: boolean}>) {const space = useScale(useAppearance().spacing)@@ -26,7 +28,7 @@ export default function StartMenuPanel({ labelId, name, version, left, right, fo<div className="grid min-h-0 min-w-0" style={{ gridTemplateRows: "minmax(0, 1fr) auto", gap: space.medium, padding: space.medium, paddingTop: 0 }}>- <div className="grid min-h-0 min-w-0 grid-cols-2" style={{ gap: space.medium }}>+ <div className={`grid min-h-0 min-w-0 ${stacked ? "grid-rows-2" : "grid-cols-2"}`} style={{ gap: space.medium }}><Well>{left}</Well>diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsxindex 27af312..7acd5ed 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx@@ -14,6 +14,7 @@ import TaskbarButton from "../taskbar/taskbar-button"import { useAppearance } from "@phreshos/react-ui"import { cssEasing } from "@client/view/appearance/motion"import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"+import { usePortrait } from "../../../orientation"const StartMenuContext = createContext<StartMenuControl | null>(null)@@ -119,6 +120,8 @@ export default memo(function StartMenu() {const [query, setQuery] = useState("")+ const portrait = usePortrait()+const terms = searchTerms(query)return <motion.div@@ -130,7 +133,7 @@ export default memo(function StartMenu() {tabIndex={-1}className={`${shellSurfaceClassName} pointer-events-auto fixed hidden open:block`}style={{- ...startMenuStyle(control.taskbar, control.spacing),+ ...startMenuStyle(control.taskbar, control.spacing, portrait),transitionBehavior: "allow-discrete",transitionDuration: reducedMotion ? "0ms" : String(transaction.duration) + "ms",transitionTimingFunction: cssEasing(transaction.easing),@@ -157,6 +160,7 @@ export default memo(function StartMenu() {left={<Programs onChoose={control.close} terms={terms} />}right={<Processes terms={terms} />}footer={<SearchBar query={query} onChange={setQuery} />}+ stacked={portrait}/></motion.div>@@ -164,9 +168,13 @@ export default memo(function StartMenu() {/*** The menu occupies the leading corner beside the Taskbar: one spacing from- * its perpendicular screen edge and two spacings beyond the Taskbar edge.+ * its perpendicular screen edge and two spacings beyond the Taskbar edge. It+ * takes the screen's shape: wide on a wide screen, and the same size turned on+ * a tall one, each within the room the screen has.*/-export function startMenuStyle(taskbar: AppearanceTaskbar, spacing: number): CSSProperties {+export function startMenuStyle(taskbar: AppearanceTaskbar, spacing: number, portrait = false): CSSProperties {+ const [long, short] = ["44rem", "32rem"]+ const [across, down] = portrait ? [short, long] : [long, short]const horizontal = taskbar.position === "top" || taskbar.position === "bottom"const taskbarInset = taskbar.size + spacing * 2const style = {@@ -179,11 +187,11 @@ export function startMenuStyle(taskbar: AppearanceTaskbar, spacing: number): CSSbottom: "auto",left: "auto",width: horizontal- ? `min(44rem, calc(100vw - ${spacing * 2}px))`- : `min(44rem, calc(100vw - ${taskbarInset + spacing}px))`,+ ? `min(${across}, calc(100vw - ${spacing * 2}px))`+ : `min(${across}, calc(100vw - ${taskbarInset + spacing}px))`,height: horizontal- ? `min(32rem, calc(100vh - ${taskbarInset + spacing}px))`- : `min(32rem, calc(100vh - ${spacing * 2}px))`+ ? `min(${down}, calc(100vh - ${taskbarInset + spacing}px))`+ : `min(${down}, calc(100vh - ${spacing * 2}px))`} satisfies CSSPropertiesif (taskbar.position === "bottom") return { ...style, left: spacing, bottom: taskbarInset }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 2a37ac6..ef44964 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@@ -1,7 +1,7 @@import { Button, ContextMenu, Panel, Surface, Text, useAppearance, useColor, useScale } from "@phreshos/react-ui"import { Map as MapIcon, Maximize2 } from "@phreshos/react-ui/icons"import WindowMenu from "../../window-menu"-import { useCallback, useEffect, useId, useRef, useState, type CSSProperties, type PointerEvent as ReactPointerEvent } from "react"+import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type PointerEvent as ReactPointerEvent } from "react"import { planeReach, type WindowRegion } from "@client/view/components/window-manager/window-geometry"import { type AppearanceTaskbar } from "@phreshos/core"import { useReducedMotion } from "@libs/react-motion"@@ -78,9 +78,14 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, oconst [open, setOpen] = useState(false)- // Where the map opens, measured from the button when it opens.+ // Where the map opens, measured from the button when it opens, and the room it has there.const [anchor, setAnchor] = useState<CSSProperties>({})+ const [room, setRoom] = useState<Room | null>(null)++ // How far the map moves inward so it stays on the screen, once it is drawn.+ const [inward, setInward] = useState(0)+const openAtPressStart = useRef(false)const reducedMotion = useReducedMotion()@@ -124,9 +129,35 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, osetAnchor(anchorStyle(trigger.current, taskbar, spacing))+ setRoom(roomBeside(trigger.current, taskbar, spacing))++ setInward(0)+element.showPopover()}+ // It starts where its button starts; where it would pass the screen's far edge, it moves back just+ // enough to stay one spacing inside, as far as the Start Menu's corner at most.+ useLayoutEffect(function () {++ const element = surface.current++ if (!open || !element || !trigger.current) return++ // Layout measures, which the entrance's brief growth does not change; the Desktop's scale comes from the button.+ const scale = trigger.current.offsetWidth ? trigger.current.getBoundingClientRect().width / trigger.current.offsetWidth : 1++ const screen = { width: window.innerWidth / scale, height: window.innerHeight / scale }++ const beyond = vertical ? element.offsetTop + element.offsetHeight - (screen.height - spacing) : element.offsetLeft + element.offsetWidth - (screen.width - spacing)++ const start = (vertical ? element.offsetTop : element.offsetLeft) - spacing++ // The map settles its own size after it is first drawn, so this looks again after every drawing.+ if (beyond > 0.5 && start > 0.5) setInward(current => current + Math.min(beyond, start))++ })+return <><Button ref={trigger} size="small" iconOnly={centered || vertical} color={centered ? undefined : "primary:soft"}@@ -146,6 +177,7 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, oclassName={`${shellSurfaceClassName} pointer-events-auto fixed hidden open:block`}style={{...anchor,+ ...(vertical ? { top: Number(anchor.top ?? 0) - inward } : { left: Number(anchor.left ?? 0) - inward }),transitionBehavior: "allow-discrete",transitionDuration: reducedMotion ? "0ms" : String(transaction.duration) + "ms",transitionTimingFunction: cssEasing(transaction.easing),@@ -159,13 +191,38 @@ export default function ViewportControl({ viewport, windows, taskbar, spacing, o>{/* Always drawn, like the Start Menu, so it leaves as it came. */}- <Panel><ViewMap labelId={`${id}-label`} viewport={viewport} windows={windows} centered={centered} menus={surface.current} /></Panel>+ <Panel><ViewMap labelId={`${id}-label`} viewport={viewport} windows={windows} centered={centered} menus={surface.current} room={room} /></Panel></motion.div></>}+/** The space a panel has on the screen, in the Desktop's own pixels. */+interface Room {+ width: number+ height: number+}++/**+ * The room beside the Taskbar for the map: the whole screen, less one spacing at its edges and the+ * Taskbar with its spacings on the Taskbar's side, as the Start Menu has.+ */+function roomBeside(button: HTMLElement, taskbar: AppearanceTaskbar, spacing: number): Room {++ const rectangle = button.getBoundingClientRect()++ const scale = button.offsetWidth ? rectangle.width / button.offsetWidth : 1++ const screen = { width: window.innerWidth / scale, height: window.innerHeight / scale }++ const taskbarSide = taskbar.size + spacing * 3++ return taskbar.position === "top" || taskbar.position === "bottom"+ ? { width: screen.width - spacing * 2, height: screen.height - taskbarSide }+ : { width: screen.width - taskbarSide, height: screen.height - spacing * 2 }+}+/*** Like the Start Menu, the map opens two spacings beyond the Taskbar's edge, starting where the button* starts. Taskbar positions name physical screen edges, so every inset stays physical.@@ -191,7 +248,7 @@ function anchorStyle(button: HTMLElement, taskbar: AppearanceTaskbar, spacing: n}/** `menus` is the map's own surface: menus open inside it, since the map is above everything else on the page. */-function ViewMap({ labelId, viewport, windows, centered, menus }: Readonly<{ labelId: string, viewport: Viewport, windows: readonly MappedWindow[], centered: boolean, menus: HTMLElement | null }>) {+function ViewMap({ labelId, viewport, windows, centered, menus, room }: Readonly<{ labelId: string, viewport: Viewport, windows: readonly MappedWindow[], centered: boolean, menus: HTMLElement | null, room: Room | null }>) {const space = useScale(useAppearance().spacing)@@ -202,13 +259,37 @@ function ViewMap({ labelId, viewport, windows, centered, menus }: Readonly<{ labconst { surface } = viewport- // One view on the map: its width from the spacing, its height in the view's own proportion, both whole pixels so the lines between views stay even.- const cell = { width: Math.round(space.xlarge * 3.25), height: Math.round(space.xlarge * 3.25 * surface.height / surface.width) }-const columns = range.maxX - range.minX + 1const rows = range.maxY - range.minY + 1+ // The panel's own words and spaces around the plane, measured once it is drawn.+ const title = useRef<HTMLElement>(null)++ const footer = useRef<HTMLDivElement>(null)++ const [chrome, setChrome] = useState({ width: space.large * 2, height: space.large * 2 + space.medium * 2 + space.xlarge * 3 })++ useLayoutEffect(function () {++ const words = (title.current?.offsetHeight ?? 0) + (footer.current?.offsetHeight ?? 0)++ if (words) setChrome(current => {+ const height = space.large * 2 + space.medium * 2 + words+ return current.height === height ? current : { ...current, height }+ })+ })++ // One view on the map: its width from the spacing, its height in the view's own proportion, smaller+ // when the room beside the Taskbar is smaller, and both whole pixels so the lines between views stay even.+ const ratio = surface.height / surface.width++ const preferred = space.xlarge * 3.25++ const width = room ? Math.min(preferred, (room.width - chrome.width) / columns, (room.height - chrome.height) / rows / ratio) : preferred++ const cell = room ? { width: Math.max(1, Math.floor(width)), height: Math.max(1, Math.floor(width * ratio)) } : { width: Math.round(width), height: Math.round(width * ratio) }+/** Where a point of the plane falls on the map. */const mapX = (planeX: number) => (planeX / surface.width + 0.5 - range.minX) * cell.width@@ -270,7 +351,7 @@ function ViewMap({ labelId, viewport, windows, centered, menus }: Readonly<{ lab// The panel is as wide as the map; its words wrap under it.return <div className="grid" style={{ gap: space.medium, padding: space.large, width: columns * cell.width, boxSizing: "content-box" }}>- <Text id={labelId} size="medium" className="flex items-center" style={{ fontWeight: 500, gap: space.small }}><MapIcon aria-hidden />Map</Text>+ <Text ref={title} id={labelId} size="medium" className="flex items-center" style={{ fontWeight: 500, gap: space.small }}><MapIcon aria-hidden />Map</Text><div className="relative">@@ -331,7 +412,7 @@ function ViewMap({ labelId, viewport, windows, centered, menus }: Readonly<{ lab</div>- <div className="flex items-center justify-between" style={{ gap: space.medium }}>+ <div ref={footer} className="flex items-center justify-between" style={{ gap: space.medium }}><Text size="xsmall" tone="secondary">Choose a view or a Window, drag the frame, or drag a Window to move it.</Text>@@ -345,7 +426,7 @@ function ViewMap({ labelId, viewport, windows, centered, menus }: Readonly<{ lab/*** A Window on the map: a small card around its icon where the Window's center is, in a light tint* of the secondary color like the Start Menu's cards, and in the primary color when it is the front- * Window. Its title shows on hover and focus. Pressing it brings the view to the Window and the Window to the front; its menu is the Window's menu, as in the Taskbar; dragging it moves the+ * Window. Its title shows on hover and focus. Pressing it brings the view to the view the Window is in, and the Window to the front; its menu is the Window's menu, as in the Taskbar; dragging it moves the* Window anywhere on the map.*/function MapWindow({ window, viewport, menus, onName, mapX, mapY, cell }: Readonly<{diff --git a/source/client/view/structure/desktop/orientation.ts b/source/client/view/structure/desktop/orientation.tsnew file mode 100644index 0000000..7bfd940--- /dev/null+++ b/source/client/view/structure/desktop/orientation.ts@@ -0,0 +1,19 @@+import { useEffect, useState } from "react"++/** Whether the screen showing this Desktop is taller than it is wide; follows the screen as it turns or resizes. */+export function usePortrait() {++ const [portrait, setPortrait] = useState(() => typeof window !== "undefined" && window.innerHeight > window.innerWidth)++ useEffect(function () {++ const follow = () => setPortrait(window.innerHeight > window.innerWidth)++ window.addEventListener("resize", follow)++ return () => window.removeEventListener("resize", follow)++ }, [])++ return portrait+}diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 635af48..39fe73d 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, useCallbaimport { useReducedMotion } from "@libs/react-motion"import { surfaceLifecyclePose, surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"import WindowPanel from "./window-panel"-import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, noPaintMargins, presentedWindowSize, planeGeometry, resolveWindowGeometry, windowPaintInsets, type PaintMargins, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"+import { absoluteWindowGeometry, constrainWindowGeometry, minimumWindowSize, noPaintMargins, 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"@@ -68,7 +68,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 = 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) {+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) {const reducedMotion = useReducedMotion()const appearance = useAppearance()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 2a2f3bb..8784c1e 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@@ -11,7 +11,7 @@ import { dirname, isAbsolute, join } from "node:path"import { isDeepStrictEqual } from "node:util"import Logs, { type LogSource } from "./logs"import { isValue, layers } from "./config"-import { parseLaunch, parseProgramDefinition, parseProgramInstallOptions, parseProgramUninstallOptions, type ProgramInstallOptions, type ProgramUninstallOptions, type ClientLaunch, type Launch, type ProgramCommandChunk, type ProgramDefinition } from "@phreshos/core"+import { parseLaunch, parseProgramDefinition, parseProgramInstallOptions, parseProgramUninstallOptions, parseRelativeValue, type ProgramInstallOptions, type ProgramUninstallOptions, type ClientLaunch, type Launch, type Position, type ProgramCommandChunk, type ProgramDefinition, type Size, type Value } from "@phreshos/core"import { type default as Process, type ProcessLaunch, type Stream } from "../process-manager/process"import { type StandardShape } from "../process-manager/process-manager"import Program, { type CommandOutput, type InstallOutput } from "./program"@@ -28,7 +28,6 @@ import {type PermissionValue,type Permissions} from "@phreshos/core"-import { windowLayerDefaults } from "@shared/window-layers"const maximumProcessesPerProgram = 20@@ -1537,19 +1536,17 @@ export default class ProgramManager extends TheLink {const layer = asked.layer ?? client.layer ?? "window"- // Unset geometry stays zero. The System only records Window values; how a Window is shown, and- // where a new one appears, is decided by the Desktop, or by whoever launches it and asks.- const size = asked.size ?? client.size ?? { width: 0, height: 0 }-- const defaults = windowLayerDefaults(layer)+ // What neither the launch nor the Program says, the System fills the same way in every layer,+ // knowing nothing of any screen: a square of fixed pixels, centered on the plane's zero.+ const size = asked.size ?? client.size ?? defaultWindowSizereturn {title: asked.title ?? client.title ?? program.title,- header: asked.header ?? client.header ?? defaults.header,+ header: asked.header ?? client.header ?? true,- position: asked.position ?? client.position ?? { x: 0, y: 0 },+ position: asked.position ?? client.position ?? centered(size),size,@@ -1572,6 +1569,34 @@ export default class ProgramManager extends TheLink {export type ProgramManagerSnapshot = ReturnType<ProgramManager["toJSON"]>+/** The size of a Window whose launch and Program name none. */+const defaultWindowSize = Object.freeze({ width: 500, height: 500 })++/** The position that puts a Window of this size with its center on the plane's zero. */+function centered(size: Size): Position {++ return { x: half(size.width), y: half(size.height) }+}++/** Minus half of a value, pixels and share alike: `500` gives `-250`, `"1/2"` gives `"-25%"`. */+function half(value: Value): Value {++ const parsed = parseRelativeValue(value)++ if (!parsed) return 0++ // Adding zero turns a halved zero's sign away: -0 is still no distance.+ const share = -parsed.relative / 2 + 0++ const pixels = -parsed.pixels / 2 + 0++ if (share === 0) return pixels++ if (pixels === 0) return `${share * 100}%`++ return `${share * 100}% ${pixels < 0 ? "-" : "+"} ${Math.abs(pixels)}`+}+// What a launcher may say at the start. Named rather than ordered,// because an order is invisible where it is written — and text, because// an option must mean one thing however the process was started, anddiff --git a/source/shared/window-layers.ts b/source/shared/window-layers.tsindex 33a7fd3..577bf90 100644--- a/source/shared/window-layers.ts+++ b/source/shared/window-layers.ts@@ -1,9 +1,5 @@import type { WindowLayer } from "@phreshos/core"-export function windowLayerDefaults(layer: WindowLayer) {- return Object.freeze({ header: layer === "window" })-}-export function isRawWindowPresentationLayer(layer: WindowLayer) {return layer === "under" || layer === "over" || layer === "shell"}diff --git a/tests/client-launch.test.ts b/tests/client-launch.test.tsindex 349cde3..ddc5129 100644--- a/tests/client-launch.test.ts+++ b/tests/client-launch.test.ts@@ -31,4 +31,19 @@ test("client launch contract", async () => {assert.equal(shape({}).header, false)assert.equal(shape({ layer: "over", header: false }).header, false)assert.throws(() => shape({ header: "hidden" } as unknown as ClientLaunch), /header state/)++ // What neither the launch nor the Program names is filled the same way in every layer.+ const bare = { client: {}, title: "Bare" }+ const bareShape = (overrides: ClientLaunch) => ProgramManager.prototype.clientShape.call(manager as unknown as ProgramManager, bare as unknown as Program, overrides)+ for (const layer of ["window", "under", "over", "shell", "wallpaper"] as const) {+ const filled = bareShape({ layer })+ assert.deepEqual(filled.size, { width: 500, height: 500 })+ assert.deepEqual(filled.position, { x: -250, y: -250 })+ assert.equal(filled.header, true)+ }+ // A size that is named is centered on zero too, shares and pixels alike.+ assert.deepEqual(bareShape({ size: { width: 800, height: "1/2" } }).position, { x: -400, y: "-25%" })+ assert.deepEqual(bareShape({ size: { width: "1/2 + 100", height: 0 } }).position, { x: "-25% - 50", y: 0 })+ // A position that is named is kept.+ assert.deepEqual(bareShape({ position: { x: 0, y: 0 } }).position, { x: 0, y: 0 })}, 120_000)