CI / test (push) Failing after 18s
- New `battery` panel module (components/battery, logic in lib/battery): a battery icon filled to
the charge with the percentage and time remaining ("73% 2:05"; time to full while charging).
The fill turns green when charging or full, amber at 20 % and below, and at 10 % the whole
button turns red and a "Battery low" popup opens by itself, once per discharge spell. A click
opens the details (charge, state, time left in words). Without a battery it shows a plug.
- Right-click "Module settings": Show percentage, Show time remaining, and Without a battery
(Show a plug / Show nothing). Saved per module in state.edn like the clocks' settings.
- New `battery` capability (wit/capabilities.wit: read -> status {percent, charge-state,
secs-left}). Served by the wasmer stub (host ints 7-9), host-wasm and wasmhost (publish-battery).
- Host side (compositor/shell/battery.mbt): reads /sys/class/power_supply, every battery
together (energy_* / power_now, or charge_* / current_now; capacity when that is all there
is; device-scope batteries like mice are skipped). The `system` snapshot the Power tab uses
now reads the battery through the same code. Time left follows a running average of the
rate, starting over when the state changes.
- A fresh panel gets the battery module before the clock only on a machine with a battery.
- wasm_stub: MAX_INST 512 -> 2048. The host test binary creates ~70 compositors without
unloading their modules; at 512 the last tests' panels came up half empty.
- Tests: sysfs reading against a fake power supply (energy and charge units, two packs,
charging, full, capacity only, no battery), the running average, the module in the panel
(text, settings, click, the critical warning, the plug), the rendering logic, and a
host-wasm test of the module.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hky51dmaUqiYW746Gz
139 lines
5.2 KiB
Plaintext
139 lines
5.2 KiB
Plaintext
package chandra: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 chandra:desktop/types@0.1.0.{draw-op, input-event, size};
|
|
use chandra: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;
|
|
|
|
/// One of a module's own settings (chandra:desktop/module-config `config-item`): `choices`
|
|
/// empty means an on/off switch whose value is "on" or "off".
|
|
record config-item {
|
|
key: string,
|
|
label: string,
|
|
choices: list<string>,
|
|
value: string,
|
|
}
|
|
/// The module's settings for its right-click menu; empty when it doesn't export module-config.
|
|
config-items: func(handle: u32) -> list<config-item>;
|
|
/// Set one of them. True when the module wants a redraw (false without module-config).
|
|
set-config: func(handle: u32, key: string, value: string) -> 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), 5 wallpapers (s), 6 session
|
|
/// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`.
|
|
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);
|
|
/// The wallpaper on the desktop now (an index into the wallpapers table).
|
|
publish-wallpaper: func(current: s32);
|
|
/// Which session settings are on: bit i for row i of the session settings table.
|
|
publish-session-settings: func(on: u32);
|
|
/// The power timeouts, in minutes (0: never).
|
|
publish-power: func(screen-off: u32, suspend: u32);
|
|
/// The battery: percent (-1: none), state (the battery capability's charge-state, as its index)
|
|
/// and estimated seconds left (0: unknown).
|
|
publish-battery: func(percent: s32, state: u32, secs-left: u32);
|
|
/// Screenshot state: bit 0 a recording is running, bit 1 recordings show the pointer.
|
|
publish-screenshot: func(state: u32);
|
|
|
|
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>);
|
|
|
|
/// A module turning a session setting on or off.
|
|
record setting-change {
|
|
index: s32,
|
|
on: bool,
|
|
}
|
|
|
|
// ---- 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,
|
|
logout,
|
|
set-wallpaper(s32),
|
|
set-session-setting(setting-change),
|
|
/// The screenshot capability: 0-3 take(mode), 10-12 start-recording(mode), 20 stop recording,
|
|
/// 30/31 hide/show the pointer in recordings.
|
|
screenshot(s32),
|
|
/// Power: new screen-off / suspend timeouts in minutes; an action now (0 suspend, 1 power
|
|
/// off, 2 restart).
|
|
set-screen-off(s32),
|
|
set-suspend-after(s32),
|
|
power-action(s32),
|
|
}
|
|
/// 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;
|
|
}
|