Desktop modules: a wasm module can fill the desktop, with Icon Desktop and Live Starfield
CI / test (push) Failing after 30s
CI / test (push) Failing after 30s
A module that exports chandra:desktop/desktop-module (wit/desktop.wit) owns the desktop behind the windows instead of a box in the panel: same sandbox, draw ops and capabilities, drawn at the output's full size and re-rendered on resize. It gets pointer and scroll events only on the empty desktop (windows, panel, popups and menus always win; a drag stays with the module until release), keys only while the desktop has focus, and can draw over the wallpaper or replace it. Its tick() asks for animation frames only while something moves; the main loop sleeps until the next one (wake_timeout), and frames pause while a window covers the desktop, so an idle desktop module costs nothing. Settings > Desktop gets "On the desktop": Wallpaper only, Clock card (default) or any installed desktop module, saved in state.edn as :desktop, loaded at login and reloaded by chandra-ctl reload. Right-click the empty desktop for Module settings and System settings. Hidden settings (empty label) are persisted by the shell, which is how Icon Desktop keeps icon positions. Samples: Icon Desktop (click to launch, drag to arrange, keyboard navigation, count and size settings) and Live Starfield (pointer steers, click or Space warps, wheel sets speed). Served by all hosts: compositor/wasm (native + MoonBit wasmhost) and Rust host-wasm. Docs in docs/desktop-modules.md; tests in compositor/host/desktop_test.mbt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgf1SwPMHVfLUbJKsB
This commit is contained in:
79 files changed
+4591
-113
No files matched your search
@@ -17,7 +17,7 @@
|
||||
|
||||
#define MAX_INST 2048
|
||||
enum { EX_INFO, EX_RENDER, EX_ONEVENT, EX_POPUP, EX_POST_INFO, EX_POST_RENDER, EX_POST_POPUP, EX_REALLOC,
|
||||
EX_CFG_ITEMS, EX_POST_CFG_ITEMS, EX_SET_CFG, EX_N };
|
||||
EX_CFG_ITEMS, EX_POST_CFG_ITEMS, EX_SET_CFG, EX_DESK_BACKDROP, EX_DESK_SCROLL, EX_DESK_TICK, EX_N };
|
||||
static const char *ex_names[EX_N] = {
|
||||
"chandra:desktop/plasmoid@0.1.0#info",
|
||||
"chandra:desktop/plasmoid@0.1.0#render",
|
||||
@@ -31,6 +31,10 @@ static const char *ex_names[EX_N] = {
|
||||
"chandra:desktop/module-config@0.1.0#config-items",
|
||||
"cabi_post_chandra:desktop/module-config@0.1.0#config-items",
|
||||
"chandra:desktop/module-config@0.1.0#set-config",
|
||||
/* optional: chandra:desktop/desktop-module (a module that fills the desktop, wit/desktop.wit) */
|
||||
"chandra:desktop/desktop-module@0.1.0#backdrop",
|
||||
"chandra:desktop/desktop-module@0.1.0#on-scroll",
|
||||
"chandra:desktop/desktop-module@0.1.0#tick",
|
||||
};
|
||||
|
||||
typedef struct Inst {
|
||||
@@ -61,17 +65,20 @@ enum {
|
||||
K_NET_STATUS, K_NET_LIST, K_NET_SCAN, K_NET_CONNECT, K_NET_DISCONNECT, K_NET_FORGET, K_NET_SET_WIFI,
|
||||
K_NET_SET_AIRPLANE,
|
||||
K_SC_LIST, K_SC_CAPTURE, K_SC_CANCEL, K_SC_RESET, K_SC_RESET_ALL,
|
||||
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH
|
||||
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH,
|
||||
K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP
|
||||
};
|
||||
typedef struct Env { Inst *inst; int kind; } Env;
|
||||
|
||||
/* ---- host data the shell publishes before calling a guest ----
|
||||
* A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */
|
||||
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS,
|
||||
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES, T_N };
|
||||
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES,
|
||||
/* fixed numbers from here (wit/host/plasmoids.wit publish-table) */
|
||||
T_DESKTOPS = 20, T_N = 32 };
|
||||
typedef struct { uint8_t *data; size_t len; } Blob;
|
||||
static Blob tables[T_N];
|
||||
static int32_t host_ints[12] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
|
||||
static int32_t host_ints[24] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
|
||||
4 screenshot state (bit 0 recording, bit 1 pointer in recordings),
|
||||
5 screen-off minutes, 6 suspend minutes (0: never),
|
||||
7 battery percent (-1: none), 8 battery charge-state, 9 battery seconds left */
|
||||
@@ -375,6 +382,11 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
|
||||
case K_LOGOUT: push_req(8, 0, NULL); break;
|
||||
case K_RELOAD: push_req(8, 1, NULL); break; /* 8: session; n 0 log out, 1 reload */
|
||||
case K_SET_WALLPAPER: push_req(9, a0, NULL); break;
|
||||
case K_DESKTOPS: build_list(in, T_DESKTOPS, "s", a0); break;
|
||||
case K_DESKTOP_CUR:
|
||||
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[20]);
|
||||
break;
|
||||
case K_SET_DESKTOP: push_req(40, a0, NULL); break;
|
||||
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
|
||||
/* Request 12 carries the screenshot code: 0-3 take, 10-12 record, 20 stop, 30/31 pointer. */
|
||||
case K_SHOT_TAKE: if (a0 >= 0 && a0 <= 3) push_req(12, a0, NULL); break;
|
||||
@@ -589,6 +601,9 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "desktops")) return K_DESKTOPS;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-desktop")) return K_DESKTOP_CUR;
|
||||
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-desktop")) return K_SET_DESKTOP;
|
||||
if (!strcmp(iface, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
|
||||
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
|
||||
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;
|
||||
@@ -882,7 +897,7 @@ void mp_host_set_table(int32_t which, moonbit_bytes_t data) {
|
||||
|
||||
MOONBIT_FFI_EXPORT
|
||||
void mp_host_set_int(int32_t which, int32_t v) {
|
||||
if (which >= 0 && which < 12) host_ints[which] = v;
|
||||
if (which >= 0 && which < 24) host_ints[which] = v; /* 20: the desktop (wallpaper.current-desktop) */
|
||||
}
|
||||
|
||||
/* Pop the next guest request: returns its kind (0 = none). Fetch its arguments with req_int / req_str. */
|
||||
|
||||
Reference in new issue
Block a user