Panel modules in the wasm compositor: the host runs them (moonplasma:host/plasmoids)
CI / test (push) Failing after 46s
CI / test (push) Failing after 46s
A component can't embed a second wasm runtime, so the compositor drives panel modules through a host import and the wasmtime host instantiates them: load, render, popup, on-event, plus the data they read (apps, windows, layouts, modules, system) and the requests they make (launch, focus window, set layout, load/unload, browse), with a zenity file chooser for 'Add widget'. - wit/worlds.wit: world plasmoid-host, every capability a module can import + the plasmoid export. The host instantiates any module against it; a module imports the subset it uses. - wit/host/plasmoids.wit + generated MoonBit bindings; compositor/wasm gets a wasm backend (wasm_host.mbt) with the same public API as the native wasmer one. - host-wasm/src/plasmoid.rs: typed component bindings, one Store per module, shared host data. Tests load the built launcher/layout modules and drive them (typed filter, Enter, launch request). - scripts/gen-native-stubs.py keeps a package's imports when it rewrites moon.pkg. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c3bebc7fd
commit
e769566d8f
23 files changed
+2001
-302
No files matched your search
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../theme.wit
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../types.wit
|
||||
@@ -0,0 +1,96 @@
|
||||
package moonplasma:host@0.1.0;
|
||||
|
||||
/// Panel modules (plasmoids) for a compositor that is itself a component. A component can't embed
|
||||
/// a second wasm runtime, so the host runs the modules (wasmtime) and the compositor drives them
|
||||
/// through this interface. It mirrors compositor/wasm: load, draw, events, plus the host data a
|
||||
/// module may read and the requests it may make.
|
||||
interface plasmoids {
|
||||
use moonplasma:desktop/types@0.1.0.{draw-op, input-event, size};
|
||||
use moonplasma:desktop/theme@0.1.0.{tokens};
|
||||
|
||||
/// A loaded module. `imports` is its capability grant: the host interfaces its binary imports
|
||||
/// (besides theme), e.g. ["clock"] or ["windows", "system"].
|
||||
record loaded {
|
||||
handle: u32,
|
||||
id: string,
|
||||
name: string,
|
||||
preferred: size,
|
||||
min-width: u32,
|
||||
stretch: bool,
|
||||
imports: list<string>,
|
||||
}
|
||||
/// Load the plasmoid component at `path`. The error is a short reason.
|
||||
load: func(path: string) -> result<loaded, string>;
|
||||
unload: func(handle: u32);
|
||||
|
||||
/// The theme the modules see through `theme.get-tokens` (set before drawing so a swap shows at once).
|
||||
set-tokens: func(t: tokens);
|
||||
render: func(handle: u32, box: size) -> list<draw-op>;
|
||||
|
||||
record popup-surface {
|
||||
box: size,
|
||||
ops: list<draw-op>,
|
||||
}
|
||||
popup: func(handle: u32) -> option<popup-surface>;
|
||||
/// Deliver an event to the module (`on-popup`: to its popup surface). True when it wants a redraw.
|
||||
on-event: func(handle: u32, on-popup: bool, event: input-event) -> bool;
|
||||
|
||||
// ---- host data modules read through their capabilities ----
|
||||
|
||||
/// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE
|
||||
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
|
||||
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
|
||||
/// (sssi: id name path loaded), 4 instances (sss: slot module name).
|
||||
publish-table: func(which: u32, rows: list<u8>);
|
||||
/// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on.
|
||||
publish-state: func(layout-mode: s32, inspector-on: bool);
|
||||
|
||||
record system-snapshot {
|
||||
cpu-permille: u32,
|
||||
mem-used-kib: u64,
|
||||
mem-total-kib: u64,
|
||||
battery-percent: s32,
|
||||
charging: bool,
|
||||
uptime-secs: u64,
|
||||
net-rx-bytes-per-sec: u64,
|
||||
net-tx-bytes-per-sec: u64,
|
||||
load-centi: u32,
|
||||
}
|
||||
publish-system: func(s: system-snapshot);
|
||||
|
||||
record window-entry {
|
||||
id: u64,
|
||||
title: string,
|
||||
app-id: string,
|
||||
focused: bool,
|
||||
}
|
||||
publish-windows: func(wins: list<window-entry>);
|
||||
|
||||
// ---- what modules asked of the host ----
|
||||
|
||||
variant request {
|
||||
launch(string),
|
||||
focus-window(s32),
|
||||
set-layout(s32),
|
||||
set-inspector(bool),
|
||||
load-module(string),
|
||||
unload-instance(string),
|
||||
browse,
|
||||
}
|
||||
/// The next pending request, oldest first.
|
||||
next-request: func() -> option<request>;
|
||||
/// A window a module asked to focus through `windows.focus` (64-bit id), since the last call.
|
||||
take-focus-request: func() -> option<u64>;
|
||||
|
||||
/// Names of the `*.wasm` files directly in `dir`, sorted.
|
||||
list-wasm-files: func(dir: string) -> list<string>;
|
||||
|
||||
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
|
||||
variant picker-state {
|
||||
open,
|
||||
cancelled,
|
||||
chosen(string),
|
||||
}
|
||||
picker-start: func() -> bool;
|
||||
picker-poll: func() -> picker-state;
|
||||
}
|
||||
@@ -75,6 +75,7 @@ interface font {
|
||||
world compositor {
|
||||
import sys;
|
||||
import font;
|
||||
import plasmoids;
|
||||
/// Run the compositor until it exits. `args` are the command-line arguments (without argv[0]).
|
||||
export run: func(args: list<string>) -> s32;
|
||||
}
|
||||
@@ -59,3 +59,19 @@ world module-manager-widget {
|
||||
include widget;
|
||||
import modules;
|
||||
}
|
||||
|
||||
/// Everything a panel module can be granted. The native host instantiates any module against this
|
||||
/// one world (a module simply imports the subset it uses) and serves each import from the data the
|
||||
/// compositor publishes (wit/host/plasmoids.wit).
|
||||
world plasmoid-host {
|
||||
import theme;
|
||||
import clock;
|
||||
import app-catalog;
|
||||
import app-launch;
|
||||
import windows;
|
||||
import layout-control;
|
||||
import inspector;
|
||||
import modules;
|
||||
import system;
|
||||
export plasmoid;
|
||||
}
|
||||
Reference in new issue
Block a user