Settings module: Session, Desktop and Panel tabs; the module manager moves in
CI / test (push) Failing after 15s
CI / test (push) Failing after 15s
- The settings popup gets a tab bar, split by where things live: Session (the switches), Desktop
(what is drawn on the desktop: the wallpaper list under a "Wallpaper" heading) and Panel (what
the module manager showed: modules in the panel to remove, modules to add, Browse...).
Left/Right or 1/2/3 switch tabs; it reopens on the tab it was left on. Modules can't be placed
on the desktop yet (every wasm module lives in the panel; the desktop card is built in), so
the Desktop tab has no module section until they can.
- The standalone module-manager module and its world are removed; the settings module imports
`modules`. Saved panels listing "module-manager" get the settings module in its place.
- DesktopShell::open_settings(SettingsTab) opens the settings module on a tab (loading it into the
panel if needed), for the panel menu and "System settings" entries; the wasm picker
("Modules..." in the panel menu) is open_settings(Panel).
- Tests: the native picker test drives the Panel tab, the wallpaper and switch tests go through
the tabs, an open_settings test; the wasm and host-wasm module tests use the settings module.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
20 files changed
+316
-917
No files matched your search
@@ -3,6 +3,7 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/session-settings" @settings,
|
||||
"chandra/desktop/interface/chandra/desktop/wallpaper" @wallpaper,
|
||||
"chandra/desktop/interface/chandra/desktop/modules" @modules,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,84 +1,144 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the settings module. The panel button opens a
|
||||
/// popup with two sections: the session settings the shell offers (`session-settings.settings`:
|
||||
/// reopen windows at login, remember window positions, dark mode), each with an on/off switch, and
|
||||
/// the wallpapers the shell can draw (`wallpaper.wallpapers`), the current one ticked. Clicking a
|
||||
/// row flips the switch or shows that wallpaper at once, and the list stays open to compare; Up and
|
||||
/// Down move the highlight, Enter or Space acts on it, Escape or a click elsewhere closes. The shell
|
||||
/// remembers every choice in state.edn.
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the settings module: the panel's "Settings"
|
||||
/// button. Its popup has three tabs, split by where things live:
|
||||
///
|
||||
/// - Session: the session settings the shell offers (`session-settings.settings`: reopen windows
|
||||
/// at login, remember window positions, dark mode), each with an on/off switch;
|
||||
/// - 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.
|
||||
///
|
||||
/// Clicking a row acts at once and the popup stays open. Up/Down move the highlight, Left/Right
|
||||
/// (or 1, 2, 3) 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
|
||||
/// panel.edn.
|
||||
|
||||
///| Popup geometry: a column of rows with a margin around them.
|
||||
let popup_w : Int = 290
|
||||
|
||||
///|
|
||||
let row_h : Int = 30
|
||||
///| Popup geometry: the tab bar, then a column of rows, with a margin around them.
|
||||
let popup_w : Int = 300
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///|
|
||||
let tab_h : Int = 30
|
||||
|
||||
///| Top of the first row (below the tab bar).
|
||||
let rows_top : Int = 40
|
||||
|
||||
///|
|
||||
let row_h : Int = 28
|
||||
|
||||
///| The switch at the right end of a setting row.
|
||||
let switch_w : Int = 34
|
||||
|
||||
///|
|
||||
let switch_h : Int = 18
|
||||
|
||||
///| A popup row: a session setting, the "Wallpaper" heading, or a wallpaper.
|
||||
///|
|
||||
let tab_names : Array[String] = ["Session", "Desktop", "Panel"]
|
||||
|
||||
///| A popup row.
|
||||
enum Row {
|
||||
Setting(Int)
|
||||
Heading(String)
|
||||
Wallpaper(Int)
|
||||
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)
|
||||
Browse
|
||||
}
|
||||
|
||||
///| Whether the popup is open, and which row is highlighted (-1: none).
|
||||
///| Whether the popup is open, its tab, and which row is highlighted (-1: none).
|
||||
let open_ : Ref[Bool] = { val: false }
|
||||
|
||||
///|
|
||||
let tab : Ref[Int] = { val: 0 }
|
||||
|
||||
///|
|
||||
let hover : Ref[Int] = { val: -1 }
|
||||
|
||||
///| The names and rows, read when the popup opens (they are fixed while it is open).
|
||||
let settings : Ref[Array[String]] = { val: [] }
|
||||
|
||||
///|
|
||||
let wallpapers : Ref[Array[String]] = { val: [] }
|
||||
|
||||
///|
|
||||
let rows : Ref[Array[Row]] = { val: [] }
|
||||
|
||||
///|
|
||||
fn popup_h() -> Int {
|
||||
margin * 2 + rows.val.length() * row_h
|
||||
///| The rows of the current tab, read live from the host (loading a module changes them).
|
||||
fn rows() -> Array[Row] {
|
||||
let rs : Array[Row] = []
|
||||
match tab.val {
|
||||
0 => {
|
||||
let names = @settings.settings()
|
||||
for i = 0; i < names.length(); i = i + 1 {
|
||||
rs.push(Setting(i, names[i]))
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
rs.push(Heading("Wallpaper"))
|
||||
let names = @wallpaper.wallpapers()
|
||||
for i = 0; i < names.length(); i = i + 1 {
|
||||
rs.push(Wallpaper(i, names[i]))
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
rs.push(Heading("In the panel (click to remove)"))
|
||||
for inst in @modules.loaded() {
|
||||
rs.push(Loaded(inst.slot, inst.name))
|
||||
}
|
||||
rs.push(Heading("Add to the panel"))
|
||||
for m in @modules.available() {
|
||||
rs.push(Available(m.path, m.name, m.loaded))
|
||||
}
|
||||
rs.push(Browse)
|
||||
}
|
||||
}
|
||||
rs
|
||||
}
|
||||
|
||||
///| Whether row `i` can be highlighted and acted on (headings can't).
|
||||
fn active(i : Int) -> Bool {
|
||||
i >= 0 && i < rows.val.length() && !(rows.val[i] is Heading(_))
|
||||
///| 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(_))
|
||||
}
|
||||
|
||||
///| First active row of `rs`, or -1.
|
||||
fn first_active(rs : Array[Row]) -> Int {
|
||||
for i = 0; i < rs.length(); i = i + 1 {
|
||||
if active(rs, i) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
///| Tab under a popup-local point, or -1.
|
||||
fn tab_at(x : Int, y : Int) -> Int {
|
||||
if y < margin || y >= margin + tab_h || x < margin || x >= popup_w - margin {
|
||||
return -1
|
||||
}
|
||||
let i = (x - margin) / tab_w()
|
||||
if i < tab_names.length() { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn tab_w() -> Int {
|
||||
(popup_w - 2 * margin) / tab_names.length()
|
||||
}
|
||||
|
||||
///| Row under a popup-local point, or -1 (headings count as none).
|
||||
fn row_at(x : Int, y : Int) -> Int {
|
||||
if x < margin || x >= popup_w - margin || y < margin {
|
||||
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 - margin) / row_h
|
||||
if active(i) { i } else { -1 }
|
||||
let i = (y - rows_top) / row_h
|
||||
if active(rs, i) { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn open() -> Unit {
|
||||
settings.val = @settings.settings()
|
||||
wallpapers.val = @wallpaper.wallpapers()
|
||||
let rs : Array[Row] = []
|
||||
for i = 0; i < settings.val.length(); i = i + 1 {
|
||||
rs.push(Setting(i))
|
||||
}
|
||||
if wallpapers.val.length() > 0 {
|
||||
rs.push(Heading("Wallpaper"))
|
||||
for i = 0; i < wallpapers.val.length(); i = i + 1 {
|
||||
rs.push(Wallpaper(i))
|
||||
}
|
||||
}
|
||||
rows.val = rs
|
||||
open_.val = true
|
||||
hover.val = if active(0) { 0 } else { -1 }
|
||||
fn popup_h(n : Int) -> Int {
|
||||
rows_top + n * row_h + margin
|
||||
}
|
||||
|
||||
///|
|
||||
fn set_tab(i : Int) -> Unit {
|
||||
tab.val = i
|
||||
hover.val = first_active(rows())
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -87,26 +147,30 @@ fn close() -> Unit {
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///| Act on row `i`: flip its setting or show its wallpaper (ignored for headings or none).
|
||||
fn act(i : Int) -> Unit {
|
||||
if !active(i) {
|
||||
///| 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 {
|
||||
if !active(rs, i) {
|
||||
return
|
||||
}
|
||||
match rows.val[i] {
|
||||
Setting(k) => {
|
||||
match rs[i] {
|
||||
Setting(k, _) => {
|
||||
let idx = k.reinterpret_as_uint()
|
||||
@settings.set_setting(idx, !@settings.is_on(idx))
|
||||
}
|
||||
Wallpaper(k) => @wallpaper.set_wallpaper(k.reinterpret_as_uint())
|
||||
Wallpaper(k, _) => @wallpaper.set_wallpaper(k.reinterpret_as_uint())
|
||||
Loaded(slot, _) => @modules.unload_instance(slot)
|
||||
Available(path, _, _) => @modules.load_module(path)
|
||||
Browse => @modules.browse()
|
||||
Heading(_) => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Move the highlight by `step` rows, skipping headings; stays put at either end.
|
||||
fn move_hover(step : Int) -> Unit {
|
||||
let rs = rows()
|
||||
let mut i = hover.val + step
|
||||
while i >= 0 && i < rows.val.length() {
|
||||
if active(i) {
|
||||
while i >= 0 && i < rs.length() {
|
||||
if active(rs, i) {
|
||||
hover.val = i
|
||||
return
|
||||
}
|
||||
@@ -154,54 +218,82 @@ pub fn popup() -> PopupSurface? {
|
||||
return None
|
||||
}
|
||||
let t = @theme.get_tokens()
|
||||
let p = t.palette
|
||||
let rs = rows()
|
||||
let w = popup_w
|
||||
let h = popup_h()
|
||||
let h = popup_h(rs.length())
|
||||
let r = t.radius.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let cur = @wallpaper.current_wallpaper().reinterpret_as_int()
|
||||
let ops : Array[@types.DrawOp] = [
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r),
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, width=1, radius=r),
|
||||
]
|
||||
for i = 0; i < rows.val.length(); i = i + 1 {
|
||||
let y = margin + i * row_h
|
||||
// Tab bar: the current tab filled with the accent.
|
||||
let tw = tab_w()
|
||||
for i = 0; i < tab_names.length(); i = i + 1 {
|
||||
let x = margin + i * tw
|
||||
let cur = i == tab.val
|
||||
if cur {
|
||||
ops.push(@ui.fill_rect(@ui.rect(x + 1, margin, tw - 2, tab_h - 2), p.accent, radius=r))
|
||||
}
|
||||
let fg = if cur { p.accent_foreground } else { p.foreground_muted }
|
||||
ops.push(@ui.text(x + tw / 2, margin + (tab_h - 2) / 2, tab_names[i], fs - 2, fg, align=CENTER, bold=cur))
|
||||
}
|
||||
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 hot = i == hover.val
|
||||
match rows.val[i] {
|
||||
Heading(label) => {
|
||||
ops.push(@ui.line(margin + 4, y + 2, w - margin - 4, y + 2, t.palette.border, width=1))
|
||||
ops.push(@ui.text(margin + 10, mid + 2, label, fs - 3, t.palette.foreground_muted, bold=true))
|
||||
}
|
||||
Setting(k) => {
|
||||
// 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(_, _) =>
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.surface_hover, radius=r))
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.surface_hover, radius=r))
|
||||
}
|
||||
ops.push(@ui.text(margin + 10, mid, settings.val[k], fs - 1, t.palette.foreground))
|
||||
_ =>
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 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))
|
||||
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.
|
||||
let on = @settings.is_on(k.reinterpret_as_uint())
|
||||
let sx = w - margin - 10 - switch_w
|
||||
let sy = mid - switch_h / 2
|
||||
let knob = switch_h / 2 - 3
|
||||
if on {
|
||||
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.accent, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, t.palette.accent_foreground))
|
||||
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), p.accent, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, p.accent_foreground))
|
||||
} else {
|
||||
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.foreground_muted, width=1, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, t.palette.foreground_muted))
|
||||
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), p.foreground_muted, width=1, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, p.foreground_muted))
|
||||
}
|
||||
}
|
||||
Wallpaper(k) => {
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.accent, radius=r))
|
||||
}
|
||||
let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
if k == cur {
|
||||
Wallpaper(k, name) => {
|
||||
if k == cur_wall {
|
||||
// A tick: two strokes.
|
||||
ops.push(@ui.line(margin + 8, mid, margin + 11, mid + 4, fg, width=2))
|
||||
ops.push(@ui.line(margin + 11, mid + 4, margin + 18, mid - 4, fg, width=2))
|
||||
ops.push(@ui.line(margin + 8, mid, margin + 11, mid + 4, list_fg, width=2))
|
||||
ops.push(@ui.line(margin + 11, mid + 4, margin + 18, mid - 4, list_fg, width=2))
|
||||
}
|
||||
ops.push(@ui.text(margin + 26, mid, wallpapers.val[k], fs - 1, fg, bold=k == cur))
|
||||
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))
|
||||
}
|
||||
}
|
||||
Browse => ops.push(@ui.text(margin + 10, mid, "Browse...", fs - 1, list_fg, bold=true))
|
||||
}
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
@@ -214,12 +306,13 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
if open_.val {
|
||||
close()
|
||||
} else {
|
||||
open()
|
||||
open_.val = true
|
||||
set_tab(tab.val) // reopens on the tab it was left on
|
||||
}
|
||||
true
|
||||
}
|
||||
(POPUP, PointerMove(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
let i = row_at(rows(), p.x, p.y)
|
||||
if i != hover.val && i >= 0 {
|
||||
hover.val = i
|
||||
true
|
||||
@@ -228,10 +321,20 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
}
|
||||
}
|
||||
(POPUP, PointerDown(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
let ti = tab_at(p.x, p.y)
|
||||
if ti >= 0 {
|
||||
if ti != tab.val {
|
||||
set_tab(ti)
|
||||
}
|
||||
return true
|
||||
}
|
||||
let rs = rows()
|
||||
let i = row_at(rs, p.x, p.y)
|
||||
if i >= 0 {
|
||||
act(i)
|
||||
hover.val = i
|
||||
act(rs, i)
|
||||
// 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) }
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -249,7 +352,12 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
close()
|
||||
true
|
||||
} else if k == "Enter" || k == " " || k == "Space" {
|
||||
act(hover.val)
|
||||
let rs = rows()
|
||||
act(rs, hover.val)
|
||||
let after = rows()
|
||||
if !active(after, hover.val) {
|
||||
hover.val = first_active(after)
|
||||
}
|
||||
true
|
||||
} else if k == "ArrowDown" || k == "Down" {
|
||||
move_hover(1)
|
||||
@@ -257,6 +365,15 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
} else if k == "ArrowUp" || k == "Up" {
|
||||
move_hover(-1)
|
||||
true
|
||||
} else if k == "ArrowRight" || k == "Right" {
|
||||
set_tab((tab.val + 1) % tab_names.length())
|
||||
true
|
||||
} else if k == "ArrowLeft" || k == "Left" {
|
||||
set_tab((tab.val + tab_names.length() - 1) % tab_names.length())
|
||||
true
|
||||
} else if k == "1" || k == "2" || k == "3" {
|
||||
set_tab(k[0].to_int() - '1'.to_int())
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user