Settings > Panel: a cleaner module selector with reordering
CI / test (push) Failing after 17s

The Panel tab was one flat list: every panel module with an "x" that removed
it on any click, then every module on disk again with cryptic "x1" counts and
a Browse row that looked selected.

- "In the panel, left to right": the modules in panel order, each with
  move up / move down / remove buttons. Clicking the row itself does nothing,
  so a stray click no longer removes a module. Backspace/Delete removes the
  highlighted one, PageUp/PageDown move it.
- "Add to the panel": grouped (Apps and windows, System, Clocks, Other),
  each with a one-line description and an Add button. A module already in the
  panel is left out, except clocks, which offer "Add another". With nothing
  left: "Everything is in the panel".
- "Browse for a module file..." is a secondary outlined button.
- Section headings are larger and full contrast; the popup is 320 wide and
  now fits a 720-high screen with the default panel.

Reordering goes through a new modules.move-instance(slot, delta) capability
call, plumbed through both hosts: wasmer stub request 17, host-wasm, the
plasmoids host WIT (move-instance(instance-move)) and wasmhost. The shell's
move_slot clamps to the ends and saves panel.edn, so the saved format is
unchanged. DesktopShell::slot_popup_texts lets tests find popup rows by text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhRDWZf5WcmrNwnFe3
This commit is contained in:
Claude committed 2026-11-25 20:35:54 +00:00
1 parent c1936299cb
commit 8ecdef17d4
16 files changed
+514 -98

No files matched your search

+41 -20
View File
@@ -596,34 +596,55 @@ test "the wasm picker opens the settings module's Panel tab, which loads and unl
ignore(comp.compose_frame())
let pr = comp.shell.slot_popup_rect(mgr)
assert_true(pr.w > 0) // the picker opened the popup
// Rows below the tab bar (40): heading, one per loaded module, heading, one per available
// module, browse; 28 each.
let loaded = comp.shell.slots().length()
assert_true(pr.h >= 40 + (loaded + 3) * 28)
let avail_y = fn(pr : @scene.Rect, k : Int) { pr.y + 40 + (loaded + 2 + k) * 28 + 13 }
let mut k_bin = -1
for k = 0; k < comp.shell.catalog.length(); k = k + 1 {
if comp.shell.catalog[k].id == "clock-binary" {
k_bin = k
// Find rows by their text: the y of the first (or last) line reading `label`.
let row_y = fn(label : String, last : Bool) -> Int {
let mut y = -1
for t in comp.shell.slot_popup_texts(mgr) {
if t.0 == label && (last || y < 0) {
y = t.2
}
}
y
}
assert_true(k_bin >= 0)
let texts = comp.shell.slot_popup_texts(mgr).map(t => t.0)
assert_true(texts.contains("In the panel, left to right"))
assert_true(texts.contains("Add to the panel"))
assert_true(texts.contains("Browse for a module file..."))
// The Add list leaves out what is already in the panel (but a clock can be added twice) and
// has no cryptic instance counts.
assert_eq(texts.filter(t => t == "Task Manager").length(), 1)
assert_false(texts.contains("x1"))
assert_true(texts.contains("Pinned apps, one click away")) // the Dock's description
let loaded = comp.shell.slots().length()
assert_eq(comp.shell.slot_of("clock-binary"), "")
click_at(comp, pr.x + 40, avail_y(pr, k_bin), 20U) // select it: it is loaded into the panel
let by = row_y("Binary Clock", false)
assert_true(by > 0)
click_at(comp, pr.x + 40, pr.y + by, 20U) // its Add row: it is loaded into the panel
assert_true(comp.shell.slot_of("clock-binary") != "")
assert_eq(comp.shell.slots().length(), loaded + 1)
// The popup stays open (it grew a row); click the loaded module's row to unload it again.
ignore(comp.compose_frame())
// A clock can go in twice, so it stays in the Add list, offered as another one.
assert_true(comp.shell.slot_popup_texts(mgr).map(t => t.0).contains("Add another"))
let pr2 = comp.shell.slot_popup_rect(mgr)
assert_true(pr2.w > 0)
assert_true(pr2.w > 0) // the popup stays open
let bin = comp.shell.slot_of("clock-binary")
let ly = row_y("Binary Clock", false) // now the panel list's row comes first
// Clicking the row itself does nothing: only its buttons act.
click_at(comp, pr2.x + 40, pr2.y + ly, 30U)
assert_eq(comp.shell.slot_of("clock-binary"), bin)
// It was added at the end; move it up one place with the up button.
let slots = comp.shell.slots()
let mut idx = -1
for i = 0; i < slots.length(); i = i + 1 {
if slots[i] == comp.shell.slot_of("clock-binary") {
idx = i
}
}
click_at(comp, pr2.x + 40, pr2.y + 40 + (1 + idx) * 28 + 13, 30U)
assert_eq(slots[slots.length() - 1], bin)
click_at(comp, pr2.x + pr2.w - 86, pr2.y + ly, 40U)
let moved = comp.shell.slots()
assert_eq(moved[moved.length() - 2], bin)
assert_eq(moved.length(), slots.length())
// Then remove it with its x button (its row moved up one place).
ignore(comp.compose_frame())
let pr3 = comp.shell.slot_popup_rect(mgr)
let ly3 = row_y("Binary Clock", false)
assert_true(ly3 < ly)
click_at(comp, pr3.x + pr3.w - 24, pr3.y + ly3, 50U)
assert_eq(comp.shell.slot_of("clock-binary"), "")
assert_eq(comp.shell.slots().length(), loaded)
// The settings module is just another module: it can be removed too, and the picker brings it
+46
View File
@@ -359,6 +359,34 @@ pub fn DesktopShell::unload_slot(self : DesktopShell, slot : String) -> Bool {
}
}
///| Move the module in `slot` `delta` places along the panel (clamped to either end) and save
/// the new order. False when there is no such slot or it is already at that end.
pub fn DesktopShell::move_slot(self : DesktopShell, slot : String, delta : Int) -> Bool {
let mut idx = -1
for i = 0; i < self.widgets.length(); i = i + 1 {
if self.widgets[i].slot == slot {
idx = i
}
}
if idx < 0 {
return false
}
let mut to = idx + delta
if to < 0 {
to = 0
}
if to > self.widgets.length() - 1 {
to = self.widgets.length() - 1
}
if to == idx {
return false
}
let w = self.widgets.remove(idx)
self.widgets.insert(to, w)
self.save_panel_config()
true
}
///| Replace the module in `slot` with the module file at `path`, keeping its place in the panel.
pub fn DesktopShell::replace_slot(self : DesktopShell, slot : String, path : String) -> Bool {
let mut idx = -1
@@ -438,6 +466,23 @@ pub fn DesktopShell::slot_popup_rect(self : DesktopShell, slot : String) -> @sce
}
}
///| The text drawn in `slot`'s open popup, with each line's popup-local origin, in drawing
/// order (empty when the popup is closed). Lets tests find a row without knowing the layout.
pub fn DesktopShell::slot_popup_texts(self : DesktopShell, slot : String) -> Array[(String, Int, Int)] {
let out = []
match self.widget_by_slot(slot) {
Some(w) =>
for op in w.popup_ops {
match op {
Text(t) => out.push((t.text, t.origin.x, t.origin.y))
_ => ()
}
}
None => ()
}
out
}
///| Publish what modules can read through their capabilities (apps, windows, layout, loaded modules).
fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
if self.apps_dirty {
@@ -624,6 +669,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
}
}
Some(UnloadInstance(slot)) => ignore(self.unload_slot(slot))
Some(MoveInstance(slot, delta)) => ignore(self.move_slot(slot, delta))
Some(Browse) =>
if self.picker is None {
self.picker = @wasm.Picker::start()
+3
View File
@@ -342,6 +342,8 @@ pub(all) enum HostRequest {
SetInspector(Bool)
LoadModule(String)
UnloadInstance(String)
/// Move a panel instance `delta` places (negative: towards the start of the panel).
MoveInstance(String, Int)
Browse
Logout
SetWallpaper(Int)
@@ -369,6 +371,7 @@ pub fn next_request() -> HostRequest? {
Some(SetInspector(on)) => Some(SetInspector(on))
Some(LoadModule(p)) => Some(LoadModule(p))
Some(UnloadInstance(s)) => Some(UnloadInstance(s))
Some(MoveInstance(m)) => Some(MoveInstance(m.slot, m.delta))
Some(Browse) => Some(Browse)
Some(Logout) => Some(Logout)
Some(SetWallpaper(i)) => Some(SetWallpaper(i))
+6
View File
@@ -764,6 +764,8 @@ pub(all) enum HostRequest {
SetInspector(Bool)
LoadModule(String)
UnloadInstance(String)
/// Move a panel instance `delta` places (negative: towards the start of the panel).
MoveInstance(String, Int)
Browse
Logout
SetWallpaper(Int)
@@ -797,6 +799,10 @@ pub fn next_request() -> HostRequest? {
4 => Some(SetInspector(c_host_req_int() != 0))
5 => Some(LoadModule(req_str()))
6 => Some(UnloadInstance(req_str()))
17 => {
let delta = c_host_req_int()
Some(MoveInstance(req_str(), delta))
}
7 => Some(Browse)
8 => Some(Logout)
9 => Some(SetWallpaper(c_host_req_int()))
+4 -1
View File
@@ -51,7 +51,7 @@ static Inst insts[MAX_INST];
/* Host imports a module can call. */
enum {
K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT,
K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_BROWSE,
K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_MOVE, K_MOD_BROWSE,
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
K_SESSION_SETTINGS, K_SESSION_IS_ON, K_SESSION_SET,
K_APP_ICON,
@@ -423,6 +423,8 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_MOD_BROWSE: push_req(7, 0, NULL); break;
case K_MOD_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; }
case K_MOD_UNLOAD: { char *s = guest_str(in, a0, a1); push_req(6, 0, s); free(s); break; }
/* move-instance(slot, delta): request 17, delta in n. */
case K_MOD_MOVE: { char *s = guest_str(in, a0, a1); push_req(17, a2, s); free(s); break; }
case K_LAUNCH: {
/* launch(id) -> result<_, string>; (ptr, len, retptr). Known catalog ids succeed; the shell spawns after the call. */
char *id = guest_str(in, a0, a1);
@@ -603,6 +605,7 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "modules") && !strcmp(fn, "loaded")) return K_MOD_LOADED;
if (!strcmp(iface, "modules") && !strcmp(fn, "load-module")) return K_MOD_LOAD;
if (!strcmp(iface, "modules") && !strcmp(fn, "unload-instance")) return K_MOD_UNLOAD;
if (!strcmp(iface, "modules") && !strcmp(fn, "move-instance")) return K_MOD_MOVE;
if (!strcmp(iface, "modules") && !strcmp(fn, "browse")) return K_MOD_BROWSE;
return K_OTHER;
}
+44 -16
View File
@@ -244,21 +244,29 @@ test "launcher module reads the host catalog, filters on typed keys and launches
}
///|
test "the settings module's Panel tab lists host modules and asks to load, unload and browse" {
test "the settings module's Panel tab lists host modules and asks to load, move, unload and browse" {
let p = load_module("session-settings")
assert_true(p.imports().contains("modules"))
let av = Table::new()
av.str("moon-disc")
av.str("Moon Phase (disc)")
av.str("/m/moon-disc.wasm")
av.int(0)
av.end_row()
for m in [
("moon-disc", "Moon Phase (disc)", "/m/moon-disc.wasm", 0),
("tasks", "Task Manager", "/m/tasks.wasm", 1),
("clock-digital", "Digital Clock", "/m/clock-digital.wasm", 1),
] {
av.str(m.0)
av.str(m.1)
av.str(m.2)
av.int(m.3)
av.end_row()
}
publish(Modules, av)
let li = Table::new()
li.str("w1")
li.str("clock-digital")
li.str("Digital Clock")
li.end_row()
for i in [("w1", "clock-digital", "Digital Clock"), ("w2", "tasks", "Task Manager")] {
li.str(i.0)
li.str(i.1)
li.str(i.2)
li.end_row()
}
publish(Instances, li)
assert_true(p.on_event(false, PointerDown(1, 1)))
assert_true(p.on_event(true, KeyDown("3"))) // the Panel tab
@@ -266,15 +274,35 @@ test "the settings module's Panel tab lists host modules and asks to load, unloa
None => fail("popup should be open")
Some(ps) => {
let ts = texts_of(ps.ops)
assert_true(ts.contains("Digital Clock"))
assert_true(ts.contains("Moon Phase (disc)"))
assert_true(ts.contains("Clocks"))
// The task manager is in the panel and one is enough: it is not offered again. A clock
// can go in twice, so it is.
assert_eq(ts.filter(t => t == "Task Manager").length(), 1)
assert_eq(ts.filter(t => t == "Digital Clock").length(), 2)
assert_true(ts.contains("Add another"))
assert_false(ts.contains("x1"))
}
}
// Below the tab bar (40), rows of 28: heading, loaded, heading, available, browse.
ignore(p.on_event(true, PointerDown(20, 40 + 28 + 3)))
ignore(p.on_event(true, PointerDown(20, 40 + 3 * 28 + 3)))
ignore(p.on_event(true, PointerDown(20, 40 + 4 * 28 + 3)))
assert_eq(drain(), [UnloadInstance("w1"), LoadModule("/m/moon-disc.wasm"), Browse])
// Below the tab bar (40): heading (28), the two panel rows (30 each, buttons up at x 222-246,
// down 248-272, remove 284-308), heading (28), "Clocks" (22), two Add rows (42 each), Browse.
ignore(p.on_event(true, PointerDown(20, 82))) // w1's row itself: nothing
ignore(p.on_event(true, PointerDown(234, 82))) // w1 is first: up does nothing
ignore(p.on_event(true, PointerDown(260, 82))) // down
ignore(p.on_event(true, PointerDown(296, 112))) // w2's remove
ignore(p.on_event(true, PointerDown(20, 190))) // add the moon
ignore(p.on_event(true, PointerDown(160, 285))) // browse
assert_eq(drain(), [
MoveInstance("w1", 1),
UnloadInstance("w2"),
LoadModule("/m/moon-disc.wasm"),
Browse,
])
// Keys: Backspace removes the highlighted panel module, PageUp moves it.
ignore(p.on_event(true, PointerMove(20, 112)))
assert_true(p.on_event(true, KeyDown("PageUp")))
assert_true(p.on_event(true, KeyDown("Backspace")))
assert_eq(drain(), [MoveInstance("w2", -1), UnloadInstance("w1")])
p.unload()
}