// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // what the desktop app's window (desktop/main.ts, on deno's main thread) and the client running in a worker (see // main.ts here) tell each other. the window has the os's events and the client draws into it // the window's surface, for deno's UnsafeWindowSurface. handles are pointers' addresses, pointers can't be posted export interface SurfaceHandles { system: "cocoa" | "win32" | "x11" | "wayland"; window: bigint; display: bigint; } export type WindowMessage = | { type: "start"; page: string; surface: SurfaceHandles; width: number; height: number; // what the client saved, see Platform.storage storage: Record; // whether the window can play sound, see desktop/openal.ts audio: boolean; // the credits of the libraries the app comes with, see desktop/libraries.ts. an app older than its client // (updated from the site) doesn't send them credits?: string; } // in pixels, what's drawn to is this big now | { type: "resize"; width: number; height: number } // code like a KeyboardEvent's, key the letter for a shortcut (see InputManager.key_down), "" otherwise | { type: "key"; down: boolean; code: string; key: string; shortcut: boolean } | { type: "text"; text: string } // buttons numbered like the dom's | { type: "button"; down: boolean; button: number } // the cursor, in pixels from the window's top left | { type: "cursor"; x: number; y: number } // the grabbed mouse moved | { type: "look"; x: number; y: number } // down is positive, about 100 for a notch, like the dom's | { type: "scroll"; amount: number } // the window lost or got focus, losing it lets go of the mouse | { type: "focus"; focused: boolean } // whether the window can be seen | { type: "shown"; shown: boolean } // the answer to read_clipboard, by the id it was asked with | { type: "clipboard"; id: number; text: string } // sources that played to their end, see web_audio.ts | { type: "audio_ended"; sources: number[] }; export type ClientMessage = | { type: "grab"; grab: boolean } | { type: "fullscreen" } // start the client over at page, see Platform.restart | { type: "restart"; page: string } | { type: "fatal"; message: string } | { type: "read_clipboard"; id: number } | { type: "write_clipboard"; text: string } | { type: "store"; key: string; value: string } | { type: "audio"; commands: AudioCommand[] }; // how a playing source sounds: everything between it and the speakers worked out, see web_audio.ts. gain 0 is silent export interface SourceSettings { gain: number; pitch: number; // where it is, with its distance falloff: full gain within ref_distance, fading linearly to 1 - rolloff at // max_distance. undefined plays it as it is, not from anywhere at: [number, number, number] | undefined; ref_distance: number; max_distance: number; rolloff: number; } // what the client's web audio has the window's openal do. ids are the client's own export type AudioCommand = // a decoded file, one array of samples a channel | { op: "buffer"; id: number; channels: Float32Array[]; sample_rate: number } | { op: "play"; id: number; buffer: number; loop: boolean; offset: number; settings: SourceSettings } | { op: "set"; id: number; settings: SourceSettings } | { op: "stop"; id: number } | { op: "listener"; position: [number, number, number]; forward: [number, number, number]; up: [number, number, number]; };