Skip to content

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

The Desktop carries out a Program's move from the positions it reports

zohayrslileh8b7cad74a929
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.ts
index 2b3019e..49b7c18 100644
--- a/source/client/view/components/desktop-host/host.ts
+++ b/source/client/view/components/desktop-host/host.ts
@@ -29,6 +29,7 @@ import {
presentationSurface,
presentationGeometry,
presentationMoveGestureStart,
+ presentationMovePoint,
presentationPosition,
presentationSize,
presentationTransaction,
@@ -1001,6 +1002,18 @@ export default function host(authManager: AuthManager, pane: string, viewport: D
return []
}
+ if (word === "presentationMoveGestureMove") {
+ const target = presentationProcess(args[0])
+ presentation.continueMoveGesture(target.identity, gestureIdentity(args[1]), frame.point(presentationMovePoint(args[2])))
+ return []
+ }
+
+ if (word === "presentationMoveGestureEnd") {
+ const target = presentationProcess(args[0])
+ presentation.endMoveGesture(target.identity, gestureIdentity(args[1]), frame.point(presentationMovePoint(args[2])))
+ return []
+ }
+
if (word === "presentationMoveGestureCancel") {
const target = presentationProcess(args[0])
const gesture = gestureIdentity(args[1])
diff --git a/source/client/view/components/desktop-host/presentation.ts b/source/client/view/components/desktop-host/presentation.ts
index 5d5b988..3a4c3dd 100644
--- a/source/client/view/components/desktop-host/presentation.ts
+++ b/source/client/view/components/desktop-host/presentation.ts
@@ -37,9 +37,12 @@ export interface DesktopMoveGestureController {
cancel(): void
}
+/** A move the Desktop carries out while the Client document holds the pointer and reports it. */
export interface DesktopMoveGesture {
ready: Promise<void>
finished: Promise<void>
+ move(point: DesktopMovePoint): void
+ end(point: DesktopMovePoint): void
cancel(): void
}
@@ -61,6 +64,8 @@ export interface PresentationHost {
observe(listener: () => void): () => void
beginMoveGesture(identity: string, gesture: string, origin: DesktopMovePoint, point: DesktopMovePoint): Promise<void>
waitMoveGesture(identity: string, gesture: string): Promise<void>
+ continueMoveGesture(identity: string, gesture: string, point: DesktopMovePoint): void
+ endMoveGesture(identity: string, gesture: string, point: DesktopMovePoint): void
cancelMoveGesture(identity: string, gesture: string): void
cancelMoveGestures(identity: string): void
move(identity: string, position: PresentationPosition, transaction?: PresentationTransactionRequest): Promise<void>
diff --git a/source/client/view/components/window-manager/presentations.ts b/source/client/view/components/window-manager/presentations.ts
index 4828357..3a531a1 100644
--- a/source/client/view/components/window-manager/presentations.ts
+++ b/source/client/view/components/window-manager/presentations.ts
@@ -208,8 +208,6 @@ export default class Presentations implements PresentationHost {
const active = { identity, movement }
this.moveGestures.set(gesture, active)
void movement.finished.catch(() => undefined)
- // The iframe must retain pointer capture until the Desktop capture
- // surface exists; otherwise early movement falls between documents.
return movement.ready.catch(error => {
if (this.moveGestures.get(gesture) === active) this.moveGestures.delete(gesture)
throw error
@@ -224,6 +222,18 @@ export default class Presentations implements PresentationHost {
}
}
+ // Positions travel from the Client document as they come; one that arrives after its move ended,
+ // or for a move of another Window, has nothing left to move.
+ public continueMoveGesture(process: string, gesture: string, point: DesktopMovePoint) {
+ const active = this.moveGestures.get(gesture)
+ if (active && active.identity === this.live.get(process)) active.movement.move(point)
+ }
+
+ public endMoveGesture(process: string, gesture: string, point: DesktopMovePoint) {
+ const active = this.moveGestures.get(gesture)
+ if (active && active.identity === this.live.get(process)) active.movement.end(point)
+ }
+
public cancelMoveGesture(process: string, gesture: string) {
const active = this.moveGesture(process, gesture)
this.moveGestures.delete(gesture)
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 1afb15b..2af54bc 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -12,12 +12,11 @@ import { motion, useMotionValue, type MotionValue } from "motion/react"
import { PlaneSlideContext, ViewCellShift } from "../plane-slide"
import { EdgeHold, against } from "../edge-hold"
import { motionTransition, resolvePresentationTransaction } from "@client/view/appearance/motion"
-import { useAppearance, Window as UIWindow, timing } from "@phreshos/react-ui"
+import { useAppearance, timing } from "@phreshos/react-ui"
import SnapPreview, { type SnapTarget } from "./snap-preview"
import useWindowGeometryMotion from "./window-geometry-motion"
import WindowGestureCommit from "./window-gesture-commit"
import { physicalToDesktopPixels, useDesktopScale } from "../desktop-scale"
-import { createPortal } from "react-dom"
/**
* One drawing on the Desktop: a standard Window, which the Desktop designs, or a Program's own drawing
@@ -148,13 +147,19 @@ export default function ({ title, header = true, surface, layer, icon, children,
const pointer = beginPointerGesture.current(origin)
if (!pointer) throw new Error("This Window cannot currently begin a move gesture")
pointer.update(point)
- let markReady: () => void = () => undefined
- const ready = new Promise<void>(resolve => { markReady = resolve })
let finish: () => void = () => undefined
const finished = new Promise<void>(resolve => { finish = resolve })
- externalMove.current = { pointer, markReady, finish }
+ const move = { pointer, finish }
+ externalMove.current = move
setExternalMoveActive(true)
- return { ready, finished, cancel: () => finishExternalMove(null) }
+ // The Client document holds the pointer and reports it; the move is ready once begun.
+ return {
+ ready: Promise.resolve(),
+ finished,
+ move: next => { if (externalMove.current === move) move.pointer.update(next) },
+ end: last => { if (externalMove.current === move) finishExternalMove(last) },
+ cancel: () => { if (externalMove.current === move) finishExternalMove(null) }
+ }
},
cancel: () => finishExternalMove(null)
}
@@ -169,9 +174,6 @@ export default function ({ title, header = true, surface, layer, icon, children,
if (!active) return
externalMove.current = null
setExternalMoveActive(false)
- // Cancellation may happen before the portal commits. Readiness must
- // still settle so the remote owner can observe the completed gesture.
- active.markReady()
if (point) active.pointer.end(point)
else active.pointer.cancel()
active.finish()
@@ -766,21 +768,6 @@ export default function ({ title, header = true, surface, layer, icon, children,
return <>
- {externalMoveActive && createPortal(<UIWindow.MoveCapture
- data-window-move-capture
- ref={element => { if (element) externalMove.current?.markReady() }}
- style={{ zIndex: 2147483647 }}
- onPointerMove={event => {
- if (!event.currentTarget.hasPointerCapture(event.pointerId)) {
- try { event.currentTarget.setPointerCapture(event.pointerId) }
- catch { /* The full-viewport capture surface still owns in-bounds movement. */ }
- }
- externalMove.current?.pointer.update({ x: event.clientX, y: event.clientY })
- }}
- onPointerUp={event => finishExternalMove({ x: event.clientX, y: event.clientY })}
- onPointerCancel={() => finishExternalMove(null)}
- />, document.body)}
-
{/* The snap preview and its result resolve the same edge contacts. */}
{gesture?.shown && <SnapPreview
shown={gesture.shown}
@@ -1049,7 +1036,6 @@ interface ActivePointerGesture {
interface ExternalMove {
pointer: ActivePointerGesture
- markReady: () => void
finish: () => void
}
diff --git a/tests/presentation.test.ts b/tests/presentation.test.ts
index df12e6e..fc9d2f6 100644
--- a/tests/presentation.test.ts
+++ b/tests/presentation.test.ts
@@ -102,6 +102,8 @@ test("a standard Window follows authoritative state but accepts only move gestur
return {
ready: new Promise<void>(resolve => { ready = resolve }),
finished: new Promise<void>(resolve => { finish = resolve }),
+ move(point) { events.push(["move", point]) },
+ end(point) { events.push(["end", point]); finish() },
cancel() { events.push("gesture-cancel") }
}
},
@@ -112,8 +114,12 @@ test("a standard Window follows authoritative state but accepts only move gestur
ready()
await beginning
const moving = presentations.waitMoveGesture("ordinary", "gesture")
- finish()
+ presentations.continueMoveGesture("ordinary", "gesture", { x: 50, y: 60 })
+ presentations.endMoveGesture("ordinary", "gesture", { x: 70, y: 80 })
await moving
+ // A position that arrives after its move ended has nothing left to move.
+ presentations.continueMoveGesture("ordinary", "gesture", { x: 90, y: 100 })
+ assert.deepEqual(events.slice(1), [["move", { x: 50, y: 60 }], ["end", { x: 70, y: 80 }]])
})
test("a Client boundary initializes each new document exactly once", async () => {