Skip to content

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

Animate standard window geometry

zohayrslilehb601a81223da
diff --git a/package.json b/package.json
index 60adfa0..83515ac 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.77",
+ "version": "0.1.78",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.ts
index b702a7a..dbff4f4 100644
--- a/source/client/view/components/window-manager/window-presentations.ts
+++ b/source/client/view/components/window-manager/window-presentations.ts
@@ -82,11 +82,15 @@ export default class WindowPresentations implements WindowPresentationHost {
|| ("size" in changes && JSON.stringify(state.size) !== JSON.stringify(changes.size))
if (maximized !== state.maximized || (!maximized && geometryChanged) || (minimized && !state.minimized)) {
this.cancel(identity, "geometry", "The followed Window presentation changed")
- changes.geometryAnimation = null
+ const target = { ...state, ...changes }
+ changes.geometryAnimation = minimized
+ ? null
+ : presentationAnimation(++this.revision, defaultPresentationTransaction(target))
}
if ("minimized" in changes && state.minimized !== changes.minimized) {
this.cancel(identity, "minimize", "The followed Window visibility changed")
- changes.minimizeAnimation = null
+ const target = { ...state, ...changes }
+ changes.minimizeAnimation = presentationAnimation(++this.revision, defaultPresentationTransaction(target))
}
next.set(identity, { ...state, ...changes })
relation.snapshot = target
@@ -229,7 +233,7 @@ export default class WindowPresentations implements WindowPresentationHost {
requirePresentationApplication(state.layer, "maximized")
if (state.maximized === maximized) return Promise.resolve()
this.cancel(identity, "geometry")
- const animation = !state.minimized ? presentationAnimation(++this.revision, state.transaction, transaction) : null
+ const animation = !state.minimized ? presentationAnimation(++this.revision, defaultPresentationTransaction(state), transaction) : null
this.replace(identity, { ...state, maximized, geometryAnimation: animation })
return this.waitFor(identity, "geometry", animation, transaction)
}
@@ -244,8 +248,9 @@ export default class WindowPresentations implements WindowPresentationHost {
const visibilityChanged = current.minimized !== projected.minimized
this.cancel(identity, "geometry")
this.cancel(identity, "minimize")
- const geometryAnimation = geometryChanged && !projected.minimized ? presentationAnimation(++this.revision, projected.transaction, transaction) : null
- const minimizeAnimation = visibilityChanged ? presentationAnimation(++this.revision, projected.transaction, transaction) : null
+ const selectedTransaction = defaultPresentationTransaction(projected)
+ const geometryAnimation = geometryChanged && !projected.minimized ? presentationAnimation(++this.revision, selectedTransaction, transaction) : null
+ const minimizeAnimation = visibilityChanged ? presentationAnimation(++this.revision, selectedTransaction, transaction) : null
this.replace(identity, {
...projected,
geometryAnimation,
@@ -310,7 +315,7 @@ export default class WindowPresentations implements WindowPresentationHost {
if (JSON.stringify(state.frame) === JSON.stringify(frame)) return Promise.resolve()
this.cancel(identity, "frame")
- const animation = presentationAnimation(++this.revision, state.transaction, transaction)
+ const animation = presentationAnimation(++this.revision, defaultPresentationTransaction(state), transaction)
this.replace(identity, { ...state, frame, frameAnimation: animation })
return this.waitFor(identity, "frame", animation, transaction)
}
@@ -395,7 +400,7 @@ export default class WindowPresentations implements WindowPresentationHost {
return Promise.resolve()
}
this.cancel(identity, "geometry")
- const animation = presentationAnimation(++this.revision, state.transaction, transaction)
+ const animation = presentationAnimation(++this.revision, defaultPresentationTransaction(state), transaction)
this.replace(identity, { ...state, position, size, geometryAnimation: animation })
return this.waitFor(identity, "geometry", animation, transaction)
}
@@ -408,7 +413,7 @@ export default class WindowPresentations implements WindowPresentationHost {
this.cancel(identity, "minimize")
if (minimized) this.cancel(identity, "geometry", "The Window presentation was minimized")
- const animation = presentationAnimation(++this.revision, state.transaction, transaction)
+ const animation = presentationAnimation(++this.revision, defaultPresentationTransaction(state), transaction)
this.replace(identity, { ...state, minimized, minimizeAnimation: animation, geometryAnimation: minimized ? null : state.geometryAnimation })
return this.waitFor(identity, "minimize", animation, transaction)
}
@@ -494,6 +499,12 @@ function presentationAnimation(revision: number, fallback: WindowState["transact
return transaction === false ? null : Object.freeze({ revision, transaction })
}
+/** Standard Window motion belongs to the Desktop; other layers use their Window value. */
+function defaultPresentationTransaction(state: Pick<WindowPresentationState, "layer" | "transaction">) {
+
+ return state.layer === "window" ? true : state.transaction
+}
+
function initialPresentationState(client: ClientState): WindowPresentationState {
const window = client.window
diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsx
index 81f582b..d8b07d2 100644
--- a/source/client/view/structure/desktop/windows/snap-preview.tsx
+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx
@@ -16,6 +16,7 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, re
position: shown.position,
size: shown.size,
animation: null,
+ transaction: true,
immediate: reducedMotion
})
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 c74ba7f..fdfb1c7 100644
--- a/source/client/view/structure/desktop/windows/window-geometry-motion.ts
+++ b/source/client/view/structure/desktop/windows/window-geometry-motion.ts
@@ -1,7 +1,7 @@
import { resolveWindowGeometry, type WindowRegion } from "@client/view/components/window-manager/window-geometry"
import { type PresentationAnimation } from "@client/view/components/desktop-host/window-presentation"
import { resolveWindowTransaction } from "@client/view/appearance/motion"
-import { type AppearanceTransaction, type Position, type Size } from "@phreshos/core"
+import { type AppearanceTransaction, type Position, type Size, type WindowTransaction } from "@phreshos/core"
import { useMotionValue, useTransform, type MotionStyle } from "motion/react"
import { useLayoutEffect, useRef } from "react"
import { WindowGeometryAnimation } from "./window-geometry-animation"
@@ -11,6 +11,7 @@ interface WindowGeometryMotionOptions {
position: Position
size: Size
animation?: PresentationAnimation | null
+ transaction?: WindowTransaction | null
immediate: boolean
onComplete?: (revision: number) => void
}
@@ -22,7 +23,7 @@ interface WindowGeometryMotionOptions {
* visible pixels, including during a pointer gesture, so releasing a drag
* cannot hand the transform to another renderer before snapping begins.
*/
-export default function useWindowGeometryMotion({ position, size, animation, immediate, onComplete }: WindowGeometryMotionOptions) {
+export default function useWindowGeometryMotion({ position, size, animation, transaction, immediate, onComplete }: WindowGeometryMotionOptions) {
const appearanceTransaction = useAppearance().transaction
const frame = useRef<HTMLDivElement>(null)
@@ -40,9 +41,9 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
const gesturing = useRef(false)
const restoringGesture = useRef(false)
const initialized = useRef(false)
- const values = useRef({ position, size, animation, immediate, onComplete })
+ const values = useRef({ position, size, animation, transaction, immediate, onComplete })
- values.current = { position, size, animation, immediate, onComplete }
+ values.current = { position, size, animation, transaction, immediate, onComplete }
function read(): WindowRegion {
@@ -133,7 +134,11 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
return
}
- const selected = animation ? resolveWindowTransaction(animation.transaction, appearanceTransaction) : null
+ const selected = animation
+ ? resolveWindowTransaction(animation.transaction, appearanceTransaction)
+ : transaction === undefined || transaction === null
+ ? null
+ : resolveWindowTransaction(transaction, appearanceTransaction)
if (!selected) {
set(region)
@@ -143,7 +148,7 @@ export default function useWindowGeometryMotion({ position, size, animation, imm
transition(region, selected, revision === undefined ? undefined : () => onComplete?.(revision))
- }, [position.x, position.y, size.width, size.height, animation?.revision, immediate])
+ }, [position.x, position.y, size.width, size.height, animation?.revision, transaction, immediate])
useLayoutEffect(function () {
diff --git a/tests/window-presentation.test.ts b/tests/window-presentation.test.ts
index af8b1ab..d679dbb 100644
--- a/tests/window-presentation.test.ts
+++ b/tests/window-presentation.test.ts
@@ -112,6 +112,24 @@ test("transaction-capable presentations use the authoritative Window transaction
await inherited
})
+test("standard Window geometry uses the Desktop Appearance transaction by default", async () => {
+ const ordinary = client("window")
+ const entries = new Map([
+ ["ordinary", { identity: "ordinary:0", client: ordinary }]
+ ]) as unknown as ReadonlyMap<string, WindowPresentationEntry>
+ const presentations = new WindowPresentations(entries, () => ordinary as never)
+
+ await presentations.move("ordinary", { x: 20, y: 30 })
+ assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)
+
+ await presentations.resize("ordinary", { width: 500, height: 400 })
+ assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)
+
+ ordinary.window.position = { x: 80, y: 90 }
+ presentations.reconcile(entries)
+ assert.equal(presentations.projection("ordinary").geometryAnimation?.transaction, true)
+})
+
test("presentation geometry events expose each applied representation change", () => {
const ordinary = client("window")
const entries = new Map([