From c7a6c8376ed5243ada6622025d80714f2d3dd657 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 20:29:12 +0000 Subject: [PATCH] Merge the 12-hour clock into the Digital Clock clock-digital12 and clock-digital had become the same module (same lib/clock code, same right-click settings), differing only in the starting format. Keep one: the Digital Clock now starts in 12-hour mode with AM/PM, and its "Time format" setting switches to 24-hour. - components/clock-digital12 is gone (and from scripts/components.txt); lib/clock drops digital12_info/digital12_config. - The default panel loads clock-digital. - "clock-digital12" stays an alias (find_module, slot_of, saved panels) and is never listed in the module picker, even if an old .wasm is still installed. - panel.edn gets :version 2. A version-1 panel is migrated once: the old 12-hour clock becomes the Digital Clock with its settings (state.edn :module-config) moved over in 12-hour mode; a panel that had the old 24-hour Digital Clock keeps 24-hour. The file is rewritten afterwards. - Tests updated, plus a migration test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DPL5hgnZsS91fwCreut8FL --- README.md | 3 +- .../chandra/desktop/module-config/stub.mbt | 2 +- components/clock-digital12/gen/ffi.mbt | 100 ---- .../chandra/desktop/module-config/README.md | 5 - .../chandra/desktop/module-config/ffi.mbt | 114 ----- .../chandra/desktop/module-config/moon.pkg | 5 - .../desktop/module-config/pkg.generated.mbti | 21 - .../chandra/desktop/module-config/stub.mbt | 16 - .../chandra/desktop/module-config/top.mbt | 11 - .../chandra/desktop/plasmoid/README.md | 1 - .../chandra/desktop/plasmoid/ffi.mbt | 431 ------------------ .../chandra/desktop/plasmoid/moon.pkg | 8 - .../desktop/plasmoid/pkg.generated.mbti | 42 -- .../chandra/desktop/plasmoid/stub.mbt | 30 -- .../chandra/desktop/plasmoid/top.mbt | 42 -- components/clock-digital12/gen/moon.pkg | 30 -- .../clock-digital12/gen/pkg.generated.mbti | 13 - compositor/host/input_test.mbt | 80 +++- compositor/host/inspector_test.mbt | 4 +- compositor/shell/module_config.mbt | 34 ++ compositor/shell/widgets.mbt | 100 +++- compositor/wasm/wasm_test.mbt | 20 +- lib/clock/clock.mbt | 15 +- lib/clock/pkg.generated.mbti | 4 - scripts/components.txt | 1 - 25 files changed, 207 insertions(+), 925 deletions(-) delete mode 100644 components/clock-digital12/gen/ffi.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/README.md delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/ffi.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/moon.pkg delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/pkg.generated.mbti delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/stub.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/module-config/top.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/README.md delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/ffi.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/moon.pkg delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/stub.mbt delete mode 100644 components/clock-digital12/gen/interface/chandra/desktop/plasmoid/top.mbt delete mode 100644 components/clock-digital12/gen/moon.pkg delete mode 100644 components/clock-digital12/gen/pkg.generated.mbti diff --git a/README.md b/README.md index 965c0f7..8d7bc33 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ Works today: * WIT package `chandra:desktop@0.1.0` (`wit/`): worlds `widget`, `clock-widget`, `launcher-widget`, `panel`, `shell`. * Four MoonBit components, each an independently built `.wasm` component of 24–33 KB: - `clock-digital`, `clock-binary` (drop-in replacement), `launcher` (kickoff-like with + `clock-digital` (12-hour with AM/PM by default, 24-hour in its right-click settings), + `clock-binary` (drop-in replacement), `launcher` (kickoff-like with keyboard search), `shell` (desktop background + bottom panel layout + theme tokens). * Host (`host/`): Node + browser, jco-transpiled components, capability grants, popup/focus input routing, hot-swap, fault isolation, Canvas2D + ASCII renderers. diff --git a/components/clock-digital/gen/interface/chandra/desktop/module-config/stub.mbt b/components/clock-digital/gen/interface/chandra/desktop/module-config/stub.mbt index c2d3da6..9bd3729 100644 --- a/components/clock-digital/gen/interface/chandra/desktop/module-config/stub.mbt +++ b/components/clock-digital/gen/interface/chandra/desktop/module-config/stub.mbt @@ -1,4 +1,4 @@ -///| The digital clock's right-click settings (time format, date line); the logic is in lib/clock. +///| The digital clock's right-click settings (time format, AM/PM, date line); the logic is in lib/clock. ///| pub fn config_items() -> Array[ConfigItem] { diff --git a/components/clock-digital12/gen/ffi.mbt b/components/clock-digital12/gen/ffi.mbt deleted file mode 100644 index 0ea9593..0000000 --- a/components/clock-digital12/gen/ffi.mbt +++ /dev/null @@ -1,100 +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 wasmExportInfo() -> Int { - @plasmoid.wasmExportInfo() -} - -///| -#doc(hidden) -pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { - @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) -} - -///| -#doc(hidden) -pub fn wasmExportConfigItems() -> Int { - @module-config.wasmExportConfigItems() -} - -///| -#doc(hidden) -pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportRenderPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { - @module-config.wasmExportSetConfig(p0, p1, p2, p3) -} - -///| -#doc(hidden) -pub fn wasmExportPopup() -> Int { - @plasmoid.wasmExportPopup() -} - -///| -#doc(hidden) -pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportInfoPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { - @plasmoid.wasmExportRender(p0, p1) -} - -///| -#doc(hidden) -pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportPopupPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportConfigItemsPostReturn(p0 : Int) -> Unit { - @module-config.wasmExportConfigItemsPostReturn(p0) -} - diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/README.md b/components/clock-digital12/gen/interface/chandra/desktop/module-config/README.md deleted file mode 100644 index 0123c3f..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Optional: a module's own settings. A module that exports this gets a "Module settings" entry in -its right-click menu, listing the items below; the shell draws the menu (the same for every -module), remembers each choice per module in state.edn (`:module-config`), and hands the saved -values back through `set-config` right after the module is loaded. A module without it simply -has no settings: the export is looked up by name, so older modules keep loading. \ No newline at end of file diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/ffi.mbt b/components/clock-digital12/gen/interface/chandra/desktop/module-config/ffi.mbt deleted file mode 100644 index 333ee9f..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/ffi.mbt +++ /dev/null @@ -1,114 +0,0 @@ -// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! - -///| -#doc(hidden) -pub fn wasmExportConfigItems() -> Int { - - let (result) : (Array[ConfigItem]) = config_items(); - let return_area = mbt_ffi_malloc(8) - - let address3 = mbt_ffi_malloc((result).length() * 32); - for index4 = 0; index4 < (result).length(); index4 = index4 + 1 { - let iter_elem : ConfigItem = (result)[(index4)] - let iter_base = address3 + (index4 * 32); - - let ptr = mbt_ffi_str2ptr((iter_elem).key) - mbt_ffi_store32((iter_base) + 4, (iter_elem).key.length()) - mbt_ffi_store32((iter_base) + 0, ptr) - - let ptr0 = mbt_ffi_str2ptr((iter_elem).label) - mbt_ffi_store32((iter_base) + 12, (iter_elem).label.length()) - mbt_ffi_store32((iter_base) + 8, ptr0) - - let address = mbt_ffi_malloc(((iter_elem).choices).length() * 8); - for index = 0; index < ((iter_elem).choices).length(); index = index + 1 { - let iter_elem : String = ((iter_elem).choices)[(index)] - let iter_base = address + (index * 8); - - let ptr1 = mbt_ffi_str2ptr(iter_elem) - mbt_ffi_store32((iter_base) + 4, iter_elem.length()) - mbt_ffi_store32((iter_base) + 0, ptr1) - - } - mbt_ffi_store32((iter_base) + 20, ((iter_elem).choices).length()) - mbt_ffi_store32((iter_base) + 16, address) - - let ptr2 = mbt_ffi_str2ptr((iter_elem).value) - mbt_ffi_store32((iter_base) + 28, (iter_elem).value.length()) - mbt_ffi_store32((iter_base) + 24, ptr2) - - } - mbt_ffi_store32((return_area) + 4, (result).length()) - mbt_ffi_store32((return_area) + 0, address3) - let ret = return_area - return ret - -} - -///| -#doc(hidden) -pub fn wasmExportConfigItemsPostReturn(p0 : Int) -> Unit { - - for index0 = 0; index0 < (mbt_ffi_load32((p0) + 4)); index0 = index0 + 1 { - let iter_base = (mbt_ffi_load32((p0) + 0)) + (index0 * 32) - mbt_ffi_free(mbt_ffi_load32((iter_base) + 0)) - mbt_ffi_free(mbt_ffi_load32((iter_base) + 8)) - - for index = 0; index < (mbt_ffi_load32((iter_base) + 20)); index = index + 1 { - let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index * 8) - mbt_ffi_free(mbt_ffi_load32((iter_base) + 0)) - - } - mbt_ffi_free(mbt_ffi_load32((iter_base) + 16)) - mbt_ffi_free(mbt_ffi_load32((iter_base) + 24)) - - } - mbt_ffi_free(mbt_ffi_load32((p0) + 0)) - -} - -///| -#doc(hidden) -pub fn wasmExportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { - - let result = mbt_ffi_ptr2str(p0, p1) - - let result0 = mbt_ffi_ptr2str(p2, p3) - - let (result1) : (Bool) = set_config(result, result0); - let ret = (if result1 { 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_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_load32(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load) - -///| -#owned(str) -extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = -#|(func (param i32) (result i32) local.get 0) - -///| -extern "wasm" fn mbt_ffi_free(position : Int) = -#|(func (param i32) local.get 0 call $moonbit.decref) - -///| -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) - diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/moon.pkg b/components/clock-digital12/gen/interface/chandra/desktop/module-config/moon.pkg deleted file mode 100644 index 827047e..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/moon.pkg +++ /dev/null @@ -1,5 +0,0 @@ -import { - "chandra/desktop/lib/clock" @logic, -} - -warnings = "-44" diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/pkg.generated.mbti b/components/clock-digital12/gen/interface/chandra/desktop/module-config/pkg.generated.mbti deleted file mode 100644 index 619f38e..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/pkg.generated.mbti +++ /dev/null @@ -1,21 +0,0 @@ -// Generated using `moon info`, DON'T EDIT IT -package "chandra/desktop/components/clock-digital12/gen/interface/chandra/desktop/module-config" - -// Values -pub fn config_items() -> Array[ConfigItem] - -pub fn set_config(String, String) -> Bool - -// Errors - -// Types and methods -pub(all) struct ConfigItem { - key : String - label : String - choices : Array[String] - value : String -} - -// Type aliases - -// Traits diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/stub.mbt b/components/clock-digital12/gen/interface/chandra/desktop/module-config/stub.mbt deleted file mode 100644 index 4685da3..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/stub.mbt +++ /dev/null @@ -1,16 +0,0 @@ -///| The digital clock's right-click settings (time format, AM/PM, date line); the logic is in lib/clock. - -///| -pub fn config_items() -> Array[ConfigItem] { - @logic.digital12_config.digital_items().map(e => { - key: e.key, - label: e.label, - choices: e.choices, - value: e.value, - }) -} - -///| -pub fn set_config(key : String, value : String) -> Bool { - @logic.digital12_config.set(key, value) -} diff --git a/components/clock-digital12/gen/interface/chandra/desktop/module-config/top.mbt b/components/clock-digital12/gen/interface/chandra/desktop/module-config/top.mbt deleted file mode 100644 index 4cea3df..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/module-config/top.mbt +++ /dev/null @@ -1,11 +0,0 @@ -// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! -///| -pub(all) struct ConfigItem { - key : String; label : String; choices : Array[String]; value : String -} -///| -declare pub fn config_items() -> Array[ConfigItem] -///| -/// Set `key` to `value` (unknown keys and values are ignored). True when the widget should redraw. -declare pub fn set_config(key : String, value : String) -> Bool - diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/README.md b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/README.md deleted file mode 100644 index 53ecf69..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/README.md +++ /dev/null @@ -1 +0,0 @@ -The widget (plasmoid) contract. \ No newline at end of file diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/ffi.mbt b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/ffi.mbt deleted file mode 100644 index b8f0a3f..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/ffi.mbt +++ /dev/null @@ -1,431 +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)) - - () - } - Image(payload6) => { - mbt_ffi_store8((iter_base) + 0, (7)) - mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x) - mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y) - mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int()) - mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int()) - mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int()) - - () - } - } - - } - 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 => () - 7 => () - _ => 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)) - - () - } - Image(payload8) => { - mbt_ffi_store8((iter_base) + 0, (7)) - mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x) - mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y) - mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int()) - mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int()) - mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int()) - - () - } - } - - } - 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 => () - 7 => () - _ => 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_free(position : Int) = -#|(func (param i32) local.get 0 call $moonbit.decref) - -///| -extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load) - -///| -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_store32(offset : Int, value : Int) = -#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store) - -///| -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) - diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/moon.pkg deleted file mode 100644 index 815a2a0..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/moon.pkg +++ /dev/null @@ -1,8 +0,0 @@ -import { - "chandra/desktop/interface/chandra/desktop/types" @types, - "chandra/desktop/interface/chandra/desktop/theme" @theme, - "chandra/desktop/interface/chandra/desktop/clock" @clock, - "chandra/desktop/lib/clock" @logic, -} - -warnings = "-44" diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti deleted file mode 100644 index 98bc546..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/pkg.generated.mbti +++ /dev/null @@ -1,42 +0,0 @@ -// Generated using `moon info`, DON'T EDIT IT -package "chandra/desktop/components/clock-digital12/gen/interface/chandra/desktop/plasmoid" - -import { - "chandra/desktop/interface/chandra/desktop/types", -} - -// Values -pub fn info() -> PlasmoidInfo - -pub fn on_event(Surface, @types.InputEvent) -> Bool - -pub fn popup() -> PopupSurface? - -pub fn render(@types.Size) -> Array[@types.DrawOp] - -// Errors - -// Types and methods -pub(all) struct PlasmoidInfo { - id : String - name : String - preferred : @types.Size - min_width : UInt32 - stretch : Bool -} - -pub(all) struct PopupSurface { - size : @types.Size - ops : Array[@types.DrawOp] -} - -pub(all) enum Surface { - WIDGET - POPUP -} -pub fn Surface::from(Int32) -> Self -pub fn Surface::ordinal(Self) -> Int32 - -// Type aliases - -// Traits diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/stub.mbt deleted file mode 100644 index 08e6fa5..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ /dev/null @@ -1,30 +0,0 @@ -///| Implementation of `chandra:desktop/plasmoid` for the 12-hour digital clock. -/// All logic lives in lib/clock; this file only adapts host capabilities. - -///| -pub fn info() -> PlasmoidInfo { - let (id, name, w, h, min_w) = @logic.digital12_info() - { - id, - name, - preferred: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, - min_width: min_w.reinterpret_as_uint(), - stretch: false, - } -} - -///| -pub fn render(size : @types.Size) -> Array[@types.DrawOp] { - let c = @logic.digital12_config - @logic.render_digital(size, @theme.get_tokens(), @clock.now(), hour12=c.hour12, show_date=c.show_date, ampm=c.ampm) -} - -///| -pub fn popup() -> PopupSurface? { - None -} - -///| -pub fn on_event(_target : Surface, _event : @types.InputEvent) -> Bool { - false -} diff --git a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/top.mbt b/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/top.mbt deleted file mode 100644 index 24d7d0e..0000000 --- a/components/clock-digital12/gen/interface/chandra/desktop/plasmoid/top.mbt +++ /dev/null @@ -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 - diff --git a/components/clock-digital12/gen/moon.pkg b/components/clock-digital12/gen/moon.pkg deleted file mode 100644 index 8357c9a..0000000 --- a/components/clock-digital12/gen/moon.pkg +++ /dev/null @@ -1,30 +0,0 @@ -import { - "chandra/desktop/components/clock-digital12/gen/interface/chandra/desktop/module-config" @module-config, - "chandra/desktop/components/clock-digital12/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", - "wasmExportConfigItems:chandra:desktop/module-config@0.1.0#config-items", - "wasmExportConfigItemsPostReturn:cabi_post_chandra:desktop/module-config@0.1.0#config-items", - "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", - "wasmExportSetConfig:chandra:desktop/module-config@0.1.0#set-config" - ], - }, - }, -) diff --git a/components/clock-digital12/gen/pkg.generated.mbti b/components/clock-digital12/gen/pkg.generated.mbti deleted file mode 100644 index bb771ef..0000000 --- a/components/clock-digital12/gen/pkg.generated.mbti +++ /dev/null @@ -1,13 +0,0 @@ -// Generated using `moon info`, DON'T EDIT IT -package "chandra/desktop/components/clock-digital12/gen" - -// Values -pub fn mbt_ffi_cabi_realloc(Int32, Int32, Int32, Int32) -> Int32 - -// Errors - -// Types and methods - -// Type aliases - -// Traits diff --git a/compositor/host/input_test.mbt b/compositor/host/input_test.mbt index 3b3e02a..8e7f0b5 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -370,7 +370,7 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui test "right-click a panel module to replace it in place, or remove it" { let comp = new_comp("swap") let before = comp.shell.slots() - let clock = rect_of(comp, "clock-digital12") + let clock = rect_of(comp, "clock-digital") assert_true(clock.w > 0) let find_row = fn(label : String) { let mut i = -1 @@ -396,7 +396,7 @@ test "right-click a panel module to replace it in place, or remove it" { assert_eq(comp.desired_cursor(), 4U) click_at(comp, ix, iy, 11U) assert_true(!comp.shell.menu_open) - assert_eq(comp.shell.slot_of("clock-digital12"), "") + assert_eq(comp.shell.slot_of("clock-digital"), "") let after = comp.shell.slots() assert_eq(after.length(), before.length()) assert_eq(after[after.length() - 1], comp.shell.slot_of("clock-binary")) // same place in the panel @@ -417,6 +417,8 @@ test "right-click a panel module to replace it in place, or remove it" { ///| test "right-click a module for its own settings: they apply at once and are remembered" { let comp = new_comp("modcfg") + // A fresh instance next to nothing else: drop the default panel's clock first. + assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital"))) assert_true(comp.shell.load_module("clock-digital")) ignore(comp.compose_frame()) let clock = rect_of(comp, "clock-digital") @@ -441,23 +443,25 @@ test "right-click a module for its own settings: they apply at once and are reme } t } - assert_false(time_text().has_suffix("M")) // 24-hour by default + assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) // 12-hour by default click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U) assert_true(comp.shell.menu_open) assert_eq(comp.shell.menu_rows[0].label, "Module settings...") assert_eq(comp.shell.menu_rows[1].label, "System settings...") click_at(comp, comp.shell.menu_rect.x + 60, row_y(0), 10U) - // The module's own menu: a "Time format" heading, its two choices, and the "Show date" switch. + // The module's own menu: a "Time format" heading, its two choices, then the switches. assert_true(comp.shell.menu_open) assert_eq(comp.shell.menu_title, "Digital Clock settings") - let h12 = find_row("12-hour") - assert_true(h12 > 0 && find_row("Time format") == h12 - 2) - assert_true(comp.shell.menu_rows[h12 - 1].ticked) // 24-hour - click_at(comp, comp.shell.menu_rect.x + 60, row_y(h12), 20U) - assert_true(comp.shell.menu_open) // stays open, now ticking 12-hour - assert_true(comp.shell.menu_rows[find_row("12-hour")].ticked) - assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) - assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("12-hour")) + let h24 = find_row("24-hour") + assert_true(h24 > 0 && find_row("Time format") == h24 - 1) + assert_true(comp.shell.menu_rows[h24 + 1].ticked) // 12-hour + assert_true(find_row("Show AM/PM") >= 0) + click_at(comp, comp.shell.menu_rect.x + 60, row_y(h24), 20U) + assert_true(comp.shell.menu_open) // stays open, now ticking 24-hour + assert_true(comp.shell.menu_rows[find_row("24-hour")].ticked) + assert_eq(find_row("Show AM/PM"), -1) // only offered in 12-hour mode + assert_false(time_text().has_suffix("M")) + assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("24-hour")) // A heading does nothing; Escape closes. click_at(comp, comp.shell.menu_rect.x + 60, row_y(find_row("Time format")), 30U) assert_true(comp.shell.menu_open) @@ -467,7 +471,7 @@ test "right-click a module for its own settings: they apply at once and are reme assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital"))) assert_true(comp.shell.load_module("clock-digital")) ignore(comp.compose_frame()) - assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) + assert_false(time_text().has_suffix("M")) } ///| @@ -529,6 +533,50 @@ test "the panel is saved to panel.edn and restored" { } } +///| +test "a panel saved with the old 12-hour clock gets the Digital Clock with the same settings" { + if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" { + let dir = @sys.getenv("XDG_CONFIG_HOME") + "/chandra" + assert_true(@sys.mkdir_p(dir)) + let state0 = @sys.read_file_bytes(dir + "/state.edn") + let write = fn(name : String, text : String) { + ignore(@sys.write_file_bytes(dir + "/" + name, @utf8.encode(text))) + } + let boot = fn() { + let s = @shell.DesktopShell::new("x") + s.persist = true + s.set_output(@scene.ThemeTokens::moon_night(), 1280, 720) + ignore(s.slots()) + s + } + // The default panel's 12-hour clock, its date line switched off. + write("panel.edn", "{:panel [\"tasks\" \"clock-digital12\" \"logout\"]}\n") + write("state.edn", "{:module-config {\"clock-digital12\" {\"date\" \"off\"} \"clock-digital\" {\"format\" \"24-hour\"}}}\n") + let a = boot() + assert_true(a.slot_of("clock-digital") != "") + assert_eq(a.slot_of("clock-digital12"), a.slot_of("clock-digital")) // the old id is an alias + assert_eq(a.module_setting("clock-digital", "format"), Some("12-hour")) + assert_eq(a.module_setting("clock-digital", "date"), Some("off")) + assert_eq(a.module_setting("clock-digital12", "date"), None) + let panel = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/panel.edn")) + assert_true(panel.contains("\"clock-digital\"") && !panel.contains("clock-digital12")) + assert_true(panel.contains(":version 2")) + // Only once: a format chosen afterwards sticks across restarts. + a.set_module_setting(a.slot_of("clock-digital"), "format", "24-hour") + assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour")) + // A panel that had the (then 24-hour) Digital Clock keeps it in 24-hour mode. + write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]}\n") + write("state.edn", "{}\n") + assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour")) + // A panel saved since then is left alone. + write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]\n :version 2}\n") + write("state.edn", "{}\n") + assert_eq(boot().module_setting("clock-digital", "format"), None) + write("panel.edn", "") + ignore(@sys.write_file_bytes(dir + "/state.edn", state0)) + } +} + ///| test "the wasm picker opens the settings module's Panel tab, which loads and unloads modules" { let comp = new_comp("manager") @@ -591,7 +639,7 @@ test "dragging a panel module reorders it" { let comp = new_comp("wdrag") let order0 = comp.shell.slots() let moon = rect_of(comp, "moon-disc") - let clock = rect_of(comp, "clock-digital12") + let clock = rect_of(comp, "clock-digital") assert_true(moon.x < clock.x) let cy = (clock.y + clock.h / 2).to_double() comp.handle_input(@nested.InputEvent::PointerMove((clock.x + clock.w / 2).to_double(), cy), 1U) @@ -605,8 +653,8 @@ test "dragging a panel module reorders it" { let order1 = comp.shell.slots() assert_eq(order1.length(), order0.length()) assert_true(order1 != order0) - assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital12")) - assert_true(rect_of(comp, "clock-digital12").x < rect_of(comp, "moon-disc").x) + assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital")) + assert_true(rect_of(comp, "clock-digital").x < rect_of(comp, "moon-disc").x) assert_true(comp.desired_cursor() != 17U) } diff --git a/compositor/host/inspector_test.mbt b/compositor/host/inspector_test.mbt index 2038670..e27e2d2 100644 --- a/compositor/host/inspector_test.mbt +++ b/compositor/host/inspector_test.mbt @@ -42,9 +42,9 @@ test "inspector shows the WIT interface of the hovered component" { ignore(@sys.write_file_bytes("_build/inspector_launcher.png", png)) // Clock, panel, window title bar and desktop resolve to their own components. - let (cx, cy) = center_of(comp, "clock-digital12") + let (cx, cy) = center_of(comp, "clock-digital") comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 5U) - assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital12")) + assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital")) comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 6U) assert_eq(comp.shell.hover_id, "desktop") diff --git a/compositor/shell/module_config.mbt b/compositor/shell/module_config.mbt index 7d276e2..9eb4365 100644 --- a/compositor/shell/module_config.mbt +++ b/compositor/shell/module_config.mbt @@ -87,6 +87,11 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key : self.module_cfg.set(id, m) } } + self.write_module_cfg() +} + +///| Write `:module-config` to state.edn, keeping every other key (a no-op without `persist`). +fn DesktopShell::write_module_cfg(self : DesktopShell) -> Unit { if !self.persist { return } @@ -107,6 +112,35 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key : write_state_file(entries) } +///| A panel saved before the 12-hour clock (clock-digital12) became part of the Digital Clock +/// (panel.edn version 1, `saved` its module list as written): keep each clock as it was. The +/// 12-hour clock's settings become the Digital Clock's, starting from 12-hour mode; a panel that +/// had only the Digital Clock keeps it in 24-hour mode (its old default) unless a format was chosen. +/// A panel with both now has two Digital Clocks sharing the Digital Clock's settings. +fn DesktopShell::migrate_module_cfg(self : DesktopShell, saved : Array[String]) -> Unit { + self.read_module_cfg() + let had12 = saved.contains("clock-digital12") + let had24 = saved.contains("clock-digital") + let old12 = self.module_cfg.get("clock-digital12") + if had12 && !had24 { + let m : Map[String, String] = { "format": "12-hour" } + match old12 { + Some(o) => for k, v in o { m.set(k, v) } + None => () + } + self.module_cfg.set("clock-digital", m) + } else if had24 && !had12 { + match self.module_cfg.get("clock-digital") { + Some(m) => if !m.contains("format") { m.set("format", "24-hour") } + None => self.module_cfg.set("clock-digital", { "format": "24-hour" }) + } + } + if (had12 && !had24) || (had24 && !had12) || old12 is Some(_) { + self.module_cfg.remove("clock-digital12") + self.write_module_cfg() + } +} + ///| The setting `key` of module `id` as last chosen, if any. pub fn DesktopShell::module_setting(self : DesktopShell, id : String, key : String) -> String? { self.read_module_cfg() diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index e6709c0..81079fd 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -13,7 +13,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", "network", "clock-digital12", "screenshot", + "launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot", "session-settings", "logout", ] @@ -25,7 +25,7 @@ fn fresh_panel(has_battery : Bool) -> Array[String] { } let out : Array[String] = [] for m in default_panel { - if m == "clock-digital12" { + if m == "clock-digital" { out.push("battery") } out.push(m) @@ -37,7 +37,21 @@ fn fresh_panel(has_battery : Bool) -> Array[String] { test "a fresh panel gets the battery module only on a machine with a battery" { assert_false(fresh_panel(false).contains("battery")) let p = fresh_panel(true) - assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital12").unwrap()) + assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital").unwrap()) +} + +///| Modules folded into another one: old id -> the module that took over. The old id still +/// works everywhere a module is named (saved panels, load_module), it is just never listed: +/// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker. +/// - clock-digital12, the 12-hour clock, is the Digital Clock, which now starts in 12-hour mode. +let retired_modules : Map[String, String] = { "clock-digital12": "clock-digital" } + +///| The id a module goes by now ("clock-digital12" -> "clock-digital"). +fn current_module_id(id : String) -> String { + match retired_modules.get(id) { + Some(n) => n + None => id + } } ///| The module whose popup holds the wasm picker (its Modules tab). @@ -111,7 +125,7 @@ fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit { for dir in module_dirs() { for f in @wasm.list_wasm_files(dir) { let id = stem(f) - if !seen.contains(id) { + if !seen.contains(id) && !retired_modules.contains(id) { seen.set(id, true) self.catalog.push({ id, path: dir + "/" + f, name: "" }) } @@ -145,6 +159,7 @@ fn DesktopShell::name_catalog(self : DesktopShell) -> Unit { ///| Catalog entry for module id `id`. fn DesktopShell::find_module(self : DesktopShell, id : String) -> CatalogEntry? { + let id = current_module_id(id) for e in self.catalog { if e.id == id { return Some(e) @@ -199,7 +214,8 @@ fn wall_secs() -> Int { ///| Panels saved before the wallpaper chooser and the module manager moved into the settings /// module list "wallpaper" or "module-manager": the settings module takes the first one's place -/// (a panel that already has it just drops them). +/// (a panel that already has it just drops them). Retired modules (clock-digital12) become +/// the module that replaced them. fn migrate_panel(entries : Array[String]) -> Array[String] { let has_settings = entries.contains("session-settings") let out : Array[String] = [] @@ -209,7 +225,7 @@ fn migrate_panel(entries : Array[String]) -> Array[String] { out.push("session-settings") } } else { - out.push(e) + out.push(current_module_id(e)) } } out @@ -223,6 +239,13 @@ test "a saved panel's wallpaper button becomes the settings module" { assert_eq(migrate_panel(["clock"]), ["clock"]) } +///| +test "a saved panel's 12-hour clock becomes the digital clock" { + assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "logout"]) + assert_eq(current_module_id("clock-digital12"), "clock-digital") + assert_eq(current_module_id("clock-binary"), "clock-binary") +} + ///| 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 { @@ -230,10 +253,20 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit { } self.booted = true self.scan_catalog() - let entries = match self.load_panel_config() { + let saved = self.load_panel_config() + let entries = match saved { Some(e) => migrate_panel(e) None => fresh_panel(read_battery().state != 0) } + match saved { + Some(old) if saved_panel_version() < panel_version => { + // Once, before the modules load so they pick up the moved settings; then the file is + // rewritten with the new names and version (also keeping modules that fail to load). + self.migrate_module_cfg(old) + write_panel_file(entries) + } + _ => () + } for e in entries { let path = if e.has_prefix("/") { e @@ -380,6 +413,7 @@ pub fn DesktopShell::slot_module(self : DesktopShell, slot : String) -> String { ///| Slot of the first loaded instance of module `id` ("" if none). pub fn DesktopShell::slot_of(self : DesktopShell, id : String) -> String { self.ensure_booted() + let id = current_module_id(id) for w in self.widgets { if w.module_id == id { return w.slot @@ -1007,30 +1041,74 @@ fn read_config_file(name : String) -> Bytes { } ///| Write the loaded modules, in panel order, as EDN: -/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"]} +/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"] :version 2} /// (catalog modules by name, others by path). A no-op unless `persist` is on. pub fn DesktopShell::save_panel_config(self : DesktopShell) -> Unit { if !self.persist || !self.booted { return } + write_panel_file(self.widgets.map(w => w.module_id)) +} + +///| panel.edn's format version (`:version`; files without one are 1). 2: written after the +/// 12-hour clock (clock-digital12) became part of the Digital Clock, whose default went from +/// 24-hour to 12-hour; an older file gets its clock settings moved over once (migrate_module_cfg). +let panel_version : Int = 2 + +///| +fn write_panel_file(names : Array[String]) -> Unit { let sb = StringBuilder::new() sb.write_string(";; Chandra panel: the wasm modules loaded into it, in order\n") sb.write_string("{:panel [") let mut first = true - for w in self.widgets { + for n in names { if !first { sb.write_string("\n ") } first = false - sb.write_string("\"" + w.module_id + "\"") + sb.write_string("\"" + n + "\"") } - sb.write_string("]}\n") + sb.write_string("]\n :version " + panel_version.to_string() + "}\n") let dir = panel_config_dir() if @sys.mkdir_p(dir) { ignore(@sys.write_file_bytes(dir + "/panel.edn", @utf8.encode(sb.to_string()))) } } +///| The `:version` of the saved panel.edn (1 when it has none). +fn saved_panel_version() -> Int { + let text = @utf8.decode_lossy(read_config_file("panel.edn")) + panel_text_version(text) +} + +///| +fn panel_text_version(text : String) -> Int { + match text.find(":version") { + None => 1 + Some(i) => { + let mut v = 0 + let mut seen = false + for j = i + 8; j < text.length(); j = j + 1 { + let c = text[j] + if c >= '0' && c <= '9' { + v = v * 10 + (c.to_int() - '0'.to_int()) + seen = true + } else if seen || (c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != ',') { + break + } + } + if seen { v } else { 1 } + } + } +} + +///| +test "panel.edn version" { + assert_eq(panel_text_version("{:panel [\"clock-digital12\"]}"), 1) + assert_eq(panel_text_version("{:panel [\"clock-digital\"]\n :version 2}\n"), 2) + assert_eq(panel_text_version("{:version 12 :panel []}"), 12) +} + ///| The module list saved in panel.edn; None when persistence is off or there is no saved panel. fn DesktopShell::load_panel_config(self : DesktopShell) -> Array[String]? { if !self.persist { diff --git a/compositor/wasm/wasm_test.mbt b/compositor/wasm/wasm_test.mbt index ed81ac7..6983275 100644 --- a/compositor/wasm/wasm_test.mbt +++ b/compositor/wasm/wasm_test.mbt @@ -97,13 +97,15 @@ fn drain() -> Array[HostRequest] { test "a module's own settings (module-config) are listed and set through wasmer" { let p = load_module("clock-digital") let items = p.config_items() - assert_eq(items.length(), 2) - assert_eq(items[0], { key: "format", label: "Time format", choices: ["24-hour", "12-hour"], value: "24-hour" }) + // 12-hour by default: Time format, Show AM/PM, Show date. + assert_eq(items.length(), 3) + assert_eq(items[0], { key: "format", label: "Time format", choices: ["24-hour", "12-hour"], value: "12-hour" }) assert_eq(items[1].choices.length(), 0) // an on/off switch - assert_true(p.set_config("format", "12-hour")) - assert_false(p.set_config("format", "12-hour")) // unchanged + assert_true(p.set_config("format", "24-hour")) + assert_false(p.set_config("format", "24-hour")) // unchanged assert_false(p.set_config("bogus", "x")) - assert_eq(p.config_items()[0].value, "12-hour") + assert_eq(p.config_items()[0].value, "24-hour") + assert_eq(p.config_items().length(), 2) // no AM/PM switch in 24-hour mode let mut ampm = false for op in p.render(p.pref_w, p.pref_h, test_tokens()) { match op { @@ -111,7 +113,7 @@ test "a module's own settings (module-config) are listed and set through wasmer" _ => () } } - assert_true(ampm) + assert_false(ampm) p.unload() // Modules without the export have no settings, and setting one is a no-op. let l = load_module("layout") @@ -287,12 +289,12 @@ test "interface explorer module toggles through the inspector capability" { } ///| -test "moon and 12-hour clock modules render from the clock capability" { +test "moon and digital clock modules render from the clock capability" { let m = load_module("moon-disc") assert_true(m.render(36, 36, test_tokens()).length() > 3) m.unload() - let c = load_module("clock-digital12") + let c = load_module("clock-digital") let ts = texts_of(c.render(120, 36, test_tokens())) - assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) + assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) // 12-hour by default c.unload() } diff --git a/lib/clock/clock.mbt b/lib/clock/clock.mbt index 6a2eaa6..30e45f3 100644 --- a/lib/clock/clock.mbt +++ b/lib/clock/clock.mbt @@ -6,12 +6,6 @@ pub fn digital_info() -> (String, String, Int, Int, Int) { ("org.chandra.clock.digital", "Digital Clock", 120, 36, 80) } -///| The 12-hour digital clock (clock-digital12, the default panel's clock): same rendering -/// and settings as the digital clock, but it starts in 12-hour mode with AM/PM. -pub fn digital12_info() -> (String, String, Int, Int, Int) { - ("org.chandra.clock.digital12", "Digital Clock (12-hour)", 120, 36, 80) -} - ///| pub fn render_digital( size : @types.Size, @@ -270,11 +264,10 @@ test "clock settings" { assert_eq(bin.length() < 30, true) // two columns fewer } -///| The digital clock module's settings (one module instance per wasm instance). -pub let digital_config : ClockConfig = ClockConfig::new() - -///| The 12-hour digital clock module's settings: starts in 12-hour mode with AM/PM. -pub let digital12_config : ClockConfig = ClockConfig::new(hour12=true) +///| The digital clock module's settings (one module instance per wasm instance): it starts in +/// 12-hour mode with AM/PM; "Time format" in its right-click settings switches to 24-hour. +/// (It replaced the separate 12-hour clock module, clock-digital12.) +pub let digital_config : ClockConfig = ClockConfig::new(hour12=true) ///| The binary clock module's settings. pub let binary_config : ClockConfig = ClockConfig::new() diff --git a/lib/clock/pkg.generated.mbti b/lib/clock/pkg.generated.mbti index 342f2b8..e2a58cb 100644 --- a/lib/clock/pkg.generated.mbti +++ b/lib/clock/pkg.generated.mbti @@ -12,10 +12,6 @@ pub let binary_config : ClockConfig pub fn binary_info() -> (String, String, Int32, Int32, Int32) -pub let digital12_config : ClockConfig - -pub fn digital12_info() -> (String, String, Int32, Int32, Int32) - pub let digital_config : ClockConfig pub fn digital_info() -> (String, String, Int32, Int32, Int32) diff --git a/scripts/components.txt b/scripts/components.txt index 2a76103..61b0338 100644 --- a/scripts/components.txt +++ b/scripts/components.txt @@ -1,6 +1,5 @@ # clock-digital clock-widget -clock-digital12 clock-widget clock-binary clock-widget launcher launcher-widget dock launcher-widget