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

@@ -6,20 +6,23 @@
/// - Desktop: what is drawn on the desktop. Today that is the wallpaper (`wallpaper.wallpapers`,
/// the current one ticked); modules can't be placed on the desktop yet, so when they can they
/// get their own section here;
/// - Panel: the modules in the panel (click to remove), every module found on the search path
/// (click to add another instance) and "Browse..." (`modules`). The panel menu's "Modules..."
/// opens this tab;
/// - Panel: the modules in the panel in panel order (left to right), each with move-up/down and
/// remove buttons; then the modules that can be added, grouped by kind with a short description
/// and an Add button (a module already in the panel is left out unless more than one makes
/// sense, like a clock); and a "Browse for a module file..." button (`modules`). The panel
/// menu's "Modules..." opens this tab;
/// - Power: the battery (`system`, when there is one), how long without input before the screen
/// turns off and before the computer suspends (a click steps through the choices), and Suspend,
/// Restart and Power off now (`power`); Restart and Power off ask for a second click.
///
/// Clicking a row acts at once and the popup stays open. Up/Down move the highlight, Left/Right
/// (or 1-4) switch tabs, Enter or Space acts on the highlighted row, Escape or a click
/// elsewhere closes. The shell remembers settings and wallpaper in state.edn, the panel in
/// Clicking a row acts at once and the popup stays open; a row in the panel list only acts through
/// its buttons, so a stray click doesn't remove anything. Up/Down move the highlight, Left/Right
/// (or 1-4) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
/// the highlighted panel module and PageUp/PageDown move it, Escape or a click elsewhere closes. The shell remembers settings and wallpaper in state.edn, the panel in
/// panel.edn.
///| Popup geometry: the tab bar, then a column of rows, with a margin around them.
let popup_w : Int = 300
let popup_w : Int = 320
///|
let margin : Int = 6
@@ -27,7 +30,8 @@ let margin : Int = 6
///|
let tab_h : Int = 30
///| Top of the first row (below the tab bar).
///| Top of the first row (below the tab bar). Rows are `row_h` tall except on the Panel tab (see
/// `row_height`).
let rows_top : Int = 40
///|
@@ -47,10 +51,14 @@ enum Row {
Heading(String)
Setting(Int, String)
Wallpaper(Int, String)
/// A loaded panel instance: slot and name.
Loaded(String, String)
/// A module on the search path: path, name and how many instances are loaded.
Available(String, String, UInt)
/// A group of modules in the Add list ("Clocks").
Category(String)
/// A loaded panel instance: slot, name, its place in the panel and how many there are.
Loaded(String, String, Int, Int)
/// A module that can be added: path, name, description and how many instances are loaded.
Available(String, String, String, UInt)
/// Every module is in the panel already.
NothingToAdd
Browse
/// A line of text (the battery).
Info(String)
@@ -100,6 +108,45 @@ let tab : Ref[Int] = { val: 0 }
///|
let hover : Ref[Int] = { val: -1 }
///| The groups of the Add list, in order.
let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other"]
///| Which group a module (by id, its file stem) belongs to; modules we don't know go in "Other".
fn category_of(id : String) -> String {
match id {
"launcher" | "dock" | "tasks" | "layout" => "Apps and windows"
"session-settings" | "network" | "battery" | "screenshot" | "logout" => "System"
"clock-digital" | "clock-binary" | "moon-disc" => "Clocks"
_ => "Other"
}
}
///| One line on what a module does ("" for modules we don't know).
fn description_of(id : String) -> String {
match id {
"launcher" => "Search and start apps"
"dock" => "Pinned apps, one click away"
"tasks" => "Your open windows"
"layout" => "Switch tiling and floating"
"session-settings" => "This settings window"
"network" => "Wi-Fi and wired network"
"battery" => "Charge and time left"
"screenshot" => "Capture or record the screen"
"logout" => "End the session"
"clock-digital" => "The time, 12 or 24-hour"
"clock-binary" => "The time in binary"
"moon-disc" => "Tonight's moon phase"
"inspector" => "Inspect the shell's interface"
_ => ""
}
}
///| Whether more than one of a module makes sense in the panel; the others leave the Add list
/// once they are in the panel.
fn allows_many(id : String) -> Bool {
id.has_prefix("clock-")
}
///| The rows of the current tab, read live from the host (loading a module changes them).
fn rows() -> Array[Row] {
let rs : Array[Row] = []
@@ -133,13 +180,30 @@ fn rows() -> Array[Row] {
rs.push(PowerNow(1, "Power off"))
}
_ => {
rs.push(Heading("In the panel (click to remove)"))
for inst in @modules.loaded() {
rs.push(Loaded(inst.slot, inst.name))
rs.push(Heading("In the panel, left to right"))
let loaded = @modules.loaded()
for i = 0; i < loaded.length(); i = i + 1 {
rs.push(Loaded(loaded[i].slot, loaded[i].name, i, loaded.length()))
}
rs.push(Heading("Add to the panel"))
for m in @modules.available() {
rs.push(Available(m.path, m.name, m.loaded))
let avail = @modules.available()
let mut any = false
for cat in categories {
let mut first = true
for m in avail {
if category_of(m.id) != cat || (m.loaded > 0U && !allows_many(m.id)) {
continue
}
if first {
rs.push(Category(cat))
first = false
}
rs.push(Available(m.path, m.name, description_of(m.id), m.loaded))
any = true
}
}
if !any {
rs.push(NothingToAdd)
}
rs.push(Browse)
}
@@ -149,7 +213,7 @@ fn rows() -> Array[Row] {
///| Whether row `i` of `rs` can be highlighted and acted on (headings can't).
fn active(rs : Array[Row], i : Int) -> Bool {
i >= 0 && i < rs.length() && !(rs[i] is (Heading(_) | Info(_)))
i >= 0 && i < rs.length() && !(rs[i] is (Heading(_) | Info(_) | Category(_) | NothingToAdd))
}
///| First active row of `rs`, or -1.
@@ -176,25 +240,100 @@ fn tab_w() -> Int {
(popup_w - 2 * margin) / tab_names.length()
}
///| Height of a row: the Panel tab's rows vary (two-line Add rows, slim group labels); every
/// other row is `row_h`.
fn row_height(r : Row) -> Int {
match r {
Loaded(_, _, _, _) => loaded_h
Category(_) => category_h
Available(_, _, _, _) => available_h
Browse => browse_h
_ => row_h
}
}
///|
let loaded_h : Int = 30
///|
let category_h : Int = 22
///|
let available_h : Int = 42
///|
let browse_h : Int = 44
///| Top of each row, popup-local.
fn row_tops(rs : Array[Row]) -> Array[Int] {
let tops = []
let mut y = rows_top
for r in rs {
tops.push(y)
y = y + row_height(r)
}
tops
}
///| Row under a popup-local point, or -1 (headings count as none).
fn row_at(rs : Array[Row], x : Int, y : Int) -> Int {
if x < margin || x >= popup_w - margin || y < rows_top {
return -1
}
let i = (y - rows_top) / row_h
if active(rs, i) { i } else { -1 }
let tops = row_tops(rs)
for i = 0; i < rs.length(); i = i + 1 {
if y >= tops[i] && y < tops[i] + row_height(rs[i]) {
return if active(rs, i) { i } else { -1 }
}
}
-1
}
///|
fn popup_h(n : Int) -> Int {
rows_top + n * row_h + margin
fn popup_h(rs : Array[Row]) -> Int {
let mut h = rows_top + margin
for r in rs {
h = h + row_height(r)
}
h
}
///| The small buttons at the right end of a panel-list row, popup-local: move up, move down,
/// remove.
let btn_size : Int = 24
///|
fn loaded_button(k : Int, top : Int) -> @types.Rect {
// Remove sits apart from the two move buttons.
let right = popup_w - margin - 6
let x = match k {
2 => right - btn_size
1 => right - btn_size - 12 - btn_size
_ => right - btn_size - 12 - 2 * btn_size - 2
}
@ui.rect(x, top + (loaded_h - 2 - btn_size) / 2, btn_size, btn_size)
}
///| Which button of a panel-list row is under popup-local `x`/`y` (0 up, 1 down, 2 remove), or -1.
fn loaded_button_at(top : Int, x : Int, y : Int) -> Int {
for k = 0; k < 3; k = k + 1 {
let b = loaded_button(k, top)
if x >= b.x && x < b.x + @ui.rect_w(b) && y >= b.y && y < b.y + @ui.rect_h(b) {
return k
}
}
-1
}
///| The button under the pointer in the highlighted row (-1: none).
let hover_btn : Ref[Int] = { val: -1 }
///|
fn set_tab(i : Int) -> Unit {
tab.val = i
armed.val = -1
hover.val = first_active(rows())
hover_btn.val = -1
}
///|
@@ -204,8 +343,9 @@ fn close() -> Unit {
hover.val = -1
}
///| Act on row `i`: flip a setting, show a wallpaper, unload or load a module, or browse.
fn act(rs : Array[Row], i : Int) -> Unit {
///| Act on row `i`: flip a setting, show a wallpaper, load a module, or browse. A panel-list row
/// acts only through button `btn` (0 move up, 1 move down, 2 remove).
fn act(rs : Array[Row], i : Int, btn~ : Int = -1) -> Unit {
if !active(rs, i) {
return
}
@@ -232,10 +372,16 @@ fn act(rs : Array[Row], i : Int) -> Unit {
@settings.set_setting(idx, !@settings.is_on(idx))
}
Wallpaper(k, _) => @wallpaper.set_wallpaper(k.reinterpret_as_uint())
Loaded(slot, _) => @modules.unload_instance(slot)
Available(path, _, _) => @modules.load_module(path)
Loaded(slot, _, idx, n) =>
match btn {
0 => if idx > 0 { @modules.move_instance(slot, -1) }
1 => if idx < n - 1 { @modules.move_instance(slot, 1) }
2 => @modules.unload_instance(slot)
_ => ()
}
Available(path, _, _, _) => @modules.load_module(path)
Browse => @modules.browse()
Heading(_) => ()
Heading(_) | Category(_) | NothingToAdd => ()
}
}
@@ -295,7 +441,8 @@ pub fn popup() -> PopupSurface? {
let p = t.palette
let rs = rows()
let w = popup_w
let h = popup_h(rs.length())
let h = popup_h(rs)
let tops = row_tops(rs)
let r = t.radius.reinterpret_as_int()
let fs = t.font_size.reinterpret_as_int()
let ops : Array[@types.DrawOp] = [
@@ -316,24 +463,29 @@ pub fn popup() -> PopupSurface? {
ops.push(@ui.line(margin, rows_top - 3, w - margin, rows_top - 3, p.border, width=1))
let cur_wall = @wallpaper.current_wallpaper().reinterpret_as_int()
for i = 0; i < rs.length(); i = i + 1 {
let y = rows_top + i * row_h
let mid = y + (row_h - 2) / 2
let y = tops[i]
let rh = row_height(rs[i])
let mid = y + (rh - 2) / 2
let hot = i == hover.val
// Hover: a soft fill behind switches, the accent behind list rows.
let list_fg = if hot { p.accent_foreground } else { p.foreground }
match rs[i] {
Heading(_) => ()
Setting(_, _) =>
Heading(_) | Category(_) | NothingToAdd | Browse => ()
// Rows with their own buttons get the soft fill, so the buttons stand out.
Setting(_, _) | Loaded(_, _, _, _) | Available(_, _, _, _) =>
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.surface_hover, radius=r))
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.surface_hover, radius=r))
}
Info(_) => ()
_ =>
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.accent, radius=r))
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.accent, radius=r))
}
}
match rs[i] {
Heading(label) => ops.push(@ui.text(margin + 8, mid, label, fs - 3, p.foreground_muted, bold=true))
Heading(label) => ops.push(@ui.text(margin + 8, mid + 2, label, fs - 1, p.foreground, bold=true))
Category(label) => ops.push(@ui.text(margin + 10, mid, label, fs - 3, p.foreground_muted, bold=true))
NothingToAdd => ops.push(@ui.text(margin + 10, mid, "Everything is in the panel", fs - 2, p.foreground_muted))
Setting(k, name) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
// The switch: an accent track with the knob on the right when on, a muted outline when off.
@@ -357,17 +509,83 @@ pub fn popup() -> PopupSurface? {
}
ops.push(@ui.text(margin + 26, mid, name, fs - 1, list_fg, bold=k == cur_wall))
}
Loaded(_, name) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, list_fg))
ops.push(@ui.text(w - margin - 10, mid, "x", fs - 1, list_fg, align=RIGHT, bold=true))
}
Available(_, name, n) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, list_fg))
if n > 0U {
ops.push(@ui.text(w - margin - 10, mid, "x" + n.to_string(), fs - 3, list_fg, align=RIGHT))
Loaded(_, name, idx, n) => {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
for k = 0; k < 3; k = k + 1 {
let enabled = match k {
0 => idx > 0
1 => idx < n - 1
_ => true
}
let b = loaded_button(k, y)
let bx = b.x
let by = b.y
let cx = bx + btn_size / 2
let cy = by + btn_size / 2
let btn_hot = hot && hover_btn.val == k && enabled
if btn_hot {
ops.push(@ui.fill_rect(b, p.accent, radius=r))
}
let ic = if btn_hot {
p.accent_foreground
} else if !enabled {
@ui.with_alpha(p.foreground_muted, 40)
} else if hot {
p.foreground
} else {
p.foreground_muted
}
match k {
0 => {
ops.push(@ui.line(cx - 5, cy + 2, cx, cy - 3, ic, width=2))
ops.push(@ui.line(cx, cy - 3, cx + 5, cy + 2, ic, width=2))
}
1 => {
ops.push(@ui.line(cx - 5, cy - 2, cx, cy + 3, ic, width=2))
ops.push(@ui.line(cx, cy + 3, cx + 5, cy - 2, ic, width=2))
}
_ => {
ops.push(@ui.line(cx - 4, cy - 4, cx + 4, cy + 4, ic, width=2))
ops.push(@ui.line(cx - 4, cy + 4, cx + 4, cy - 4, ic, width=2))
}
}
}
}
Browse => ops.push(@ui.text(margin + 10, mid, "Browse...", fs - 1, list_fg, bold=true))
Available(_, name, desc, n) => {
if desc == "" {
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
} else {
ops.push(@ui.text(margin + 10, y + 13, name, fs - 1, p.foreground))
ops.push(@ui.text(margin + 10, y + 29, desc, fs - 3, p.foreground_muted))
}
// The Add button: outlined, filled with the accent while its row is highlighted.
let label = if n > 0U { "Add another" } else { "Add" }
let bw = @ui.text_width(label, fs - 2) + 20
let bh = 24
let bx = w - margin - 8 - bw
let by = mid - bh / 2
if hot {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.accent, radius=bh / 2))
} else {
ops.push(@ui.stroke_rect(@ui.rect(bx, by, bw, bh), p.accent, width=1, radius=bh / 2))
}
let bfg = if hot { p.accent_foreground } else { p.accent }
ops.push(@ui.text(bx + bw / 2, mid, label, fs - 2, bfg, align=CENTER, bold=true))
}
Browse => {
// A secondary button below the list: an outline, softly filled while highlighted.
ops.push(@ui.line(margin + 4, y + 2, w - margin - 4, y + 2, p.border, width=1))
let label = "Browse for a module file..."
let bw = @ui.text_width(label, fs - 2) + 28
let bh = 28
let bx = (w - bw) / 2
let by = y + 9
if hot {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.surface_hover, radius=r))
}
ops.push(@ui.stroke_rect(@ui.rect(bx, by, bw, bh), if hot { p.accent } else { p.border }, width=1, radius=r))
ops.push(@ui.text(w / 2, by + bh / 2, label, fs - 2, if hot { p.foreground } else { p.foreground_muted }, align=CENTER))
}
Info(text) => ops.push(@ui.text(margin + 10, mid, text, fs - 1, p.foreground))
Timeout(k, label) => {
let m = if k == 0 { @power.screen_off_minutes() } else { @power.suspend_minutes() }
@@ -396,9 +614,16 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
true
}
(POPUP, PointerMove(p)) => {
let i = row_at(rows(), p.x, p.y)
if i != hover.val && i >= 0 {
let rs = rows()
let i = row_at(rs, p.x, p.y)
let b = if i >= 0 && rs[i] is Loaded(_, _, _, _) {
loaded_button_at(row_tops(rs)[i], p.x, p.y)
} else {
-1
}
if i >= 0 && (i != hover.val || b != hover_btn.val) {
hover.val = i
hover_btn.val = b
true
} else {
false
@@ -415,10 +640,26 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
let rs = rows()
let i = row_at(rs, p.x, p.y)
if i >= 0 {
act(rs, i)
let btn = if rs[i] is Loaded(_, _, _, _) {
loaded_button_at(row_tops(rs)[i], p.x, p.y)
} else {
-1
}
act(rs, i, btn~)
// A module list changes length: keep the highlight on a real row.
let after = rows()
hover.val = if active(after, i) { i } else { first_active(after) }
// A moved module: keep the highlight on it, under the pointer's button.
match rs[i] {
Loaded(_, _, idx, n) =>
if btn == 0 && idx > 0 {
hover.val = i - 1
} else if btn == 1 && idx < n - 1 {
hover.val = i + 1
}
_ => ()
}
hover_btn.val = -1
}
true
}
@@ -443,6 +684,25 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
hover.val = first_active(after)
}
true
} else if k == "Backspace" || k == "Delete" || k == "PageUp" || k == "PageDown" {
let rs = rows()
match (if active(rs, hover.val) { Some(rs[hover.val]) } else { None }) {
Some(Loaded(_, _, idx, n)) => {
let btn = if k == "PageUp" { 0 } else if k == "PageDown" { 1 } else { 2 }
act(rs, hover.val, btn~)
if btn == 0 && idx > 0 {
hover.val = hover.val - 1
} else if btn == 1 && idx < n - 1 {
hover.val = hover.val + 1
}
let after = rows()
if !active(after, hover.val) {
hover.val = first_active(after)
}
true
}
_ => false
}
} else if k == "ArrowDown" || k == "Down" {
move_hover(1)
true