Skip to content

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

Refine desktop window interactions

zohayrslileh825742e7f005
diff --git a/source/client/view/components/desktop-host/local-window.ts b/source/client/view/components/desktop-host/local-window.ts
index 9b0a631..ae68b06 100644
--- a/source/client/view/components/desktop-host/local-window.ts
+++ b/source/client/view/components/desktop-host/local-window.ts
@@ -10,6 +10,7 @@ import {
type WindowLayer,
type WindowState
} from "@phreshos/core"
+import { isDesktopReplacementLayer } from "@shared/desktop-replacement"
export type LocalAnimation = Readonly<{
revision: number
@@ -92,7 +93,7 @@ export function parseLocalWindowTransaction(value: unknown): AppearanceTransacti
export function requireLocalSurfaceLayer(layer: WindowLayer) {
if (layer === "window") throw new Error("A standard Window already owns its host Surface")
- if (layer === "wallpaper") throw new Error("The wallpaper layer does not allow a local Surface")
+ if (isDesktopReplacementLayer(layer)) throw new Error(`The ${layer} layer does not allow a local Surface`)
}
function easing(value: unknown): Easing {
diff --git a/source/client/view/components/window-manager/layer-policy.ts b/source/client/view/components/window-manager/layer-policy.ts
index 466fdf0..ed90c54 100644
--- a/source/client/view/components/window-manager/layer-policy.ts
+++ b/source/client/view/components/window-manager/layer-policy.ts
@@ -8,7 +8,8 @@ const properties: Readonly<Record<WindowLayer, readonly PresentationProperty[]>>
window: ["title", "position", "size", "minimized", "maximized", "depth"],
under: ["position", "size", "minimized", "maximized", "depth", "surface"],
over: ["position", "size", "minimized", "maximized", "depth", "surface"],
- wallpaper: []
+ wallpaper: [],
+ "start-menu": []
}
export function requireLocalProperty(layer: WindowLayer, property: PresentationProperty) {
diff --git a/source/client/view/components/window-manager/local-windows.ts b/source/client/view/components/window-manager/local-windows.ts
index 8fdb1ef..ca372ec 100644
--- a/source/client/view/components/window-manager/local-windows.ts
+++ b/source/client/view/components/window-manager/local-windows.ts
@@ -7,6 +7,8 @@ import {
type WindowState
} from "@phreshos/core"
import { type LocalWindowHost, type LocalWindowState } from "../desktop-host/local-window"
+import { isDesktopReplacementLayer } from "@shared/desktop-replacement"
+import { type WindowRegion } from "./window-geometry"
export interface LocalWindowEntry {
identity: string
@@ -21,7 +23,8 @@ export default class LocalWindows implements LocalWindowHost {
private readonly live = new Map<string, string>()
private readonly authoritative = new Map<string, LocalWindowState>()
private readonly waiting = new Map<string, WaitingAnimation>()
- private readonly readers = new Map<string, LocalGeometryReader>()
+ private readonly representations = new Map<string, LocalGeometryRepresentation>()
+ private readonly representationListeners = new Map<string, () => void>()
private readonly following = new Map<string, FollowingWindow>()
private revision = 0
private changed: (windows: ReadonlyMap<string, LocalWindowState>) => void = () => undefined
@@ -93,7 +96,7 @@ export default class LocalWindows implements LocalWindowHost {
if (!this.windows.has(identity)) return
const next = new Map(this.windows)
next.delete(identity)
- this.readers.delete(identity)
+ this.removeRepresentation(identity)
this.authoritative.delete(identity)
this.following.delete(identity)
@@ -105,8 +108,11 @@ export default class LocalWindows implements LocalWindowHost {
public state(process: string) {
const { identity, state } = this.existing(process)
- const geometry = this.readers.get(identity)?.()
- return windowState(state, frontmost(this.windows, state.layer) === identity, geometry)
+ const geometry = this.representations.get(identity)?.read()
+ return windowState(state, frontmost(this.windows, state.layer) === identity, geometry && {
+ position: { x: geometry.x, y: geometry.y },
+ size: { width: geometry.width, height: geometry.height }
+ })
}
/** Returns the values currently driving this desktop's representation. */
@@ -115,15 +121,70 @@ export default class LocalWindows implements LocalWindowHost {
return this.existing(process).state
}
- public readonly represent = (process: string, reader: LocalGeometryReader | null) => {
+ public readonly represent = (process: string, representation: LocalGeometryRepresentation | null) => {
const identity = this.live.get(process)
if (!identity) return
- if (reader) this.readers.set(identity, reader)
+ this.removeRepresentation(identity)
+
+ if (representation) {
+
+ this.representations.set(identity, representation)
+
+ this.representationListeners.set(identity, representation.listen(() => {
+
+ if (this.representations.get(identity) !== representation) return
+
+ this.publish(new Map(this.windows))
+ }))
+ }
+
+ this.publish(new Map(this.windows))
+ }
+
+ public representedGeometry(process: string) {
+
+ const identity = this.live.get(process)
+
+ return identity ? this.representations.get(identity)?.read() ?? null : null
+ }
+
+ public presentGeometry(process: string, geometry: WindowRegion) {
+
+ const identity = this.live.get(process)
+
+ if (!identity) return false
+
+ const representation = this.representations.get(identity)
+
+ if (!representation) return false
+
+ representation.present(geometry)
+
+ return true
+ }
+
+ public beginGeometry(process: string) {
- else this.readers.delete(identity)
+ const identity = this.live.get(process)
+
+ return identity ? this.representations.get(identity)?.begin() ?? null : null
+ }
+
+ public finishGeometry(process: string) {
+
+ const identity = this.live.get(process)
+
+ if (identity) this.representations.get(identity)?.finish()
+ }
+
+ public cancelGeometry(process: string) {
+
+ const identity = this.live.get(process)
+
+ if (identity) this.representations.get(identity)?.cancel()
}
public move(process: string, position: WindowState["position"], transaction?: RequestedTransaction) {
@@ -292,6 +353,15 @@ export default class LocalWindows implements LocalWindowHost {
this.publish(next)
}
+ private removeRepresentation(identity: string) {
+
+ this.representationListeners.get(identity)?.()
+
+ this.representationListeners.delete(identity)
+
+ this.representations.delete(identity)
+ }
+
private changeGeometry(identity: string, value: WindowGeometry, transaction?: RequestedTransaction) {
const state = this.windows.get(identity)
@@ -381,11 +451,11 @@ function localState(client: ClientState): LocalWindowState {
return {
...authoritativeState(client),
title: window.layer === "window" ? window.title : "",
- position: window.layer === "wallpaper" ? { x: 0, y: 0 } : window.position,
- size: window.layer === "wallpaper" ? { width: "100%", height: "100%" } : window.size,
- minimized: window.layer === "wallpaper" ? false : window.minimized,
- maximized: window.layer === "wallpaper" ? true : window.maximized,
- depth: window.layer === "wallpaper" ? 0 : window.depth,
+ position: isDesktopReplacementLayer(window.layer) ? { x: 0, y: 0 } : window.position,
+ size: isDesktopReplacementLayer(window.layer) ? { width: "100%", height: "100%" } : window.size,
+ minimized: isDesktopReplacementLayer(window.layer) ? false : window.minimized,
+ maximized: isDesktopReplacementLayer(window.layer) ? true : window.maximized,
+ depth: isDesktopReplacementLayer(window.layer) ? 0 : window.depth,
}
}
@@ -419,10 +489,20 @@ function windowState(local: LocalWindowState, front: boolean, geometry?: Readonl
}
}
-export type LocalGeometryReader = () => Readonly<{
- position: WindowState["position"]
- size: WindowState["size"]
-}>
+export interface LocalGeometryRepresentation {
+
+ read: () => WindowRegion
+
+ present: (geometry: WindowRegion) => void
+
+ begin: () => WindowRegion | null
+
+ finish: () => void
+
+ cancel: () => void
+
+ listen: (settled: () => void) => () => void
+}
function frontmost(windows: ReadonlyMap<string, LocalWindowState>, layer: LocalWindowState["layer"]) {
diff --git a/source/client/view/components/window-manager/shared-resize.ts b/source/client/view/components/window-manager/shared-resize.ts
new file mode 100644
index 0000000..31fb6de
--- /dev/null
+++ b/source/client/view/components/window-manager/shared-resize.ts
@@ -0,0 +1,217 @@
+import { minimumWindowSize, type WindowRegion } from "./window-geometry"
+
+export interface SharedResizeWindow {
+
+ identity: string
+
+ geometry: WindowRegion
+}
+
+export interface SharedResizeBoundary {
+
+ identity: string
+
+ orientation: "horizontal" | "vertical"
+
+ position: number
+
+ start: number
+
+ end: number
+
+ before: readonly string[]
+
+ after: readonly string[]
+}
+
+const alignmentTolerance = 1
+
+/** Finds connected contacts between opposite edges of visible standard windows. */
+export function sharedResizeBoundaries(windows: readonly SharedResizeWindow[]) {
+
+ const contacts: Contact[] = []
+
+ for (let firstIndex = 0; firstIndex < windows.length; firstIndex++) {
+
+ for (let secondIndex = firstIndex + 1; secondIndex < windows.length; secondIndex++) {
+
+ const first = windows[firstIndex]
+
+ const second = windows[secondIndex]
+
+ verticalContact(contacts, first, second)
+
+ verticalContact(contacts, second, first)
+
+ horizontalContact(contacts, first, second)
+
+ horizontalContact(contacts, second, first)
+ }
+ }
+
+ const groups: Contact[][] = []
+
+ for (const contact of contacts) {
+
+ const touching = groups.filter(group => group.some(member => connected(member, contact)))
+
+ if (!touching.length) {
+
+ groups.push([contact])
+
+ continue
+ }
+
+ const merged = [contact, ...touching.flat()]
+
+ for (const group of touching) groups.splice(groups.indexOf(group), 1)
+
+ groups.push(merged)
+ }
+
+ return groups.map(boundary)
+}
+
+/** Applies one boundary displacement while preserving every participant's far edge. */
+export function resizeSharedBoundary(boundary: SharedResizeBoundary, windows: readonly SharedResizeWindow[], requestedDelta: number) {
+
+ const participants = new Map(windows.map(window => [window.identity, window.geometry]))
+
+ let minimumDelta = Number.NEGATIVE_INFINITY
+
+ let maximumDelta = Number.POSITIVE_INFINITY
+
+ for (const identity of boundary.before) {
+
+ const geometry = required(participants, identity)
+
+ minimumDelta = Math.max(minimumDelta, minimum(boundary.orientation) - span(geometry, boundary.orientation))
+ }
+
+ for (const identity of boundary.after) {
+
+ const geometry = required(participants, identity)
+
+ maximumDelta = Math.min(maximumDelta, span(geometry, boundary.orientation) - minimum(boundary.orientation))
+ }
+
+ const delta = Math.min(Math.max(requestedDelta, minimumDelta), maximumDelta)
+
+ const geometries = new Map<string, WindowRegion>()
+
+ for (const identity of boundary.before) {
+
+ const geometry = required(participants, identity)
+
+ geometries.set(identity, boundary.orientation === "vertical"
+ ? { ...geometry, width: geometry.width + delta }
+ : { ...geometry, height: geometry.height + delta })
+ }
+
+ for (const identity of boundary.after) {
+
+ const geometry = required(participants, identity)
+
+ geometries.set(identity, boundary.orientation === "vertical"
+ ? { ...geometry, x: geometry.x + delta, width: geometry.width - delta }
+ : { ...geometry, y: geometry.y + delta, height: geometry.height - delta })
+ }
+
+ return { delta, geometries }
+}
+
+interface Contact {
+
+ orientation: SharedResizeBoundary["orientation"]
+
+ position: number
+
+ start: number
+
+ end: number
+
+ before: string
+
+ after: string
+}
+
+function verticalContact(contacts: Contact[], before: SharedResizeWindow, after: SharedResizeWindow) {
+
+ const edge = before.geometry.x + before.geometry.width
+
+ if (!near(edge, after.geometry.x)) return
+
+ const start = Math.max(before.geometry.y, after.geometry.y)
+
+ const end = Math.min(before.geometry.y + before.geometry.height, after.geometry.y + after.geometry.height)
+
+ if (end <= start) return
+
+ contacts.push({ orientation: "vertical", position: (edge + after.geometry.x) / 2, start, end, before: before.identity, after: after.identity })
+}
+
+function horizontalContact(contacts: Contact[], before: SharedResizeWindow, after: SharedResizeWindow) {
+
+ const edge = before.geometry.y + before.geometry.height
+
+ if (!near(edge, after.geometry.y)) return
+
+ const start = Math.max(before.geometry.x, after.geometry.x)
+
+ const end = Math.min(before.geometry.x + before.geometry.width, after.geometry.x + after.geometry.width)
+
+ if (end <= start) return
+
+ contacts.push({ orientation: "horizontal", position: (edge + after.geometry.y) / 2, start, end, before: before.identity, after: after.identity })
+}
+
+function connected(first: Contact, second: Contact) {
+
+ return first.orientation === second.orientation
+ && near(first.position, second.position)
+ && second.start <= first.end + alignmentTolerance
+ && first.start <= second.end + alignmentTolerance
+}
+
+function boundary(contacts: readonly Contact[]): SharedResizeBoundary {
+
+ const orientation = contacts[0].orientation
+
+ const before = [...new Set(contacts.map(contact => contact.before))].sort()
+
+ const after = [...new Set(contacts.map(contact => contact.after))].sort()
+
+ return {
+ identity: `${orientation}:${before.join(",")}:${after.join(",")}`,
+ orientation,
+ position: contacts.reduce((total, contact) => total + contact.position, 0) / contacts.length,
+ start: Math.min(...contacts.map(contact => contact.start)),
+ end: Math.max(...contacts.map(contact => contact.end)),
+ before,
+ after
+ }
+}
+
+function span(geometry: WindowRegion, orientation: SharedResizeBoundary["orientation"]) {
+
+ return orientation === "vertical" ? geometry.width : geometry.height
+}
+
+function minimum(orientation: SharedResizeBoundary["orientation"]) {
+
+ return orientation === "vertical" ? minimumWindowSize.width : minimumWindowSize.height
+}
+
+function near(first: number, second: number) {
+
+ return Math.abs(first - second) <= alignmentTolerance
+}
+
+function required(windows: ReadonlyMap<string, WindowRegion>, identity: string) {
+
+ const geometry = windows.get(identity)
+
+ if (!geometry) throw new Error(`The shared resize Window "${identity}" is unavailable`)
+
+ return geometry
+}
diff --git a/source/client/view/components/window-manager/window-geometry.ts b/source/client/view/components/window-manager/window-geometry.ts
index 0e2e46a..9c2b1ab 100644
--- a/source/client/view/components/window-manager/window-geometry.ts
+++ b/source/client/view/components/window-manager/window-geometry.ts
@@ -18,6 +18,8 @@ export interface WindowSurfaceSize {
height: number
}
+export const minimumWindowSize = Object.freeze({ width: 260, height: 160 })
+
/**
* Every window type uses this same calculation inside the CSS containing
* block supplied by its layer. Every expression is one relative coefficient
diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.ts
index 39d060d..eeb9216 100644
--- a/source/client/view/components/window-manager/window-manager.ts
+++ b/source/client/view/components/window-manager/window-manager.ts
@@ -1,11 +1,13 @@
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 { ReactTunnel } from "@the-link/react"
-import { Layer } from "@server/core/link-manager/auth-manager/program-manager/config"
-import { type Position, type Size, type Value } from "@phreshos/core"
+import { type Layer, type Position, type Size, type Value } from "@phreshos/core"
import { useCallback, useRef, useState } from "react"
import { type default as AuthManager } from "@client/core/link-manager/auth-manager/auth-manager"
import LocalWindows from "./local-windows"
+import { isDesktopReplacementLayer } from "@shared/desktop-replacement"
+import { type SharedResizeWindow } from "./shared-resize"
+import { type WindowRegion } from "./window-geometry"
/**
* The authorized view's windows: processes that have one. A window is a
@@ -112,7 +114,7 @@ export default function useWindows(authManager: AuthManager) {
const gone = [...previousClients.current.values()].filter(previous => currentClients.get(previous.record.identity)?.client !== previous.client)
- const departed = new Set(gone.filter(({ client }) => client.window.layer === "wallpaper").map(({ identity }) => identity))
+ const departed = new Set(gone.filter(({ client }) => isDesktopReplacementLayer(client.window.layer)).map(({ identity }) => identity))
for (const identity of departed) localWindow.remove(identity)
@@ -157,7 +159,7 @@ export default function useWindows(authManager: AuthManager) {
const summit = useCallback((layer: Layer) => [...peer.processes.values()].reduce((highest, process) => process.client?.window.layer === layer ? Math.max(highest, process.client.window.depth) : highest, 0), [peer])
// Resolve the front window of every layer in one pass.
- const fronts: Record<Layer, Process | null> = { wallpaper: null, under: null, window: null, over: null }
+ const fronts: Record<Layer, Process | null> = { wallpaper: null, under: null, window: null, over: null, "start-menu": null }
for (const process of records) {
@@ -328,13 +330,88 @@ export default function useWindows(authManager: AuthManager) {
.sort((one, other) => (rank.get(one.identity) ?? Number.MAX_SAFE_INTEGER) - (rank.get(other.identity) ?? Number.MAX_SAFE_INTEGER))
- const panesByLayer: Record<Layer, typeof panes> = { wallpaper: [], under: [], window: [], over: [] }
+ const panesByLayer: Record<Layer, typeof panes> = { wallpaper: [], under: [], window: [], over: [], "start-menu": [] }
for (const pane of panes) {
panesByLayer[pane.local.layer].push(pane)
}
+ const sharedResizeWindows: SharedResizeWindow[] = panesByLayer.window.flatMap(function (pane) {
+
+ if (pane.closing || pane.stopping || pane.local.minimized || pane.local.maximized) return []
+
+ const geometry = localWindow.representedGeometry(pane.record.identity)
+
+ if (!geometry) return []
+
+ return [{ identity: pane.record.identity, geometry }]
+ })
+
+ const presentSharedResize = useCallback(function (geometries: ReadonlyMap<string, WindowRegion>) {
+
+ for (const [identity, geometry] of geometries) localWindow.presentGeometry(identity, geometry)
+
+ }, [localWindow])
+
+ const beginSharedResize = useCallback(function (identities: readonly string[]) {
+
+ const geometries = new Map<string, WindowRegion>()
+
+ for (const identity of identities) {
+
+ const geometry = localWindow.beginGeometry(identity)
+
+ if (geometry) {
+
+ geometries.set(identity, geometry)
+
+ continue
+ }
+
+ for (const started of geometries.keys()) localWindow.cancelGeometry(started)
+
+ return null
+ }
+
+ return geometries
+
+ }, [localWindow])
+
+ const finishSharedResize = useCallback(function (identities: readonly string[]) {
+
+ for (const identity of identities) localWindow.finishGeometry(identity)
+
+ }, [localWindow])
+
+ const cancelSharedResize = useCallback(function (identities: readonly string[]) {
+
+ for (const identity of identities) localWindow.cancelGeometry(identity)
+
+ }, [localWindow])
+
+ const commitSharedResize = useCallback(function (geometries: ReadonlyMap<string, WindowRegion>) {
+
+ for (const [identity, region] of geometries) {
+
+ const process = peer.processes.get(identity)
+
+ const window = process?.client?.window
+
+ if (!window || window.layer !== "window") continue
+
+ const geometry = {
+ position: { x: region.x, y: region.y },
+ size: { width: region.width, height: region.height }
+ }
+
+ void localWindow.geometry(identity, geometry)
+
+ commit(window.setGeometry(geometry))
+ }
+
+ }, [commit, localWindow, peer])
+
return {
records,
@@ -347,6 +424,15 @@ export default function useWindows(authManager: AuthManager) {
localWindow,
+ sharedResize: {
+ windows: sharedResizeWindows,
+ begin: beginSharedResize,
+ present: presentSharedResize,
+ commit: commitSharedResize,
+ finish: finishSharedResize,
+ cancel: cancelSharedResize
+ },
+
close,
closed,
diff --git a/source/client/view/structure/desktop/desktop-display.tsx b/source/client/view/structure/desktop/desktop-display.tsx
index d8ec999..3c9c77b 100644
--- a/source/client/view/structure/desktop/desktop-display.tsx
+++ b/source/client/view/structure/desktop/desktop-display.tsx
@@ -5,7 +5,7 @@ import { desktopDisplayStyle } from "./geometry"
* The desktop's visible stacking structure. Each program layer owns a
* containing block; window geometry remains identical inside every layer.
*/
-export default function DesktopDisplay({ wallpaper, underWindows, windows, overWindows, windowSurfaceRef, taskbar }: DesktopDisplayProps) {
+export default function DesktopDisplay({ wallpaper, underWindows, windows, sharedResizeBoundaries, overWindows, windowSurfaceRef, taskbar }: DesktopDisplayProps) {
return <div className="m-(--desktop-gutter) grid min-h-0 grid-cols-1 grid-rows-[1fr_auto] gap-(--desktop-gutter)" style={desktopDisplayStyle}>
@@ -25,6 +25,8 @@ export default function DesktopDisplay({ wallpaper, underWindows, windows, overW
{windows}
+ {sharedResizeBoundaries}
+
</div>
<div className="pointer-events-none absolute inset-0 z-3 overflow-hidden">
@@ -46,6 +48,8 @@ interface DesktopDisplayProps {
windows: ReactNode
+ sharedResizeBoundaries: ReactNode
+
overWindows: ReactNode
windowSurfaceRef: Ref<HTMLDivElement>
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 07ce26e..1ae6bd9 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -1,4 +1,4 @@
-import { type Layer } from "@server/core/link-manager/auth-manager/program-manager/config"
+import { type Layer } from "@phreshos/core"
import { useCallback, useEffect, useRef, useState } from "react"
import { ApplicationContext, AuthManagerContext } from "../../contexts"
import useClientHost from "../../components/desktop-host/client-host"
@@ -18,6 +18,8 @@ import { ReadyWallpaper, WallpaperBackground } from "./wallpaper/wallpaper"
import Loading from "../../components/loading"
import { useRequirement } from "@libs/readiness"
import { useAppearance, usePreferences, useThemedValue } from "@phreshos/react-ui"
+import { isDesktopReplacementLayer } from "@shared/desktop-replacement"
+import SharedResizeBoundaries from "./windows/shared-resize-boundaries"
export default function Workspace() {
@@ -46,6 +48,7 @@ export default function Workspace() {
const [fileWallpaperReady, setFileWallpaperReady] = useState(false)
const hasWallpaperClient = windows.records.some(record => record.client?.window.layer === "wallpaper")
+ const hasStartMenuClient = windows.records.some(record => record.client?.window.layer === "start-menu")
const wallpaperReady = hasWallpaperClient || fileWallpaperReady
const desktop = useRef<HTMLDivElement>(null)
@@ -156,7 +159,7 @@ export default function Workspace() {
stopping={stopping}
- entering={layer === "wallpaper" ? false : entering}
+ entering={isDesktopReplacementLayer(layer) ? false : entering}
door={application.doors.program}
@@ -193,7 +196,7 @@ export default function Workspace() {
const taskbar = <Taskbar
- leading={<StartMenu />}
+ leading={<StartMenu replacement={hasStartMenuClient ? renderWindows("start-menu") : undefined} />}
trailing={<SignOut />}
@@ -248,6 +251,8 @@ export default function Workspace() {
windows={renderWindows("window")}
+ sharedResizeBoundaries={<SharedResizeBoundaries {...windows.sharedResize} />}
+
overWindows={renderWindows("over")}
windowSurfaceRef={windowSurfaceRef}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
index 2561ebf..28e9faf 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx
@@ -63,7 +63,7 @@ export default function ({ label, trigger, children, className, style, ...props
// the iframe becomes this document's active element.
function closeForProgramFrame() {
- if (document.activeElement instanceof HTMLIFrameElement) close()
+ if (document.activeElement instanceof HTMLIFrameElement && !surface.current?.contains(document.activeElement)) close()
}
window.addEventListener("blur", closeForProgramFrame)
diff --git a/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
index 7d11d60..7ad23c4 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/processes/processes.tsx
@@ -31,11 +31,11 @@ export default function Processes({ terms }: Readonly<{ terms: readonly string[]
</div>
- return <ScrollArea role="group" aria-label="Processes" className="h-full min-h-0">
+ return <div role="group" aria-label="Processes" className="grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)]">
- <div className="grid content-start">
+ <h3 className="px-3 py-2 text-xs font-medium opacity-60">Processes · {matching.length}</h3>
- <h3 className="sticky top-0 z-10 px-3 py-2 text-xs font-medium opacity-60">Processes · {matching.length}</h3>
+ <ScrollArea className="h-full min-h-0">
<ul className="m-0 grid list-none content-start gap-1 p-2">
@@ -43,7 +43,7 @@ export default function Processes({ terms }: Readonly<{ terms: readonly string[]
</ul>
- </div>
+ </ScrollArea>
- </ScrollArea>
+ </div>
}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsx
index 3579531..f70a736 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/programs/launcher-item.tsx
@@ -9,7 +9,7 @@ export default function ({ icon, label, description, children, className, ...pro
type="button"
- className={`group grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-3 rounded-xl px-3 py-2 text-start outline-none hover:bg-white/45 focus-visible:bg-white/55 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-white/85 active:bg-white/65 ${className ?? ""}`}
+ className={`group grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-3 rounded-xl px-3 py-2 text-start outline-none active:scale-[0.98] ${className ?? ""}`}
>
diff --git a/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
index e952772..cd56d2c 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/programs/programs.tsx
@@ -30,11 +30,11 @@ export default function Programs({ onChoose, terms }: ProgramsProps) {
</div>
- return <ScrollArea role="group" aria-label="Programs" className="h-full min-h-0">
+ return <div role="group" aria-label="Programs" className="grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)]">
- <div className="grid content-start">
+ <h3 className="px-3 py-2 text-xs font-medium opacity-60">Programs · {programs.length}</h3>
- <h3 className="sticky top-0 z-10 px-3 py-2 text-xs font-medium opacity-60">Programs · {programs.length}</h3>
+ <ScrollArea className="h-full min-h-0">
<div className="grid content-start gap-1 p-2">{programs.map(record => <ProgramItem
@@ -48,9 +48,9 @@ export default function Programs({ onChoose, terms }: ProgramsProps) {
/>)}</div>
- </div>
+ </ScrollArea>
- </ScrollArea>
+ </div>
}
function ProgramItem({ icon, record, onChoose }: { icon: string, record: Program, onChoose: () => void }) {
diff --git a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
index c0fe521..294b2a2 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/start-menu.tsx
@@ -1,5 +1,5 @@
import logo from "@/assets/bundled/logo.png"
-import { memo, useState } from "react"
+import { memo, useState, type ReactNode } from "react"
import Launcher from "./launcher"
import Programs from "./programs/programs"
import Processes from "./processes/processes"
@@ -9,7 +9,7 @@ import SearchBar from "./search-bar"
import { searchTerms } from "./search"
/** The taskbar entry point for current and future desktop actions. */
-export default memo(function StartMenu() {
+export default memo(function StartMenu({ replacement }: Readonly<{ replacement?: ReactNode }>) {
const application = ApplicationContext.useValue()
@@ -33,14 +33,17 @@ export default memo(function StartMenu() {
>
- {(close, labelId) => <StartMenuPanel
- labelId={labelId}
- name={application.displayName}
- version={application.version}
- left={<Programs onChoose={close} terms={terms} />}
- right={<Processes terms={terms} />}
- footer={<SearchBar query={query} onChange={setQuery} />}
- />}
+ {(close, labelId) => replacement ? <>
+ <h2 id={labelId} className="sr-only">{application.displayName}</h2>
+ {replacement}
+ </> : <StartMenuPanel
+ labelId={labelId}
+ name={application.displayName}
+ version={application.version}
+ left={<Programs onChoose={close} terms={terms} />}
+ right={<Processes terms={terms} />}
+ footer={<SearchBar query={query} onChange={setQuery} />}
+ />}
</Launcher>
})
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index 3db2ceb..2f93983 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -2,7 +2,7 @@ import Process from "@client/core/link-manager/auth-manager/process-manager/proc
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 LocalAnimation, type LocalSurfaceState } from "@client/view/components/desktop-host/local-window"
-import { type LocalGeometryReader } from "@client/view/components/window-manager/local-windows"
+import { type LocalGeometryRepresentation } from "@client/view/components/window-manager/local-windows"
import { type Position, type Size, type Theme } from "@phreshos/core"
import Spinner from "@client/view/components/spinner"
import Window from "./window"
@@ -37,7 +37,7 @@ export default memo(function ({ identity, record, assetId, client, title, icon,
const snap = useCallback((position: Position, size: Size) => onSnap(record, position, size), [onSnap, record])
- const represent = useCallback((reader: LocalGeometryReader | null) => onLocalRepresentation(record.identity, reader), [onLocalRepresentation, record])
+ const represent = useCallback((representation: LocalGeometryRepresentation | null) => onLocalRepresentation(record.identity, representation), [onLocalRepresentation, record])
const frameSource = programFrameSource(assetId, door)
@@ -220,7 +220,7 @@ interface ProcessWindowProps {
onLocalAnimationComplete: (kind: "geometry" | "minimize" | "surface", revision: number) => void
- onLocalRepresentation: (identity: string, reader: LocalGeometryReader | null) => void
+ onLocalRepresentation: (identity: string, representation: LocalGeometryRepresentation | null) => void
paintSurfaceSize?: WindowSurfaceSize
diff --git a/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx b/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx
new file mode 100644
index 0000000..c143eb2
--- /dev/null
+++ b/source/client/view/structure/desktop/windows/shared-resize-boundaries.tsx
@@ -0,0 +1,155 @@
+import { type PointerEvent as ReactPointerEvent, useState } from "react"
+import { resizeSharedBoundary, sharedResizeBoundaries, type SharedResizeBoundary, type SharedResizeWindow } from "@client/view/components/window-manager/shared-resize"
+import { type WindowRegion } from "@client/view/components/window-manager/window-geometry"
+
+const thickness = 4
+
+export default function SharedResizeBoundaries({ windows, begin, present, commit, finish, cancel }: SharedResizeBoundariesProps) {
+
+ const boundaries = sharedResizeBoundaries(windows)
+
+ const [active, setActive] = useState<ActiveBoundary | null>(null)
+
+ function grab(event: ReactPointerEvent<HTMLDivElement>, boundary: SharedResizeBoundary) {
+
+ event.preventDefault()
+
+ const handle = event.currentTarget
+
+ const identities = [...new Set([...boundary.before, ...boundary.after])]
+
+ handle.setPointerCapture(event.pointerId)
+
+ const start = boundary.orientation === "vertical" ? event.clientX : event.clientY
+
+ let gestureWindows: SharedResizeWindow[] | null = null
+
+ let result: ReturnType<typeof resizeSharedBoundary> | null = null
+
+ let frame = 0
+
+ function update(pointer: globalThis.PointerEvent) {
+
+ const coordinate = boundary.orientation === "vertical" ? pointer.clientX : pointer.clientY
+
+ const requestedDelta = coordinate - start
+
+ if (requestedDelta === 0) return
+
+ if (!gestureWindows) {
+
+ const started = begin(identities)
+
+ if (!started) return
+
+ gestureWindows = windows.map(window => ({
+ ...window,
+ geometry: started.get(window.identity) ?? window.geometry
+ }))
+ }
+
+ result = resizeSharedBoundary(boundary, gestureWindows, requestedDelta)
+
+ if (frame) return
+
+ frame = requestAnimationFrame(function () {
+
+ frame = 0
+
+ if (!result) return
+
+ present(result.geometries)
+
+ setActive({ boundary, delta: result.delta })
+ })
+ }
+
+ function release(pointer: globalThis.PointerEvent) {
+
+ if (frame) cancelAnimationFrame(frame)
+
+ handle.removeEventListener("pointermove", update)
+
+ handle.removeEventListener("pointerup", release)
+
+ handle.removeEventListener("pointercancel", release)
+
+ if (pointer.type === "pointerup") {
+
+ if (result && result.delta !== 0) {
+
+ present(result.geometries)
+
+ commit(result.geometries)
+
+ finish(identities)
+ }
+
+ else if (gestureWindows) cancel(identities)
+ }
+
+ else if (gestureWindows) cancel(identities)
+
+ setActive(null)
+ }
+
+ handle.addEventListener("pointermove", update)
+
+ handle.addEventListener("pointerup", release)
+
+ handle.addEventListener("pointercancel", release)
+
+ setActive({ boundary, delta: 0 })
+ }
+
+ return <div className="pointer-events-none absolute inset-0 z-[2147483647]">
+
+ {(active ? [active.boundary] : boundaries).map(boundary => {
+
+ const delta = active?.boundary.identity === boundary.identity ? active.delta : 0
+
+ const vertical = boundary.orientation === "vertical"
+
+ return <div
+ key={boundary.identity}
+ data-shared-window-resize={boundary.orientation}
+ onPointerDown={event => grab(event, boundary)}
+ className={`pointer-events-auto absolute touch-none ${vertical ? "cursor-col-resize" : "cursor-row-resize"}`}
+ style={vertical ? {
+ left: boundary.position + delta - thickness / 2,
+ top: boundary.start,
+ width: thickness,
+ height: boundary.end - boundary.start
+ } : {
+ left: boundary.start,
+ top: boundary.position + delta - thickness / 2,
+ width: boundary.end - boundary.start,
+ height: thickness
+ }}
+ />
+ })}
+
+ </div>
+}
+
+interface SharedResizeBoundariesProps {
+
+ windows: readonly SharedResizeWindow[]
+
+ begin: (identities: readonly string[]) => ReadonlyMap<string, WindowRegion> | null
+
+ present: (geometries: ReadonlyMap<string, WindowRegion>) => void
+
+ commit: (geometries: ReadonlyMap<string, WindowRegion>) => void
+
+ finish: (identities: readonly string[]) => void
+
+ cancel: (identities: readonly string[]) => void
+}
+
+interface ActiveBoundary {
+
+ boundary: SharedResizeBoundary
+
+ delta: number
+}
diff --git a/source/client/view/structure/desktop/windows/window-geometry-animation.ts b/source/client/view/structure/desktop/windows/window-geometry-animation.ts
index 644cc9f..072b49f 100644
--- a/source/client/view/structure/desktop/windows/window-geometry-animation.ts
+++ b/source/client/view/structure/desktop/windows/window-geometry-animation.ts
@@ -4,6 +4,7 @@ import { animate, type AnimationPlaybackControls, type MotionValue } from "motio
import { motionTransition } from "@client/view/appearance/motion"
const axes = ["x", "y", "width", "height"] as const
+const sizeAxes = ["width", "height"] as const
type Axis = typeof axes[number]
type Flight = {
target: number
@@ -41,6 +42,33 @@ export class WindowGeometryAnimation {
transition(region: WindowRegion, transaction: AppearanceTransaction, complete?: () => void) {
+ this.animate(region, transaction, axes, complete)
+ }
+
+ /** Moves directly while preserving an in-flight size transition. */
+ setPosition(position: Pick<WindowRegion, "x" | "y">) {
+
+ for (const axis of ["x", "y"] as const) {
+ const flight = this.flights.get(axis)
+ this.flights.delete(axis)
+ flight?.control?.stop()
+ this.values[axis].set(position[axis])
+ }
+
+ this.finish()
+ }
+
+ /** Starts from the visible size while the pointer immediately owns position. */
+ transitionSize(region: WindowRegion, transaction: AppearanceTransaction, complete?: () => void) {
+
+ this.stop()
+ this.values.x.set(region.x)
+ this.values.y.set(region.y)
+ this.animate(region, transaction, sizeAxes, complete)
+ }
+
+ private animate(region: WindowRegion, transaction: AppearanceTransaction, animatedAxes: readonly Axis[], complete?: () => void) {
+
if (transaction.duration === 0) {
this.set(region)
complete?.()
@@ -56,7 +84,7 @@ export class WindowGeometryAnimation {
this.layout.width.set(region.width || Math.max(this.values.width.get(), 1))
this.layout.height.set(region.height || Math.max(this.values.height.get(), 1))
- for (const axis of axes) {
+ for (const axis of animatedAxes) {
const previous = this.flights.get(axis)
if (previous?.target === region[axis] && previous.timing === timing) continue
diff --git a/source/client/view/structure/desktop/windows/window-geometry-motion.ts b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
index d23385a..d0c930c 100644
--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts
+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
@@ -31,12 +31,15 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
const height = useMotionValue(typeof size.height === "number" ? size.height : 0)
const layoutWidth = useMotionValue(width.get())
const layoutHeight = useMotionValue(height.get())
+ const transformOrigin = useMotionValue("0px 0px")
const scaleX = useTransform(() => layoutWidth.get() === 0 ? 1 : width.get() / layoutWidth.get())
const scaleY = useTransform(() => layoutHeight.get() === 0 ? 1 : height.get() / layoutHeight.get())
const animator = useRef<WindowGeometryAnimation | null>(null)
if (!animator.current) animator.current = new WindowGeometryAnimation({ x, y, width, height }, { width: layoutWidth, height: layoutHeight })
const gesturing = useRef(false)
+ const restoringGesture = useRef(false)
const initialized = useRef(false)
+ const settlementListeners = useRef(new Set<() => void>())
const values = useRef({ position, size, animation, immediate, onComplete })
values.current = { position, size, animation, immediate, onComplete }
@@ -51,22 +54,54 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
animator.current!.stop()
}
+ function announceSettlement() {
+
+ for (const listener of settlementListeners.current) listener()
+ }
+
+ function listen(settled: () => void) {
+
+ settlementListeners.current.add(settled)
+
+ return () => settlementListeners.current.delete(settled)
+ }
+
+ function completeGestureRestore() {
+
+ if (!restoringGesture.current) return
+
+ restoringGesture.current = false
+ transformOrigin.set("0px 0px")
+ }
+
function set(region: WindowRegion) {
animator.current!.set(region)
}
+ function present(region: WindowRegion) {
+
+ stop()
+ set(region)
+ }
+
function transition(region: WindowRegion, transaction: AppearanceTransaction = appearanceTransaction, complete?: () => void) {
if (immediate) {
set(region)
+ announceSettlement()
complete?.()
return
}
- animator.current!.transition(region, transaction, complete)
+ animator.current!.transition(region, transaction, () => {
+
+ completeGestureRestore()
+ announceSettlement()
+ complete?.()
+ })
}
function resolve() {
@@ -118,7 +153,11 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
const region = resolve()
- if (region) set(region)
+ if (region) {
+
+ set(region)
+ announceSettlement()
+ }
})
observer.observe(parent)
@@ -135,6 +174,7 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
if (!parent) return null
+ completeGestureRestore()
gesturing.current = true
stop()
@@ -143,31 +183,62 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
function updateGesture(region: WindowRegion) {
- set(region)
+ if (restoringGesture.current) animator.current!.setPosition(region)
+
+ else set(region)
+ }
+
+ function restoreGesture(region: WindowRegion) {
+
+ const shown = read()
+ const scaleX = region.width === 0 ? 1 : shown.width / region.width
+ const scaleY = region.height === 0 ? 1 : shown.height / region.height
+ const originX = scaleX === 1 ? 0 : (shown.x - region.x) / (1 - scaleX)
+ const originY = scaleY === 1 ? 0 : (shown.y - region.y) / (1 - scaleY)
+
+ restoringGesture.current = true
+ transformOrigin.set(`${originX}px ${originY}px`)
+ animator.current!.transitionSize(region, appearanceTransaction, () => {
+
+ completeGestureRestore()
+ announceSettlement()
+ })
}
function finishGesture(region?: WindowRegion) {
gesturing.current = false
- if (region) transition(region)
+ if (region) {
+
+ completeGestureRestore()
+ transition(region)
+ }
}
function cancelGesture() {
gesturing.current = false
+ completeGestureRestore()
const region = resolve()
- if (region) set(region)
+ if (region) {
+
+ set(region)
+ announceSettlement()
+ }
}
return {
frame,
- style: { x, y, width: layoutWidth, height: layoutHeight, scaleX, scaleY, transformOrigin: "0 0" } satisfies MotionStyle,
+ style: { x, y, width: layoutWidth, height: layoutHeight, scaleX, scaleY, transformOrigin } satisfies MotionStyle,
read,
+ present,
+ listen,
beginGesture,
updateGesture,
+ restoreGesture,
finishGesture,
cancelGesture
}
diff --git a/source/client/view/structure/desktop/windows/window-header.tsx b/source/client/view/structure/desktop/windows/window-header.tsx
index 4fd8709..bb838a5 100644
--- a/source/client/view/structure/desktop/windows/window-header.tsx
+++ b/source/client/view/structure/desktop/windows/window-header.tsx
@@ -1,18 +1,16 @@
-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useState } from "react"
+import { PointerEvent as ReactPointerEvent, ReactNode } from "react"
import { motion } from "motion/react"
import { motionTransition } from "@client/view/appearance/motion"
-import { useAppearance } from "@phreshos/react-ui"
-
-const control = {
- base: { borderColor: "transparent", backgroundColor: "rgba(255, 255, 255, 0.15)", color: "#475569", scale: 1 },
- hover: { borderColor: "rgba(255, 255, 255, 0.7)", backgroundColor: "rgba(255, 255, 255, 0.65)", color: "#0f172a", scale: 1 },
- danger: { borderColor: "rgba(253, 164, 175, 0.7)", backgroundColor: "#f43f5e", color: "#ffffff", scale: 1 }
-}
+import { Button, type ButtonColor, useAppearance, useThemedValue } from "@phreshos/react-ui"
/** The visible chrome above an ordinary window's content. */
export default function WindowHeader({ title, icon, active, whole, reducedMotion, stopping, onGrab, onMinimize, onMaximize, onClose }: WindowHeaderProps) {
- const transition = motionTransition(useAppearance().transaction, reducedMotion)
+ const appearance = useAppearance()
+
+ const transition = motionTransition(appearance.transaction, reducedMotion)
+
+ const foreground = useThemedValue(appearance.colors).foreground
return <div
@@ -51,15 +49,15 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
transition={transition}
>{title}</motion.span>
- <div className="grid shrink-0 grid-flow-col auto-cols-max gap-1" onPointerDown={event => event.stopPropagation()}>
+ <div className="grid shrink-0 grid-flow-col auto-cols-max gap-1" onPointerDown={event => event.stopPropagation()} onDoubleClick={event => event.stopPropagation()}>
- {onMinimize && <Control label="Minimise" reducedMotion={reducedMotion} focusOnPointerDown={false} onClick={onMinimize}>
+ {onMinimize && <Control label="Minimise" foreground={foreground} preventFocusOnPress onPress={onMinimize}>
<path d="M1.5 7.5h7" />
</Control>}
- {onMaximize && <Control label={whole ? "Restore" : "Fill"} reducedMotion={reducedMotion} onClick={onMaximize}>
+ {onMaximize && <Control label={whole ? "Restore" : "Fill"} foreground={foreground} onPress={onMaximize}>
{whole
@@ -69,7 +67,7 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
</Control>}
- {onClose && <Control label="Close" reducedMotion={reducedMotion} focusOnPointerDown={false} onClick={onClose} disabled={stopping} danger>
+ {onClose && <Control label="Close" foreground={foreground} color="danger:base" preventFocusOnPress onPress={onClose} disabled={stopping}>
<path d="M1.5 1.5 8.5 8.5M8.5 1.5 1.5 8.5" />
@@ -80,84 +78,17 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
</div>
}
-// A pointer control acts on the press: click waits for the release, and that
-// wait reads as lag on something meant to feel mechanical. Keyboard and
-// assistive technology still use the button's native click activation.
-function Control({ label, danger = false, focusOnPointerDown = true, reducedMotion, children, onClick, ...props }: ControlProps) {
-
- const [interaction, setInteraction] = useState<"base" | "hover" | "pressed">("base")
+function Control({ label, foreground, children, ...props }: ControlProps) {
- const hover = danger ? control.danger : control.hover
-
- const pressed = {
- ...hover,
- backgroundColor: danger ? "#e11d48" : "rgba(255, 255, 255, 0.8)",
- scale: 0.95
- }
-
- const values = interaction === "pressed" ? pressed : interaction === "hover" ? hover : control.base
-
- return <motion.button
+ return <Button
{...props}
aria-label={label}
- initial={false}
-
- animate={values}
-
- transition={motionTransition(useAppearance().transaction, reducedMotion)}
-
- onPointerEnter={() => {
-
- setInteraction("hover")
- }}
-
- onPointerLeave={() => {
-
- setInteraction("base")
- }}
-
- onPointerDown={event => {
-
- event.stopPropagation()
-
- if (event.button !== 0) return
+ size="xsmall"
- setInteraction("pressed")
-
- if (focusOnPointerDown) event.currentTarget.focus({ preventScroll: true })
-
- // Minimise and close act without focusing their window. Preventing
- // the pointer's default focus keeps that action from raising it.
- else event.preventDefault()
-
- onClick?.()
- }}
-
- onPointerUp={() => setInteraction("hover")}
-
- onPointerCancel={() => setInteraction("base")}
-
- onKeyDown={event => {
-
- if (event.key === "Enter" || event.key === " ") setInteraction("pressed")
- }}
-
- onKeyUp={event => {
-
- if (event.key === "Enter" || event.key === " ") setInteraction("base")
- }}
-
- onClick={event => {
-
- event.stopPropagation()
-
- if (event.detail === 0) onClick?.()
- }}
-
- className="grid size-6 place-items-center rounded-md border border-transparent bg-white/15 outline-none shadow-sm disabled:pointer-events-none disabled:opacity-40 focus-visible:relative focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-sky-500"
+ style={{ color: foreground }}
>
@@ -167,7 +98,7 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti
</svg>
- </motion.button>
+ </Button>
}
interface WindowHeaderProps {
@@ -193,15 +124,19 @@ interface WindowHeaderProps {
onClose?: () => void
}
-interface ControlProps extends Omit<ComponentProps<"button">, "onAnimationStart" | "onClick" | "onDrag" | "onDragEnd" | "onDragStart"> {
+interface ControlProps {
label: string
- danger?: boolean
+ foreground: string
- focusOnPointerDown?: boolean
+ color?: ButtonColor
- reducedMotion: boolean
+ preventFocusOnPress?: boolean
+
+ disabled?: boolean
+
+ onPress: () => void
- onClick?: () => void
+ children: ReactNode
}
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index bd20c93..95b089f 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -2,12 +2,12 @@ import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useEffect
import { useReducedMotion } from "@libs/react-motion"
import { surfacePresencePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
import WindowPanel from "./window-panel"
-import { absoluteWindowGeometry, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
+import { absoluteWindowGeometry, minimumWindowSize, resolveWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "@client/view/components/window-manager/window-geometry"
import { type Position, type Size } from "@phreshos/core"
import WindowHeader from "./window-header"
import WindowSurface from "./window-surface"
import { type LocalAnimation, type LocalSurfaceState } from "@client/view/components/desktop-host/local-window"
-import { type LocalGeometryReader } from "@client/view/components/window-manager/local-windows"
+import { type LocalGeometryRepresentation } from "@client/view/components/window-manager/local-windows"
import { motion } from "motion/react"
import { motionTransition } from "@client/view/appearance/motion"
import { useAppearance } from "@phreshos/react-ui"
@@ -53,7 +53,7 @@ const surfacePose = {
closing: { scale: 0.86, y: 12, opacity: 0 }
}
-export default function ({ title, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onLocalAnimationComplete, onLocalRepresentation, onFocusCapture, active = false, bare = false, closing = false, stopping = false, minimized = false, maximized = false, animateEntrance = true, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, localSurface, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = 260, minHeight = 160, className, style, ...props }: WindowProps) {
+export default function ({ title, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onLocalAnimationComplete, onLocalRepresentation, onFocusCapture, active = false, bare = false, closing = false, stopping = false, minimized = false, maximized = false, animateEntrance = true, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, localSurface, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {
const reducedMotion = useReducedMotion()
const appearanceTransaction = useAppearance().transaction
@@ -80,21 +80,20 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
if (!onLocalRepresentation) return
- const read: LocalGeometryReader = function () {
-
- const shown = geometryMotion.read()
-
- return {
- position: { x: shown.x, y: shown.y },
- size: { width: shown.width, height: shown.height }
- }
+ const representation: LocalGeometryRepresentation = {
+ read: geometryMotion.read,
+ present: geometryMotion.present,
+ begin: () => geometryMotion.beginGesture()?.region ?? null,
+ finish: geometryMotion.finishGesture,
+ cancel: geometryMotion.cancelGesture,
+ listen: geometryMotion.listen
}
- onLocalRepresentation(read)
+ onLocalRepresentation(representation)
return () => onLocalRepresentation(null)
- }, [onLocalRepresentation, position, size])
+ }, [onLocalRepresentation])
const closureCompleted = useRef(false)
@@ -294,7 +293,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const ratio = Math.min(Math.max((pointerX - origin.x) / origin.width, 0), 1)
- if (maximized) {
+ const restoringMaximized = maximized
+
+ if (restoringMaximized) {
const stored = resolveWindowGeometry(position, size, bounds)
origin = { ...origin, width: stored.width, height: stored.height }
onMaximize?.()
@@ -310,7 +311,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
onMove?.(origin.x, origin.y)
- geometryMotion.updateGesture(current)
+ if (restoringMaximized) geometryMotion.restoreGesture(current)
+
+ else geometryMotion.updateGesture(current)
setGesture({ origin, current, zone, shown })
return
@@ -602,7 +605,7 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "
onLocalAnimationComplete?: (kind: "geometry" | "minimize" | "surface", revision: number) => void
- onLocalRepresentation?: (reader: LocalGeometryReader | null) => void
+ onLocalRepresentation?: (representation: LocalGeometryRepresentation | null) => void
/** Surface used only to decide which painted edges receive an inset. */
paintSurfaceSize?: WindowSurfaceSize
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.ts
index 64232ae..985951d 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
@@ -34,6 +34,7 @@ import {
type WindowLayer,
type WindowState
} from "@phreshos/core"
+import { isDesktopReplacementLayer, type DesktopReplacementLayer } from "@shared/desktop-replacement"
import type { ServerRuntime, ServerRuntimeFactory } from "@server/core/server-runtime"
import { permissionCatalog } from "@server/core/permissions"
@@ -909,25 +910,26 @@ export default class ProcessManager extends TheLink {
return new Window(shown, shape.position, shape.size, ++this.highest, shape.minimize, shape.maximize)
}
- private wallpaperChanges: Promise<unknown> = Promise.resolve()
+ private readonly replacementChanges = new Map<DesktopReplacementLayer, Promise<unknown>>()
- private serializeClientLayer<Result>(layer: string | undefined, work: () => Promise<Result>): Promise<Result> {
- if (layer !== "wallpaper") return work()
- const next = this.wallpaperChanges.catch(() => undefined).then(work)
- this.wallpaperChanges = next.catch(() => undefined)
+ private serializeClientLayer<Result>(layer: Layer | undefined, work: () => Promise<Result>): Promise<Result> {
+ if (!isDesktopReplacementLayer(layer)) return work()
+ const current = this.replacementChanges.get(layer) ?? Promise.resolve()
+ const next = current.catch(() => undefined).then(work)
+ this.replacementChanges.set(layer, next.catch(() => undefined))
return next
}
- private async replaceWallpaper() {
- const occupied = [...this.processes.values()].filter(process => process.client?.window.layer === "wallpaper")
+ private async replaceDesktopPresentation(layer: DesktopReplacementLayer) {
+ const occupied = [...this.processes.values()].filter(process => process.client?.window.layer === layer)
for (const process of occupied) await this.exitProcess(process.identity, "complete")
}
/** Claims the role after serialized replacement has released its previous owner. */
private activateClient(process: Process, window: Window, service: boolean) {
- if (window.layer === "wallpaper" && [...this.processes.values()].some(
- current => current.client?.window.layer === "wallpaper"
- )) throw new Error("A Client Endpoint is already running in the wallpaper layer")
+ if (isDesktopReplacementLayer(window.layer) && [...this.processes.values()].some(
+ current => current.client?.window.layer === window.layer
+ )) throw new Error(`A Client Endpoint is already running in the ${window.layer} layer`)
process.startClient(window, service)
}
@@ -950,7 +952,7 @@ export default class ProcessManager extends TheLink {
throw new Error("This program already has a process with that name")
}
- if (client && shape?.layer === "wallpaper") await this.replaceWallpaper()
+ if (client && shape && isDesktopReplacementLayer(shape.layer)) await this.replaceDesktopPresentation(shape.layer)
// Who had focus before this one opened, in the layer it is
// opening into. A window is born on top of its own layer and
@@ -1240,7 +1242,7 @@ export default class ProcessManager extends TheLink {
const before = this.front(window.layer)
- if (window.layer === "wallpaper") await this.replaceWallpaper()
+ if (isDesktopReplacementLayer(window.layer)) await this.replaceDesktopPresentation(window.layer)
this.activateClient(process, window, launch.service ?? process.program.client.service)
diff --git a/source/server/core/permissions.ts b/source/server/core/permissions.ts
index 7668c70..13640b4 100644
--- a/source/server/core/permissions.ts
+++ b/source/server/core/permissions.ts
@@ -318,7 +318,7 @@ export const permissionCatalog = new PermissionCatalog({
layers: {
default: [],
title: "Window layers",
- description: "Select the under, over, and wallpaper layers in Client Endpoint launches."
+ description: "Select the under, over, wallpaper, and start-menu layers in Client Endpoint launches."
},
network: {
default: [],
diff --git a/source/shared/desktop-replacement.ts b/source/shared/desktop-replacement.ts
new file mode 100644
index 0000000..2090c9b
--- /dev/null
+++ b/source/shared/desktop-replacement.ts
@@ -0,0 +1,9 @@
+import type { WindowLayer } from "@phreshos/core"
+
+/** Window roles that replace one fixed Desktop-owned presentation. */
+export type DesktopReplacementLayer = Extract<WindowLayer, "wallpaper" | "start-menu">
+
+export function isDesktopReplacementLayer(layer: WindowLayer | undefined): layer is DesktopReplacementLayer {
+
+ return layer === "wallpaper" || layer === "start-menu"
+}
diff --git a/tests/client-layer-permissions.test.ts b/tests/client-layer-permissions.test.ts
index 24920ea..6cba8cf 100644
--- a/tests/client-layer-permissions.test.ts
+++ b/tests/client-layer-permissions.test.ts
@@ -56,7 +56,9 @@ function fixture() {
}
}
-test.each(["under", "over", "wallpaper"] as const)("Client launch routes check %s before delegation", async layer => {
+const restrictedLayers = ["under", "over", "wallpaper", "start-menu"] as const
+
+test.each(restrictedLayers)("Client launch routes check %s before delegation", async layer => {
const f = fixture()
const program = { identity: f.program.identity, reference: f.program.reference }
const process = { identity: f.process.identity, reference: f.process.reference }
@@ -68,7 +70,7 @@ test.each(["under", "over", "wallpaper"] as const)("Client launch routes check %
["launch", program, "set", launch],
["start-endpoint", process, "client", { layer }]
] as const
- const anotherLayer = layer === "under" ? "over" : layer === "over" ? "wallpaper" : "under"
+ const anotherLayer = restrictedLayers.find(candidate => candidate !== layer)!
const deniedPermissions: Permissions[] = [{}, { programs: [] }, { layers: [anotherLayer] }, { all: [], layers: false }]
for (const denied of deniedPermissions) {
f.permissions(denied)
@@ -134,7 +136,7 @@ test("Client layer authorization validates explicit choices without reinterpreti
expect(f.createProcess).toHaveBeenCalledOnce()
})
-test.each(["under", "over", "wallpaper"] as const)("Client run streams authorize %s before creating an iterator", async layer => {
+test.each(restrictedLayers)("Client run streams authorize %s before creating an iterator", async layer => {
const f = fixture()
const boundary = new ClientProcessBoundary(f.process.identity, { contentWindow: null } as HTMLIFrameElement, f.auth,
() => ({ size: { width: 100, height: 100 } }), {} as never, { release: vi.fn() } as never)
@@ -160,6 +162,7 @@ test("the layer catalog uses exact assignments before all", () => {
expect(permissionCatalog.allows("layers", ["under"], { layers: ["under"] })).toBe(true)
expect(permissionCatalog.allows("layers", ["under", "over"], { layers: [] })).toBe(true)
expect(permissionCatalog.allows("layers", ["wallpaper"], { layers: [] })).toBe(true)
+ expect(permissionCatalog.allows("layers", ["start-menu"], { layers: [] })).toBe(true)
expect(permissionCatalog.allows("layers", ["over"], { all: [], layers: false })).toBe(false)
expect(permissionCatalog.allows("layers", ["over"], { all: [] })).toBe(true)
expect(() => permissionCatalog.declarations({ layers: false })).toThrow()
diff --git a/tests/client-surface.test.ts b/tests/client-surface.test.ts
index 6463aa8..53dcec3 100644
--- a/tests/client-surface.test.ts
+++ b/tests/client-surface.test.ts
@@ -52,15 +52,30 @@ test("client surface contract", async () => {
assert.deepEqual(second.state("ordinary").position, { x: 0, y: 0 })
assert.deepEqual(ordinary.window.position, { x: 0, y: 0 })
- // A reader reports the rectangle currently painted by the browser. Policy
+ // A representation reports the rectangle currently painted by the browser. Policy
// such as fill/restore still needs the underlying projection, because a
// relative full-surface value and its measured pixels are not equivalent.
- first.represent("ordinary", () => ({ position: { x: 0, y: 0 }, size: { width: 1200, height: 800 } }))
+ first.represent("ordinary", representation({ x: 0, y: 0, width: 1200, height: 800 }))
assert.deepEqual(first.state("ordinary").size, { width: 1200, height: 800 })
assert.deepEqual(first.projection("ordinary").size, { width: 300, height: 200 })
first.represent("ordinary", null)
- first.represent("bare", () => ({ position: { x: 65, y: 75 }, size: { width: 290, height: 190 } }))
+ let settleRepresentation: () => void = () => undefined
+ let representationPublications = 0
+ first.listen(() => { representationPublications++ })
+ first.represent("ordinary", {
+ ...representation({ x: 0, y: 0, width: 1200, height: 800 }),
+ listen(settled) {
+ settleRepresentation = settled
+ return () => { settleRepresentation = () => undefined }
+ }
+ })
+ const registrationPublication = representationPublications
+ settleRepresentation()
+ assert.equal(representationPublications, registrationPublication + 1)
+ first.represent("ordinary", null)
+
+ first.represent("bare", representation({ x: 65, y: 75, width: 290, height: 190 }))
assert.deepEqual(first.state("bare").position, { x: 65, y: 75 })
assert.deepEqual(first.state("bare").size, { width: 290, height: 190 })
first.represent("bare", null)
@@ -322,6 +337,17 @@ test("client surface contract", async () => {
return value
}
+ function representation(geometry: { x: number, y: number, width: number, height: number }) {
+ return {
+ read: () => geometry,
+ present(next: typeof geometry) { geometry = next },
+ begin: () => geometry,
+ finish() {},
+ cancel() {},
+ listen() { return () => undefined }
+ }
+ }
+
function surface(windows: LocalWindows, identity: string) {
const value = represented(windows, identity).surface
assert(value)
diff --git a/tests/wallpaper-lifecycle.test.ts b/tests/desktop-replacement-lifecycle.test.ts
similarity index 60%
rename from tests/wallpaper-lifecycle.test.ts
rename to tests/desktop-replacement-lifecycle.test.ts
index 2604c53..832ff83 100644
--- a/tests/wallpaper-lifecycle.test.ts
+++ b/tests/desktop-replacement-lifecycle.test.ts
@@ -5,14 +5,17 @@ import type AuthManager from "@server/core/link-manager/auth-manager/auth-manage
import Program from "@server/core/link-manager/auth-manager/program-manager/program"
import ProcessManager from "@server/core/link-manager/auth-manager/process-manager/process-manager"
import type { ServerRuntimeFactory } from "@server/core/server-runtime"
+import type { DesktopReplacementLayer } from "@shared/desktop-replacement"
-function fixture() {
+const replacementLayers = ["wallpaper", "start-menu"] as const satisfies readonly DesktopReplacementLayer[]
+
+function fixture(replacementLayer: DesktopReplacementLayer) {
const auth = new TheLink() as unknown as AuthManager
const manager = new ProcessManager(auth)
- const program = new Program({ identity: "wallpaper-test", client: { location: "https://example.test/" } })
+ const program = new Program({ identity: "replacement-test", client: { location: "https://example.test/" } })
vi.spyOn(program, "validate").mockResolvedValue()
- const shape = (layer: Layer = "wallpaper") => ({
- title: "Wallpaper", position: { x: 20, y: 30 }, size: { width: 320, height: 240 },
+ const shape = (layer: Layer = replacementLayer) => ({
+ title: "Replacement", position: { x: 20, y: 30 }, size: { width: 320, height: 240 },
layer, minimize: false, maximize: false
})
Object.assign(auth, {
@@ -21,65 +24,65 @@ function fixture() {
clientShape(_program: Program, launch: ClientLaunch) { return shape(launch.layer) }
}
})
- const register = (identity: string, layer: Layer | null = "wallpaper", runtime: ServerRuntimeFactory<Program> | null = null) => manager.register(
+ const register = (identity: string, layer: Layer | null = replacementLayer, runtime: ServerRuntimeFactory<Program> | null = null) => manager.register(
identity, null, program, {}, { server: null, client: null, options: {} },
runtime, layer !== null, layer === null ? null : shape(layer), null
)
return { manager, register }
}
-test("concurrent wallpaper launches replace the incumbent Process in order", async () => {
- const { manager, register } = fixture()
+test.each(replacementLayers)("concurrent %s launches replace the incumbent Process in order", async replacementLayer => {
+ const { manager, register } = fixture(replacementLayer)
const results = await Promise.allSettled([register("first"), register("second")])
expect(results.map(result => result.status)).toEqual(["fulfilled", "fulfilled"])
expect(manager.processes.has("first")).toBe(false)
expect(manager.processes.has("second")).toBe(true)
expect(manager.processes.size).toBe(1)
const incumbent = [...manager.processes.values()][0]!
- expect(incumbent.client?.window.layer).toBe("wallpaper")
+ expect(incumbent.client?.window.layer).toBe(replacementLayer)
incumbent.client!.window.minimized = true
await register("third")
expect(manager.processes.has(incumbent.identity)).toBe(false)
expect(incumbent.client).toBeNull()
await register("ordinary", "window")
await register("overlay", "over")
- expect((await register("replacement")).client?.window.layer).toBe("wallpaper")
+ expect((await register("replacement")).client?.window.layer).toBe(replacementLayer)
expect(manager.processes.has("third")).toBe(false)
expect(manager.processes.has("ordinary")).toBe(true)
expect(manager.processes.has("overlay")).toBe(true)
})
-test("wallpaper replacement finishes before the new Server runtime is created", async () => {
- const { manager, register } = fixture()
+test.each(replacementLayers)("%s replacement finishes before the new Server runtime is created", async replacementLayer => {
+ const { manager, register } = fixture(replacementLayer)
await register("incumbent")
const runtime = vi.fn(() => {
expect(manager.processes.has("incumbent")).toBe(false)
throw new Error("runtime creation failed")
})
- await expect(register("replacement", "wallpaper", runtime)).rejects.toThrow("runtime creation failed")
+ await expect(register("replacement", replacementLayer, runtime)).rejects.toThrow("runtime creation failed")
expect(runtime).toHaveBeenCalledOnce()
expect(manager.processes.size).toBe(0)
await register("next")
expect(manager.processes.has("next")).toBe(true)
})
-test("starting an existing Client and creating a Process share the wallpaper claim", async () => {
- const { manager, register } = fixture()
+test.each(replacementLayers)("starting an existing Client and creating a Process share the %s claim", async replacementLayer => {
+ const { manager, register } = fixture(replacementLayer)
await register("existing", null)
const results = await Promise.allSettled([
- manager.startClient("existing", { layer: "wallpaper" }), register("new")
+ manager.startClient("existing", { layer: replacementLayer }), register("new")
])
expect(results.filter(result => result.status === "fulfilled")).toHaveLength(2)
- expect([...manager.processes.values()].filter(process => process.client?.window.layer === "wallpaper")).toHaveLength(1)
+ expect([...manager.processes.values()].filter(process => process.client?.window.layer === replacementLayer)).toHaveLength(1)
expect(manager.processes.has("existing")).toBe(false)
const waiting = await register("waiting", null)
- await manager.startClient("waiting", { layer: "wallpaper" })
+ await manager.startClient("waiting", { layer: replacementLayer })
expect(manager.processes.has("new")).toBe(false)
- expect(waiting.client?.window.layer).toBe("wallpaper")
+ expect(waiting.client?.window.layer).toBe(replacementLayer)
})
-test("failed activation releases the wallpaper claim", async () => {
- const { manager, register } = fixture()
+test.each(replacementLayers)("failed activation releases the %s claim", async replacementLayer => {
+ const { manager, register } = fixture(replacementLayer)
let fail = true
manager.$outbound.subscribe("/client-start", () => {
if (fail) throw new Error("publication failed")
@@ -87,9 +90,9 @@ test("failed activation releases the wallpaper claim", async () => {
await expect(register("failed")).rejects.toThrow("publication failed")
expect(manager.processes.has("failed")).toBe(false)
await register("existing", null)
- await expect(manager.startClient("existing", { layer: "wallpaper" })).rejects.toThrow("publication failed")
+ await expect(manager.startClient("existing", { layer: replacementLayer })).rejects.toThrow("publication failed")
expect(manager.processes.get("existing")!.client).toBeNull()
fail = false
- await manager.startClient("existing", { layer: "wallpaper" })
- expect(manager.processes.get("existing")!.client?.window.layer).toBe("wallpaper")
+ await manager.startClient("existing", { layer: replacementLayer })
+ expect(manager.processes.get("existing")!.client?.window.layer).toBe(replacementLayer)
})
diff --git a/tests/desktop-wallpaper.test.tsx b/tests/desktop-replacements.test.tsx
similarity index 55%
rename from tests/desktop-wallpaper.test.tsx
rename to tests/desktop-replacements.test.tsx
index b7ca252..3a3c3eb 100644
--- a/tests/desktop-wallpaper.test.tsx
+++ b/tests/desktop-replacements.test.tsx
@@ -3,30 +3,45 @@ import { renderToStaticMarkup } from "react-dom/server"
import { AppearanceProvider } 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 type { ReactNode } from "react"
const fixture = vi.hoisted(() => ({
processes: new Map<string, Process>(),
- pane: vi.fn(), fallback: vi.fn()
+ pane: vi.fn(), fallback: vi.fn(), startMenu: vi.fn()
}))
vi.mock("@client/view/contexts", () => ({
ApplicationContext: { useValue: () => ({ doors: { program: "/program" } }) },
AuthManagerContext: { useValue: () => ({
processManager: { processes: fixture.processes },
- programManager: { programs: new Map([["wallpaper-program", { assetId: "wallpaper-assets" }]]) }
+ programManager: { programs: new Map([
+ ["wallpaper-program", { assetId: "wallpaper-assets" }],
+ ["start-menu-program", { assetId: "start-menu-assets" }]
+ ]) }
}) }
}))
vi.mock("@the-link/react", () => ({ ReactTunnel: { useFactory: () => ({ useSubscribe() {} }) } }))
vi.mock("@client/view/components/desktop-host/client-host", () => ({ default: () => ({}) }))
vi.mock("@client/view/components/program-access", () => ({ default: () => null }))
vi.mock("@libs/readiness", () => ({ useRequirement: () => () => {} }))
-vi.mock("@client/view/structure/desktop/taskbar/taskbar", () => ({ default: () => null }))
+vi.mock("@client/view/structure/desktop/taskbar/taskbar", () => ({
+ default: ({ leading }: { leading: ReactNode }) => <div data-taskbar>{leading}</div>
+}))
+vi.mock("@client/view/structure/desktop/taskbar/launcher/start-menu", () => ({
+ default: ({ replacement }: { replacement?: ReactNode }) => {
+ fixture.startMenu(replacement)
+ return <div data-start-menu>{replacement ?? <div data-default-start-menu />}</div>
+ }
+}))
vi.mock("@client/view/structure/desktop/wallpaper/wallpaper", () => ({
WallpaperBackground: (props: unknown) => { fixture.fallback(props); return <div data-default-wallpaper /> },
ReadyWallpaper: () => null
}))
vi.mock("@client/view/structure/desktop/windows/process-window", () => ({
- default: (props: unknown) => { fixture.pane(props); return <iframe title="Wallpaper Client" /> }
+ default: (props: { client: { window: { layer: string } } }) => {
+ fixture.pane(props)
+ return <iframe title={`${props.client.window.layer} Client`} />
+ }
}))
test("Desktop replaces its default wallpaper with the running Client and restores the fallback after stop", () => {
@@ -47,7 +62,7 @@ test("Desktop replaces its default wallpaper with the running Client and restore
fixture.processes.set(record.identity, record)
fixture.fallback.mockClear()
const running = render()
- expect(running).toContain('title="Wallpaper Client"')
+ expect(running).toContain('title="wallpaper Client"')
expect(running).not.toContain("data-default-wallpaper")
expect(fixture.fallback).not.toHaveBeenCalled()
expect(fixture.pane.mock.lastCall?.[0]).toMatchObject({
@@ -61,3 +76,33 @@ test("Desktop replaces its default wallpaper with the running Client and restore
expect(fixture.pane).not.toHaveBeenCalled()
expect(fixture.fallback).toHaveBeenCalledOnce()
})
+
+test("Desktop replaces the built-in Start Menu in its existing host and restores the fallback after stop", () => {
+ const render = () => renderToStaticMarkup(<AppearanceProvider preferences={{ theme: "light", animations: true }}><Workspace /></AppearanceProvider>)
+ fixture.processes.clear()
+ fixture.pane.mockClear()
+ fixture.startMenu.mockClear()
+ expect(render()).toContain("data-default-start-menu")
+
+ const record = {
+ identity: "start-menu-process", program: "start-menu-program",
+ client: { window: {
+ layer: "start-menu", title: "Internal", position: { x: 200, y: 300 },
+ size: { width: 100, height: 100 }, minimized: true, maximized: false, depth: 20
+ } }
+ } as unknown as Process
+ fixture.processes.set(record.identity, record)
+ fixture.pane.mockClear()
+ const running = render()
+ expect(running).toContain('title="start-menu Client"')
+ expect(running).not.toContain("data-default-start-menu")
+ expect(fixture.pane.mock.lastCall?.[0]).toMatchObject({
+ bare: true, minimized: false, maximized: true, entering: false, localSurface: null,
+ position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, depth: 0
+ })
+
+ record.client = null
+ fixture.pane.mockClear()
+ expect(render()).toContain("data-default-start-menu")
+ expect(fixture.pane).not.toHaveBeenCalled()
+})
diff --git a/tests/local-window-layers.test.ts b/tests/local-window-layers.test.ts
index 067e2d5..ac7f7ef 100644
--- a/tests/local-window-layers.test.ts
+++ b/tests/local-window-layers.test.ts
@@ -17,8 +17,8 @@ function fixture(layer: WindowLayer) {
return { own, target, entries, windows }
}
-test("wallpaper local geometry and visibility belong to Desktop, not authoritative state", async () => {
- const { own, target, entries, windows } = fixture("wallpaper")
+test.each(["wallpaper", "start-menu"] as const)("%s local geometry and visibility belong to Desktop, not authoritative state", async layer => {
+ const { own, target, entries, windows } = fixture(layer)
const initial = windows.projection("own")
expect(initial).toMatchObject({ title: "", position: { x: 0, y: 0 }, size: { width: "100%", height: "100%" }, minimized: false, maximized: true, depth: 0, surface: null })
const operations = [
@@ -29,7 +29,7 @@ test("wallpaper local geometry and visibility belong to Desktop, not authoritati
() => windows.title("own", "Local"), () => windows.raise("own"),
() => windows.addSurface("own"), () => windows.removeSurface("own")
]
- for (const operation of operations) expect(operation).toThrow(/wallpaper layer does not allow/)
+ for (const operation of operations) expect(operation).toThrow(new RegExp(`${layer} layer does not allow`))
own.window.position = { x: 500, y: 600 }
windows.reconcile(entries)
expect(windows.projection("own")).toEqual(initial)
diff --git a/tests/permissions.test.ts b/tests/permissions.test.ts
index 195e93d..ffeffdd 100644
--- a/tests/permissions.test.ts
+++ b/tests/permissions.test.ts
@@ -23,7 +23,7 @@ test("permissions contract", async () => {
layers: {
default: [],
title: "Window layers",
- description: "Select the under, over, and wallpaper layers in Client Endpoint launches."
+ description: "Select the under, over, wallpaper, and start-menu layers in Client Endpoint launches."
},
network: {
default: [],
diff --git a/tests/shared-window-resize.test.ts b/tests/shared-window-resize.test.ts
new file mode 100644
index 0000000..13d275b
--- /dev/null
+++ b/tests/shared-window-resize.test.ts
@@ -0,0 +1,100 @@
+import assert from "node:assert/strict"
+import { resizeSharedBoundary, sharedResizeBoundaries, type SharedResizeWindow } from "@client/view/components/window-manager/shared-resize"
+import { test } from "vitest"
+
+test("a shared boundary resizes the windows on both sides", () => {
+
+ const windows: SharedResizeWindow[] = [
+ { identity: "left", geometry: { x: 0, y: 0, width: 500, height: 600 } },
+ { identity: "right", geometry: { x: 500, y: 0, width: 500, height: 600 } }
+ ]
+
+ const boundaries = sharedResizeBoundaries(windows)
+
+ assert.equal(boundaries.length, 1)
+
+ assert.deepEqual(boundaries[0], {
+ identity: "vertical:left:right",
+ orientation: "vertical",
+ position: 500,
+ start: 0,
+ end: 600,
+ before: ["left"],
+ after: ["right"]
+ })
+
+ const resized = resizeSharedBoundary(boundaries[0], windows, 80)
+
+ assert.equal(resized.delta, 80)
+
+ assert.deepEqual(resized.geometries.get("left"), { x: 0, y: 0, width: 580, height: 600 })
+
+ assert.deepEqual(resized.geometries.get("right"), { x: 580, y: 0, width: 420, height: 600 })
+})
+
+test("one continuous boundary coordinates every window that shares it", () => {
+
+ const windows: SharedResizeWindow[] = [
+ { identity: "left-top", geometry: { x: 0, y: 0, width: 500, height: 300 } },
+ { identity: "left-bottom", geometry: { x: 0, y: 300, width: 500, height: 300 } },
+ { identity: "right-top", geometry: { x: 500, y: 0, width: 500, height: 300 } },
+ { identity: "right-bottom", geometry: { x: 500, y: 300, width: 500, height: 300 } }
+ ]
+
+ const boundary = sharedResizeBoundaries(windows).find(candidate => candidate.orientation === "vertical")
+
+ assert(boundary)
+
+ assert.deepEqual(boundary.before, ["left-bottom", "left-top"])
+
+ assert.deepEqual(boundary.after, ["right-bottom", "right-top"])
+
+ assert.deepEqual([boundary.start, boundary.end], [0, 600])
+})
+
+test("the smallest participating window constrains the whole boundary", () => {
+
+ const windows: SharedResizeWindow[] = [
+ { identity: "left", geometry: { x: 0, y: 0, width: 500, height: 600 } },
+ { identity: "right-small", geometry: { x: 500, y: 0, width: 300, height: 300 } },
+ { identity: "right-large", geometry: { x: 500, y: 300, width: 500, height: 300 } }
+ ]
+
+ const boundary = sharedResizeBoundaries(windows).find(candidate => candidate.orientation === "vertical")
+
+ assert(boundary)
+
+ const resized = resizeSharedBoundary(boundary, windows, 100)
+
+ assert.equal(resized.delta, 40)
+
+ assert.equal(resized.geometries.get("right-small")?.width, 260)
+
+ assert.equal(resized.geometries.get("right-large")?.width, 460)
+})
+
+test("a horizontal boundary changes heights and the lower origins", () => {
+
+ const windows: SharedResizeWindow[] = [
+ { identity: "top", geometry: { x: 0, y: 0, width: 700, height: 300 } },
+ { identity: "bottom", geometry: { x: 0, y: 300, width: 700, height: 400 } }
+ ]
+
+ const boundary = sharedResizeBoundaries(windows).find(candidate => candidate.orientation === "horizontal")
+
+ assert(boundary)
+
+ const resized = resizeSharedBoundary(boundary, windows, -50)
+
+ assert.deepEqual(resized.geometries.get("top"), { x: 0, y: 0, width: 700, height: 250 })
+
+ assert.deepEqual(resized.geometries.get("bottom"), { x: 0, y: 250, width: 700, height: 450 })
+})
+
+test("unaligned and merely overlapping windows have no shared boundary", () => {
+
+ assert.deepEqual(sharedResizeBoundaries([
+ { identity: "first", geometry: { x: 0, y: 0, width: 400, height: 400 } },
+ { identity: "second", geometry: { x: 300, y: 100, width: 400, height: 400 } }
+ ]), [])
+})
diff --git a/tests/window-geometry-animation.test.ts b/tests/window-geometry-animation.test.ts
index 52319b6..ca7fc8b 100644
--- a/tests/window-geometry-animation.test.ts
+++ b/tests/window-geometry-animation.test.ts
@@ -66,6 +66,35 @@ test("retargeting preserves visible size and pointer interruption restores unsca
expect(layout.width.get()).toBe(480)
})
+test("gesture restore animates size while pointer movement remains direct", () => {
+ const { animator, values, layout } = create()
+ const target = { x: 80, y: 40, width: 500, height: 360 }
+ const complete = vi.fn()
+
+ animator.transitionSize(target, timing, complete)
+
+ expect(values.x.get()).toBe(80)
+ expect(values.y.get()).toBe(40)
+ expect(values.width.get()).toBe(initial.width)
+ expect(values.height.get()).toBe(initial.height)
+ expect(layout.width.get()).toBe(500)
+ expect(layout.height.get()).toBe(360)
+ expect(runs).toHaveLength(2)
+
+ animator.setPosition({ x: 120, y: 90 })
+
+ expect(values.x.get()).toBe(120)
+ expect(values.y.get()).toBe(90)
+ expect(runs.every(run => run.stop.mock.calls.length === 0)).toBe(true)
+ expect(complete).not.toHaveBeenCalled()
+
+ for (const run of runs) run.finish()
+
+ expect(values.width.get()).toBe(500)
+ expect(values.height.get()).toBe(360)
+ expect(complete).toHaveBeenCalledOnce()
+})
+
test("zero-size destinations retain finite backing dimensions until completion", () => {
const { animator, values, layout } = create()
animator.transition({ ...initial, width: 0, height: 0 }, timing)