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
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
pub fn mbt_ffi_cabi_realloc(
|
||||
src_offset : Int,
|
||||
src_size : Int,
|
||||
_dst_alignment : Int,
|
||||
dst_size : Int,
|
||||
) -> Int {
|
||||
// malloc
|
||||
if src_offset == 0 && src_size == 0 {
|
||||
return mbt_ffi_malloc(dst_size)
|
||||
}
|
||||
// free
|
||||
if dst_size == 0 {
|
||||
mbt_ffi_free(src_offset)
|
||||
return 0
|
||||
}
|
||||
// realloc
|
||||
let dst = mbt_ffi_malloc(dst_size)
|
||||
mbt_ffi_copy(dst, src_offset, if src_size < dst_size { src_size } else { dst_size })
|
||||
mbt_ffi_free(src_offset)
|
||||
dst
|
||||
}
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_copy(dest : Int, src : Int, len : Int) =
|
||||
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||
@plasmoid.wasmExportRender(p0, p1)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportRenderPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportInfoPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfo() -> Int {
|
||||
@plasmoid.wasmExportInfo()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportPopupPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopup() -> Int {
|
||||
@plasmoid.wasmExportPopup()
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
The widget (plasmoid) contract.
|
||||
@@ -1,409 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfo() -> Int {
|
||||
|
||||
let (result) : (PlasmoidInfo) = info();
|
||||
let return_area = mbt_ffi_malloc(32)
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((result).id)
|
||||
mbt_ffi_store32((return_area) + 4, (result).id.length())
|
||||
mbt_ffi_store32((return_area) + 0, ptr)
|
||||
|
||||
let ptr0 = mbt_ffi_str2ptr((result).name)
|
||||
mbt_ffi_store32((return_area) + 12, (result).name.length())
|
||||
mbt_ffi_store32((return_area) + 8, ptr0)
|
||||
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
|
||||
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
|
||||
let ret = return_area
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||
|
||||
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
|
||||
let address = mbt_ffi_malloc((result).length() * 32);
|
||||
for index = 0; index < (result).length(); index = index + 1 {
|
||||
let iter_elem : @types.DrawOp = (result)[(index)]
|
||||
let iter_base = address + (index * 32);
|
||||
|
||||
match iter_elem {
|
||||
FillRect(payload) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (0))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
|
||||
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
StrokeRect(payload0) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (1))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
|
||||
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
Line(payload1) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (2))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
|
||||
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
Circle(payload2) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (3))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
|
||||
|
||||
()
|
||||
}
|
||||
Text(payload3) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (4))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((payload3).text)
|
||||
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
|
||||
mbt_ffi_store32((iter_base) + 12, ptr)
|
||||
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
|
||||
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
|
||||
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
|
||||
|
||||
()
|
||||
}
|
||||
PushClip(payload4) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (5))
|
||||
mbt_ffi_store32((iter_base) + 4, (payload4).x)
|
||||
mbt_ffi_store32((iter_base) + 8, (payload4).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
PopClip => {
|
||||
mbt_ffi_store8((iter_base) + 0, (6))
|
||||
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||
mbt_ffi_store32((return_area) + 0, address)
|
||||
let ret = return_area
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
|
||||
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
|
||||
|
||||
match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||
0 => ()
|
||||
1 => ()
|
||||
2 => ()
|
||||
3 => ()
|
||||
4 => {
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
|
||||
|
||||
}
|
||||
5 => ()
|
||||
6 => ()
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopup() -> Int {
|
||||
|
||||
let (result) : (PopupSurface?) = popup();
|
||||
let return_area = mbt_ffi_malloc(20)
|
||||
|
||||
match (result) {
|
||||
None => {
|
||||
mbt_ffi_store8((return_area) + 0, (0))
|
||||
|
||||
()
|
||||
}
|
||||
Some(payload0) => {
|
||||
mbt_ffi_store8((return_area) + 0, (1))
|
||||
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
|
||||
|
||||
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
|
||||
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
|
||||
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
|
||||
let iter_base = address + (index * 32);
|
||||
|
||||
match iter_elem {
|
||||
FillRect(payload1) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (0))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
|
||||
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
StrokeRect(payload2) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (1))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
|
||||
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
Line(payload3) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (2))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
|
||||
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
|
||||
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
|
||||
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
Circle(payload4) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (3))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
|
||||
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
|
||||
|
||||
()
|
||||
}
|
||||
Text(payload5) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (4))
|
||||
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
|
||||
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((payload5).text)
|
||||
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
|
||||
mbt_ffi_store32((iter_base) + 12, ptr)
|
||||
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
|
||||
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
|
||||
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
|
||||
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
|
||||
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
|
||||
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
|
||||
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
|
||||
|
||||
()
|
||||
}
|
||||
PushClip(payload6) => {
|
||||
mbt_ffi_store8((iter_base) + 0, (5))
|
||||
mbt_ffi_store32((iter_base) + 4, (payload6).x)
|
||||
mbt_ffi_store32((iter_base) + 8, (payload6).y)
|
||||
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
|
||||
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
|
||||
|
||||
()
|
||||
}
|
||||
PopClip => {
|
||||
mbt_ffi_store8((iter_base) + 0, (6))
|
||||
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
|
||||
mbt_ffi_store32((return_area) + 12, address)
|
||||
|
||||
()
|
||||
}
|
||||
}
|
||||
let ret = return_area
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
|
||||
match (mbt_ffi_load8_u((p0) + 0)) {
|
||||
0 => ()
|
||||
1 => {
|
||||
|
||||
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
|
||||
|
||||
match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||
0 => ()
|
||||
1 => ()
|
||||
2 => ()
|
||||
3 => ()
|
||||
4 => {
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
|
||||
|
||||
}
|
||||
5 => ()
|
||||
6 => ()
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
|
||||
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
|
||||
let lifted = match (p1) {
|
||||
0 => {
|
||||
|
||||
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
|
||||
}
|
||||
1 => {
|
||||
|
||||
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
|
||||
}
|
||||
2 => {
|
||||
|
||||
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
|
||||
}
|
||||
3 => {
|
||||
|
||||
@types.InputEvent::PointerLeave
|
||||
}
|
||||
4 => {
|
||||
|
||||
@types.InputEvent::FocusLost
|
||||
}
|
||||
5 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(p2, p3)
|
||||
|
||||
@types.InputEvent::KeyDown(result)
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
|
||||
let ret = (if result0 { 1 } else { 0 })
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import {
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/interface/chandra/desktop/wallpaper" @wallpaper,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
@@ -1,175 +0,0 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the wallpaper chooser. The panel button
|
||||
/// opens a popup listing the wallpapers the shell can draw (`wallpaper.wallpapers`), the current
|
||||
/// one ticked. Clicking a row switches the desktop to it at once (the list stays open to compare); Enter
|
||||
/// picks the highlighted row and closes, Escape or a click elsewhere closes. The shell remembers the choice across restarts.
|
||||
|
||||
///| Popup geometry: a column of rows with a margin around them.
|
||||
let popup_w : Int = 180
|
||||
|
||||
///|
|
||||
let row_h : Int = 30
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///| 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: [] }
|
||||
|
||||
///|
|
||||
fn popup_h() -> Int {
|
||||
margin * 2 + names.val.length() * row_h
|
||||
}
|
||||
|
||||
///| Row under a popup-local point, or -1.
|
||||
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 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn open() -> Unit {
|
||||
names.val = @wallpaper.wallpapers()
|
||||
open_.val = true
|
||||
hover.val = @wallpaper.current_wallpaper().reinterpret_as_int()
|
||||
}
|
||||
|
||||
///|
|
||||
fn close() -> Unit {
|
||||
open_.val = false
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///|
|
||||
fn choose(i : Int) -> Unit {
|
||||
if i >= 0 && i < names.val.length() {
|
||||
@wallpaper.set_wallpaper(i.reinterpret_as_uint())
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn info() -> PlasmoidInfo {
|
||||
{
|
||||
id: "org.chandra.wallpaper",
|
||||
name: "Wallpaper",
|
||||
preferred: { w: 96, h: 34 },
|
||||
min_width: 70,
|
||||
stretch: false,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||
let t = @theme.get_tokens()
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
let r = t.radius.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let bg = if open_.val { t.palette.accent } else { t.palette.surface_hover }
|
||||
let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
// A tiny landscape swatch, then the label.
|
||||
let sw = 18
|
||||
let sx = 8
|
||||
let sy = (h - 14) / 2
|
||||
[
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
|
||||
@ui.fill_rect(@ui.rect(sx, sy, sw, 14), t.palette.desktop_top, radius=2),
|
||||
@ui.circle(sx + sw - 5, sy + 4, 2, t.palette.accent_foreground),
|
||||
@ui.fill_rect(@ui.rect(sx, sy + 9, sw, 5), t.palette.desktop_bottom, radius=2),
|
||||
@ui.stroke_rect(@ui.rect(sx, sy, sw, 14), fg, width=1, radius=2),
|
||||
@ui.text(sx + sw + 6, h / 2, "Wallpaper", fs - 2, fg),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn popup() -> PopupSurface? {
|
||||
if !open_.val {
|
||||
return None
|
||||
}
|
||||
let t = @theme.get_tokens()
|
||||
let w = popup_w
|
||||
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 {
|
||||
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.accent, radius=r))
|
||||
}
|
||||
let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
let mid = y + (row_h - 2) / 2
|
||||
if i == 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, names.val[i], fs - 1, fg, bold=i == cur))
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
match (target, event) {
|
||||
(WIDGET, PointerDown(_)) => {
|
||||
if open_.val {
|
||||
close()
|
||||
} else {
|
||||
open()
|
||||
}
|
||||
true
|
||||
}
|
||||
(POPUP, PointerMove(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
if i != hover.val && i >= 0 {
|
||||
hover.val = i
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(POPUP, PointerDown(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
if i >= 0 {
|
||||
choose(i)
|
||||
hover.val = i
|
||||
}
|
||||
true
|
||||
}
|
||||
(_, FocusLost) =>
|
||||
if open_.val {
|
||||
close()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(_, KeyDown(k)) =>
|
||||
if !open_.val {
|
||||
false
|
||||
} else if k == "Escape" {
|
||||
close()
|
||||
true
|
||||
} else if k == "Enter" {
|
||||
choose(hover.val)
|
||||
close()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
pub(all) struct PlasmoidInfo {
|
||||
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
|
||||
}
|
||||
///|
|
||||
pub(all) struct PopupSurface {
|
||||
size : @types.Size; ops : Array[@types.DrawOp]
|
||||
}
|
||||
///|
|
||||
pub(all) enum Surface {
|
||||
WIDGET; POPUP
|
||||
} derive()
|
||||
|
||||
///|
|
||||
pub fn Surface::ordinal(self : Surface) -> Int {
|
||||
match self {
|
||||
WIDGET => 0
|
||||
POPUP => 1
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Surface::from(self : Int) -> Surface {
|
||||
match self {
|
||||
0 => WIDGET
|
||||
1 => POPUP
|
||||
_ => panic()
|
||||
}
|
||||
}
|
||||
///|
|
||||
declare pub fn info() -> PlasmoidInfo
|
||||
///|
|
||||
/// Draw the widget into a `size` box (local coordinates).
|
||||
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
|
||||
///|
|
||||
/// Present when the widget wants a popup surface (e.g. a launcher menu).
|
||||
declare pub fn popup() -> PopupSurface?
|
||||
///|
|
||||
/// Returns true when the widget's visuals changed and a redraw is needed.
|
||||
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import {
|
||||
"chandra/desktop/components/wallpaper/gen/interface/chandra/desktop/plasmoid" @plasmoid,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
|
||||
pkgtype(kind: "foreign_library")
|
||||
|
||||
options(
|
||||
link: {
|
||||
"wasm": {
|
||||
"export-memory-name": "memory",
|
||||
"heap-start-address": 16,
|
||||
"exports": [
|
||||
"mbt_ffi_cabi_realloc:cabi_realloc",
|
||||
"wasmExportInfo:chandra:desktop/plasmoid@0.1.0#info",
|
||||
"wasmExportInfoPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#info",
|
||||
"wasmExportOnEvent:chandra:desktop/plasmoid@0.1.0#on-event",
|
||||
"wasmExportPopup:chandra:desktop/plasmoid@0.1.0#popup",
|
||||
"wasmExportPopupPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#popup",
|
||||
"wasmExportRender:chandra:desktop/plasmoid@0.1.0#render",
|
||||
"wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render"
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -32,7 +32,9 @@ pub(all) struct ChandraCompositor {
|
||||
popups : Array[HostPopup]
|
||||
server : @wayland.WaylandServer
|
||||
wm : @wm.WmState
|
||||
theme : @scene.ThemeTokens
|
||||
/// The theme in use: `dark_theme` (the configured one) or Moon Day, per the Dark mode setting.
|
||||
mut theme : @scene.ThemeTokens
|
||||
dark_theme : @scene.ThemeTokens
|
||||
mut output_w : Int
|
||||
mut output_h : Int
|
||||
mut work_area : @wm.Rect
|
||||
@@ -108,6 +110,7 @@ pub fn ChandraCompositor::new(
|
||||
server,
|
||||
wm,
|
||||
theme,
|
||||
dark_theme: theme,
|
||||
output_w,
|
||||
output_h,
|
||||
work_area,
|
||||
@@ -440,6 +443,7 @@ pub fn ChandraCompositor::set_layout_mode(
|
||||
pub fn ChandraCompositor::restore_state(self : ChandraCompositor) -> Unit {
|
||||
let st = self.shell.load_state()
|
||||
self.shell.apply_state(st)
|
||||
self.apply_theme()
|
||||
match st.layout {
|
||||
Some(0) => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||
Some(1) => self.set_layout_mode(@wm.LayoutMode::Monocle)
|
||||
@@ -963,12 +967,22 @@ fn ChandraCompositor::activate_task(self : ChandraCompositor, wid : UInt64) -> U
|
||||
)
|
||||
}
|
||||
|
||||
///| Use the dark (configured) or the light theme, as the shell's Dark mode setting says, for the
|
||||
/// shell, the panel modules, the window decorations and the switcher; redraws everything.
|
||||
pub fn ChandraCompositor::apply_theme(self : ChandraCompositor) -> Unit {
|
||||
let t = if self.shell.dark_mode { self.dark_theme } else { @scene.ThemeTokens::moon_day() }
|
||||
self.theme = t
|
||||
self.shell.set_output(t, self.output_w, self.output_h)
|
||||
self.damage.mark_full()
|
||||
}
|
||||
|
||||
///| Carry out what panel modules asked for: focus a window, switch layout.
|
||||
fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit {
|
||||
for a in self.shell.take_actions() {
|
||||
match a {
|
||||
@shell.ShellAction::FocusWindow(wid) => self.activate_task(wid)
|
||||
@shell.ShellAction::Logout => self.quit_requested = true
|
||||
@shell.ShellAction::ThemeChanged => self.apply_theme()
|
||||
@shell.ShellAction::SetLayout(m) =>
|
||||
match m {
|
||||
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||
|
||||
@@ -1134,23 +1134,28 @@ fn click_wallpaper_ops(comp : @host.ChandraCompositor, x : Int, y : Int, t : UIn
|
||||
}
|
||||
|
||||
///|
|
||||
test "the wallpaper module lists the wallpapers and switches the desktop to the one clicked" {
|
||||
test "the settings module lists the wallpapers and switches the desktop to the one clicked" {
|
||||
let comp = new_comp("wallpaper")
|
||||
let slot = comp.shell.slot_of("wallpaper")
|
||||
let slot = comp.shell.slot_of("session-settings")
|
||||
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
||||
assert_eq(comp.shell.slot_of("wallpaper"), "") // the standalone chooser is gone
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// A click opens the list; nothing changes yet.
|
||||
click_module(comp, "wallpaper", 1U)
|
||||
// A click opens the list; nothing changes yet. The wallpapers follow the three settings and a
|
||||
// "Wallpaper" heading, so the first is row 4.
|
||||
click_module(comp, "session-settings", 1U)
|
||||
let pr = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr.h >= 6 * 2 + 5 * 30) // one row per wallpaper
|
||||
assert_true(pr.h >= 6 * 2 + (4 + 5) * 30) // one row per setting and wallpaper, and the heading
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// Third row: Starfield. The list stays open and the backdrop is drawn anew.
|
||||
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 5U)
|
||||
// The heading does nothing.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 3 * 30 + 5, 3U)
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// Third wallpaper: Starfield. The list stays open and the backdrop is drawn anew.
|
||||
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + (4 + 2) * 30 + 5, 5U)
|
||||
assert_eq(comp.shell.wallpaper_sel, 2)
|
||||
assert_true(star > 0)
|
||||
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
||||
// Last row: Solid, a single fill. Escape then closes the list.
|
||||
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 4 * 30 + 5, 10U), 1)
|
||||
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + (4 + 4) * 30 + 5, 10U), 1)
|
||||
assert_eq(comp.shell.wallpaper_sel, 4)
|
||||
comp.shell.key_down("Escape")
|
||||
ignore(comp.compose_frame())
|
||||
@@ -1255,7 +1260,7 @@ test "the open windows are saved as the session and a restored app's window gets
|
||||
}
|
||||
|
||||
///|
|
||||
test "the session settings module flips the session settings from its popup" {
|
||||
test "the settings module flips the session settings from its popup" {
|
||||
let comp = new_comp("sessset")
|
||||
let slot = comp.shell.slot_of("session-settings")
|
||||
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
||||
@@ -1264,7 +1269,7 @@ test "the session settings module flips the session settings from its popup" {
|
||||
// A click opens the list of switches; nothing changes yet.
|
||||
click_module(comp, "session-settings", 1U)
|
||||
let pr = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr.h >= 6 * 2 + 2 * 32) // one row per setting
|
||||
assert_true(pr.h >= 6 * 2 + 3 * 30) // one row per setting
|
||||
assert_true(comp.shell.restore_session)
|
||||
// First row: "Reopen windows at login" goes off, and on again with a second click.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 5, 5U)
|
||||
@@ -1274,12 +1279,22 @@ test "the session settings module flips the session settings from its popup" {
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 5, 10U)
|
||||
assert_true(comp.shell.restore_session)
|
||||
// Second row: "Remember window positions"; then Down and Enter flip it back from the keyboard.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 32 + 5, 15U)
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 30 + 5, 15U)
|
||||
assert_false(comp.shell.remember_windows)
|
||||
comp.shell.key_down("Enter")
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.remember_windows)
|
||||
assert_true(comp.shell.restore_session)
|
||||
// Third row: Dark mode. Off switches the shell, panel and decorations to the light theme.
|
||||
assert_eq(comp.theme.name, "Moon Night")
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 20U)
|
||||
assert_false(comp.shell.dark_mode)
|
||||
assert_eq(comp.theme.name, "Moon Day")
|
||||
assert_eq(comp.shell.tokens.name, "Moon Day")
|
||||
comp.shell.key_down("Enter") // the highlight stayed on Dark mode
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.dark_mode)
|
||||
assert_eq(comp.theme.name, "Moon Night")
|
||||
comp.shell.key_down("Escape")
|
||||
ignore(comp.compose_frame())
|
||||
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
||||
@@ -1323,5 +1338,16 @@ test "session settings are saved to state.edn and restored, and take effect" {
|
||||
assert_false(text2.contains(":remember-windows"))
|
||||
assert_eq(b.shell.load_session().length(), 1)
|
||||
assert_eq(b.shell.saved_window("foot"), Some((10, 20, 300, 200)))
|
||||
// Dark mode off is saved as :theme :light and the next start comes up light.
|
||||
b.shell.set_session_setting(2, false)
|
||||
assert_true(read_state_edn().contains(":theme :light"))
|
||||
let c = new_comp("sess-c")
|
||||
c.shell.persist = true
|
||||
assert_eq(c.theme.name, "Moon Night")
|
||||
c.restore_state()
|
||||
assert_false(c.shell.dark_mode)
|
||||
assert_eq(c.theme.name, "Moon Day")
|
||||
c.shell.set_session_setting(2, true)
|
||||
assert_false(read_state_edn().contains(":theme"))
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,30 @@ pub fn ThemeTokens::moon_night() -> ThemeTokens {
|
||||
}
|
||||
}
|
||||
|
||||
///| The light counterpart of `moon_night` (config/themes/moon-day.json): what the settings
|
||||
/// module's "Dark mode" switch turns to when off.
|
||||
pub fn ThemeTokens::moon_day() -> ThemeTokens {
|
||||
{
|
||||
name: "Moon Day",
|
||||
palette: {
|
||||
desktop_top: Rgba::from_hex("#cfe3ff"),
|
||||
desktop_bottom: Rgba::from_hex("#8fb4e8"),
|
||||
surface: Rgba::from_hex("#f4f6fbf2"),
|
||||
surface_hover: Rgba::from_hex("#dde3f0"),
|
||||
surface_popup: Rgba::from_hex("#fbfcfff5"),
|
||||
foreground: Rgba::from_hex("#1b2233"),
|
||||
foreground_muted: Rgba::from_hex("#5b6577"),
|
||||
accent: Rgba::from_hex("#3b6bff"),
|
||||
accent_foreground: Rgba::from_hex("#ffffff"),
|
||||
border: Rgba::from_hex("#b9c3d6"),
|
||||
},
|
||||
font_size: 14,
|
||||
radius: 6,
|
||||
spacing: 6,
|
||||
panel_height: 44,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn json_str(obj : Map[String, Json], key : String, fallback : String) -> String {
|
||||
match obj.get(key) {
|
||||
|
||||
@@ -139,6 +139,8 @@ pub(all) enum ShellAction {
|
||||
FocusWindow(UInt64)
|
||||
/// A module (the logout button) asked to end the session.
|
||||
Logout
|
||||
/// The Dark mode setting changed: the compositor swaps the theme (see `dark_mode`).
|
||||
ThemeChanged
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| One wasm module loaded into the panel.
|
||||
@@ -206,6 +208,8 @@ pub(all) struct DesktopShell {
|
||||
/// last session's windows at the next start, and remember where floating windows were left.
|
||||
mut restore_session : Bool
|
||||
mut remember_windows : Bool
|
||||
/// Dark mode (the configured theme) or light (Moon Day); saved as `:theme :light` when off.
|
||||
mut dark_mode : Bool
|
||||
mut desk_set : Bool
|
||||
mut desk_x : Int
|
||||
mut desk_y : Int
|
||||
@@ -292,6 +296,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
wallpaper_sel: 0,
|
||||
restore_session: true,
|
||||
remember_windows: true,
|
||||
dark_mode: true,
|
||||
desk_set: false,
|
||||
desk_x: 0,
|
||||
desk_y: 0,
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
/// :recent ["foot" "dolphin"] ; the launcher's recently started apps, newest first
|
||||
/// :windows {"foot" {:x 80 :y 60 :w 640 :h 480}} ; floating windows' last place, by app id
|
||||
/// :desktop-card {:x 900 :y 24} ; where the desktop card was dragged to (absent: default spot)
|
||||
/// :wallpaper :aurora ; the wallpaper module's choice (absent: :plasma-glow)
|
||||
/// :wallpaper :aurora ; the settings module's wallpaper (absent: :plasma-glow)
|
||||
/// :theme :light ; the settings module's Dark mode switch is off (absent: dark)
|
||||
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
|
||||
/// ; the windows open when the last session ended, reopened at
|
||||
/// ; the next start (see session.mbt in compositor/host)
|
||||
@@ -31,6 +32,8 @@ pub(all) struct SavedState {
|
||||
/// Session settings; None when the file doesn't say (both default to on).
|
||||
restore_session : Bool?
|
||||
remember_windows : Bool?
|
||||
/// From `:theme`: true for :dark, false for :light.
|
||||
dark_mode : Bool?
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -44,6 +47,7 @@ let layout_names : Array[String] = ["tiling", "monocle", "floating"]
|
||||
///| The keys this build owns; everything else in the file is kept as it is.
|
||||
let owned_keys : Array[String] = [
|
||||
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
|
||||
"theme",
|
||||
]
|
||||
|
||||
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
|
||||
@@ -87,6 +91,7 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
wallpaper: None,
|
||||
restore_session: None,
|
||||
remember_windows: None,
|
||||
dark_mode: None,
|
||||
}
|
||||
}
|
||||
let entries = read_state_file()
|
||||
@@ -186,6 +191,11 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
wallpaper,
|
||||
restore_session: flag("restore-session"),
|
||||
remember_windows: flag("remember-windows"),
|
||||
dark_mode: match lookup_key(entries, "theme") {
|
||||
Some(Keyword("light")) => Some(false)
|
||||
Some(Keyword("dark")) => Some(true)
|
||||
_ => None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +216,10 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
|
||||
Some(b) => self.remember_windows = b
|
||||
None => ()
|
||||
}
|
||||
match st.dark_mode {
|
||||
Some(b) => self.dark_mode = b
|
||||
None => ()
|
||||
}
|
||||
match st.desk {
|
||||
Some((x, y)) => {
|
||||
self.desk_set = true
|
||||
@@ -278,6 +292,9 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel])))
|
||||
}
|
||||
// Session settings are written only when off: absent means on, as for a hand-written file.
|
||||
if !self.dark_mode {
|
||||
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
|
||||
}
|
||||
if !self.remember_windows {
|
||||
entries.insert(2, (@edn.Value::Keyword("remember-windows"), @edn.Value::Bool(false)))
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "session-settings",
|
||||
"logout",
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "session-settings", "logout",
|
||||
]
|
||||
|
||||
///| The module whose popup is the wasm picker.
|
||||
@@ -172,6 +171,30 @@ fn wall_secs() -> Int {
|
||||
@sys.wall_time_field(3) * 3600 + @sys.wall_time_field(4) * 60 + @sys.wall_time_field(5)
|
||||
}
|
||||
|
||||
///| Panels saved before the wallpaper chooser moved into the settings module list "wallpaper":
|
||||
/// the settings module takes its place (once; a panel that already has it just drops it).
|
||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
let has_settings = entries.contains("session-settings")
|
||||
let out : Array[String] = []
|
||||
for e in entries {
|
||||
if e == "wallpaper" {
|
||||
if !has_settings && !out.contains("session-settings") {
|
||||
out.push("session-settings")
|
||||
}
|
||||
} else {
|
||||
out.push(e)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
test "a saved panel's wallpaper button becomes the settings module" {
|
||||
assert_eq(migrate_panel(["launcher", "wallpaper", "logout"]), ["launcher", "session-settings", "logout"])
|
||||
assert_eq(migrate_panel(["wallpaper", "session-settings"]), ["session-settings"])
|
||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||
}
|
||||
|
||||
///| Load the panel on first use: the saved layout if there is one, else the default modules.
|
||||
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
if self.booted {
|
||||
@@ -180,7 +203,7 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
self.booted = true
|
||||
self.scan_catalog()
|
||||
let entries = match self.load_panel_config() {
|
||||
Some(e) => e
|
||||
Some(e) => migrate_panel(e)
|
||||
None => default_panel
|
||||
}
|
||||
for e in entries {
|
||||
@@ -446,11 +469,15 @@ pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
|
||||
}
|
||||
|
||||
///| The session settings the session settings module lists, in index order.
|
||||
let session_setting_names : Array[String] = ["Reopen windows at login", "Remember window positions"]
|
||||
let session_setting_names : Array[String] = [
|
||||
"Reopen windows at login", "Remember window positions", "Dark mode",
|
||||
]
|
||||
|
||||
///| Which session settings are on: bit i for `session_setting_names[i]`.
|
||||
fn DesktopShell::session_settings_bits(self : DesktopShell) -> Int {
|
||||
(if self.restore_session { 1 } else { 0 }) | (if self.remember_windows { 2 } else { 0 })
|
||||
(if self.restore_session { 1 } else { 0 }) |
|
||||
(if self.remember_windows { 2 } else { 0 }) |
|
||||
(if self.dark_mode { 4 } else { 0 })
|
||||
}
|
||||
|
||||
///| Turn session setting `i` on or off (ignored when out of range) and remember it in state.edn.
|
||||
@@ -458,6 +485,11 @@ pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool
|
||||
match i {
|
||||
0 => self.restore_session = on
|
||||
1 => self.remember_windows = on
|
||||
2 =>
|
||||
if self.dark_mode != on {
|
||||
self.dark_mode = on
|
||||
self.actions.push(ThemeChanged)
|
||||
}
|
||||
_ => return
|
||||
}
|
||||
@wasm.publish_session_settings(self.session_settings_bits())
|
||||
|
||||
+30
-49
@@ -595,30 +595,46 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallpaper_module_lists_the_wallpapers_and_requests_a_switch() {
|
||||
fn settings_module_shows_switches_and_wallpapers_and_requests_changes() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("wallpaper")).expect("wallpaper loads");
|
||||
assert!(l.imports.contains(&"wallpaper".to_string()));
|
||||
let l = rt.load(&module("session-settings")).expect("session-settings loads");
|
||||
assert!(l.imports.contains(&"session-settings".to_string()));
|
||||
let h = l.handle;
|
||||
let names = ["Plasma glow", "Aurora", "Starfield"];
|
||||
let mut t = (names.len() as u32).to_le_bytes().to_vec();
|
||||
for n in names {
|
||||
t.extend((n.len() as u32).to_le_bytes());
|
||||
t.extend(n.as_bytes());
|
||||
}
|
||||
rt.shared.borrow_mut().tables[T_WALLPAPERS] = t;
|
||||
assert!(l.imports.contains(&"wallpaper".to_string()));
|
||||
let table = |names: &[&str]| {
|
||||
let mut t = (names.len() as u32).to_le_bytes().to_vec();
|
||||
for n in names {
|
||||
t.extend((n.len() as u32).to_le_bytes());
|
||||
t.extend(n.as_bytes());
|
||||
}
|
||||
t
|
||||
};
|
||||
let names = ["Reopen windows at login", "Remember window positions", "Dark mode"];
|
||||
let walls = ["Plasma glow", "Aurora", "Starfield"];
|
||||
rt.shared.borrow_mut().tables[T_SESSION_SETTINGS] = table(&names);
|
||||
rt.shared.borrow_mut().tables[T_WALLPAPERS] = table(&walls);
|
||||
rt.shared.borrow_mut().session_settings = 0b101; // reopen on, remember off, dark on
|
||||
rt.shared.borrow_mut().wallpaper = 1;
|
||||
assert!(texts(&rt.render(h, Size { w: 96, h: 34 })).contains(&"Wallpaper".to_string()));
|
||||
// A click opens the list of every wallpaper; nothing is requested yet.
|
||||
assert!(texts(&rt.render(h, Size { w: 92, h: 34 })).contains(&"Settings".to_string()));
|
||||
// A click opens the list of every setting; nothing is requested yet.
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
|
||||
let p = rt.popup(h).expect("popup open");
|
||||
for n in names {
|
||||
for n in names.iter().chain(walls.iter()).chain(["Wallpaper"].iter()) {
|
||||
assert!(texts(&p.ops).contains(&n.to_string()), "{n} listed");
|
||||
}
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// Third row: Starfield.
|
||||
// First row is on: a click asks to turn it off. Second row is off: a click asks for on.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(0, false))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 30 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(1, true))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 2 * 30 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(2, false))));
|
||||
// Row 3 is the "Wallpaper" heading (nothing); rows 4.. are the wallpapers: Starfield.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 3 * 30 + 5 })));
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 6 * 30 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetWallpaper(2))));
|
||||
// The list stays open; Escape closes it without another request.
|
||||
assert!(rt.popup(h).is_some());
|
||||
@@ -627,39 +643,4 @@ mod tests {
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
rt.unload(h);
|
||||
}
|
||||
#[test]
|
||||
fn session_settings_module_shows_switches_and_requests_a_flip() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("session-settings")).expect("session-settings loads");
|
||||
assert!(l.imports.contains(&"session-settings".to_string()));
|
||||
let h = l.handle;
|
||||
let names = ["Reopen windows at login", "Remember window positions"];
|
||||
let mut t = (names.len() as u32).to_le_bytes().to_vec();
|
||||
for n in names {
|
||||
t.extend((n.len() as u32).to_le_bytes());
|
||||
t.extend(n.as_bytes());
|
||||
}
|
||||
rt.shared.borrow_mut().tables[T_SESSION_SETTINGS] = t;
|
||||
rt.shared.borrow_mut().session_settings = 0b01; // reopen on, remember off
|
||||
assert!(texts(&rt.render(h, Size { w: 86, h: 34 })).contains(&"Session".to_string()));
|
||||
// A click opens the list of every setting; nothing is requested yet.
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
|
||||
let p = rt.popup(h).expect("popup open");
|
||||
for n in names {
|
||||
assert!(texts(&p.ops).contains(&n.to_string()), "{n} listed");
|
||||
}
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// First row is on: a click asks to turn it off. Second row is off: a click asks for on.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(0, false))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 32 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(1, true))));
|
||||
// The list stays open; Escape closes it without another request.
|
||||
assert!(rt.popup(h).is_some());
|
||||
assert!(rt.on_event(h, true, InputEvent::KeyDown("Escape".to_string())));
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
rt.unload(h);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
Session settings: how the login session starts and what it remembers. The shell keeps them in
|
||||
state.edn; a module with this capability lists them as on/off switches and flips them.
|
||||
Session settings: how the login session starts, what it remembers and how it looks (dark or
|
||||
light). The shell keeps them in state.edn; a module with this capability lists them as on/off
|
||||
switches and flips them.
|
||||
@@ -1,2 +1,3 @@
|
||||
The desktop wallpaper. The shell draws a fixed set of wallpapers (from draw ops, coloured by the
|
||||
theme); a module with this capability lists them and picks which one is on the desktop.
|
||||
theme); a module with this capability (the settings module) lists them and picks which one is on
|
||||
the desktop.
|
||||
@@ -9,5 +9,4 @@ layout layout-widget
|
||||
inspector inspector-widget
|
||||
module-manager module-manager-widget
|
||||
logout logout-widget
|
||||
wallpaper wallpaper-widget
|
||||
session-settings session-settings-widget
|
||||
@@ -118,7 +118,8 @@ interface session {
|
||||
}
|
||||
|
||||
/// The desktop wallpaper. The shell draws a fixed set of wallpapers (from draw ops, coloured by the
|
||||
/// theme); a module with this capability lists them and picks which one is on the desktop.
|
||||
/// theme); a module with this capability (the settings module) lists them and picks which one is on
|
||||
/// the desktop.
|
||||
interface wallpaper {
|
||||
/// Display names, indexed by choice.
|
||||
wallpapers: func() -> list<string>;
|
||||
@@ -127,8 +128,9 @@ interface wallpaper {
|
||||
set-wallpaper: func(index: u32);
|
||||
}
|
||||
|
||||
/// Session settings: how the login session starts and what it remembers. The shell keeps them in
|
||||
/// state.edn; a module with this capability lists them as on/off switches and flips them.
|
||||
/// Session settings: how the login session starts, what it remembers and how it looks (dark or
|
||||
/// light). The shell keeps them in state.edn; a module with this capability lists them as on/off
|
||||
/// switches and flips them.
|
||||
interface session-settings {
|
||||
/// Display names, indexed by setting.
|
||||
settings: func() -> list<string>;
|
||||
|
||||
+2
-7
@@ -85,14 +85,9 @@ world logout-widget {
|
||||
import session;
|
||||
}
|
||||
|
||||
/// Wallpaper chooser.
|
||||
world wallpaper-widget {
|
||||
include widget;
|
||||
import wallpaper;
|
||||
}
|
||||
|
||||
/// Session settings switches.
|
||||
/// The settings module: session switches (restore, window places, dark mode) and the wallpaper.
|
||||
world session-settings-widget {
|
||||
include widget;
|
||||
import session-settings;
|
||||
import wallpaper;
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
Session settings switches.
|
||||
The settings module: session switches (restore, window places, dark mode) and the wallpaper.
|
||||
@@ -1 +0,0 @@
|
||||
Wallpaper chooser.
|
||||
@@ -1,2 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
warnings = "-44"
|
||||
Reference in new issue
Block a user