diff --git a/components/module-manager/gen/ffi.mbt b/components/module-manager/gen/ffi.mbt deleted file mode 100644 index de56926..0000000 --- a/components/module-manager/gen/ffi.mbt +++ /dev/null @@ -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 wasmExportInfo() -> Int { - @plasmoid.wasmExportInfo() -} - -///| -#doc(hidden) -pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportRenderPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportPopup() -> Int { - @plasmoid.wasmExportPopup() -} - -///| -#doc(hidden) -pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { - @plasmoid.wasmExportRender(p0, p1) -} - -///| -#doc(hidden) -pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportInfoPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { - @plasmoid.wasmExportPopupPostReturn(p0) -} - -///| -#doc(hidden) -pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { - @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) -} - diff --git a/components/module-manager/gen/interface/chandra/desktop/plasmoid/README.md b/components/module-manager/gen/interface/chandra/desktop/plasmoid/README.md deleted file mode 100644 index 53ecf69..0000000 --- a/components/module-manager/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/module-manager/gen/interface/chandra/desktop/plasmoid/ffi.mbt b/components/module-manager/gen/interface/chandra/desktop/plasmoid/ffi.mbt deleted file mode 100644 index ce350f1..0000000 --- a/components/module-manager/gen/interface/chandra/desktop/plasmoid/ffi.mbt +++ /dev/null @@ -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_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) - -///| -#owned(str) -extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = -#|(func (param i32) (result i32) local.get 0) - -///| -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_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) - -///| -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_free(position : Int) = -#|(func (param i32) local.get 0 call $moonbit.decref) - diff --git a/components/module-manager/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/module-manager/gen/interface/chandra/desktop/plasmoid/moon.pkg deleted file mode 100644 index 487aa1d..0000000 --- a/components/module-manager/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/modules" @modules, - "chandra/desktop/lib/ui" @ui, -} - -warnings = "-44" diff --git a/components/module-manager/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/module-manager/gen/interface/chandra/desktop/plasmoid/stub.mbt deleted file mode 100644 index 903ead3..0000000 --- a/components/module-manager/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ /dev/null @@ -1,186 +0,0 @@ -///| Implementation of `chandra:desktop/plasmoid` for the module manager: a panel -/// button whose popup lists the loaded instances (click to unload), every module found -/// on the search path (click to load another instance) and a "Browse..." row. - -///| -let open_ : Ref[Bool] = Ref::new(false) - -///| -let hover : Ref[Int] = Ref::new(-1) - -///| Layout, shared with the host tests: header 24, rows 28, 4px margin. -let margin : Int = 4 - -///| -let header_h : Int = 24 - -///| -let row_h : Int = 28 - -///| -let popup_w : Int = 300 - -///| -pub fn info() -> PlasmoidInfo { - { - id: "org.chandra.module-manager", - name: "Module Manager", - preferred: { w: 110, h: 34 }, - min_width: 60, - 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 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 } - [ - @ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=t.radius.reinterpret_as_int()), - @ui.text(w / 2, h / 2, "Modules", t.font_size.reinterpret_as_int(), fg, align=CENTER, bold=true), - ] -} - -///| Total popup height for `l` loaded and `a` available rows. -fn popup_h(l : Int, a : Int) -> Int { - margin + header_h + l * row_h + header_h + a * row_h + row_h + margin -} - -///| -pub fn popup() -> PopupSurface? { - if !open_.val { - return None - } - let t = @theme.get_tokens() - let p = t.palette - let fs = t.font_size.reinterpret_as_int() - let r = t.radius.reinterpret_as_int() - let loaded = @modules.loaded() - let avail = @modules.available() - let w = popup_w - let h = popup_h(loaded.length(), avail.length()) - let ops = [ - @ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r + 4), - @ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, radius=r + 4), - ] - let mut y = margin - ops.push(@ui.text(14, y + header_h / 2, "Loaded (click to unload)", fs - 2, p.foreground_muted, bold=true)) - y += header_h - let mut row = 0 - for inst in loaded { - row_bg(ops, row, y, w, r, p) - let fg = if row == hover.val { p.accent_foreground } else { p.foreground } - ops.push(@ui.text(14, y + row_h / 2, inst.name, fs, fg)) - ops.push(@ui.text(w - 14, y + row_h / 2, "x", fs, fg, align=RIGHT, bold=true)) - y += row_h - row += 1 - } - ops.push(@ui.text(14, y + header_h / 2, "Available (click to load)", fs - 2, p.foreground_muted, bold=true)) - y += header_h - for m in avail { - row_bg(ops, row, y, w, r, p) - let fg = if row == hover.val { p.accent_foreground } else { p.foreground } - ops.push(@ui.text(14, y + row_h / 2, m.name, fs, fg)) - if m.loaded > 0U { - ops.push(@ui.text(w - 14, y + row_h / 2, "x" + m.loaded.to_string(), fs - 2, fg, align=RIGHT)) - } - y += row_h - row += 1 - } - row_bg(ops, row, y, w, r, p) - let fg = if row == hover.val { p.accent_foreground } else { p.foreground } - ops.push(@ui.text(14, y + row_h / 2, "Browse...", fs, fg, bold=true)) - Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops }) -} - -///| -fn row_bg( - ops : Array[@types.DrawOp], - row : Int, - y : Int, - w : Int, - r : Int, - p : @theme.Palette, -) -> Unit { - if row == hover.val { - ops.push(@ui.fill_rect(@ui.rect(6, y, w - 12, row_h - 2), p.accent, radius=r)) - } -} - -///| Row index under popup-local `pt` (loaded rows, then available rows, then Browse), or -1. -fn row_at(pt : @types.Point, l : Int, a : Int) -> Int { - if pt.x < 6 || pt.x >= popup_w - 6 { - return -1 - } - let mut y = pt.y - margin - header_h - if y >= 0 && y < l * row_h { - return y / row_h - } - y -= l * row_h + header_h - if y >= 0 && y < (a + 1) * row_h { - return l + y / row_h - } - -1 -} - -///| -pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { - match (target, event) { - (WIDGET, PointerDown(_)) => { - open_.val = !open_.val - hover.val = -1 - true - } - (POPUP, PointerMove(pt)) => { - let i = row_at(pt, @modules.loaded().length(), @modules.available().length()) - if i != hover.val { - hover.val = i - true - } else { - false - } - } - (POPUP, PointerLeave) => - if hover.val != -1 { - hover.val = -1 - true - } else { - false - } - (POPUP, PointerDown(pt)) => { - let loaded = @modules.loaded() - let avail = @modules.available() - let i = row_at(pt, loaded.length(), avail.length()) - if i >= 0 { - if i < loaded.length() { - @modules.unload_instance(loaded[i].slot) - } else if i - loaded.length() < avail.length() { - @modules.load_module(avail[i - loaded.length()].path) - } else { - @modules.browse() - } - hover.val = -1 - } - true - } - (_, FocusLost) => - if open_.val { - open_.val = false - hover.val = -1 - true - } else { - false - } - (_, KeyDown("Escape")) => - if open_.val { - open_.val = false - true - } else { - false - } - _ => false - } -} diff --git a/components/module-manager/gen/interface/chandra/desktop/plasmoid/top.mbt b/components/module-manager/gen/interface/chandra/desktop/plasmoid/top.mbt deleted file mode 100644 index 24d7d0e..0000000 --- a/components/module-manager/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/module-manager/gen/moon.pkg b/components/module-manager/gen/moon.pkg deleted file mode 100644 index d743f9d..0000000 --- a/components/module-manager/gen/moon.pkg +++ /dev/null @@ -1,26 +0,0 @@ -import { - "chandra/desktop/components/module-manager/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" - ], - }, - }, -) diff --git a/components/session-settings/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/session-settings/gen/interface/chandra/desktop/plasmoid/moon.pkg index 184c507..e82142b 100644 --- a/components/session-settings/gen/interface/chandra/desktop/plasmoid/moon.pkg +++ b/components/session-settings/gen/interface/chandra/desktop/plasmoid/moon.pkg @@ -3,6 +3,7 @@ import { "chandra/desktop/interface/chandra/desktop/theme" @theme, "chandra/desktop/interface/chandra/desktop/session-settings" @settings, "chandra/desktop/interface/chandra/desktop/wallpaper" @wallpaper, + "chandra/desktop/interface/chandra/desktop/modules" @modules, "chandra/desktop/lib/ui" @ui, } diff --git a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt index 557bc02..2127863 100644 --- a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -1,84 +1,144 @@ -///| Implementation of `chandra:desktop/plasmoid` for the settings module. The panel button opens a -/// popup with two sections: the session settings the shell offers (`session-settings.settings`: -/// reopen windows at login, remember window positions, dark mode), each with an on/off switch, and -/// the wallpapers the shell can draw (`wallpaper.wallpapers`), the current one ticked. Clicking a -/// row flips the switch or shows that wallpaper at once, and the list stays open to compare; Up and -/// Down move the highlight, Enter or Space acts on it, Escape or a click elsewhere closes. The shell -/// remembers every choice in state.edn. +///| Implementation of `chandra:desktop/plasmoid` for the settings module: the panel's "Settings" +/// button. Its popup has three tabs, split by where things live: +/// +/// - Session: the session settings the shell offers (`session-settings.settings`: reopen windows +/// at login, remember window positions, dark mode), each with an on/off switch; +/// - Desktop: what is drawn on the desktop. Today that is the wallpaper (`wallpaper.wallpapers`, +/// the current one ticked); modules can't be placed on the desktop yet, so when they can they +/// get their own section here; +/// - Panel: the modules in the panel (click to remove), every module found on the search path +/// (click to add another instance) and "Browse..." (`modules`). The panel menu's "Modules..." +/// opens this tab. +/// +/// Clicking a row acts at once and the popup stays open. Up/Down move the highlight, Left/Right +/// (or 1, 2, 3) switch tabs, Enter or Space acts on the highlighted row, Escape or a click +/// elsewhere closes. The shell remembers settings and wallpaper in state.edn, the panel in +/// panel.edn. -///| Popup geometry: a column of rows with a margin around them. -let popup_w : Int = 290 - -///| -let row_h : Int = 30 +///| Popup geometry: the tab bar, then a column of rows, with a margin around them. +let popup_w : Int = 300 ///| let margin : Int = 6 +///| +let tab_h : Int = 30 + +///| Top of the first row (below the tab bar). +let rows_top : Int = 40 + +///| +let row_h : Int = 28 + ///| The switch at the right end of a setting row. let switch_w : Int = 34 ///| let switch_h : Int = 18 -///| A popup row: a session setting, the "Wallpaper" heading, or a wallpaper. +///| +let tab_names : Array[String] = ["Session", "Desktop", "Panel"] + +///| A popup row. enum Row { - Setting(Int) Heading(String) - Wallpaper(Int) + Setting(Int, String) + Wallpaper(Int, String) + /// A loaded panel instance: slot and name. + Loaded(String, String) + /// A module on the search path: path, name and how many instances are loaded. + Available(String, String, UInt) + Browse } -///| Whether the popup is open, and which row is highlighted (-1: none). +///| Whether the popup is open, its tab, and which row is highlighted (-1: none). let open_ : Ref[Bool] = { val: false } +///| +let tab : Ref[Int] = { val: 0 } + ///| let hover : Ref[Int] = { val: -1 } -///| The names and rows, read when the popup opens (they are fixed while it is open). -let settings : Ref[Array[String]] = { val: [] } - -///| -let wallpapers : Ref[Array[String]] = { val: [] } - -///| -let rows : Ref[Array[Row]] = { val: [] } - -///| -fn popup_h() -> Int { - margin * 2 + rows.val.length() * row_h +///| The rows of the current tab, read live from the host (loading a module changes them). +fn rows() -> Array[Row] { + let rs : Array[Row] = [] + match tab.val { + 0 => { + let names = @settings.settings() + for i = 0; i < names.length(); i = i + 1 { + rs.push(Setting(i, names[i])) + } + } + 1 => { + rs.push(Heading("Wallpaper")) + let names = @wallpaper.wallpapers() + for i = 0; i < names.length(); i = i + 1 { + rs.push(Wallpaper(i, names[i])) + } + } + _ => { + rs.push(Heading("In the panel (click to remove)")) + for inst in @modules.loaded() { + rs.push(Loaded(inst.slot, inst.name)) + } + rs.push(Heading("Add to the panel")) + for m in @modules.available() { + rs.push(Available(m.path, m.name, m.loaded)) + } + rs.push(Browse) + } + } + rs } -///| Whether row `i` can be highlighted and acted on (headings can't). -fn active(i : Int) -> Bool { - i >= 0 && i < rows.val.length() && !(rows.val[i] is Heading(_)) +///| Whether row `i` of `rs` can be highlighted and acted on (headings can't). +fn active(rs : Array[Row], i : Int) -> Bool { + i >= 0 && i < rs.length() && !(rs[i] is Heading(_)) +} + +///| First active row of `rs`, or -1. +fn first_active(rs : Array[Row]) -> Int { + for i = 0; i < rs.length(); i = i + 1 { + if active(rs, i) { + return i + } + } + -1 +} + +///| Tab under a popup-local point, or -1. +fn tab_at(x : Int, y : Int) -> Int { + if y < margin || y >= margin + tab_h || x < margin || x >= popup_w - margin { + return -1 + } + let i = (x - margin) / tab_w() + if i < tab_names.length() { i } else { -1 } +} + +///| +fn tab_w() -> Int { + (popup_w - 2 * margin) / tab_names.length() } ///| Row under a popup-local point, or -1 (headings count as none). -fn row_at(x : Int, y : Int) -> Int { - if x < margin || x >= popup_w - margin || y < margin { +fn row_at(rs : Array[Row], x : Int, y : Int) -> Int { + if x < margin || x >= popup_w - margin || y < rows_top { return -1 } - let i = (y - margin) / row_h - if active(i) { i } else { -1 } + let i = (y - rows_top) / row_h + if active(rs, i) { i } else { -1 } } ///| -fn open() -> Unit { - settings.val = @settings.settings() - wallpapers.val = @wallpaper.wallpapers() - let rs : Array[Row] = [] - for i = 0; i < settings.val.length(); i = i + 1 { - rs.push(Setting(i)) - } - if wallpapers.val.length() > 0 { - rs.push(Heading("Wallpaper")) - for i = 0; i < wallpapers.val.length(); i = i + 1 { - rs.push(Wallpaper(i)) - } - } - rows.val = rs - open_.val = true - hover.val = if active(0) { 0 } else { -1 } +fn popup_h(n : Int) -> Int { + rows_top + n * row_h + margin +} + +///| +fn set_tab(i : Int) -> Unit { + tab.val = i + hover.val = first_active(rows()) } ///| @@ -87,26 +147,30 @@ fn close() -> Unit { hover.val = -1 } -///| Act on row `i`: flip its setting or show its wallpaper (ignored for headings or none). -fn act(i : Int) -> Unit { - if !active(i) { +///| Act on row `i`: flip a setting, show a wallpaper, unload or load a module, or browse. +fn act(rs : Array[Row], i : Int) -> Unit { + if !active(rs, i) { return } - match rows.val[i] { - Setting(k) => { + match rs[i] { + Setting(k, _) => { let idx = k.reinterpret_as_uint() @settings.set_setting(idx, !@settings.is_on(idx)) } - Wallpaper(k) => @wallpaper.set_wallpaper(k.reinterpret_as_uint()) + Wallpaper(k, _) => @wallpaper.set_wallpaper(k.reinterpret_as_uint()) + Loaded(slot, _) => @modules.unload_instance(slot) + Available(path, _, _) => @modules.load_module(path) + Browse => @modules.browse() Heading(_) => () } } ///| Move the highlight by `step` rows, skipping headings; stays put at either end. fn move_hover(step : Int) -> Unit { + let rs = rows() let mut i = hover.val + step - while i >= 0 && i < rows.val.length() { - if active(i) { + while i >= 0 && i < rs.length() { + if active(rs, i) { hover.val = i return } @@ -154,54 +218,82 @@ pub fn popup() -> PopupSurface? { return None } let t = @theme.get_tokens() + let p = t.palette + let rs = rows() let w = popup_w - let h = popup_h() + let h = popup_h(rs.length()) let r = t.radius.reinterpret_as_int() let fs = t.font_size.reinterpret_as_int() - let cur = @wallpaper.current_wallpaper().reinterpret_as_int() let ops : Array[@types.DrawOp] = [ - @ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r), - @ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r), + @ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius=r), + @ui.stroke_rect(@ui.rect(0, 0, w, h), p.border, width=1, radius=r), ] - for i = 0; i < rows.val.length(); i = i + 1 { - let y = margin + i * row_h + // Tab bar: the current tab filled with the accent. + let tw = tab_w() + for i = 0; i < tab_names.length(); i = i + 1 { + let x = margin + i * tw + let cur = i == tab.val + if cur { + ops.push(@ui.fill_rect(@ui.rect(x + 1, margin, tw - 2, tab_h - 2), p.accent, radius=r)) + } + let fg = if cur { p.accent_foreground } else { p.foreground_muted } + ops.push(@ui.text(x + tw / 2, margin + (tab_h - 2) / 2, tab_names[i], fs - 2, fg, align=CENTER, bold=cur)) + } + ops.push(@ui.line(margin, rows_top - 3, w - margin, rows_top - 3, p.border, width=1)) + let cur_wall = @wallpaper.current_wallpaper().reinterpret_as_int() + for i = 0; i < rs.length(); i = i + 1 { + let y = rows_top + i * row_h let mid = y + (row_h - 2) / 2 let hot = i == hover.val - match rows.val[i] { - Heading(label) => { - ops.push(@ui.line(margin + 4, y + 2, w - margin - 4, y + 2, t.palette.border, width=1)) - ops.push(@ui.text(margin + 10, mid + 2, label, fs - 3, t.palette.foreground_muted, bold=true)) - } - Setting(k) => { + // Hover: a soft fill behind switches, the accent behind list rows. + let list_fg = if hot { p.accent_foreground } else { p.foreground } + match rs[i] { + Heading(_) => () + Setting(_, _) => if hot { - ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.surface_hover, radius=r)) + ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.surface_hover, radius=r)) } - ops.push(@ui.text(margin + 10, mid, settings.val[k], fs - 1, t.palette.foreground)) + _ => + if hot { + ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), p.accent, radius=r)) + } + } + match rs[i] { + Heading(label) => ops.push(@ui.text(margin + 8, mid, label, fs - 3, p.foreground_muted, bold=true)) + Setting(k, name) => { + ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground)) // The switch: an accent track with the knob on the right when on, a muted outline when off. let on = @settings.is_on(k.reinterpret_as_uint()) let sx = w - margin - 10 - switch_w let sy = mid - switch_h / 2 let knob = switch_h / 2 - 3 if on { - ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.accent, radius=switch_h / 2)) - ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, t.palette.accent_foreground)) + ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), p.accent, radius=switch_h / 2)) + ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, p.accent_foreground)) } else { - ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), t.palette.foreground_muted, width=1, radius=switch_h / 2)) - ops.push(@ui.circle(sx + switch_h / 2, mid, knob, t.palette.foreground_muted)) + ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), p.foreground_muted, width=1, radius=switch_h / 2)) + ops.push(@ui.circle(sx + switch_h / 2, mid, knob, p.foreground_muted)) } } - Wallpaper(k) => { - if hot { - ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.accent, radius=r)) - } - let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground } - if k == cur { + Wallpaper(k, name) => { + if k == cur_wall { // A tick: two strokes. - ops.push(@ui.line(margin + 8, mid, margin + 11, mid + 4, fg, width=2)) - ops.push(@ui.line(margin + 11, mid + 4, margin + 18, mid - 4, fg, width=2)) + ops.push(@ui.line(margin + 8, mid, margin + 11, mid + 4, list_fg, width=2)) + ops.push(@ui.line(margin + 11, mid + 4, margin + 18, mid - 4, list_fg, width=2)) } - ops.push(@ui.text(margin + 26, mid, wallpapers.val[k], fs - 1, fg, bold=k == cur)) + ops.push(@ui.text(margin + 26, mid, name, fs - 1, list_fg, bold=k == cur_wall)) } + Loaded(_, name) => { + ops.push(@ui.text(margin + 10, mid, name, fs - 1, list_fg)) + ops.push(@ui.text(w - margin - 10, mid, "x", fs - 1, list_fg, align=RIGHT, bold=true)) + } + Available(_, name, n) => { + ops.push(@ui.text(margin + 10, mid, name, fs - 1, list_fg)) + if n > 0U { + ops.push(@ui.text(w - margin - 10, mid, "x" + n.to_string(), fs - 3, list_fg, align=RIGHT)) + } + } + Browse => ops.push(@ui.text(margin + 10, mid, "Browse...", fs - 1, list_fg, bold=true)) } } Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops }) @@ -214,12 +306,13 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { if open_.val { close() } else { - open() + open_.val = true + set_tab(tab.val) // reopens on the tab it was left on } true } (POPUP, PointerMove(p)) => { - let i = row_at(p.x, p.y) + let i = row_at(rows(), p.x, p.y) if i != hover.val && i >= 0 { hover.val = i true @@ -228,10 +321,20 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { } } (POPUP, PointerDown(p)) => { - let i = row_at(p.x, p.y) + let ti = tab_at(p.x, p.y) + if ti >= 0 { + if ti != tab.val { + set_tab(ti) + } + return true + } + let rs = rows() + let i = row_at(rs, p.x, p.y) if i >= 0 { - act(i) - hover.val = i + act(rs, i) + // A module list changes length: keep the highlight on a real row. + let after = rows() + hover.val = if active(after, i) { i } else { first_active(after) } } true } @@ -249,7 +352,12 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { close() true } else if k == "Enter" || k == " " || k == "Space" { - act(hover.val) + let rs = rows() + act(rs, hover.val) + let after = rows() + if !active(after, hover.val) { + hover.val = first_active(after) + } true } else if k == "ArrowDown" || k == "Down" { move_hover(1) @@ -257,6 +365,15 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { } else if k == "ArrowUp" || k == "Up" { move_hover(-1) true + } else if k == "ArrowRight" || k == "Right" { + set_tab((tab.val + 1) % tab_names.length()) + true + } else if k == "ArrowLeft" || k == "Left" { + set_tab((tab.val + tab_names.length() - 1) % tab_names.length()) + true + } else if k == "1" || k == "2" || k == "3" { + set_tab(k[0].to_int() - '1'.to_int()) + true } else { false } diff --git a/compositor/host/input_test.mbt b/compositor/host/input_test.mbt index c3dfa4c..5e4f047 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -393,27 +393,29 @@ test "the panel is saved to panel.edn and restored" { } ///| -test "the wasm picker opens the module manager, which loads and unloads modules" { +test "the wasm picker opens the settings module's Panel tab, which loads and unloads modules" { let comp = new_comp("manager") - // The manager is not in the default panel: the picker loads it on demand. + // The settings module is in the default panel; the standalone module manager is gone. assert_eq(comp.shell.slot_of("module-manager"), "") + let mgr = comp.shell.slot_of("session-settings") + assert_true(mgr != "") let n0 = comp.shell.slots().length() - // Right-click empty panel space (the margin): the menu offers the module manager. + // Right-click empty panel space (the margin): the menu offers the module list. let panel = comp.shell.panel_rect click_at(comp, 1, panel.y + 5, 1U, btn=273U) assert_true(comp.shell.menu_open) - assert_eq(comp.shell.menu_rows[0].label, "Module manager...") + assert_eq(comp.shell.menu_rows[0].label, "Modules...") let m = comp.shell.menu_rect click_at(comp, m.x + m.w / 2, m.y + 26 + 14, 10U) - assert_eq(comp.shell.slots().length(), n0 + 1) - let mgr = comp.shell.slot_of("module-manager") - assert_true(mgr != "") + assert_eq(comp.shell.slots().length(), n0) // nothing new was loaded for it ignore(comp.compose_frame()) let pr = comp.shell.slot_popup_rect(mgr) - assert_true(pr.w > 0) // the picker opened the app's popup - // Rows: header(24), one per loaded module (28), header(24), one per available module (28), browse. + assert_true(pr.w > 0) // the picker opened the popup + // Rows below the tab bar (40): heading, one per loaded module, heading, one per available + // module, browse; 28 each. let loaded = comp.shell.slots().length() - let avail_y = fn(k : Int) { pr.y + 4 + 24 + loaded * 28 + 24 + k * 28 + 14 } + assert_true(pr.h >= 40 + (loaded + 3) * 28) + let avail_y = fn(pr : @scene.Rect, k : Int) { pr.y + 40 + (loaded + 2 + k) * 28 + 13 } let mut k_bin = -1 for k = 0; k < comp.shell.catalog.length(); k = k + 1 { if comp.shell.catalog[k].id == "clock-binary" { @@ -422,10 +424,11 @@ test "the wasm picker opens the module manager, which loads and unloads modules" } assert_true(k_bin >= 0) assert_eq(comp.shell.slot_of("clock-binary"), "") - click_at(comp, pr.x + 40, avail_y(k_bin), 20U) // select it: it is loaded into the panel + click_at(comp, pr.x + 40, avail_y(pr, k_bin), 20U) // select it: it is loaded into the panel assert_true(comp.shell.slot_of("clock-binary") != "") assert_eq(comp.shell.slots().length(), loaded + 1) - // The popup stays open; click the loaded module's row to unload it again. + // The popup stays open (it grew a row); click the loaded module's row to unload it again. + ignore(comp.compose_frame()) let pr2 = comp.shell.slot_popup_rect(mgr) assert_true(pr2.w > 0) let slots = comp.shell.slots() @@ -435,14 +438,15 @@ test "the wasm picker opens the module manager, which loads and unloads modules" idx = i } } - click_at(comp, pr2.x + 40, pr2.y + 4 + 24 + idx * 28 + 14, 30U) + click_at(comp, pr2.x + 40, pr2.y + 40 + (1 + idx) * 28 + 13, 30U) assert_eq(comp.shell.slot_of("clock-binary"), "") assert_eq(comp.shell.slots().length(), loaded) - // The manager is just another module: it can be removed too, and the picker brings it back. + // The settings module is just another module: it can be removed too, and the picker brings it + // back. assert_true(comp.shell.unload_slot(mgr)) - assert_eq(comp.shell.slot_of("module-manager"), "") + assert_eq(comp.shell.slot_of("session-settings"), "") assert_true(comp.shell.open_module_manager()) - assert_true(comp.shell.slot_of("module-manager") != "") + assert_true(comp.shell.slot_of("session-settings") != "") } ///| @@ -1140,22 +1144,21 @@ test "the settings module lists the wallpapers and switches the desktop to the o 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. The wallpapers follow the three settings and a - // "Wallpaper" heading, so the first is row 4. + // A click opens the popup on its Session tab; the Desktop tab (the second of three 96 px + // tabs) lists the wallpapers below a heading. Nothing changes yet. click_module(comp, "session-settings", 1U) + let p0 = comp.shell.slot_popup_rect(slot) + click_at(comp, p0.x + 6 + 96 + 48, p0.y + 6 + 14, 3U) let pr = comp.shell.slot_popup_rect(slot) - 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) - // The heading does nothing. - click_at(comp, pr.x + 40, pr.y + 6 + 3 * 30 + 5, 3U) + assert_true(pr.h >= 40 + 6 * 28) // heading and one row per wallpaper below the tab bar 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) + let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 40 + 3 * 28 + 13, 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 + 4) * 30 + 5, 10U), 1) + assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 40 + 5 * 28 + 13, 10U), 1) assert_eq(comp.shell.wallpaper_sel, 4) comp.shell.key_down("Escape") ignore(comp.compose_frame()) @@ -1269,17 +1272,17 @@ test "the 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 + 3 * 30) // one row per setting + assert_true(pr.h >= 40 + 3 * 28) // one row per setting below the tab bar 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) + click_at(comp, pr.x + 40, pr.y + 40 + 13, 5U) assert_false(comp.shell.restore_session) assert_true(comp.shell.remember_windows) assert_true(comp.shell.slot_popup_rect(slot).w > 0) // the list stays open - click_at(comp, pr.x + 40, pr.y + 6 + 5, 10U) + click_at(comp, pr.x + 40, pr.y + 40 + 13, 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 + 30 + 5, 15U) + click_at(comp, pr.x + 40, pr.y + 40 + 28 + 13, 15U) assert_false(comp.shell.remember_windows) comp.shell.key_down("Enter") ignore(comp.compose_frame()) @@ -1287,7 +1290,7 @@ test "the settings module flips the session settings from its popup" { 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) + click_at(comp, pr.x + 40, pr.y + 40 + 2 * 28 + 13, 20U) assert_false(comp.shell.dark_mode) assert_eq(comp.theme.name, "Moon Day") assert_eq(comp.shell.tokens.name, "Moon Day") @@ -1351,3 +1354,16 @@ test "session settings are saved to state.edn and restored, and take effect" { assert_false(read_state_edn().contains(":theme")) } } + +///| +test "open_settings opens the settings module on the tab asked for" { + let comp = new_comp("opensettings") + let slot = comp.shell.slot_of("session-settings") + assert_true(comp.shell.open_settings(Desktop)) + ignore(comp.compose_frame()) + let pr = comp.shell.slot_popup_rect(slot) + assert_eq(pr.h, 40 + 6 * 28 + 6) // the Wallpaper heading and the five wallpapers + assert_true(comp.shell.open_settings(Session)) + ignore(comp.compose_frame()) + assert_eq(comp.shell.slot_popup_rect(slot).h, 40 + 3 * 28 + 6) // the three settings +} diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index 455215c..381b542 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -5,17 +5,18 @@ /// A module is a wasm plasmoid component (`chandra:desktop/plasmoid`). Its imports /// are the capabilities it was granted: `theme` and `clock` always, `app-catalog` / /// `app-launch` for the application menu, `windows` for the task list, `layout-control` -/// for the layout switcher, `inspector` for the Interface Explorer button and `modules` -/// for the module manager. The manager is itself just a module: the wasm picker -/// ("Module manager..." in the panel menu) loads it on demand and opens it. +/// for the layout switcher, `inspector` for the Interface Explorer button, and +/// `session-settings`, `wallpaper` and `modules` for the settings module. Managing modules is a +/// tab of that module: the wasm picker ("Modules..." in the panel menu) loads it on demand and +/// opens that tab. ///| 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", "session-settings", "logout", ] -///| The module whose popup is the wasm picker. -let manager_module : String = "module-manager" +///| The module whose popup holds the wasm picker (its Modules tab). +let manager_module : String = "session-settings" ///| Directories searched for `*.wasm` modules, highest priority first. fn module_dirs() -> Array[String] { @@ -171,13 +172,14 @@ 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). +///| 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). 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 e == "wallpaper" || e == "module-manager" { if !has_settings && !out.contains("session-settings") { out.push("session-settings") } @@ -192,6 +194,7 @@ fn migrate_panel(entries : Array[String]) -> Array[String] { 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(["module-manager", "clock", "wallpaper"]), ["session-settings", "clock"]) assert_eq(migrate_panel(["clock"]), ["clock"]) } @@ -586,9 +589,19 @@ fn DesktopShell::poll_picker(self : DesktopShell) -> Unit { } } -///| The wasm picker: open the module manager app to choose what to load, loading the -/// manager itself first if it is not in the panel. -pub fn DesktopShell::open_module_manager(self : DesktopShell) -> Bool { +///| Tabs of the settings module's popup, for `open_settings`. +pub(all) enum SettingsTab { + /// The session switches. + Session + /// What is on the desktop: the wallpaper (modules can't be placed on the desktop yet). + Desktop + /// The panel's modules: remove, add, browse. + Panel +} derive(Eq, Debug) + +///| Open the settings module ("System settings") on `tab`, loading it into the panel first if it +/// isn't there. False when it can't be found or loaded. +pub fn DesktopShell::open_settings(self : DesktopShell, tab : SettingsTab) -> Bool { self.ensure_booted() let mut mgr : Widget? = None for w in self.widgets { @@ -599,7 +612,7 @@ pub fn DesktopShell::open_module_manager(self : DesktopShell) -> Bool { if mgr is None { match self.find_module(manager_module) { None => { - self.say("Module manager not found (build it with scripts/build-modules.sh)") + self.say("Settings module not found (build it with scripts/build-modules.sh)") return false } Some(c) => mgr = self.load_path(c.path) @@ -612,12 +625,24 @@ pub fn DesktopShell::open_module_manager(self : DesktopShell) -> Bool { if w.popup_rect.w == 0 { ignore(self.deliver(w, false, PointerDown(0, 0))) } + // The module's keys 1, 2, 3 pick its tabs. + let key = match tab { + Session => "1" + Desktop => "2" + Panel => "3" + } + ignore(self.deliver(w, true, KeyDown(key))) self.save_panel_config() true } } } +///| The wasm picker: open the settings module on its Panel tab to choose what to load. +pub fn DesktopShell::open_module_manager(self : DesktopShell) -> Bool { + self.open_settings(Panel) +} + // ---------------------------------------------------------------- right-click menu ///| Title row height and item row height of the menu. @@ -658,13 +683,13 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool } } rows.push({ label: "Remove widget", kind: 1, arg: "" }) - rows.push({ label: "Module manager...", kind: 2, arg: "" }) + rows.push({ label: "Modules...", kind: 2, arg: "" }) self.open_menu(w.pl.name, rows, w.slot, x) true } None => if inside(self.panel_rect, x, y) { - self.open_menu("Add widget", [{ label: "Module manager...", kind: 2, arg: "" }], "", x) + self.open_menu("Add widget", [{ label: "Modules...", kind: 2, arg: "" }], "", x) true } else { was_open diff --git a/compositor/wasm/wasm_test.mbt b/compositor/wasm/wasm_test.mbt index 3266486..5ba396a 100644 --- a/compositor/wasm/wasm_test.mbt +++ b/compositor/wasm/wasm_test.mbt @@ -177,8 +177,8 @@ test "launcher module reads the host catalog, filters on typed keys and launches } ///| -test "module manager lists host modules and asks to load, unload and browse" { - let p = load_module("module-manager") +test "the settings module's Panel tab lists host modules and asks to load, unload and browse" { + let p = load_module("session-settings") assert_true(p.imports().contains("modules")) let av = Table::new() av.str("moon-disc") @@ -194,6 +194,7 @@ test "module manager lists host modules and asks to load, unload and browse" { li.end_row() publish(Instances, li) assert_true(p.on_event(false, PointerDown(1, 1))) + assert_true(p.on_event(true, KeyDown("3"))) // the Panel tab match p.popup() { None => fail("popup should be open") Some(ps) => { @@ -202,10 +203,10 @@ test "module manager lists host modules and asks to load, unload and browse" { assert_true(ts.contains("Moon Phase (disc)")) } } - // rows: header(24) loaded(28) header(24) available(28) browse(28) - ignore(p.on_event(true, PointerDown(20, 4 + 24 + 3))) - ignore(p.on_event(true, PointerDown(20, 4 + 24 + 28 + 24 + 3))) - ignore(p.on_event(true, PointerDown(20, 4 + 24 + 28 + 24 + 28 + 3))) + // Below the tab bar (40), rows of 28: heading, loaded, heading, available, browse. + ignore(p.on_event(true, PointerDown(20, 40 + 28 + 3))) + ignore(p.on_event(true, PointerDown(20, 40 + 3 * 28 + 3))) + ignore(p.on_event(true, PointerDown(20, 40 + 4 * 28 + 3))) assert_eq(drain(), [UnloadInstance("w1"), LoadModule("/m/moon-disc.wasm"), Browse]) p.unload() } diff --git a/host-wasm/src/plasmoid.rs b/host-wasm/src/plasmoid.rs index 0282b81..f771018 100644 --- a/host-wasm/src/plasmoid.rs +++ b/host-wasm/src/plasmoid.rs @@ -620,21 +620,24 @@ mod tests { 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.iter().chain(walls.iter()).chain(["Wallpaper"].iter()) { + for n in names.iter().chain(["Session", "Desktop", "Panel"].iter()) { 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!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 13 }))); 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!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 28 + 13 }))); 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!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 2 * 28 + 13 }))); 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 }))); + // The Desktop tab (second of three 96 px tabs): row 0 is the "Wallpaper" heading + // (nothing), rows 1.. the wallpapers: Starfield. + assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 6 + 96 + 48, y: 6 + 14 }))); + assert!(texts(&rt.popup(h).unwrap().ops).contains(&"Starfield".to_string())); + assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 13 }))); assert!(rt.shared.borrow().requests.is_empty()); - assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 6 * 30 + 5 }))); + assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 3 * 28 + 13 }))); 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()); diff --git a/scripts/components.txt b/scripts/components.txt index 4b61b37..4d694a1 100644 --- a/scripts/components.txt +++ b/scripts/components.txt @@ -7,6 +7,5 @@ shell shell tasks taskbar-widget layout layout-widget inspector inspector-widget -module-manager module-manager-widget logout logout-widget session-settings session-settings-widget diff --git a/wit/worlds.wit b/wit/worlds.wit index a844b73..1e9c0fd 100644 --- a/wit/worlds.wit +++ b/wit/worlds.wit @@ -54,12 +54,6 @@ world inspector-widget { import inspector; } -/// Loads and unloads the system's wasm modules; the wasm picker opens this app. -world module-manager-widget { - include widget; - import modules; -} - /// Everything a panel module can be granted. The native host instantiates any module against this /// one world (a module simply imports the subset it uses) and serves each import from the data the /// compositor publishes (wit/host/plasmoids.wit). @@ -85,9 +79,11 @@ world logout-widget { import session; } -/// The settings module: session switches (restore, window places, dark mode) and the wallpaper. +/// The settings module: session switches (restore, window places, dark mode), the wallpaper, and +/// the panel's modules (load, unload, browse); the panel menu's "Modules..." opens that tab. world session-settings-widget { include widget; import session-settings; import wallpaper; + import modules; } diff --git a/world/module-manager-widget/README.md b/world/module-manager-widget/README.md deleted file mode 100644 index dd708cf..0000000 --- a/world/module-manager-widget/README.md +++ /dev/null @@ -1 +0,0 @@ -Loads and unloads the system's wasm modules; the wasm picker opens this app. \ No newline at end of file diff --git a/world/module-manager-widget/ffi_import.mbt b/world/module-manager-widget/ffi_import.mbt deleted file mode 100644 index cdedbce..0000000 --- a/world/module-manager-widget/ffi_import.mbt +++ /dev/null @@ -1,2 +0,0 @@ -// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! - diff --git a/world/module-manager-widget/import.mbt b/world/module-manager-widget/import.mbt deleted file mode 100644 index cdedbce..0000000 --- a/world/module-manager-widget/import.mbt +++ /dev/null @@ -1,2 +0,0 @@ -// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! - diff --git a/world/module-manager-widget/moon.pkg b/world/module-manager-widget/moon.pkg deleted file mode 100644 index e2a6033..0000000 --- a/world/module-manager-widget/moon.pkg +++ /dev/null @@ -1 +0,0 @@ -warnings = "-44" diff --git a/world/session-settings-widget/README.md b/world/session-settings-widget/README.md index fe8106a..aca952e 100644 --- a/world/session-settings-widget/README.md +++ b/world/session-settings-widget/README.md @@ -1 +1,2 @@ -The settings module: session switches (restore, window places, dark mode) and the wallpaper. \ No newline at end of file +The settings module: session switches (restore, window places, dark mode), the wallpaper, and +the panel's modules (load, unload, browse); the panel menu's "Modules..." opens that tab. \ No newline at end of file