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
209 lines
7.3 KiB
Plaintext
209 lines
7.3 KiB
Plaintext
package chandra:desktop@0.1.0;
|
|
|
|
/// Host-brokered capabilities. A component can only call what its world
|
|
/// imports AND what the host grants it in the desktop manifest.
|
|
|
|
interface clock {
|
|
use types.{datetime};
|
|
/// Local wall-clock time (the host owns the time zone).
|
|
now: func() -> datetime;
|
|
}
|
|
|
|
interface app-catalog {
|
|
use types.{app-entry};
|
|
/// Installed applications (static list in the PoC; .desktop files later).
|
|
list-apps: func() -> list<app-entry>;
|
|
}
|
|
|
|
interface app-launch {
|
|
/// Ask the host to start an application by catalog id.
|
|
launch: func(id: string) -> result<_, string>;
|
|
}
|
|
|
|
/// Live machine state, sampled by the host about once a second. The widget never
|
|
/// opens /proc or /sys itself: it can only see what this interface hands it, and
|
|
/// the host can serve it from anything (Linux /proc, a mock, a remote machine).
|
|
interface system {
|
|
record snapshot {
|
|
/// Busy CPU time since the previous sample, 0..1000.
|
|
cpu-permille: u32,
|
|
mem-used-kib: u64,
|
|
mem-total-kib: u64,
|
|
/// 0..100, or -1 when the machine has no battery.
|
|
battery-percent: s32,
|
|
charging: bool,
|
|
uptime-secs: u64,
|
|
net-rx-bytes-per-sec: u64,
|
|
net-tx-bytes-per-sec: u64,
|
|
/// 1-minute load average x 100.
|
|
load-centi: u32,
|
|
}
|
|
read: func() -> snapshot;
|
|
}
|
|
|
|
|
|
/// The window list, as shown by a task bar. `id` is an opaque host handle.
|
|
interface windows {
|
|
record window-info {
|
|
id: u32,
|
|
title: string,
|
|
/// 1 when the window has keyboard focus.
|
|
focused: u32,
|
|
/// 1 when the window is minimized (it stays listed so it can be restored).
|
|
minimized: u32,
|
|
}
|
|
list-windows: func() -> list<window-info>;
|
|
/// Focus, raise (and un-minimize) a window.
|
|
focus-window: func(id: u32);
|
|
|
|
/// Richer, id-stable view for widgets that show more than a task bar (the Pulse widget).
|
|
record window-detail {
|
|
id: u64,
|
|
title: string,
|
|
app-id: string,
|
|
focused: bool,
|
|
}
|
|
all: func() -> list<window-detail>;
|
|
/// Raise and focus a window (restoring it if minimized).
|
|
focus: func(id: u64);
|
|
|
|
}
|
|
|
|
/// App icons. The host finds the app's .desktop file (by desktop id or StartupWMClass), reads its
|
|
/// Icon= key and looks it up in the freedesktop icon themes; the widget only gets a handle to draw
|
|
/// with a `draw-op.image`, never a path or pixels.
|
|
interface icons {
|
|
/// The icon of the app whose windows carry `app-id`, or 0 when the host has none (draw your
|
|
/// own stand-in then).
|
|
app-icon: func(app-id: string) -> u32;
|
|
}
|
|
|
|
/// The window manager's layout mode (tiling / monocle / floating).
|
|
interface layout-control {
|
|
/// Display names, indexed by mode.
|
|
layout-modes: func() -> list<string>;
|
|
current-layout: func() -> u32;
|
|
set-layout: func(mode: u32);
|
|
}
|
|
|
|
/// The Interface Explorer: hover any system component to see its WIT.
|
|
interface inspector {
|
|
is-on: func() -> bool;
|
|
set-on: func(on: bool);
|
|
}
|
|
|
|
/// Hot-swap of the system's own wasm modules. A module with this capability
|
|
/// is a module manager: it decides what is loaded into the panel.
|
|
interface modules {
|
|
/// A loadable module found on the module search path.
|
|
record module-info {
|
|
/// File stem, e.g. "clock-digital".
|
|
id: string,
|
|
name: string,
|
|
path: string,
|
|
/// How many instances are loaded in the panel right now.
|
|
loaded: u32,
|
|
}
|
|
/// A module instance currently loaded in the panel, in panel order.
|
|
record instance-info {
|
|
slot: string,
|
|
module: string,
|
|
name: string,
|
|
}
|
|
available: func() -> list<module-info>;
|
|
loaded: func() -> list<instance-info>;
|
|
/// Load the module file at `path` into the panel (any number of instances).
|
|
load-module: func(path: string);
|
|
/// Unload one loaded instance, freeing its panel space.
|
|
unload-instance: func(slot: string);
|
|
/// Ask the host to show its native file chooser for a .wasm elsewhere on disk.
|
|
browse: func();
|
|
}
|
|
|
|
/// Ending the login session. A module with this capability is a logout button: the host stops the
|
|
/// compositor, and the display manager takes the screen back.
|
|
interface session {
|
|
logout: func();
|
|
}
|
|
|
|
/// The desktop wallpaper. The shell draws a fixed set of wallpapers (from draw ops, coloured by the
|
|
/// theme); a module with this capability (the settings module) lists them and picks which one is on
|
|
/// the desktop.
|
|
interface wallpaper {
|
|
/// Display names, indexed by choice.
|
|
wallpapers: func() -> list<string>;
|
|
current-wallpaper: func() -> u32;
|
|
/// Show wallpaper `index` (out-of-range indices are ignored). The choice is remembered.
|
|
set-wallpaper: func(index: u32);
|
|
}
|
|
|
|
/// Session settings: how the login session starts, what it remembers and how it looks (dark or
|
|
/// light). The shell keeps them in state.edn; a module with this capability lists them as on/off
|
|
/// switches and flips them.
|
|
interface session-settings {
|
|
/// Display names, indexed by setting.
|
|
settings: func() -> list<string>;
|
|
/// Whether setting `index` is on (false for an out-of-range index).
|
|
is-on: func(index: u32) -> bool;
|
|
/// Turn setting `index` on or off (out-of-range indices are ignored). The choice is remembered.
|
|
set-setting: func(index: u32, on: bool);
|
|
}
|
|
|
|
/// Screenshots and screen recordings, after KDE Spectacle. The compositor captures (it alone sees
|
|
/// the screen); a module with this capability offers the modes and starts them.
|
|
interface screenshot {
|
|
/// Take a screenshot: 0 rectangular region (drawn on the selection overlay), 1 full screen,
|
|
/// 2 active window, 3 window under cursor (clicked on the overlay). It is saved to
|
|
/// ~/Pictures/Screenshots and put on the clipboard. Other values are ignored.
|
|
take: func(mode: u32);
|
|
/// Record the screen to ~/Videos/Screencasts: 0 a region (picked on the overlay), 1 the full
|
|
/// screen, 2 a window (clicked on the overlay). While a recording runs this stops it instead.
|
|
start-recording: func(mode: u32);
|
|
/// Stop the recording, if one is running.
|
|
stop-recording: func();
|
|
/// Whether a recording is running.
|
|
is-recording: func() -> bool;
|
|
/// Whether recordings show the pointer, and switching that.
|
|
records-pointer: func() -> bool;
|
|
set-records-pointer: func(on: bool);
|
|
}
|
|
|
|
/// Power: when the login session turns the screen off and suspends after no input, and suspend,
|
|
/// restart or power off now (through logind). A module with this capability is the settings
|
|
/// module's Power tab. The shell keeps the timeouts in state.edn.
|
|
interface power {
|
|
/// Minutes without input before the screen turns off; 0: never.
|
|
screen-off-minutes: func() -> u32;
|
|
set-screen-off-minutes: func(minutes: u32);
|
|
/// Minutes without input before the computer suspends; 0: never.
|
|
suspend-minutes: func() -> u32;
|
|
set-suspend-minutes: func(minutes: u32);
|
|
/// Suspend, power off or restart now.
|
|
suspend: func();
|
|
power-off: func();
|
|
reboot: func();
|
|
}
|
|
|
|
/// The battery, as the battery panel module shows it. The host samples it about once a second
|
|
/// (on Linux from /sys/class/power_supply, every battery together); the module never reads it
|
|
/// itself.
|
|
interface battery {
|
|
enum charge-state {
|
|
/// No battery: a desktop on mains power.
|
|
none,
|
|
discharging,
|
|
charging,
|
|
full,
|
|
/// On mains power but not charging (a charge limit, or the battery is too warm).
|
|
not-charging,
|
|
}
|
|
record status {
|
|
/// 0..100, or -1 without a battery.
|
|
percent: s32,
|
|
state: charge-state,
|
|
/// Estimated seconds until empty while discharging, until full while charging; 0 unknown.
|
|
secs-left: u32,
|
|
}
|
|
read: func() -> status;
|
|
}
|