From 44bb77871dee7e60e19aea717b19460266dd0e86 Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 11:41:38 -0800 Subject: [PATCH] Panel: add a Show Desktop module at the panel's end - Clicking it hides every window, as Super+D does; it stays lit while the desktop is shown. - A second click brings the hidden windows back. - New show-desktop capability (wit toggle and publish-desktop-shown) for the wasm module. - Added to the default panel after session settings; existing panels are unchanged. - Test covers hiding, the lit state, and restoring the windows. --- README.md | 2 + components/show-desktop/gen/ffi.mbt | 82 ++++ .../chandra/desktop/plasmoid/README.md | 1 + .../chandra/desktop/plasmoid/ffi.mbt | 431 ++++++++++++++++++ .../chandra/desktop/plasmoid/moon.pkg | 8 + .../chandra/desktop/plasmoid/stub.mbt | 76 +++ .../chandra/desktop/plasmoid/top.mbt | 42 ++ components/show-desktop/gen/moon.pkg | 26 ++ compositor/host/compositor.mbt | 2 + compositor/host/input_test.mbt | 35 ++ compositor/shell/shell.mbt | 6 + compositor/shell/widgets.mbt | 4 + compositor/wasm/wasm_host.mbt | 8 + compositor/wasm/wasm_native.mbt | 8 + compositor/wasm/wasm_stub.c | 11 +- .../chandra/desktop/show-desktop/README.md | 1 + .../chandra/desktop/show-desktop/ffi.mbt | 8 + .../chandra/desktop/show-desktop/moon.pkg | 1 + .../chandra/desktop/show-desktop/top.mbt | 18 + interface/chandra/host/plasmoids/ffi.mbt | 51 ++- .../chandra/host/plasmoids/native_stub.mbt | 51 ++- interface/chandra/host/plasmoids/top.mbt | 12 + scripts/components.txt | 1 + wasmhost/bin/plasmoids.mbt | 8 + wit/capabilities.wit | 8 + wit/host/plasmoids.wit | 4 + wit/worlds.wit | 7 + world/show-desktop-widget/README.md | 1 + world/show-desktop-widget/ffi_import.mbt | 2 + world/show-desktop-widget/import.mbt | 2 + world/show-desktop-widget/moon.pkg | 1 + 31 files changed, 869 insertions(+), 49 deletions(-) create mode 100644 components/show-desktop/gen/ffi.mbt create mode 100644 components/show-desktop/gen/interface/chandra/desktop/plasmoid/README.md create mode 100644 components/show-desktop/gen/interface/chandra/desktop/plasmoid/ffi.mbt create mode 100644 components/show-desktop/gen/interface/chandra/desktop/plasmoid/moon.pkg create mode 100644 components/show-desktop/gen/interface/chandra/desktop/plasmoid/stub.mbt create mode 100644 components/show-desktop/gen/interface/chandra/desktop/plasmoid/top.mbt create mode 100644 components/show-desktop/gen/moon.pkg create mode 100644 interface/chandra/desktop/show-desktop/README.md create mode 100644 interface/chandra/desktop/show-desktop/ffi.mbt create mode 100644 interface/chandra/desktop/show-desktop/moon.pkg create mode 100644 interface/chandra/desktop/show-desktop/top.mbt create mode 100644 world/show-desktop-widget/README.md create mode 100644 world/show-desktop-widget/ffi_import.mbt create mode 100644 world/show-desktop-widget/import.mbt create mode 100644 world/show-desktop-widget/moon.pkg diff --git a/README.md b/README.md index f5d53fc..a0fc642 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,8 @@ a recording shortcut again to stop. * **Clocks**: the Digital Clock (12-hour with AM/PM by default, 24-hour in its Module settings) and a binary clock. * **Screenshot**, **Layout** (Tile | Float), **Inspector** (interface explorer). +* **Show Desktop** (add it from Settings > Panel): hides every window, as Super+D does, and stays lit while + the desktop is shown; click it again to bring the windows back. * **Settings**: tabs for Session (reopen windows at login, remember window positions, dark mode), Desktop (what fills the desktop, wallpapers), Panel (add, remove and replace modules), Power (screen off and suspend when idle, battery, suspend / restart / power off), Shortcuts and Apps (the default web diff --git a/components/show-desktop/gen/ffi.mbt b/components/show-desktop/gen/ffi.mbt new file mode 100644 index 0000000..23d443e --- /dev/null +++ b/components/show-desktop/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 wasmExportInfo() -> Int { + @plasmoid.wasmExportInfo() +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + @plasmoid.wasmExportRender(p0, p1) +} + +///| +#doc(hidden) +pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportRenderPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + @plasmoid.wasmExportPopup() +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + @plasmoid.wasmExportOnEvent(p0, p1, p2, p3) +} + +///| +#doc(hidden) +pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportPopupPostReturn(p0) +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + @plasmoid.wasmExportInfoPostReturn(p0) +} + diff --git a/components/show-desktop/gen/interface/chandra/desktop/plasmoid/README.md b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/README.md new file mode 100644 index 0000000..53ecf69 --- /dev/null +++ b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/README.md @@ -0,0 +1 @@ +The widget (plasmoid) contract. \ No newline at end of file diff --git a/components/show-desktop/gen/interface/chandra/desktop/plasmoid/ffi.mbt b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/ffi.mbt new file mode 100644 index 0000000..c9225b8 --- /dev/null +++ b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/ffi.mbt @@ -0,0 +1,431 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +#doc(hidden) +pub fn wasmExportInfo() -> Int { + + let (result) : (PlasmoidInfo) = info(); + let return_area = mbt_ffi_malloc(32) + + let ptr = mbt_ffi_str2ptr((result).id) + mbt_ffi_store32((return_area) + 4, (result).id.length()) + mbt_ffi_store32((return_area) + 0, ptr) + + let ptr0 = mbt_ffi_str2ptr((result).name) + mbt_ffi_store32((return_area) + 12, (result).name.length()) + mbt_ffi_store32((return_area) + 8, ptr0) + mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int()) + mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 })) + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit { + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + mbt_ffi_free(mbt_ffi_load32((p0) + 8)) + +} + +///| +#doc(hidden) +pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int { + + let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()}); + let return_area = mbt_ffi_malloc(8) + + let address = mbt_ffi_malloc((result).length() * 32); + for index = 0; index < (result).length(); index = index + 1 { + let iter_elem : @types.DrawOp = (result)[(index)] + let iter_base = address + (index * 32); + + match iter_elem { + FillRect(payload) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 4, ((payload).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int()) + + () + } + StrokeRect(payload0) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int()) + + () + } + Line(payload1) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store32((iter_base) + 4, ((payload1).start).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).start).y) + mbt_ffi_store32((iter_base) + 12, ((payload1).end).x) + mbt_ffi_store32((iter_base) + 16, ((payload1).end).y) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int()) + + () + } + Circle(payload2) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 4, ((payload2).center).x) + mbt_ffi_store32((iter_base) + 8, ((payload2).center).y) + mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int()) + mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int()) + mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int()) + mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int()) + mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 })) + + () + } + Text(payload3) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x) + mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y) + + let ptr = mbt_ffi_str2ptr((payload3).text) + mbt_ffi_store32((iter_base) + 16, (payload3).text.length()) + mbt_ffi_store32((iter_base) + 12, ptr) + mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int()) + mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int()) + mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int()) + mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int()) + mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal()) + mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 })) + + () + } + PushClip(payload4) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store32((iter_base) + 4, (payload4).x) + mbt_ffi_store32((iter_base) + 8, (payload4).y) + mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int()) + + () + } + PopClip => { + mbt_ffi_store8((iter_base) + 0, (6)) + + () + } + Image(payload6) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int()) + + () + } + } + + } + mbt_ffi_store32((return_area) + 4, (result).length()) + mbt_ffi_store32((return_area) + 0, address) + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit { + + for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32) + + match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => () + 1 => () + 2 => () + 3 => () + 4 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + } + 5 => () + 6 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 0)) + +} + +///| +#doc(hidden) +pub fn wasmExportPopup() -> Int { + + let (result) : (PopupSurface?) = popup(); + let return_area = mbt_ffi_malloc(20) + + match (result) { + None => { + mbt_ffi_store8((return_area) + 0, (0)) + + () + } + Some(payload0) => { + mbt_ffi_store8((return_area) + 0, (1)) + mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int()) + mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int()) + + let address = mbt_ffi_malloc(((payload0).ops).length() * 32); + for index = 0; index < ((payload0).ops).length(); index = index + 1 { + let iter_elem : @types.DrawOp = ((payload0).ops)[(index)] + let iter_base = address + (index * 32); + + match iter_elem { + FillRect(payload1) => { + mbt_ffi_store8((iter_base) + 0, (0)) + mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int()) + + () + } + StrokeRect(payload2) => { + mbt_ffi_store8((iter_base) + 0, (1)) + mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int()) + + () + } + Line(payload3) => { + mbt_ffi_store8((iter_base) + 0, (2)) + mbt_ffi_store32((iter_base) + 4, ((payload3).start).x) + mbt_ffi_store32((iter_base) + 8, ((payload3).start).y) + mbt_ffi_store32((iter_base) + 12, ((payload3).end).x) + mbt_ffi_store32((iter_base) + 16, ((payload3).end).y) + mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int()) + mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int()) + mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int()) + mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int()) + mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int()) + + () + } + Circle(payload4) => { + mbt_ffi_store8((iter_base) + 0, (3)) + mbt_ffi_store32((iter_base) + 4, ((payload4).center).x) + mbt_ffi_store32((iter_base) + 8, ((payload4).center).y) + mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int()) + mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int()) + mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int()) + mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int()) + mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 })) + + () + } + Text(payload5) => { + mbt_ffi_store8((iter_base) + 0, (4)) + mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x) + mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y) + + let ptr = mbt_ffi_str2ptr((payload5).text) + mbt_ffi_store32((iter_base) + 16, (payload5).text.length()) + mbt_ffi_store32((iter_base) + 12, ptr) + mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int()) + mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int()) + mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int()) + mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int()) + mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int()) + mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal()) + mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 })) + + () + } + PushClip(payload6) => { + mbt_ffi_store8((iter_base) + 0, (5)) + mbt_ffi_store32((iter_base) + 4, (payload6).x) + mbt_ffi_store32((iter_base) + 8, (payload6).y) + mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int()) + + () + } + PopClip => { + mbt_ffi_store8((iter_base) + 0, (6)) + + () + } + Image(payload8) => { + mbt_ffi_store8((iter_base) + 0, (7)) + mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x) + mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y) + mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int()) + mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int()) + + () + } + } + + } + mbt_ffi_store32((return_area) + 16, ((payload0).ops).length()) + mbt_ffi_store32((return_area) + 12, address) + + () + } + } + let ret = return_area + return ret + +} + +///| +#doc(hidden) +pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit { + + match (mbt_ffi_load8_u((p0) + 0)) { + 0 => () + 1 => { + + for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 { + let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32) + + match (mbt_ffi_load8_u((iter_base) + 0)) { + 0 => () + 1 => () + 2 => () + 3 => () + 4 => { + mbt_ffi_free(mbt_ffi_load32((iter_base) + 12)) + + } + 5 => () + 6 => () + 7 => () + _ => panic() + } + + } + mbt_ffi_free(mbt_ffi_load32((p0) + 12)) + + } + _ => panic() + } + +} + +///| +#doc(hidden) +pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int { + + let lifted = match (p1) { + 0 => { + + @types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3}) + } + 1 => { + + @types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3}) + } + 2 => { + + @types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3}) + } + 3 => { + + @types.InputEvent::PointerLeave + } + 4 => { + + @types.InputEvent::FocusLost + } + 5 => { + + let result = mbt_ffi_ptr2str(p2, p3) + + @types.InputEvent::KeyDown(result) + } + _ => panic() + } + + let (result0) : (Bool) = on_event(Surface::from(p0), lifted); + let ret = (if result0 { 1 } else { 0 }) + return ret + +} + +///| +extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = +#|(func (param i32) (result i32) (local i32) +#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc +#| local.tee 1 i32.const 0 call $moonbit.init_array8 +#| local.get 1) + +///| +extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load) + +///| +#owned(str) +extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) = +#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store) + +///| +extern "wasm" fn mbt_ffi_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) + +///| +extern "wasm" fn mbt_ffi_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_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/show-desktop/gen/interface/chandra/desktop/plasmoid/moon.pkg b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/moon.pkg new file mode 100644 index 0000000..69457f6 --- /dev/null +++ b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/moon.pkg @@ -0,0 +1,8 @@ +import { + "chandra/desktop/interface/chandra/desktop/types" @types, + "chandra/desktop/interface/chandra/desktop/theme" @theme, + "chandra/desktop/interface/chandra/desktop/show-desktop" @desk, + "chandra/desktop/lib/ui" @ui, +} + +warnings = "-44" diff --git a/components/show-desktop/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/stub.mbt new file mode 100644 index 0000000..d5fd295 --- /dev/null +++ b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -0,0 +1,76 @@ +///| Implementation of `chandra:desktop/plasmoid` for Show Desktop, after KDE's: a panel button +/// that hides every window of the active workspace (as Super+D does) and, clicked again while +/// nothing is on screen, brings them back. It stays lit while the desktop is shown. + +///| The pointer is over the button. +let hovered : Ref[Bool] = { val: false } + +///| +pub fn info() -> PlasmoidInfo { + { + id: "org.chandra.show-desktop", + name: "Show Desktop", + preferred: { w: 34, h: 34 }, + min_width: 34, + stretch: false, + } +} + +///| A monitor on its stand; with a window on it unless the desktop is shown. +fn monitor(cx : Int, cy : Int, c : @types.Color, empty : Bool) -> Array[@types.DrawOp] { + let ops = [ + @ui.stroke_rect(@ui.rect(cx - 10, cy - 8, 20, 14), c, width=1, radius=2), + @ui.line(cx, cy + 6, cx, cy + 9, c), + @ui.line(cx - 5, cy + 9, cx + 5, cy + 9, c), + ] + if !empty { + ops.push(@ui.fill_rect(@ui.rect(cx - 6, cy - 5, 10, 7), c, radius=1)) + } + ops +} + +///| +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 shown = @desk.is_shown() + let bg = if shown { t.palette.accent } else { t.palette.surface_hover } + let fg = if shown { t.palette.accent_foreground } else { t.palette.foreground } + let ops : Array[@types.DrawOp] = [] + if shown || hovered.val { + ops.push(@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=t.radius.reinterpret_as_int())) + } + ops.append(monitor(w / 2, h / 2 - 1, fg, shown)) + ops +} + +///| +pub fn popup() -> PopupSurface? { + None +} + +///| +pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { + match (target, event) { + (WIDGET, PointerDown(_)) => { + @desk.toggle() + true + } + (WIDGET, PointerMove(_)) => + if hovered.val { + false + } else { + hovered.val = true + true + } + (WIDGET, PointerLeave) => + if hovered.val { + hovered.val = false + true + } else { + false + } + _ => false + } +} diff --git a/components/show-desktop/gen/interface/chandra/desktop/plasmoid/top.mbt b/components/show-desktop/gen/interface/chandra/desktop/plasmoid/top.mbt new file mode 100644 index 0000000..24d7d0e --- /dev/null +++ b/components/show-desktop/gen/interface/chandra/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/show-desktop/gen/moon.pkg b/components/show-desktop/gen/moon.pkg new file mode 100644 index 0000000..d45be82 --- /dev/null +++ b/components/show-desktop/gen/moon.pkg @@ -0,0 +1,26 @@ +import { + "chandra/desktop/components/show-desktop/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/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index a3acbca..3a58eea 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -1336,6 +1336,7 @@ fn ChandraCompositor::build_scene( (if self.rec_pointer { 2 } else { 0 }) self.shell.osk_visible = self.osk_visible self.shell.rotation = self.pending_rotation.unwrap_or(self.rotation) + self.shell.desktop_shown = self.desktop_shown() // A window over the whole desktop (maximized, fullscreen, monocle) pauses a desktop module's // animation: nobody can see it. self.shell.set_desktop_covered(self.desktop_covered()) @@ -2025,6 +2026,7 @@ fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit { } @shell.ShellAction::SetOskVisible(v) => self.osk_set_manual_visible(v) @shell.ShellAction::SetRotation(r) => self.request_rotation(r) + @shell.ShellAction::ToggleDesktop => self.toggle_show_desktop() @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 53138cf..0e3a87b 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -1460,6 +1460,41 @@ test "super+d minimizes every window to show the desktop, and again brings them assert_false(comp.wm.windows.get(2UL).unwrap().minimized) } +///| +test "the show desktop module hides the windows, lights up, and a second click brings them back" { + let socket_path = "/tmp/wayland-moon-showdesk-" + @sys.getpid().to_string() + ".sock" + let theme = @scene.ThemeTokens::moon_night() + let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap() + assert_true(comp.shell.load_module("show-desktop")) + ignore(comp.compose_frame()) + ignore(open_and_configure_client(comp, socket_path, "A", "a")) + ignore(open_and_configure_client(comp, socket_path, "B", "b")) + ignore(comp.compose_frame()) + // Lit (the accent behind the icon) only while the desktop is shown. + let lit = fn() { + match comp.shell.slot_ops(comp.shell.slot_of("show-desktop")) { + [FillRect(f), ..] => { + let a = comp.shell.tokens.palette.accent + f.color.r == a.r && f.color.g == a.g && f.color.b == a.b + } + _ => false + } + } + assert_false(lit()) + click_module(comp, "show-desktop", 1U) + assert_true(comp.wm.windows.get(1UL).unwrap().minimized) + assert_true(comp.wm.windows.get(2UL).unwrap().minimized) + assert_true(comp.desktop_shown()) + ignore(comp.compose_frame()) + assert_true(lit()) + click_module(comp, "show-desktop", 10U) + assert_false(comp.wm.windows.get(1UL).unwrap().minimized) + assert_false(comp.wm.windows.get(2UL).unwrap().minimized) + assert_false(comp.desktop_shown()) + ignore(comp.compose_frame()) + assert_false(lit()) +} + ///| Click (x, y) without drawing, then return the next scene's wallpaper op count (0: no new scene). fn click_wallpaper_ops(comp : @host.ChandraCompositor, x : Int, y : Int, t : UInt) -> Int { comp.handle_input(@nested.InputEvent::PointerMove(x.to_double(), y.to_double()), t) diff --git a/compositor/shell/shell.mbt b/compositor/shell/shell.mbt index 3ab998c..98c2385 100644 --- a/compositor/shell/shell.mbt +++ b/compositor/shell/shell.mbt @@ -172,6 +172,8 @@ pub(all) enum ShellAction { SetOskVisible(Bool) /// The Rotate panel module asked to set display rotation (0..3). SetRotation(Int) + /// The Show Desktop module was clicked: hide the windows, or bring them back (as Super+D). + ToggleDesktop } derive(Eq, Debug) ///| One wasm module loaded into the panel. @@ -289,6 +291,9 @@ pub(all) struct DesktopShell { mut osk_visible : Bool /// Current display rotation 0..3 (published to `rotation`). mut rotation : Int + /// What the Show Desktop module is told (the compositor sets it every frame): the windows are + /// hidden and another toggle would bring them back. + mut desktop_shown : Bool /// The network service (network.mbt), while a module imports `network`. mut net : @network.NetService? mut remember_windows : Bool @@ -468,6 +473,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell { screenshot_state: 2, osk_visible: false, rotation: 0, + desktop_shown: false, net: None, remember_windows: true, native_auth_agent: true, diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index fa08480..5bcae53 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -855,6 +855,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit { if self.any_cap("rotation") { @wasm.publish_rotation(self.rotation) } + if self.any_cap("show-desktop") { + @wasm.publish_desktop_shown(self.desktop_shown) + } if self.any_cap("battery") { let b = self.battery.refresh() @wasm.publish_battery(b.percent, b.state, b.secs_left) @@ -1033,6 +1036,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit { Some(GameLibrary(code, game, mode)) => self.gamelib.request(code, game, mode) Some(SetOskVisible(v)) => self.actions.push(SetOskVisible(v)) Some(SetRotation(r)) => self.actions.push(SetRotation(r)) + Some(ToggleDesktop) => self.actions.push(ToggleDesktop) Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) } Some(Network(code, ssid, password)) => self.network_request(code, ssid, password) Some(SetInspector(on)) => self.set_inspecting(on) diff --git a/compositor/wasm/wasm_host.mbt b/compositor/wasm/wasm_host.mbt index 9e2ce9c..b929028 100644 --- a/compositor/wasm/wasm_host.mbt +++ b/compositor/wasm/wasm_host.mbt @@ -427,6 +427,11 @@ pub fn publish_rotation(rot : Int) -> Unit { @hostpl.publish_rotation(rot.reinterpret_as_uint()) } +///| Publish whether show-desktop has the windows hidden. +pub fn publish_desktop_shown(shown : Bool) -> Unit { + @hostpl.publish_desktop_shown(shown) +} + ///| The power timeouts, in minutes (0: never). pub fn publish_power(screen_off : Int, suspend : Int) -> Unit { @hostpl.publish_power(screen_off.reinterpret_as_uint(), suspend.reinterpret_as_uint()) @@ -487,6 +492,8 @@ pub(all) enum HostRequest { SetOskVisible(Bool) /// The rotation capability: set display orientation (0..3). SetRotation(Int) + /// The show-desktop capability's `toggle`: hide the windows, or bring back the ones it hid. + ToggleDesktop } derive(Eq, Debug) ///| @@ -518,6 +525,7 @@ pub fn next_request() -> HostRequest? { Some(GameLibrary(r)) => Some(GameLibrary(r.action, r.game, r.mode)) Some(SetOskVisible(v)) => Some(SetOskVisible(v)) Some(SetRotation(r)) => Some(SetRotation(r)) + Some(ToggleDesktop) => Some(ToggleDesktop) } } diff --git a/compositor/wasm/wasm_native.mbt b/compositor/wasm/wasm_native.mbt index 03a60d5..2b10662 100644 --- a/compositor/wasm/wasm_native.mbt +++ b/compositor/wasm/wasm_native.mbt @@ -841,6 +841,11 @@ pub fn publish_rotation(rot : Int) -> Unit { c_host_set_int(12, rot) } +///| Publish whether show-desktop has the windows hidden. +pub fn publish_desktop_shown(shown : Bool) -> Unit { + c_host_set_int(13, if shown { 1 } else { 0 }) +} + ///| Publish the power timeouts, in minutes (0: never). pub fn publish_power(screen_off : Int, suspend : Int) -> Unit { c_host_set_int(5, screen_off) @@ -905,6 +910,8 @@ pub(all) enum HostRequest { SetOskVisible(Bool) /// The rotation capability: set display orientation (0..3). SetRotation(Int) + /// The show-desktop capability's `toggle`: hide the windows, or bring back the ones it hid. + ToggleDesktop } derive(Eq, Debug) ///| @@ -949,6 +956,7 @@ pub fn next_request() -> HostRequest? { 20 => Some(SetBrightness(c_host_req_int())) 21 => Some(SetOskVisible(c_host_req_int() != 0)) 22 => Some(SetRotation(c_host_req_int())) + 23 => Some(ToggleDesktop) 40 => Some(SetDesktop(c_host_req_int())) 44 => Some(FaceUnlock(c_host_req_int())) 45 => { diff --git a/compositor/wasm/wasm_stub.c b/compositor/wasm/wasm_stub.c index e9483ac..f0c6a47 100644 --- a/compositor/wasm/wasm_stub.c +++ b/compositor/wasm/wasm_stub.c @@ -69,7 +69,8 @@ enum { K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP, K_FU_STATUS, K_FU_FACES, K_FU_ENROLL, K_FU_REMOVE, K_FU_SET_IN_USE, K_FU_REFRESH, K_GL_STATUS, K_GL_GAMES, K_GL_MODES, K_GL_LAUNCH, K_GL_STOP, K_GL_FOCUS, K_GL_REFRESH, - K_OSK_IS_VISIBLE, K_OSK_SET_VISIBLE, K_ROT_CURRENT, K_ROT_SET + K_OSK_IS_VISIBLE, K_OSK_SET_VISIBLE, K_ROT_CURRENT, K_ROT_SET, + K_DESK_SHOWN, K_DESK_TOGGLE }; typedef struct Env { Inst *inst; int kind; } Env; @@ -87,7 +88,7 @@ static int32_t host_ints[24] = {[7] = -1, [10] = -1}; /* 0 layout mode, 1 inspec 5 screen-off minutes, 6 suspend minutes (0: never), 7 battery percent (-1: none), 8 battery charge-state, 9 battery seconds left, 10 backlight brightness percent (-1: none), 11 osk visible (0/1), - 12 display rotation (0..3) */ + 12 display rotation (0..3), 13 desktop shown (show-desktop hid the windows) */ /* ---- requests a guest made of the host (launch, focus, ...) ; drained by the shell after each call ---- */ typedef struct { int kind; int32_t n; char *s; } Req; @@ -503,6 +504,10 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_ if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[12]); break; case K_ROT_SET: push_req(22, a0, NULL); break; + case K_DESK_SHOWN: + if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[13] != 0); + break; + case K_DESK_TOGGLE: push_req(23, 0, 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; } case K_MOD_UNLOAD: { char *s = guest_str(in, a0, a1); push_req(6, 0, s); free(s); break; } @@ -716,6 +721,8 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) { if (!strcmp(iface, "osk") && !strcmp(fn, "set-visible")) return K_OSK_SET_VISIBLE; if (!strcmp(iface, "rotation") && !strcmp(fn, "current")) return K_ROT_CURRENT; if (!strcmp(iface, "rotation") && !strcmp(fn, "set-rotation")) return K_ROT_SET; + if (!strcmp(iface, "show-desktop") && !strcmp(fn, "is-shown")) return K_DESK_SHOWN; + if (!strcmp(iface, "show-desktop") && !strcmp(fn, "toggle")) return K_DESK_TOGGLE; if (!strcmp(iface, "modules") && !strcmp(fn, "available")) return K_MOD_AVAILABLE; if (!strcmp(iface, "modules") && !strcmp(fn, "loaded")) return K_MOD_LOADED; if (!strcmp(iface, "modules") && !strcmp(fn, "load-module")) return K_MOD_LOAD; diff --git a/interface/chandra/desktop/show-desktop/README.md b/interface/chandra/desktop/show-desktop/README.md new file mode 100644 index 0000000..e94bb9d --- /dev/null +++ b/interface/chandra/desktop/show-desktop/README.md @@ -0,0 +1 @@ +Show the desktop (Super+D): hide every window of the active workspace, and bring them back. \ No newline at end of file diff --git a/interface/chandra/desktop/show-desktop/ffi.mbt b/interface/chandra/desktop/show-desktop/ffi.mbt new file mode 100644 index 0000000..d8fb07f --- /dev/null +++ b/interface/chandra/desktop/show-desktop/ffi.mbt @@ -0,0 +1,8 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + +///| +fn wasmImportIsShown() -> Int = "chandra:desktop/show-desktop@0.1.0" "is-shown" + +///| +fn wasmImportToggle() = "chandra:desktop/show-desktop@0.1.0" "toggle" + diff --git a/interface/chandra/desktop/show-desktop/moon.pkg b/interface/chandra/desktop/show-desktop/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/interface/chandra/desktop/show-desktop/moon.pkg @@ -0,0 +1 @@ +warnings = "-44" diff --git a/interface/chandra/desktop/show-desktop/top.mbt b/interface/chandra/desktop/show-desktop/top.mbt new file mode 100644 index 0000000..f517af2 --- /dev/null +++ b/interface/chandra/desktop/show-desktop/top.mbt @@ -0,0 +1,18 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! +///| +/// True while the windows are hidden and `toggle` would bring them back. +pub fn is_shown() -> Bool { + + let result : Int = wasmImportIsShown(); + let ret = (result != 0) + return ret + +} +///| +/// Hide the windows to show the desktop, or (while it is shown) bring back the ones it hid. +pub fn toggle() -> Unit { + + wasmImportToggle(); + +} + diff --git a/interface/chandra/host/plasmoids/ffi.mbt b/interface/chandra/host/plasmoids/ffi.mbt index a17d92a..7becde9 100644 --- a/interface/chandra/host/plasmoids/ffi.mbt +++ b/interface/chandra/host/plasmoids/ffi.mbt @@ -66,6 +66,9 @@ fn wasmImportPublishOsk(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-osk ///| fn wasmImportPublishRotation(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-rotation" +///| +fn wasmImportPublishDesktopShown(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-desktop-shown" + ///| fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) = "chandra:host/plasmoids@0.1.0" "publish-system" @@ -88,16 +91,13 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll" ///| -extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load) +extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load8_u) ///| -extern "wasm" fn mbt_ffi_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) +#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_ptr2str(ptr : Int, len : Int) -> String = @@ -113,29 +113,32 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int = #| 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_store64(offset : Int, value : Int64) = #|(func (param i32) (param i64) local.get 0 local.get 1 i64.store) -///| -#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_load64(offset : Int) -> Int64 = -#|(func (param i32) (result i64) local.get 0 i64.load) - ///| 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_load8_u(offset : Int) -> Int = -#|(func (param i32) (result i32) local.get 0 i32.load8_u) +extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 = +#|(func (param i32) (result i64) local.get 0 i64.load) + +///| +extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) = +#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store) + +///| +extern "wasm" fn mbt_ffi_free(position : Int) = +#|(func (param i32) local.get 0 call $moonbit.decref) + +///| +#owned(str) +extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int = +#|(func (param i32) (result i32) local.get 0) + +///| +extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int = +#|(func (param i32) (result i32) local.get 0 i32.load) diff --git a/interface/chandra/host/plasmoids/native_stub.mbt b/interface/chandra/host/plasmoids/native_stub.mbt index 43d74f1..4768b13 100644 --- a/interface/chandra/host/plasmoids/native_stub.mbt +++ b/interface/chandra/host/plasmoids/native_stub.mbt @@ -110,6 +110,11 @@ fn wasmImportPublishRotation(p0 : Int) -> Unit { abort("wasm-only host import") } +///| +fn wasmImportPublishDesktopShown(p0 : Int) -> Unit { + abort("wasm-only host import") +} + ///| fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) -> Unit { abort("wasm-only host import") @@ -146,17 +151,12 @@ fn wasmImportPickerPoll(p0 : Int) -> Unit { } ///| -fn mbt_ffi_load32(offset : Int) -> Int { +fn mbt_ffi_load8_u(offset : Int) -> Int { abort("wasm-only") } ///| -fn mbt_ffi_free(position : Int) -> Unit { - abort("wasm-only") -} - -///| -fn mbt_ffi_store32(offset : Int, value : Int) -> Unit { +fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { abort("wasm-only") } @@ -170,32 +170,37 @@ fn mbt_ffi_malloc(size : Int) -> Int { abort("wasm-only") } -///| -fn mbt_ffi_str2ptr(str : String) -> Int { - abort("wasm-only") -} - ///| fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit { abort("wasm-only") } -///| -fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int { - abort("wasm-only") -} - -///| -fn mbt_ffi_load64(offset : Int) -> Int64 { - abort("wasm-only") -} - ///| fn mbt_ffi_store8(offset : Int, value : Int) -> Unit { abort("wasm-only") } ///| -fn mbt_ffi_load8_u(offset : Int) -> Int { +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_free(position : Int) -> Unit { + abort("wasm-only") +} + +///| +fn mbt_ffi_str2ptr(str : String) -> Int { + abort("wasm-only") +} + +///| +fn mbt_ffi_load32(offset : Int) -> Int { abort("wasm-only") } diff --git a/interface/chandra/host/plasmoids/top.mbt b/interface/chandra/host/plasmoids/top.mbt index 93a9dba..c7b2010 100644 --- a/interface/chandra/host/plasmoids/top.mbt +++ b/interface/chandra/host/plasmoids/top.mbt @@ -72,6 +72,7 @@ pub(all) enum Request { SetBrightness(Int) SetOskVisible(Bool) SetRotation(Int) + ToggleDesktop } ///| /// A native file-chooser dialog (zenity on the host session) for "Add widget". @@ -520,6 +521,13 @@ pub fn publish_rotation(rot : UInt) -> Unit { wasmImportPublishRotation((rot).reinterpret_as_int()); +} +///| +/// Whether show-desktop has the windows hidden (a toggle would bring them back). +pub fn publish_desktop_shown(shown : Bool) -> Unit { + + wasmImportPublishDesktopShown((if shown { 1 } else { 0 })); + } ///| pub fn publish_system(s : SystemSnapshot) -> Unit { @@ -683,6 +691,10 @@ pub fn next_request() -> Request? { Request::SetRotation(mbt_ffi_load32((return_area) + 8)) } + 25 => { + + Request::ToggleDesktop + } _ => panic() } diff --git a/scripts/components.txt b/scripts/components.txt index 8b3153e..4112bed 100644 --- a/scripts/components.txt +++ b/scripts/components.txt @@ -15,3 +15,4 @@ starfield starfield-widget gamerig-library gamerig-library-widget osk osk-widget rotate rotate-widget +show-desktop show-desktop-widget diff --git a/wasmhost/bin/plasmoids.mbt b/wasmhost/bin/plasmoids.mbt index 9b527a6..0aefeb9 100644 --- a/wasmhost/bin/plasmoids.mbt +++ b/wasmhost/bin/plasmoids.mbt @@ -272,6 +272,7 @@ fn request_val(r : @wasm.HostRequest) -> @wt.Val { ) SetOskVisible(b) => Variant("set-osk-visible", Some(Bool(b))) SetRotation(n) => Variant("set-rotation", Some(S32(n))) + ToggleDesktop => Variant("toggle-desktop", None) } } @@ -504,6 +505,13 @@ fn plasmoid_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] { none }, ), + ( + "publish-desktop-shown", + a => { + @wasm.publish_desktop_shown(a[0].to_bool()) + none + }, + ), ( "publish-system", a => { diff --git a/wit/capabilities.wit b/wit/capabilities.wit index 2ab7cec..1ad2f22 100644 --- a/wit/capabilities.wit +++ b/wit/capabilities.wit @@ -86,6 +86,14 @@ interface layout-control { set-layout: func(mode: u32); } +/// Show the desktop (Super+D): hide every window of the active workspace, and bring them back. +interface show-desktop { + /// True while the windows are hidden and `toggle` would bring them back. + is-shown: func() -> bool; + /// Hide the windows to show the desktop, or (while it is shown) bring back the ones it hid. + toggle: func(); +} + /// The Interface Explorer: hover any system component to see its WIT. interface inspector { is-on: func() -> bool; diff --git a/wit/host/plasmoids.wit b/wit/host/plasmoids.wit index 918bef7..43573ae 100644 --- a/wit/host/plasmoids.wit +++ b/wit/host/plasmoids.wit @@ -96,6 +96,8 @@ interface plasmoids { publish-osk: func(visible: bool); /// Current display orientation (0 = 0°, 1 = 90° CW, 2 = 180°, 3 = 270° CW). publish-rotation: func(rot: u32); + /// Whether show-desktop has the windows hidden (a toggle would bring them back). + publish-desktop-shown: func(shown: bool); record system-snapshot { cpu-permille: u32, @@ -189,6 +191,8 @@ interface plasmoids { set-osk-visible(bool), /// The rotation capability: set display orientation (0..3). set-rotation(s32), + /// The show-desktop capability's `toggle`: hide the windows, or bring them back. + toggle-desktop, } /// The next pending request, oldest first. next-request: func() -> option; diff --git a/wit/worlds.wit b/wit/worlds.wit index 64547c0..a650ded 100644 --- a/wit/worlds.wit +++ b/wit/worlds.wit @@ -106,6 +106,7 @@ world plasmoid-host { import game-library; import osk; import rotation; + import show-desktop; export plasmoid; } @@ -187,6 +188,12 @@ world osk-widget { import osk; } +/// Show Desktop button: hides the windows, a second click brings them back. +world show-desktop-widget { + include widget; + import show-desktop; +} + /// Display rotation button ("Rot"): rotates 90° clockwise on click. world rotate-widget { include widget; diff --git a/world/show-desktop-widget/README.md b/world/show-desktop-widget/README.md new file mode 100644 index 0000000..7500613 --- /dev/null +++ b/world/show-desktop-widget/README.md @@ -0,0 +1 @@ +Show Desktop button: hides the windows, a second click brings them back. \ No newline at end of file diff --git a/world/show-desktop-widget/ffi_import.mbt b/world/show-desktop-widget/ffi_import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/show-desktop-widget/ffi_import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/show-desktop-widget/import.mbt b/world/show-desktop-widget/import.mbt new file mode 100644 index 0000000..cdedbce --- /dev/null +++ b/world/show-desktop-widget/import.mbt @@ -0,0 +1,2 @@ +// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT! + diff --git a/world/show-desktop-widget/moon.pkg b/world/show-desktop-widget/moon.pkg new file mode 100644 index 0000000..e2a6033 --- /dev/null +++ b/world/show-desktop-widget/moon.pkg @@ -0,0 +1 @@ +warnings = "-44"