An open-source, self-hosted system for apps built with web technologies.
The Desktop moves a Program's Window by the pointer when it reaches it, else by the reports
zohayrslileh6fbf42c98e79
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 49b7c18..a62c6f1 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -28,7 +28,6 @@ import {import {presentationSurface,presentationGeometry,- presentationMoveGestureStart,presentationMovePoint,presentationPosition,presentationSize,@@ -985,13 +984,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "presentationMoveGestureBegin") {const target = presentationProcess(args[0])const gesture = gestureIdentity(args[1])- const start = presentationMoveGestureStart(args[2])- await presentation.beginMoveGesture(- target.identity,- gesture,- frame.point(start.origin),- frame.point(start.point)- )+ presentation.beginMoveGesture(target.identity, gesture, frame.point(presentationMovePoint(args[2])))return []}@@ -1010,7 +1003,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "presentationMoveGestureEnd") {const target = presentationProcess(args[0])- presentation.endMoveGesture(target.identity, gestureIdentity(args[1]), frame.point(presentationMovePoint(args[2])))+ presentation.endMoveGesture(target.identity, gestureIdentity(args[1]))return []}diff --git a/source/client/view/components/desktop-host/presentation.ts b/source/client/view/components/desktop-host/presentation.tsindex 3a4c3dd..b165d03 100644--- a/source/client/view/components/desktop-host/presentation.ts+++ b/source/client/view/components/desktop-host/presentation.ts@@ -2,7 +2,6 @@ import {parsePresentationSurface,parsePresentationTransaction,type WindowLayer,- type PresentationMoveGestureStart,type PresentationMovePoint,type PresentationGeometry,type PresentationAnchor,@@ -33,16 +32,15 @@ export interface PresentationFrame {}export interface DesktopMoveGestureController {- begin(origin: DesktopMovePoint, point: DesktopMovePoint): DesktopMoveGesture+ begin(origin: DesktopMovePoint): DesktopMoveGesturecancel(): 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+ end(): voidcancel(): void}@@ -62,10 +60,10 @@ export interface PresentationHost {begin(identity: string): voiddrawing(identity: string, frame: HTMLIFrameElement): PresentationStateobserve(listener: () => void): () => void- beginMoveGesture(identity: string, gesture: string, origin: DesktopMovePoint, point: DesktopMovePoint): Promise<void>+ beginMoveGesture(identity: string, gesture: string, origin: DesktopMovePoint): voidwaitMoveGesture(identity: string, gesture: string): Promise<void>continueMoveGesture(identity: string, gesture: string, point: DesktopMovePoint): void- endMoveGesture(identity: string, gesture: string, point: DesktopMovePoint): void+ endMoveGesture(identity: string, gesture: string): voidcancelMoveGesture(identity: string, gesture: string): voidcancelMoveGestures(identity: string): voidmove(identity: string, position: PresentationPosition, transaction?: PresentationTransactionRequest): Promise<void>@@ -85,11 +83,6 @@ export function presentationMovePoint(value: unknown): PresentationMovePoint {return Object.freeze({ x: record.x, y: record.y })}-export function presentationMoveGestureStart(value: unknown): PresentationMoveGestureStart {- const record = plain(value, "Window move gesture start")- return Object.freeze({ origin: presentationMovePoint(record.origin), point: presentationMovePoint(record.point) })-}-/** The drawing is written in pixels; shares belong to the Window, which every Desktop resolves itself. */export function presentationPosition(value: unknown): PresentationPosition {const record = plain(value, "Presentation position")diff --git a/source/client/view/components/window-manager/presentations.ts b/source/client/view/components/window-manager/presentations.tsindex 3a531a1..c5d0ed5 100644--- a/source/client/view/components/window-manager/presentations.ts+++ b/source/client/view/components/window-manager/presentations.ts@@ -198,20 +198,15 @@ export default class Presentations implements PresentationHost {else this.moveGestureControllers.delete(identity)}- public beginMoveGesture(process: string, gesture: string, origin: DesktopMovePoint, point: DesktopMovePoint) {+ public beginMoveGesture(process: string, gesture: string, origin: DesktopMovePoint) {const { identity, state } = this.existing(process)requirePresentationMoveGesture(state.layer)if ([...this.moveGestures.values()].some(active => active.identity === identity)) throw new Error("This Window already has an active move gesture")const controller = this.moveGestureControllers.get(identity)if (!controller) throw new Error("This Window cannot currently begin a move gesture")- const movement = controller.begin(origin, point)- const active = { identity, movement }- this.moveGestures.set(gesture, active)+ const movement = controller.begin(origin)+ this.moveGestures.set(gesture, { identity, movement })void movement.finished.catch(() => undefined)- return movement.ready.catch(error => {- if (this.moveGestures.get(gesture) === active) this.moveGestures.delete(gesture)- throw error- })}public async waitMoveGesture(process: string, gesture: string) {@@ -229,9 +224,9 @@ export default class Presentations implements PresentationHost {if (active && active.identity === this.live.get(process)) active.movement.move(point)}- public endMoveGesture(process: string, gesture: string, point: DesktopMovePoint) {+ public endMoveGesture(process: string, gesture: string) {const active = this.moveGestures.get(gesture)- if (active && active.identity === this.live.get(process)) active.movement.end(point)+ if (active && active.identity === this.live.get(process)) active.movement.end()}public cancelMoveGesture(process: string, gesture: string) {diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 2af54bc..e9e47e7 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -17,6 +17,7 @@ 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@@ -142,22 +143,22 @@ export default function ({ title, header = true, surface, layer, icon, children,const moveGestureController = useRef<DesktopMoveGestureController | null>(null)if (!moveGestureController.current) {moveGestureController.current = {- begin(origin, point) {+ begin(origin) {if (externalMove.current) throw new Error("This Window already has an active move gesture")const pointer = beginPointerGesture.current(origin)if (!pointer) throw new Error("This Window cannot currently begin a move gesture")- pointer.update(point)let finish: () => void = () => undefinedconst finished = new Promise<void>(resolve => { finish = resolve })- const move = { pointer, finish }+ // The Desktop lays a layer over the screen and moves the Window by the pointer that+ // reaches it; until one does, and where none ever does, by the places the Client document+ // reports. The move settles at the last place either gave.+ const move: ExternalMove = { pointer, finish, own: false, last: origin }externalMove.current = movesetExternalMoveActive(true)- // 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) },+ move: next => { if (externalMove.current === move && !move.own) { move.last = next; move.pointer.update(next) } },+ end: () => { if (externalMove.current === move) finishExternalMove(move.last) },cancel: () => { if (externalMove.current === move) finishExternalMove(null) }}},@@ -165,8 +166,8 @@ export default function ({ title, header = true, surface, layer, icon, children,}}- const beginWindowMoveGesture = useCallback<BeginPresentationMoveGesture>(start => {- return moveGestureController.current!.begin(start.origin, start.point)+ const beginWindowMoveGesture = useCallback<BeginPresentationMoveGesture>(origin => {+ return moveGestureController.current!.begin(origin)}, [])function finishExternalMove(point: DesktopMovePoint | null) {@@ -768,6 +769,28 @@ export default function ({ title, header = true, surface, layer, icon, children,return <>+ {externalMoveActive && createPortal(<div+ data-window-move-capture=""+ style={{ position: "fixed", inset: 0, zIndex: 2147483647, touchAction: "none", userSelect: "none", cursor: "grabbing" }}+ onPointerMove={event => {+ const move = externalMove.current+ // Only a pressed pointer moves the Window; one that arrives after the release is hover.+ if (!move || (event.buttons & 1) === 0) return+ if (!move.own) {+ move.own = true+ try { event.currentTarget.setPointerCapture(event.pointerId) }+ catch { /* The layer covers the screen; it hears the pointer anyway. */ }+ }+ move.last = { x: event.clientX, y: event.clientY }+ move.pointer.update(move.last)+ }}+ onPointerUp={event => {+ const move = externalMove.current+ if (move?.own) finishExternalMove({ x: event.clientX, y: event.clientY })+ }}+ onPointerCancel={() => { if (externalMove.current?.own) finishExternalMove(null) }}+ />, document.body)}+{/* The snap preview and its result resolve the same edge contacts. */}{gesture?.shown && <SnapPreviewshown={gesture.shown}@@ -1037,6 +1060,9 @@ interface ActivePointerGesture {interface ExternalMove {pointer: ActivePointerGesturefinish: () => void+ /** The pointer reached the Desktop's layer, which now moves the Window by it. */+ own: boolean+ last: DesktopMovePoint}/**diff --git a/tests/presentation-layers.test.ts b/tests/presentation-layers.test.tsindex c057139..8bc7129 100644--- a/tests/presentation-layers.test.ts+++ b/tests/presentation-layers.test.ts@@ -26,7 +26,7 @@ test("wallpaper is fixed and rejects both raw operations and move gestures", ()expect(() => presentations.move("own", { x: 1, y: 2 })).toThrow(/does not support raw/)expect(() => presentations.setInteractive("own", false)).toThrow(/does not support raw/)expect(() => presentations.raise("own")).toThrow(/does not support raw/)- expect(() => presentations.beginMoveGesture("own", "gesture", { x: 0, y: 0 }, { x: 1, y: 1 })).toThrow(/nowhere to move/)+ expect(() => presentations.beginMoveGesture("own", "gesture", { x: 0, y: 0 })).toThrow(/nowhere to move/)})test.each(["under", "over", "shell"] as const)("%s is controlled only through raw presentation operations", async layer => {@@ -52,7 +52,7 @@ test.each(["under", "over", "shell"] as const)("%s is controlled only through rapresentations.begin("own")expect(presentations.projection("own").interactive).toBe(true)// A raw drawing may hand a move to the Desktop too, once its Window can take one.- expect(() => presentations.beginMoveGesture("own", "gesture", { x: 0, y: 0 }, { x: 1, y: 1 })).toThrow(/cannot currently begin/)+ expect(() => presentations.beginMoveGesture("own", "gesture", { x: 0, y: 0 })).toThrow(/cannot currently begin/)})test("standard Window presentation is exclusively Desktop-controlled", () => {diff --git a/tests/presentation.test.ts b/tests/presentation.test.tsindex fc9d2f6..bb4d5af 100644--- a/tests/presentation.test.ts+++ b/tests/presentation.test.ts@@ -94,32 +94,27 @@ test("a standard Window follows authoritative state but accepts only move gesturassert.notEqual(restoring.revision, maximizing.revision)const events: unknown[] = []- let ready!: () => voidlet finish!: () => voidpresentations.registerMoveGesture("ordinary", {- begin(origin, point) {- events.push([origin, point])+ begin(origin) {+ events.push(["begin", origin])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() },+ end() { events.push("end"); finish() },cancel() { events.push("gesture-cancel") }}},cancel() { events.push("cancel") }})- const beginning = presentations.beginMoveGesture("ordinary", "gesture", { x: 10, y: 20 }, { x: 30, y: 40 })- assert.deepEqual(events, [[{ x: 10, y: 20 }, { x: 30, y: 40 }]])- ready()- await beginning+ presentations.beginMoveGesture("ordinary", "gesture", { x: 10, y: 20 })const moving = presentations.waitMoveGesture("ordinary", "gesture")presentations.continueMoveGesture("ordinary", "gesture", { x: 50, y: 60 })- presentations.endMoveGesture("ordinary", "gesture", { x: 70, y: 80 })+ presentations.endMoveGesture("ordinary", "gesture")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 }]])+ assert.deepEqual(events, [["begin", { x: 10, y: 20 }], ["move", { x: 50, y: 60 }], "end"])})test("a Client boundary initializes each new document exactly once", async () => {