diff --git a/components/compositor/gen/world/compositor/ffi.mbt b/components/compositor/gen/world/compositor/ffi.mbt index 955dffa..77e1b5b 100644 --- a/components/compositor/gen/world/compositor/ffi.mbt +++ b/components/compositor/gen/world/compositor/ffi.mbt @@ -20,6 +20,13 @@ pub fn wasmExportRun(p0 : Int, p1 : Int) -> Int { } +///| +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_load32(offset : Int) -> Int = #|(func (param i32) (result i32) local.get 0 i32.load) @@ -28,10 +35,3 @@ extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = 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/logout/gen/ffi.mbt b/components/logout/gen/ffi.mbt new file mode 100644 index 0000000..fdb4cb6 --- /dev/null +++ b/components/logout/gen/ffi.mbt @@ -0,0 +1,82 @@ +// 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 wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + @plasmoid.wasmExportPopup() +} + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + @plasmoid.wasmExportInfo() +} + +///| +#doc(hidden) +pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportRenderPostReturn(p0) +} + +///| +#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) +} + diff --git a/components/logout/gen/interface/moonplasma/desktop/plasmoid/README.md b/components/logout/gen/interface/moonplasma/desktop/plasmoid/README.md new file mode 100644 index 0000000..53ecf69 --- /dev/null +++ b/components/logout/gen/interface/moonplasma/desktop/plasmoid/README.md @@ -0,0 +1 @@ +The widget (plasmoid) contract. \ No newline at end of file diff --git a/components/logout/gen/interface/moonplasma/desktop/plasmoid/ffi.mbt b/components/logout/gen/interface/moonplasma/desktop/plasmoid/ffi.mbt new file mode 100644 index 0000000..08b246c --- /dev/null +++ b/components/logout/gen/interface/moonplasma/desktop/plasmoid/ffi.mbt @@ -0,0 +1,409 @@ +// 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 + +} + +///| +#owned(str) +extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +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_load32(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load) + +///| +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_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) + +///| +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_store8(offset : Int, value : Int) = +#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8) + diff --git a/components/logout/gen/interface/moonplasma/desktop/plasmoid/moon.pkg b/components/logout/gen/interface/moonplasma/desktop/plasmoid/moon.pkg new file mode 100644 index 0000000..42ff2f4 --- /dev/null +++ b/components/logout/gen/interface/moonplasma/desktop/plasmoid/moon.pkg @@ -0,0 +1,8 @@ +import { + "moonplasma/desktop/interface/moonplasma/desktop/types" @types, + "moonplasma/desktop/interface/moonplasma/desktop/theme" @theme, + "moonplasma/desktop/interface/moonplasma/desktop/session" @session, + "moonplasma/desktop/lib/ui" @ui, +} + +warnings = "-44" diff --git a/components/logout/gen/interface/moonplasma/desktop/plasmoid/stub.mbt b/components/logout/gen/interface/moonplasma/desktop/plasmoid/stub.mbt new file mode 100644 index 0000000..1003e42 --- /dev/null +++ b/components/logout/gen/interface/moonplasma/desktop/plasmoid/stub.mbt @@ -0,0 +1,154 @@ +///| Implementation of `moonplasma:desktop/plasmoid` for the logout button. A click on the panel +/// button opens a small popup, "Log out | Cancel", so a stray click can't end the session; Enter +/// confirms and Escape (or a click elsewhere) cancels. Confirming calls `session.logout`, which +/// makes the host stop the compositor and hand the screen back to the display manager. + +///| Popup geometry: a column of two rows with a margin around them. +let popup_w : Int = 150 + +///| +let row_h : Int = 30 + +///| +let margin : Int = 6 + +///| +let rows : Array[String] = ["Log out", "Cancel"] + +///| Whether the popup is open, and which row the pointer is over (-1: none). +let open_ : Ref[Bool] = { val: false } + +///| +let hover : Ref[Int] = { val: -1 } + +///| +fn popup_h() -> Int { + margin * 2 + rows.length() * row_h +} + +///| Row under a popup-local y, or -1. +fn row_at(x : Int, y : Int) -> Int { + if x < margin || x >= popup_w - margin || y < margin { + return -1 + } + let i = (y - margin) / row_h + if i < rows.length() { i } else { -1 } +} + +///| +fn close() -> Unit { + open_.val = false + hover.val = -1 +} + +///| +pub fn info() -> PlasmoidInfo { + { + id: "org.moonplasma.logout", + name: "Log out", + preferred: { w: 84, h: 34 }, + min_width: 70, + stretch: false, + } +} + +///| +pub fn render(size : @types.Size) -> Array[@types.DrawOp] { + let t = @theme.get_tokens() + let w = size.w.reinterpret_as_int() + let h = size.h.reinterpret_as_int() + let r = t.radius.reinterpret_as_int() + let fs = t.font_size.reinterpret_as_int() + let bg = if open_.val { t.palette.accent } else { t.palette.surface_hover } + let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground } + [ + @ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r), + @ui.text(w / 2, h / 2, "Log out", fs - 2, fg, align=CENTER), + ] +} + +///| +pub fn popup() -> PopupSurface? { + if !open_.val { + return None + } + let t = @theme.get_tokens() + let w = popup_w + let h = popup_h() + let r = t.radius.reinterpret_as_int() + let fs = t.font_size.reinterpret_as_int() + let ops : Array[@types.DrawOp] = [ + @ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r), + @ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r), + ] + for i = 0; i < rows.length(); i = i + 1 { + let y = margin + i * row_h + let hot = i == hover.val + if hot { + ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.accent, radius=r)) + } + let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground } + ops.push(@ui.text(margin + 12, y + (row_h - 2) / 2, rows[i], fs - 1, fg, bold=i == 0)) + } + Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops }) +} + +///| +pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { + match (target, event) { + (WIDGET, PointerDown(_)) => { + if open_.val { + close() + } else { + open_.val = true + hover.val = -1 + } + true + } + (POPUP, PointerMove(p)) => { + let i = row_at(p.x, p.y) + if i != hover.val { + hover.val = i + true + } else { + false + } + } + (POPUP, PointerLeave) => + if hover.val != -1 { + hover.val = -1 + true + } else { + false + } + (POPUP, PointerDown(p)) => { + let i = row_at(p.x, p.y) + close() + if i == 0 { + @session.logout() + } + true + } + (_, FocusLost) => + if open_.val { + close() + true + } else { + false + } + (_, KeyDown(k)) => + if !open_.val { + false + } else if k == "Escape" { + close() + true + } else if k == "Enter" { + close() + @session.logout() + true + } else { + false + } + _ => false + } +} diff --git a/components/logout/gen/interface/moonplasma/desktop/plasmoid/top.mbt b/components/logout/gen/interface/moonplasma/desktop/plasmoid/top.mbt new file mode 100644 index 0000000..24d7d0e --- /dev/null +++ b/components/logout/gen/interface/moonplasma/desktop/plasmoid/top.mbt @@ -0,0 +1,42 @@ +// 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/logout/gen/moon.pkg b/components/logout/gen/moon.pkg new file mode 100644 index 0000000..3d32b86 --- /dev/null +++ b/components/logout/gen/moon.pkg @@ -0,0 +1,26 @@ +import { + "moonplasma/desktop/components/logout/gen/interface/moonplasma/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:moonplasma:desktop/plasmoid@0.1.0#info", + "wasmExportInfoPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#info", + "wasmExportOnEvent:moonplasma:desktop/plasmoid@0.1.0#on-event", + "wasmExportPopup:moonplasma:desktop/plasmoid@0.1.0#popup", + "wasmExportPopupPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#popup", + "wasmExportRender:moonplasma:desktop/plasmoid@0.1.0#render", + "wasmExportRenderPostReturn:cabi_post_moonplasma:desktop/plasmoid@0.1.0#render" + ], + }, + }, +) diff --git a/compositor/app/app.mbt b/compositor/app/app.mbt index ae79f71..67c5c9f 100644 --- a/compositor/app/app.mbt +++ b/compositor/app/app.mbt @@ -169,7 +169,7 @@ pub fn run(args : Array[String]) -> Int { frames = frames + 1 match kms { Some(k) => { - if !k.poll() { + if !k.poll() || comp.quit_requested { break } let now_ms = @sys.monotonic_ms().to_uint() @@ -187,6 +187,9 @@ pub fn run(args : Array[String]) -> Int { None => () } comp.step() + if comp.quit_requested { + break + } match nested { Some(n) => { if !n.poll() { diff --git a/compositor/bin/main.mbt b/compositor/bin/main.mbt index c8ad670..e07dd2d 100644 --- a/compositor/bin/main.mbt +++ b/compositor/bin/main.mbt @@ -118,6 +118,9 @@ fn main { println("moon-plasma compositor listening on " + socket_path + " (wasi-gfx surface active)") while true { comp.step() + if comp.quit_requested { + break + } match kms { Some(k) => { if !k.poll() { diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index 5c808d5..5dd9ee5 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -51,6 +51,8 @@ pub(all) struct MoonPlasmaCompositor { /// A Super key is down and nothing else was pressed since: releasing it opens the launcher. mut super_solo : Bool mut layout_mode : @wm.LayoutMode + /// Set when the user asked to end the session (the logout button); the main loop then exits. + mut quit_requested : Bool } ///| @@ -99,6 +101,7 @@ pub fn MoonPlasmaCompositor::new( mods: 0U, super_solo: false, layout_mode: @wm.LayoutMode::Tiling, + quit_requested: false, }) } @@ -762,6 +765,7 @@ fn MoonPlasmaCompositor::run_shell_actions(self : MoonPlasmaCompositor) -> Unit for a in self.shell.take_actions() { match a { @shell.ShellAction::FocusWindow(wid) => self.activate_task(wid) + @shell.ShellAction::Logout => self.quit_requested = true @shell.ShellAction::SetLayout(m) => match m { 0 => self.set_layout_mode(@wm.LayoutMode::Tiling) diff --git a/compositor/host/input_test.mbt b/compositor/host/input_test.mbt index 6d4491a..2f9c590 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -817,3 +817,28 @@ test "dragging a floating window's corner resizes it" { assert_eq(g1.w, g0.w - 50) assert_eq(g1.h, g0.h - 40) } + +///| +test "the logout button asks first, then ends the session" { + let comp = new_comp("logout") + let slot = comp.shell.slot_of("logout") + assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel + assert_false(comp.quit_requested) + // A click opens the popup; nothing is requested yet. + click_module(comp, "logout", 1U) + let pr = comp.shell.slot_popup_rect(slot) + assert_true(pr.w > 0) + ignore(comp.compose_frame()) + assert_false(comp.quit_requested) + // Cancel (second row) closes it without logging out. + click_at(comp, pr.x + 20, pr.y + 6 + 30 + 5, 5U) + assert_eq(comp.shell.slot_popup_rect(slot).w, 0) + assert_false(comp.quit_requested) + // Open again and choose Log out (first row). + click_module(comp, "logout", 10U) + let pr2 = comp.shell.slot_popup_rect(slot) + assert_true(pr2.w > 0) + click_at(comp, pr2.x + 20, pr2.y + 6 + 5, 15U) + ignore(comp.compose_frame()) + assert_true(comp.quit_requested) +} diff --git a/compositor/shell/shell.mbt b/compositor/shell/shell.mbt index 662fcac..6169425 100644 --- a/compositor/shell/shell.mbt +++ b/compositor/shell/shell.mbt @@ -137,6 +137,8 @@ pub(all) struct WinInfo { pub(all) enum ShellAction { SetLayout(Int) FocusWindow(UInt64) + /// A module (the logout button) asked to end the session. + Logout } derive(Eq, Debug) ///| One wasm module loaded into the panel. diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index 4d1ef62..ee3b23a 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -11,7 +11,7 @@ ///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right. let default_panel : Array[String] = [ - "launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", + "launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "logout", ] ///| The module whose popup is the wasm picker. @@ -435,6 +435,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit { } Some(FocusWindow(n)) => self.actions.push(FocusWindow(n.to_int64().to_uint64())) Some(SetLayout(m)) => self.actions.push(SetLayout(m)) + Some(Logout) => self.actions.push(Logout) Some(SetInspector(on)) => self.set_inspecting(on) Some(LoadModule(path)) => { match self.load_path(path) { diff --git a/compositor/wasm/wasm_host.mbt b/compositor/wasm/wasm_host.mbt index e93fd99..85b100f 100644 --- a/compositor/wasm/wasm_host.mbt +++ b/compositor/wasm/wasm_host.mbt @@ -268,6 +268,7 @@ pub(all) enum HostRequest { LoadModule(String) UnloadInstance(String) Browse + Logout } derive(Eq, Debug) ///| @@ -281,6 +282,7 @@ pub fn next_request() -> HostRequest? { Some(LoadModule(p)) => Some(LoadModule(p)) Some(UnloadInstance(s)) => Some(UnloadInstance(s)) Some(Browse) => Some(Browse) + Some(Logout) => Some(Logout) } } diff --git a/compositor/wasm/wasm_native.mbt b/compositor/wasm/wasm_native.mbt index 681080d..cb010f0 100644 --- a/compositor/wasm/wasm_native.mbt +++ b/compositor/wasm/wasm_native.mbt @@ -643,6 +643,7 @@ pub(all) enum HostRequest { LoadModule(String) UnloadInstance(String) Browse + Logout } derive(Eq, Debug) ///| @@ -662,6 +663,7 @@ pub fn next_request() -> HostRequest? { 5 => Some(LoadModule(req_str())) 6 => Some(UnloadInstance(req_str())) 7 => Some(Browse) + 8 => Some(Logout) _ => None } } diff --git a/compositor/wasm/wasm_stub.c b/compositor/wasm/wasm_stub.c index 10fedf7..d0d94ff 100644 --- a/compositor/wasm/wasm_stub.c +++ b/compositor/wasm/wasm_stub.c @@ -47,7 +47,7 @@ static Inst insts[MAX_INST]; enum { K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT, K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_BROWSE, - K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID + K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT }; typedef struct Env { Inst *inst; int kind; } Env; @@ -274,6 +274,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_ break; case K_SET_LAYOUT: push_req(3, a0, NULL); break; case K_FOCUS: push_req(2, a0, NULL); break; + case K_LOGOUT: push_req(8, 0, NULL); break; case K_INSPECT_SET: push_req(4, a0, NULL); break; case K_MOD_BROWSE: push_req(7, 0, NULL); break; case K_MOD_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; } @@ -401,6 +402,7 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) { if (!strcmp(iface, "windows") && !strcmp(fn, "all")) return K_WIN_ALL; if (!strcmp(iface, "windows") && !strcmp(fn, "focus")) return K_WIN_FOCUS_ID; if (!strcmp(iface, "system") && !strcmp(fn, "read")) return K_SYSTEM_READ; + if (!strcmp(iface, "session") && !strcmp(fn, "logout")) return K_LOGOUT; if (!strcmp(iface, "layout-control") && !strcmp(fn, "layout-modes")) return K_LAYOUTS; if (!strcmp(iface, "layout-control") && !strcmp(fn, "current-layout")) return K_LAYOUT_CUR; if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT; diff --git a/host-wasm/src/main.rs b/host-wasm/src/main.rs index b8f192b..94f859f 100644 --- a/host-wasm/src/main.rs +++ b/host-wasm/src/main.rs @@ -197,6 +197,7 @@ impl moonplasma::host::plasmoids::Host for State { Req::LoadModule(s) => R::LoadModule(s), Req::UnloadInstance(s) => R::UnloadInstance(s), Req::Browse => R::Browse, + Req::Logout => R::Logout, }) } diff --git a/host-wasm/src/plasmoid.rs b/host-wasm/src/plasmoid.rs index edcc649..d509a8e 100644 --- a/host-wasm/src/plasmoid.rs +++ b/host-wasm/src/plasmoid.rs @@ -33,6 +33,7 @@ pub enum Req { LoadModule(String), UnloadInstance(String), Browse, + Logout, } pub const T_APPS: usize = 0; @@ -265,6 +266,12 @@ impl d::modules::Host for PState { } } +impl d::session::Host for PState { + fn logout(&mut self) { + self.shared.borrow_mut().requests.push_back(Req::Logout); + } +} + impl d::system::Host for PState { fn read(&mut self) -> d::system::Snapshot { self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot { @@ -521,4 +528,37 @@ mod tests { assert!(!texts(&ops).is_empty()); rt.unload(l.handle); } + + #[test] + fn logout_asks_for_confirmation_then_requests_it() { + let mut rt = runtime(); + let l = rt.load(&module("logout")).expect("logout loads"); + assert!(l.imports.contains(&"session".to_string())); + let h = l.handle; + assert!(!rt.render(h, Size { w: 84, h: 34 }).is_empty()); + // Closed: no popup. A click opens it; nothing is requested yet. + assert!(rt.popup(h).is_none()); + assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 }))); + let p = rt.popup(h).expect("popup open"); + assert!(texts(&p.ops).contains(&"Log out".to_string()) && texts(&p.ops).contains(&"Cancel".to_string())); + assert!(rt.shared.borrow().requests.is_empty()); + // Cancel row (second): closes without logging out. + assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 30 + 5 }))); + assert!(rt.popup(h).is_none()); + assert!(rt.shared.borrow().requests.is_empty()); + // Escape also cancels. + rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })); + assert!(rt.on_event(h, true, InputEvent::KeyDown("Escape".to_string()))); + assert!(rt.shared.borrow().requests.is_empty()); + // Open again and click the first row: that is the logout request. + rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })); + assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 }))); + assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Logout))); + assert!(rt.popup(h).is_none()); + // Enter confirms too. + rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })); + rt.on_event(h, true, InputEvent::KeyDown("Enter".to_string())); + assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Logout))); + rt.unload(h); + } } diff --git a/interface/moonplasma/desktop/session/README.md b/interface/moonplasma/desktop/session/README.md new file mode 100644 index 0000000..9633372 --- /dev/null +++ b/interface/moonplasma/desktop/session/README.md @@ -0,0 +1,2 @@ +Ending the login session. A module with this capability is a logout button: the host stops the +compositor, and the display manager takes the screen back. \ No newline at end of file diff --git a/interface/moonplasma/desktop/session/ffi.mbt b/interface/moonplasma/desktop/session/ffi.mbt new file mode 100644 index 0000000..01d1ade --- /dev/null +++ b/interface/moonplasma/desktop/session/ffi.mbt @@ -0,0 +1,5 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +fn wasmImportLogout() = "moonplasma:desktop/session@0.1.0" "logout" + diff --git a/interface/moonplasma/desktop/session/moon.pkg b/interface/moonplasma/desktop/session/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/interface/moonplasma/desktop/session/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/interface/moonplasma/desktop/session/top.mbt b/interface/moonplasma/desktop/session/top.mbt new file mode 100644 index 0000000..a030bf5 --- /dev/null +++ b/interface/moonplasma/desktop/session/top.mbt @@ -0,0 +1,8 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +pub fn logout() -> Unit { + + wasmImportLogout(); + +} + diff --git a/interface/moonplasma/host/display/ffi.mbt b/interface/moonplasma/host/display/ffi.mbt index 62f0bf6..139fc2e 100644 --- a/interface/moonplasma/host/display/ffi.mbt +++ b/interface/moonplasma/host/display/ffi.mbt @@ -21,25 +21,10 @@ fn wasmImportTakeInput(p0 : Int) = "moonplasma:host/display@0.1.0" "take-input" ///| fn wasmImportClose() = "moonplasma:host/display@0.1.0" "close" -///| -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_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] = -#|(func (param i32) (param i32) (result i32) -#| local.get 0 -#| local.get 1 call $moonbit.init_array8 -#| local.get 0) - ///| extern "wasm" fn mbt_ffi_loadf64(offset : Int) -> Double = #|(func (param i32) (result f64) local.get 0 f64.load) -///| -extern "wasm" fn mbt_ffi_free(position : Int) = -#|(func (param i32) local.get 0 call $moonbit.decref) - ///| extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = #|(func (param i32) (result i32) (local i32) @@ -48,11 +33,26 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = #| local.get 1) ///| -#owned(bytes) -extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> 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_load32(offset : Int) -> Int = #|(func (param i32) (result i32) local.get 0 i32.load) +///| +extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] = +#|(func (param i32) (param i32) (result i32) +#| local.get 0 +#| local.get 1 call $moonbit.init_array8 +#| local.get 0) + +///| +extern "wasm" fn mbt_ffi_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) + +///| +#owned(bytes) +extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = +#|(func (param i32) (result i32) local.get 0) + diff --git a/interface/moonplasma/host/display/native_stub.mbt b/interface/moonplasma/host/display/native_stub.mbt index c2a3eaf..8eb084e 100644 --- a/interface/moonplasma/host/display/native_stub.mbt +++ b/interface/moonplasma/host/display/native_stub.mbt @@ -35,33 +35,18 @@ fn wasmImportClose() -> Unit { abort("wasm-only host import") } -///| -fn mbt_ffi_load8_u(offset : Int) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] { - abort("wasm-only") -} - ///| fn mbt_ffi_loadf64(offset : Int) -> Double { abort("wasm-only") } -///| -fn mbt_ffi_free(position : Int) -> Unit { - abort("wasm-only") -} - ///| fn mbt_ffi_malloc(size : Int) -> Int { abort("wasm-only") } ///| -fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { +fn mbt_ffi_load8_u(offset : Int) -> Int { abort("wasm-only") } @@ -69,3 +54,18 @@ fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { fn mbt_ffi_load32(offset : Int) -> Int { abort("wasm-only") } + +///| +fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] { + abort("wasm-only") +} + +///| +fn mbt_ffi_free(position : Int) -> Unit { + abort("wasm-only") +} + +///| +fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { + abort("wasm-only") +} diff --git a/interface/moonplasma/host/font/ffi.mbt b/interface/moonplasma/host/font/ffi.mbt index 3a49083..01ee793 100644 --- a/interface/moonplasma/host/font/ffi.mbt +++ b/interface/moonplasma/host/font/ffi.mbt @@ -7,19 +7,9 @@ fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Int = "moonplasma:host/font@0 fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "moonplasma:host/font@0.1.0" "rasterise" ///| -extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] = -#|(func (param i32) (param i32) (result i32) -#| local.get 0 -#| local.get 1 call $moonbit.init_array8 -#| local.get 0) - -///| -extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load) - -///| -extern "wasm" fn mbt_ffi_free(position : Int) = -#|(func (param i32) local.get 0 call $moonbit.decref) +#owned(str) +extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = +#|(func (param i32) (result i32) local.get 0) ///| extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = @@ -29,7 +19,17 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = #| 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_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] = +#|(func (param i32) (param i32) (result i32) +#| local.get 0 +#| local.get 1 call $moonbit.init_array8 +#| 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_load32(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load) diff --git a/interface/moonplasma/host/font/native_stub.mbt b/interface/moonplasma/host/font/native_stub.mbt index 903424e..dc0caa5 100644 --- a/interface/moonplasma/host/font/native_stub.mbt +++ b/interface/moonplasma/host/font/native_stub.mbt @@ -11,17 +11,7 @@ fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit { } ///| -fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] { - abort("wasm-only") -} - -///| -fn mbt_ffi_load32(offset : Int) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_free(position : Int) -> Unit { +fn mbt_ffi_str2ptr(str : String) -> Int { abort("wasm-only") } @@ -31,6 +21,16 @@ fn mbt_ffi_malloc(size : Int) -> Int { } ///| -fn mbt_ffi_str2ptr(str : String) -> Int { +fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] { + abort("wasm-only") +} + +///| +fn mbt_ffi_free(position : Int) -> Unit { + abort("wasm-only") +} + +///| +fn mbt_ffi_load32(offset : Int) -> Int { abort("wasm-only") } diff --git a/interface/moonplasma/host/plasmoids/ffi.mbt b/interface/moonplasma/host/plasmoids/ffi.mbt index 5962a14..f135e9a 100644 --- a/interface/moonplasma/host/plasmoids/ffi.mbt +++ b/interface/moonplasma/host/plasmoids/ffi.mbt @@ -45,33 +45,6 @@ fn wasmImportPickerStart() -> Int = "moonplasma:host/plasmoids@0.1.0" "picker-st ///| fn wasmImportPickerPoll(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "picker-poll" -///| -extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 = -#|(func (param i32) (result i64) local.get 0 i64.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_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) - -///| -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_ptr2str(ptr : Int, len : Int) -> String = #|(func (param i32) (param i32) (result i32) @@ -80,9 +53,16 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String = #| local.get 0) ///| -#owned(bytes) -extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = -#|(func (param i32) (result i32) 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_load64(offset : Int) -> Int64 = +#|(func (param i32) (result i64) local.get 0 i64.load) + +///| +extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load8_u) ///| #owned(str) @@ -93,7 +73,27 @@ extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = #|(func (param i32) (result i32) local.get 0 i32.load) +///| +extern "wasm" fn mbt_ffi_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) + ///| extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) = #|(func (param i32) (param i64) local.get 0 local.get 1 i64.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) + +///| +#owned(bytes) +extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) = +#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store) + diff --git a/interface/moonplasma/host/plasmoids/native_stub.mbt b/interface/moonplasma/host/plasmoids/native_stub.mbt index ed27fe4..51554b6 100644 --- a/interface/moonplasma/host/plasmoids/native_stub.mbt +++ b/interface/moonplasma/host/plasmoids/native_stub.mbt @@ -76,12 +76,7 @@ fn wasmImportPickerPoll(p0 : Int) -> Unit { } ///| -fn mbt_ffi_load64(offset : Int) -> Int64 { - abort("wasm-only") -} - -///| -fn mbt_ffi_load8_u(offset : Int) -> Int { +fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String { abort("wasm-only") } @@ -91,27 +86,12 @@ fn mbt_ffi_store8(offset : Int, value : Int) -> Unit { } ///| -fn mbt_ffi_free(position : Int) -> Unit { +fn mbt_ffi_load64(offset : Int) -> Int64 { abort("wasm-only") } ///| -fn mbt_ffi_store32(offset : Int, value : Int) -> Unit { - abort("wasm-only") -} - -///| -fn mbt_ffi_malloc(size : Int) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String { - abort("wasm-only") -} - -///| -fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { +fn mbt_ffi_load8_u(offset : Int) -> Int { abort("wasm-only") } @@ -125,7 +105,27 @@ fn mbt_ffi_load32(offset : Int) -> Int { abort("wasm-only") } +///| +fn mbt_ffi_free(position : Int) -> Unit { + abort("wasm-only") +} + ///| fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit { abort("wasm-only") } + +///| +fn mbt_ffi_malloc(size : Int) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_store32(offset : Int, value : Int) -> Unit { + abort("wasm-only") +} diff --git a/interface/moonplasma/host/plasmoids/top.mbt b/interface/moonplasma/host/plasmoids/top.mbt index 2304765..7cd7b5a 100644 --- a/interface/moonplasma/host/plasmoids/top.mbt +++ b/interface/moonplasma/host/plasmoids/top.mbt @@ -27,6 +27,7 @@ pub(all) enum Request { LoadModule(String) UnloadInstance(String) Browse + Logout } ///| /// A native file-chooser dialog (zenity on the host session) for "Add widget". @@ -395,6 +396,10 @@ pub fn next_request() -> Request? { Request::Browse } + 7 => { + + Request::Logout + } _ => panic() } diff --git a/interface/moonplasma/host/sys/ffi.mbt b/interface/moonplasma/host/sys/ffi.mbt index 0c9c157..bd3ae6c 100644 --- a/interface/moonplasma/host/sys/ffi.mbt +++ b/interface/moonplasma/host/sys/ffi.mbt @@ -72,6 +72,13 @@ fn wasmImportHasExe(p0 : Int, p1 : Int) -> Int = "moonplasma:host/sys@0.1.0" "ha ///| fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "moonplasma:host/sys@0.1.0" "spawn" +///| +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_ptr2str(ptr : Int, len : Int) -> String = #|(func (param i32) (param i32) (result i32) @@ -94,20 +101,13 @@ extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] = #| local.get 1 call $moonbit.init_array8 #| local.get 0) -///| -#owned(bytes) -extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = -#|(func (param i32) (result i32) local.get 0) - ///| #owned(str) extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = #|(func (param i32) (result i32) local.get 0) ///| -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(bytes) +extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int = +#|(func (param i32) (result i32) local.get 0) diff --git a/interface/moonplasma/host/sys/native_stub.mbt b/interface/moonplasma/host/sys/native_stub.mbt index 1ad04a2..4bc29a1 100644 --- a/interface/moonplasma/host/sys/native_stub.mbt +++ b/interface/moonplasma/host/sys/native_stub.mbt @@ -120,6 +120,11 @@ fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { abort("wasm-only host import") } +///| +fn mbt_ffi_malloc(size : Int) -> Int { + abort("wasm-only") +} + ///| fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String { abort("wasm-only") @@ -140,17 +145,12 @@ fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] { abort("wasm-only") } -///| -fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { - abort("wasm-only") -} - ///| fn mbt_ffi_str2ptr(str : String) -> Int { abort("wasm-only") } ///| -fn mbt_ffi_malloc(size : Int) -> Int { +fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { abort("wasm-only") } diff --git a/justfile b/justfile index c5d81e9..e80aaa1 100644 --- a/justfile +++ b/justfile @@ -84,6 +84,10 @@ run-drm-native: build-release modules install-session: compositor-wasm host-wasm modules run0 python3 session/install.py +# Dev install: symlink the session into this checkout, so after one root install `just compositor-wasm host-wasm modules` is all a rebuild needs. +install-session-dev: compositor-wasm host-wasm modules + run0 python3 session/install.py --link + # Install the login session with the native compositor instead. install-session-native: build-release modules run0 python3 session/install.py --native diff --git a/scripts/components.txt b/scripts/components.txt index 6fdcfef..b86e90f 100644 --- a/scripts/components.txt +++ b/scripts/components.txt @@ -12,3 +12,4 @@ tasks taskbar-widget layout layout-widget inspector inspector-widget module-manager module-manager-widget +logout logout-widget diff --git a/session/install.py b/session/install.py index 0b62e19..5406d87 100755 --- a/session/install.py +++ b/session/install.py @@ -2,9 +2,14 @@ """Install (or remove) the Moon Plasma login session. Run as root, once: run0 python3 session/install.py # install: the compositor as a wasm component + run0 python3 session/install.py --link # dev: symlink into this checkout (see below) run0 python3 session/install.py --native # install the native compositor instead run0 python3 session/install.py --remove # uninstall +With --link nothing is copied: the installed files are symlinks to the build outputs in this +checkout, so after one root install, `just compositor-wasm host-wasm modules` is all it takes for the +next login to run your latest build (no root, no reinstall). The checkout must stay where it is. + Installs: /usr/local/bin/moon-plasma-host wasmtime host that runs the compositor component /usr/local/share/moon-plasma/compositor.wasm the compositor, as a WebAssembly component @@ -18,6 +23,7 @@ import os, shutil, sys root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) native = "--native" in sys.argv +linked = "--link" in sys.argv exe = os.path.join(root, "_build/native/release/build/compositor/bin/bin.exe") host = os.path.join(root, "host-wasm/target/release/moon-plasma-host") component = os.path.join(root, "build/compositor.wasm") @@ -31,11 +37,11 @@ targets = [ if "--remove" in sys.argv: for t in targets: - if os.path.exists(t): + if os.path.lexists(t): os.remove(t) print("removed", t) - if os.path.isdir(share): - shutil.rmtree(share) + if os.path.isdir(share) and not os.path.islink(share): + shutil.rmtree(share) # removes symlinks, never what they point at print("removed", share) sys.exit(0) @@ -56,34 +62,54 @@ def put(src, dst, mode): os.replace(dst + ".new", dst) # atomic: safe to reinstall over a running binary print("installed", dst) +def link(src, dst): + """dst -> src (replacing whatever is there), for --link installs.""" + os.makedirs(os.path.dirname(dst), exist_ok=True) + if os.path.lexists(dst): + if os.path.isdir(dst) and not os.path.islink(dst): + shutil.rmtree(dst) + else: + os.remove(dst) + os.symlink(src, dst) + print("linked", dst, "->", src) + def drop(path): if os.path.exists(path): os.remove(path) print("removed", path) +install = link if linked else (lambda src, dst: put(src, dst, 0o755 if "/bin/" in dst else 0o644)) if native: - put(exe, "/usr/local/bin/moon-plasma", 0o755) + install(exe, "/usr/local/bin/moon-plasma") drop("/usr/local/bin/moon-plasma-host") # the launcher falls back to the native binary else: - put(host, "/usr/local/bin/moon-plasma-host", 0o755) + install(host, "/usr/local/bin/moon-plasma-host") drop("/usr/local/bin/moon-plasma") os.makedirs(share, exist_ok=True) if not native: - put(component, os.path.join(share, "compositor.wasm"), 0o644) -put(os.path.join(root, "session/moon-plasma-session"), "/usr/local/bin/moon-plasma-session", 0o755) + install(component, os.path.join(share, "compositor.wasm")) +install(os.path.join(root, "session/moon-plasma-session"), "/usr/local/bin/moon-plasma-session") +# The display-manager entry stays a real file: some managers don't follow symlinks there. put(os.path.join(root, "session/moon-plasma.desktop"), "/usr/share/wayland-sessions/moon-plasma.desktop", 0o644) # Read at runtime relative to the working directory (the launcher cd's here): the Interface Explorer # shows wit/, the theme comes from config/, and assets/fonts holds the Allo font. for d in ("config", "wit", "assets"): dst = os.path.join(share, d) - if os.path.isdir(dst): - shutil.rmtree(dst) + if linked: + link(os.path.join(root, d), dst) + continue + if os.path.lexists(dst): + shutil.rmtree(dst) if os.path.isdir(dst) and not os.path.islink(dst) else os.remove(dst) shutil.copytree(os.path.join(root, d), dst) print("installed", dst) mods = os.path.join(root, "build/components") dst = os.path.join(share, "modules") -if os.path.isdir(dst): - shutil.rmtree(dst) +if linked: + link(mods, dst) + print("done: pick 'Moon Plasma' in the session menu; rebuild with `just compositor-wasm host-wasm modules`") + sys.exit(0) +if os.path.lexists(dst): + shutil.rmtree(dst) if os.path.isdir(dst) and not os.path.islink(dst) else os.remove(dst) os.makedirs(dst, exist_ok=True) n = 0 for f in sorted(os.listdir(mods)) if os.path.isdir(mods) else []: diff --git a/wit/capabilities.wit b/wit/capabilities.wit index 038ab32..68891a3 100644 --- a/wit/capabilities.wit +++ b/wit/capabilities.wit @@ -110,3 +110,10 @@ interface modules { /// Ask the host to show its native file chooser for a .wasm elsewhere on disk. browse: func(); } + +/// Ending the login session. A module with this capability is a logout button: the host stops the +/// compositor, and the display manager takes the screen back. +interface session { + logout: func(); +} + diff --git a/wit/host/plasmoids.wit b/wit/host/plasmoids.wit index cde4f2a..1aeb7c0 100644 --- a/wit/host/plasmoids.wit +++ b/wit/host/plasmoids.wit @@ -76,6 +76,7 @@ interface plasmoids { load-module(string), unload-instance(string), browse, + logout, } /// The next pending request, oldest first. next-request: func() -> option; diff --git a/wit/worlds.wit b/wit/worlds.wit index 38d3f82..e1d9e3b 100644 --- a/wit/worlds.wit +++ b/wit/worlds.wit @@ -73,5 +73,13 @@ world plasmoid-host { import inspector; import modules; import system; + import session; export plasmoid; } + +/// Logout button. +world logout-widget { + include widget; + import session; +} + diff --git a/world/logout-widget/README.md b/world/logout-widget/README.md new file mode 100644 index 0000000..61b0f6e --- /dev/null +++ b/world/logout-widget/README.md @@ -0,0 +1 @@ +Logout button. \ No newline at end of file diff --git a/world/logout-widget/ffi_import.mbt b/world/logout-widget/ffi_import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/logout-widget/ffi_import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/logout-widget/import.mbt b/world/logout-widget/import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/logout-widget/import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/logout-widget/moon.pkg b/world/logout-widget/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/world/logout-widget/moon.pkg @@ -0,0 +1 @@ +warnings = "-44"