Module settings in each module's right-click menu, and System settings
CI / test (push) Failing after 15s

- New optional WIT export `chandra:desktop/module-config` (wit/plasmoid.wit): config-items (key,
  label, choices, current value; no choices = an on/off switch) and set-config. Hosts look it up
  by name, so modules without it (or prebuilt ones like Pulse) load as before.
- Right-click a panel module: "Module settings..." (or a greyed "No module settings"), then
  "System settings..." (the settings module, Session tab), then Replace with... and Remove widget.
  The "Modules..." row is gone; right-clicking empty panel space offers "System settings..." on the
  Panel tab instead. Module settings open in the same menu: on/off rows with a check box, choices
  under a heading with the current one ticked; clicking applies at once and the menu stays open.
- Choices are saved per module id in state.edn as :module-config {"clock-digital" {"format"
  "12-hour"}} (module_config.mbt; not an owned key, so save_state keeps it) and handed back through
  set-config whenever the module is loaded. Other instances of the module follow a change.
- Both hosts: wasmer stub (optional exports 8-10, canonical-ABI decoding in wasm_native.mbt) and
  host-wasm (chandra:host/plasmoids config-items/set-config, bound with a separate `configurable`
  world so the export stays optional).
- Adopted by the digital clock (Time format 24-hour/12-hour, Show date) and the binary clock (Show
  seconds); clock-widget now exports module-config.
- Tests: native menu end-to-end (open, pick 12-hour, heading inert, reload keeps it), state.edn
  round trip, EDN unit test, wasmer and host-wasm module-config tests, lib/clock settings test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjuApkJR4sVRYDpDLy
This commit is contained in:
Claude committed 2026-11-25 18:58:43 +00:00
1 parent a7909014b8
commit 4fc4a963b4
37 files changed
+1285 -128

No files matched your search

+105 -27
View File
@@ -143,6 +143,15 @@ let ex_post_popup : Int = 6
///|
let ex_realloc : Int = 7
///| The optional `module-config` exports (absent in most modules: calls then return -1).
let ex_cfg_items : Int = 8
///|
let ex_post_cfg_items : Int = 9
///|
let ex_set_cfg : Int = 10
///| The 64-byte `theme.tokens` record (name left empty) the guest reads through get-tokens.
pub fn pack_tokens(t : @theme.Tokens) -> Bytes {
let b = FixedArray::make(64, b'\x00')
@@ -513,37 +522,106 @@ pub fn Plasmoid::on_event(self : Plasmoid, popup : Bool, ev : PlasmoidEvent) ->
PointerUp(x, y) => c_wasm_call(self.handle, ex_onevent, target, 2, x, y)
PointerLeave => c_wasm_call(self.handle, ex_onevent, target, 3, 0, 0)
FocusLost => c_wasm_call(self.handle, ex_onevent, target, 4, 0, 0)
KeyDown(k) => {
// The guest owns a UTF-16 copy of the key name.
let b : Array[Byte] = []
let mut units = 0
for ch in k {
let c = ch.to_int()
if c >= 0x10000 {
let v = c - 0x10000
let hi = 0xD800 + (v >> 10)
let lo = 0xDC00 + (v & 0x3FF)
b.push((hi & 0xFF).to_byte())
b.push((hi >> 8).to_byte())
b.push((lo & 0xFF).to_byte())
b.push((lo >> 8).to_byte())
units = units + 2
} else {
b.push((c & 0xFF).to_byte())
b.push((c >> 8).to_byte())
units = units + 1
}
KeyDown(k) =>
match self.guest_str(k) {
None => -1
Some((ptr, units)) => c_wasm_call(self.handle, ex_onevent, target, 5, ptr, units)
}
let ptr = c_wasm_call(self.handle, ex_realloc, 0, 0, 2, if units * 2 < 4 { 4 } else { units * 2 })
if ptr < 0 {
-1
} else {
ignore(c_wasm_write(self.handle, ptr, Bytes::from_array(b), b.length()))
c_wasm_call(self.handle, ex_onevent, target, 5, ptr, units)
}
r == 1
}
///| Copy `s` into guest memory as UTF-16 (the guest owns the copy): (pointer, code units).
fn Plasmoid::guest_str(self : Plasmoid, s : String) -> (Int, Int)? {
let b : Array[Byte] = []
let mut units = 0
for ch in s {
let c = ch.to_int()
if c >= 0x10000 {
let v = c - 0x10000
let hi = 0xD800 + (v >> 10)
let lo = 0xDC00 + (v & 0x3FF)
b.push((hi & 0xFF).to_byte())
b.push((hi >> 8).to_byte())
b.push((lo & 0xFF).to_byte())
b.push((lo >> 8).to_byte())
units = units + 2
} else {
b.push((c & 0xFF).to_byte())
b.push((c >> 8).to_byte())
units = units + 1
}
}
let ptr = c_wasm_call(self.handle, ex_realloc, 0, 0, 2, if units * 2 < 4 { 4 } else { units * 2 })
if ptr <= 0 {
return None
}
if units > 0 {
ignore(c_wasm_write(self.handle, ptr, Bytes::from_array(b), b.length()))
}
Some((ptr, units))
}
///| One of a module's own settings (the WIT `module-config.config-item`): `choices` empty means
/// an on/off switch whose value is "on" or "off".
pub(all) struct ConfigItem {
key : String
label : String
choices : Array[String]
value : String
} derive(Eq, Debug)
///| The module's settings for its right-click menu; empty when it doesn't export `module-config`.
pub fn Plasmoid::config_items(self : Plasmoid) -> Array[ConfigItem] {
let out : Array[ConfigItem] = []
let ra = c_wasm_call(self.handle, ex_cfg_items, 0, 0, 0, 0)
if ra <= 0 {
return out
}
match self.mem(ra, 8) {
None => ()
Some(hdr) => {
let base = rd32(hdr, 0)
let n = rd32(hdr, 4)
if n > 0 && n <= 64 {
match self.mem(base, n * 32) {
None => ()
Some(b) =>
for i = 0; i < n; i = i + 1 {
let o = i * 32
let choices : Array[String] = []
let cn = rd32(b, o + 20)
if cn > 0 && cn <= 64 {
match self.mem(rd32(b, o + 16), cn * 8) {
None => ()
Some(cb) =>
for k = 0; k < cn; k = k + 1 {
choices.push(self.str(rd32(cb, k * 8), rd32(cb, k * 8 + 4)))
}
}
}
out.push({
key: self.str(rd32(b, o), rd32(b, o + 4)),
label: self.str(rd32(b, o + 8), rd32(b, o + 12)),
choices,
value: self.str(rd32(b, o + 24), rd32(b, o + 28)),
})
}
}
}
}
}
r == 1
ignore(c_wasm_call(self.handle, ex_post_cfg_items, ra, 0, 0, 0))
out
}
///| Set one of the module's settings. True when the widget asks for a redraw; false when it has no
/// `module-config` export, ignored the value, or trapped.
pub fn Plasmoid::set_config(self : Plasmoid, key : String, value : String) -> Bool {
match (self.guest_str(key), self.guest_str(value)) {
(Some((kp, kn)), Some((vp, vn))) => c_wasm_call(self.handle, ex_set_cfg, kp, kn, vp, vn) == 1
_ => false
}
}
///| Host interfaces (capabilities) the module's binary imports, e.g. ["theme", "clock"].