wasmhost

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package wasmhost is the desktop shell's wasmbox (wasmdesk) backend: it drives a go-widgets widget tree as an external wasmbox client, painting into the compositor's shared surface and translating wasmbox input messages into toolkit events.

It is the browser analogue of github.com/go-widgets/window's native X11 / Wayland backend. window v0.4.0 has no js/wasm backend yet (its Open returns ErrUnsupported off Linux), so the desktop shell supplies its own wasmbox host here; the platform split mirrors window's exactly — Run on js/wasm, an ErrUnsupported stub elsewhere — so the same clients/desktop entry point cross-builds on every target.

The rendering core (Host) is platform-independent and fully unit-tested on native: only the thin syscall/js glue in host_js.go is browser-only. Host reuses the shell's incremental-present root (scene.HostRoot): each frame it repaints just the damaged rectangles and reports their bounding box as the wasmbox commit{damage}, so the small-rect present the native window backend does flows through the compositor's blit too.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("wasmhost: the wasmbox backend is only available on js/wasm")

ErrUnsupported is returned by Open on platforms other than js/wasm, mirroring window.ErrUnsupported so a cross-build stays green everywhere.

Functions

func Run

func Run(_ toolkit.Widget, _ *toolkit.Theme) error

Run is unavailable off js/wasm: there is no wasmbox compositor to attach to, so it returns ErrUnsupported. The rendering core (Host) and the input mapping stay compiled and unit-tested on every platform; only this entry point is gated, mirroring window.Open's Linux-only gating so cross-builds stay green.

Types

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host binds a go-widgets root widget to a persistent RGBA framebuffer and drives it: Frame renders the next frame (incrementally when the root opts in) and returns the damage to present; Input dispatches a decoded wasmbox event into the tree. It owns no js state, so it is exercised end-to-end on native.

func NewHost

func NewHost(root toolkit.Widget, theme *toolkit.Theme, w, h int) *Host

NewHost builds a Host over a fresh w×h framebuffer bound to root. When root implements the incremental seam (RenderDamaged) frames present only the damaged rectangles; otherwise every frame is a full repaint.

func (*Host) Buffer

func (h *Host) Buffer() []byte

Buffer is the RGBA framebuffer the compositor's shared surface mirrors.

func (*Host) Frame

func (h *Host) Frame() toolkit.Rect

Frame renders the next frame into the framebuffer and returns the rectangle to present. The first frame (the initial map) always reports the whole surface; afterwards an incremental root reports the bounding box of the rectangles it repainted (empty when nothing changed), and a plain root always repaints and reports the whole surface.

func (*Host) Input

func (h *Host) Input(in InputEvent) bool

Input dispatches a decoded wasmbox event into the widget tree, returning whether it produced any toolkit event (so the js glue can skip a needless frame for an event the shell ignores).

func (*Host) Size

func (h *Host) Size() (int, int)

Size returns the framebuffer dimensions.

type InputEvent

type InputEvent struct {
	Kind   string
	X, Y   int
	Key    string
	Code   string
	DeltaY int
}

InputEvent is one decoded wasmbox input message (the fields the compositor puts on event objects it posts to a client: kind, surface-local x/y, the keyboard key/code, and the wheel deltaY). host_js.go decodes the js value into this struct so the mapping logic stays pure and testable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL