Settings module: the wallpaper chooser moves in, and a Dark mode switch
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- The session settings module becomes the panel's "Settings" button. Its popup lists the session switches, then a "Wallpaper" heading and the wallpapers (current one ticked); a click on a wallpaper shows it at once, as the old chooser did. Up/Down skip the heading. - The standalone wallpaper module and its world are removed. A saved panel.edn that lists "wallpaper" gets the settings module in its place (or just drops it when Settings is there). - New "Dark mode" setting (on by default). Off swaps the compositor to the Moon Day palette (ThemeTokens::moon_day, the values of config/themes/moon-day.json) for the shell, panel modules, window decorations and the switcher; on goes back to the configured theme. Saved in state.edn as :theme :light (absent or :dark: dark) and applied at startup by restore_state. - Tests: the native wallpaper test drives the settings module, the settings test flips Dark mode and checks the theme, the state.edn round trip covers :theme, panel migration unit test, and the host-wasm test covers the switches and the wallpaper rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
26 files changed
+295
-878
No files matched your search
@@ -2,6 +2,7 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/session-settings" @settings,
|
||||
"chandra/desktop/interface/chandra/desktop/wallpaper" @wallpaper,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +1,84 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the session settings. The panel button opens
|
||||
/// a popup listing the session settings the shell offers (`session-settings.settings`), each with
|
||||
/// an on/off switch. Clicking a row (or Enter or Space on the highlighted one) flips it at once, and
|
||||
/// the shell remembers it in state.edn; Up/Down move the highlight; Escape or a click elsewhere
|
||||
/// closes the popup.
|
||||
///| 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.
|
||||
|
||||
///| Popup geometry: a column of rows with a margin around them.
|
||||
let popup_w : Int = 290
|
||||
|
||||
///|
|
||||
let row_h : Int = 32
|
||||
let row_h : Int = 30
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///| The switch at the right end of a row.
|
||||
///| 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.
|
||||
enum Row {
|
||||
Setting(Int)
|
||||
Heading(String)
|
||||
Wallpaper(Int)
|
||||
}
|
||||
|
||||
///| Whether the popup is open, and which row is highlighted (-1: none).
|
||||
let open_ : Ref[Bool] = { val: false }
|
||||
|
||||
///|
|
||||
let hover : Ref[Int] = { val: -1 }
|
||||
|
||||
///| The names, read when the popup opens (the list is fixed while it is open).
|
||||
let names : Ref[Array[String]] = { val: [] }
|
||||
///| 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 + names.val.length() * row_h
|
||||
margin * 2 + rows.val.length() * row_h
|
||||
}
|
||||
|
||||
///| Row under a popup-local point, or -1.
|
||||
///| 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(_))
|
||||
}
|
||||
|
||||
///| 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 {
|
||||
return -1
|
||||
}
|
||||
let i = (y - margin) / row_h
|
||||
if i < names.val.length() { i } else { -1 }
|
||||
if active(i) { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn open() -> Unit {
|
||||
names.val = @settings.settings()
|
||||
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 names.val.length() > 0 { 0 } else { -1 }
|
||||
hover.val = if active(0) { 0 } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -55,11 +87,30 @@ fn close() -> Unit {
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///| Flip setting `i` (ignored when out of range).
|
||||
fn toggle(i : Int) -> Unit {
|
||||
if i >= 0 && i < names.val.length() {
|
||||
let idx = i.reinterpret_as_uint()
|
||||
@settings.set_setting(idx, !@settings.is_on(idx))
|
||||
///| Act on row `i`: flip its setting or show its wallpaper (ignored for headings or none).
|
||||
fn act(i : Int) -> Unit {
|
||||
if !active(i) {
|
||||
return
|
||||
}
|
||||
match rows.val[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())
|
||||
Heading(_) => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Move the highlight by `step` rows, skipping headings; stays put at either end.
|
||||
fn move_hover(step : Int) -> Unit {
|
||||
let mut i = hover.val + step
|
||||
while i >= 0 && i < rows.val.length() {
|
||||
if active(i) {
|
||||
hover.val = i
|
||||
return
|
||||
}
|
||||
i = i + step
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +118,8 @@ fn toggle(i : Int) -> Unit {
|
||||
pub fn info() -> PlasmoidInfo {
|
||||
{
|
||||
id: "org.chandra.session-settings",
|
||||
name: "Session",
|
||||
preferred: { w: 86, h: 34 },
|
||||
name: "Settings",
|
||||
preferred: { w: 92, h: 34 },
|
||||
min_width: 34,
|
||||
stretch: false,
|
||||
}
|
||||
@@ -92,7 +143,7 @@ pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||
@ui.circle(gx + 14, gy, 4, fg),
|
||||
]
|
||||
if w >= 70 {
|
||||
ops.push(@ui.text(gx + 26, gy, "Session", fs - 2, fg))
|
||||
ops.push(@ui.text(gx + 26, gy, "Settings", fs - 2, fg))
|
||||
}
|
||||
ops
|
||||
}
|
||||
@@ -107,29 +158,50 @@ pub fn popup() -> PopupSurface? {
|
||||
let h = popup_h()
|
||||
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),
|
||||
]
|
||||
for i = 0; i < names.val.length(); i = i + 1 {
|
||||
for i = 0; i < rows.val.length(); i = i + 1 {
|
||||
let y = margin + i * row_h
|
||||
let hot = i == hover.val
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.surface_hover, radius=r))
|
||||
}
|
||||
let mid = y + (row_h - 2) / 2
|
||||
ops.push(@ui.text(margin + 10, mid, names.val[i], fs - 1, t.palette.foreground))
|
||||
// The switch: an accent track with the knob on the right when on, a muted outline when off.
|
||||
let on = @settings.is_on(i.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))
|
||||
} 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))
|
||||
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) => {
|
||||
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.text(margin + 10, mid, settings.val[k], fs - 1, t.palette.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))
|
||||
} 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))
|
||||
}
|
||||
}
|
||||
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 {
|
||||
// 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.text(margin + 26, mid, wallpapers.val[k], fs - 1, fg, bold=k == cur))
|
||||
}
|
||||
}
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
@@ -158,7 +230,7 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
(POPUP, PointerDown(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
if i >= 0 {
|
||||
toggle(i)
|
||||
act(i)
|
||||
hover.val = i
|
||||
}
|
||||
true
|
||||
@@ -177,17 +249,13 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
close()
|
||||
true
|
||||
} else if k == "Enter" || k == " " || k == "Space" {
|
||||
toggle(hover.val)
|
||||
act(hover.val)
|
||||
true
|
||||
} else if k == "ArrowDown" || k == "Down" {
|
||||
if hover.val + 1 < names.val.length() {
|
||||
hover.val = hover.val + 1
|
||||
}
|
||||
move_hover(1)
|
||||
true
|
||||
} else if k == "ArrowUp" || k == "Up" {
|
||||
if hover.val > 0 {
|
||||
hover.val = hover.val - 1
|
||||
}
|
||||
move_hover(-1)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
Reference in new issue
Block a user