An open-source, self-hosted system for apps built with web technologies.
Only the Desktop that maximizes a Window takes its view to it
zohayrslileh299692807367
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 2ea789d..46c945e 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -1067,7 +1067,11 @@ export default function host(authManager: AuthManager, pane: string, viewport: D}if (word === "maximize") {- await windowOf(await permittedProcess(args[0])).maximize(args[1] !== false)+ const target = await permittedProcess(args[0])+ const maximized = args[1] !== false+ const request = windowOf(target).maximize(maximized)+ presentation.maximize(target.identity, maximized, request)+ await requestreturn [pane]}diff --git a/source/client/view/components/desktop-host/presentation.ts b/source/client/view/components/desktop-host/presentation.tsindex 5d5b988..34db159 100644--- a/source/client/view/components/desktop-host/presentation.ts+++ b/source/client/view/components/desktop-host/presentation.ts@@ -70,6 +70,8 @@ export interface PresentationHost {setInteractive(identity: string, interactive: boolean): voidsetAnchor(identity: string, anchor: PresentationAnchor): voidraise(identity: string): void+ /** This Desktop maximizes or restores a Process's Window; `request` is the request to the System. */+ maximize(process: string, maximized: boolean, request: Promise<unknown>): voidcomplete(identity: string, kind: "geometry" | "surface", revision: number): void}diff --git a/source/client/view/components/window-manager/presentations.ts b/source/client/view/components/window-manager/presentations.tsindex e49399b..7ce0684 100644--- a/source/client/view/components/window-manager/presentations.ts+++ b/source/client/view/components/window-manager/presentations.ts@@ -66,6 +66,7 @@ export default class Presentations implements PresentationHost {private readonly moveGestureControllers = new Map<string, DesktopMoveGestureController>()private readonly moveGestures = new Map<string, ActiveMoveGesture>()private readonly anticipated = new Map<string, { change: AnticipatedWindow, pending: number }>()+ private readonly maximizedHere = new Set<string>()private readonly observers = new Set<() => void>()private readonly watching = new Map<string, () => void>()private fronts = 0@@ -137,6 +138,23 @@ export default class Presentations implements PresentationHost {})}+ /**+ * This Desktop maximizes or restores a Window, from its header or from the Program inside it. The+ * change shows at once, and a Window maximized from here is known as such until its request settles,+ * so this Desktop's view follows it; a Window maximized from another Desktop leaves this view alone.+ */+ public maximize(process: string, maximized: boolean, request: Promise<unknown>) {+ const identity = this.live.get(process)+ if (maximized && identity) {+ this.maximizedHere.add(identity)+ request.catch(() => undefined).finally(() => this.maximizedHere.delete(identity))+ }+ this.anticipate(process, { maximized }, request)+ }++ /** Whether this Desktop is maximizing this Window: it asked, and the System has not answered yet. */+ public maximizingHere(identity: string) { return this.maximizedHere.has(identity) }+public projection(process: string) { return this.existing(process).state }/** Where this Desktop looks on the plane, which drawings fixed to it are shown against. */diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.tsindex e3e2893..056e131 100644--- a/source/client/view/components/window-manager/window-manager.ts+++ b/source/client/view/components/window-manager/window-manager.ts@@ -324,7 +324,7 @@ export default function useWindows(authManager: AuthManager) {if (!window || window.layer !== "window") return Promise.resolve(false)const maximized = !presentation.projection(process.identity).maximizedconst request = window.maximize(maximized)- presentation.anticipate(process.identity, { maximized }, request)+ presentation.maximize(process.identity, maximized, request)return settle(request)}, [presentation, settle])diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 5f5a63a..edddc64 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -421,9 +421,9 @@ export default function Workspace() {const launchPlacement = useMemo<LaunchPlacement>(() => ({ place, reveal }), [place, reveal])- // A Window the person can see, maximized, fills the whole view it is in: unless the view rests on- // exactly that view, the view goes with it there, so the Window fills the screen. One out of sight,- // maximized, leaves the view where the person is.+ // A Window maximized from this Desktop fills the whole view it is in: unless the view rests on+ // exactly that view, this view goes with it there, so the Window fills the screen. A Window+ // maximized from another Desktop, or by the System, leaves this view where the person is.const wasMaximized = useRef(new Map<string, boolean>())useLayoutEffect(function () {@@ -436,15 +436,14 @@ export default function Workspace() {now.set(window.identity, window.maximized)if (!window.maximized || before.get(window.identity) !== false || window.minimized) continue+ if (!windows.presentation.maximizingHere(window.identity)) continueconst { region } = window- const seen = region.x < offset.x + windowSurfaceSize.width / 2 && region.x + region.width > offset.x - windowSurfaceSize.width / 2- && region.y < offset.y + windowSurfaceSize.height / 2 && region.y + region.height > offset.y - windowSurfaceSize.height / 2const view = { x: Math.round((region.x + region.width / 2) / windowSurfaceSize.width), y: Math.round((region.y + region.height / 2) / windowSurfaceSize.height) }// Against where the view exactly is, not the view nearest to it: a view resting between two// would show the maximized Window cut at the edges of its own view.- if (seen && (view.x !== views.x || view.y !== views.y)) viewport.moveTo(view)+ if (view.x !== views.x || view.y !== views.y) viewport.moveTo(view)}wasMaximized.current = nowdiff --git a/tests/presentation.test.ts b/tests/presentation.test.tsindex 886daa9..26ea348 100644--- a/tests/presentation.test.ts+++ b/tests/presentation.test.ts@@ -67,6 +67,36 @@ test("transactionAndWait resolves only after the matching local animation", asynawait usingAppearance})+test("only a Window this Desktop maximizes is known as maximized from here, until its request settles", async () => {+ const ordinary = client("window")+ const entries = entry("ordinary", ordinary)+ const presentations = new Presentations(entries, () => ordinary as never)+ const [identity] = [...presentations.windows.keys()]++ // Maximized from another Desktop: the System's state changes, and this Desktop asked nothing.+ ordinary.window.maximized = true+ presentations.reconcile(entries)+ assert.equal(presentations.projection("ordinary").maximized, true)+ assert.equal(presentations.maximizingHere(identity!), false)++ ordinary.window.maximized = false+ presentations.reconcile(entries)+ let answer!: () => void+ const request = new Promise<void>(resolve => { answer = resolve })+ presentations.maximize("ordinary", true, request)+ assert.equal(presentations.projection("ordinary").maximized, true)+ assert.equal(presentations.maximizingHere(identity!), true)++ answer()+ await request+ await Promise.resolve()+ assert.equal(presentations.maximizingHere(identity!), false)++ // Restoring from here is not maximizing.+ presentations.maximize("ordinary", false, Promise.resolve())+ assert.equal(presentations.maximizingHere(identity!), false)+})+test("a standard Window follows authoritative state but accepts only move gestures", async () => {const ordinary = client("window")const entries = entry("ordinary", ordinary)