From 51852f0dacd8b127bf480b7a7a7e7b0f8c9ae2fd Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 10:56:12 -0800 Subject: [PATCH 1/5] Advertise zwp_linux_dmabuf_v1 so Mesa EGL clients stop using llvmpipe - Add zwp_linux_dmabuf_v1 (v4 feedback names the render node). Only linear ARGB8888 and XRGB8888 are accepted, because the compositor reads a buffer by mapping its dma-buf. - Bracket dma-buf reads with DMA_BUF_IOCTL_SYNC in the compositor and in the wasm host, so the CPU sees the GPU's finished writes. - Keep every wl_surface.frame callback since the last commit instead of only the last one. Zed and Mesa's EGL queue several and wait on all of them. - rs_capture maps a dma-buf afresh on each capture rather than using the pool cache, which could hand a later buffer an earlier buffer's pixels. - Restart xdg-desktop-portal in the background once the compositor socket exists, so the restart no longer delays compositor startup by about 30 s. --- compositor/host/e2e_test.mbt | 58 +++++++ compositor/sys/sys_stub.c | 11 ++ compositor/wayland/server.mbt | 274 ++++++++++++++++++++++++++++++++-- session/chandra-session | 9 +- wasmhost/bin/raster_stub.c | 30 +++- 5 files changed, 366 insertions(+), 16 deletions(-) diff --git a/compositor/host/e2e_test.mbt b/compositor/host/e2e_test.mbt index 8632d7a..982b7e5 100644 --- a/compositor/host/e2e_test.mbt +++ b/compositor/host/e2e_test.mbt @@ -498,3 +498,61 @@ test "swapchain pools sent in one message all keep their fds, and a bare commit @sys.close_fd(c.fd) comp.close() } + +///| +test "a linear zwp_linux_dmabuf_v1 buffer is shown like an shm one" { + // Without this global Mesa's Wayland EGL falls back to llvmpipe and Zed warns about it. + let socket_path = "/tmp/wayland-moon-dmabuf-" + @sys.getpid().to_string() + ".sock" + let theme = @scene.ThemeTokens::moon_night() + let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap() + let (c, _shm, surf, xdg, _tl, _deco) = open_and_configure_client( + comp, socket_path, "Zed", "dev.zed.Zed", + ) + match c.configure_serial { + Some(ser) => { + let ack = @wayland.WireWriter::new() + ack.u32(ser) + c.send(ack.finish_msg(xdg, 4U)) + } + None => () + } + assert_true(c.globals.contains("zwp_linux_dmabuf_v1")) + let dmabuf = bind_global(c, 2U, "zwp_linux_dmabuf_v1", 4U) + let params = c.alloc_id() + let cp = @wayland.WireWriter::new() + cp.u32(params) + c.send(cp.finish_msg(dmabuf, 1U)) + let w = c.configured_w + let h = c.configured_h + let fd = solid_memfd(w, h, b'\x00', b'\xff', b'\x00') + // add(fd, plane 0, offset 0, stride, modifier LINEAR) and create_immed in one flush. + let msg : Array[Byte] = [] + let add = @wayland.WireWriter::new() + add.u32(0U) + add.u32(0U) + add.u32((w * 4).reinterpret_as_uint()) + add.u32(0U) + add.u32(0U) + for b in add.finish_msg(params, 1U) { + msg.push(b) + } + let buf = c.alloc_id() + let ci = @wayland.WireWriter::new() + ci.u32(buf) + ci.i32(w) + ci.i32(h) + ci.u32(0x34325241U) + ci.u32(0U) + for b in ci.finish_msg(params, 3U) { + msg.push(b) + } + assert_true(@sys.sendmsg_fds(c.fd, Bytes::from_array(msg), [fd]) > 0) + let win = comp.windows.get(1UL).unwrap() + let cx = win.geometry.x + win.geometry.w / 2 + let cy = win.geometry.y + win.geometry.h / 2 + attach_commit(comp, c, surf, Some(buf)) + assert_eq(comp.compose_frame().pixel(cx, cy), Some(@scene.Rgba::new(0, 0xff, 0, 0xff))) + @sys.close_fd(fd) + @sys.close_fd(c.fd) + comp.close() +} diff --git a/compositor/sys/sys_stub.c b/compositor/sys/sys_stub.c index 3e1232a..e48345e 100644 --- a/compositor/sys/sys_stub.c +++ b/compositor/sys/sys_stub.c @@ -288,6 +288,15 @@ int32_t mp_pwrite_bytes(int32_t fd, moonbit_bytes_t buf, int32_t len, int32_t of return w < 0 ? -1 : (int32_t)w; } +#include +#include + +/* Wait for the GPU to finish writing a dma-buf before the CPU reads it; harmless on shm files. */ +static void dmabuf_sync(int fd, int start) { + struct dma_buf_sync sync = { .flags = (start ? DMA_BUF_SYNC_START : DMA_BUF_SYNC_END) | DMA_BUF_SYNC_READ }; + ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); +} + MOONBIT_FFI_EXPORT moonbit_bytes_t mp_mmap_read(int32_t fd, int32_t size) { if (fd < 0 || size <= 0) { @@ -302,7 +311,9 @@ moonbit_bytes_t mp_mmap_read(int32_t fd, int32_t size) { return moonbit_make_bytes_raw(0); } moonbit_bytes_t out = moonbit_make_bytes_raw(size); + dmabuf_sync(fd, 1); memcpy(out, ptr, (size_t)size); + dmabuf_sync(fd, 0); munmap(ptr, (size_t)size); return out; } diff --git a/compositor/wayland/server.mbt b/compositor/wayland/server.mbt index a1e102d..d4ddef4 100644 --- a/compositor/wayland/server.mbt +++ b/compositor/wayland/server.mbt @@ -106,6 +106,9 @@ enum ObjKind { /// zwp_text_input_manager_v3 and its zwp_text_input_v3 objects (text_input.mbt). ObjTextInputMgr ObjTextInput + ObjDmabuf + ObjDmabufParams(UInt) + ObjDmabufFeedback } ///| @@ -127,13 +130,23 @@ struct ShmBufferState { format : Int } +///| A zwp_linux_buffer_params_v1 being filled in: only one linear plane is supported. +struct DmabufParams { + mut fd : Int + mut offset : Int + mut stride : Int + mut modifier_ok : Bool +} + ///| struct SurfaceState { /// Pending state: the buffer attached since the last commit. A commit takes it, so a commit /// without a new attach (a client changing only its regions or geometry) neither shows the /// old buffer again nor releases it a second time: the client may already be drawing into it. mut attached_buffer : UInt? - mut pending_frame_cb : UInt? + /// Every wl_surface.frame callback since the last commit; a client may queue several (Zed + /// and Mesa's EGL each do) and waits on all of them. + pending_frame_cbs : Array[UInt] mut xdg_surface_id : UInt? mut window_id : UInt64? /// wl_surface.set_buffer_scale: the buffer is this many times the window's size. @@ -223,6 +236,7 @@ struct ClientConn { surfaces : Map[UInt, SurfaceState] shm_pools : Map[UInt, ShmPoolState] shm_buffers : Map[UInt, ShmBufferState] + dmabuf_params : Map[UInt, DmabufParams] xdg_surfaces : Map[UInt, XdgSurfaceState] subsurfaces : Map[UInt, SubState] toplevels : Map[UInt64, ToplevelState] @@ -267,6 +281,7 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn { surfaces: {}, shm_pools: {}, shm_buffers: {}, + dmabuf_params: {}, xdg_surfaces: {}, subsurfaces: {}, toplevels: {}, @@ -334,6 +349,11 @@ fn ClientConn::close_all(self : ClientConn) -> Unit { for _, pool in self.shm_pools { @sys.close_fd(pool.fd) } + for _, p in self.dmabuf_params { + if p.fd >= 0 { + @sys.close_fd(p.fd) + } + } for fd in self.pending_fds { @sys.close_fd(fd) } @@ -485,6 +505,7 @@ fn emit_registry_globals(c : ClientConn, reg_id : UInt) -> Unit { (10U, "org_kde_kwin_server_decoration_manager", 1U), (11U, "zwp_primary_selection_device_manager_v1", 1U), (12U, "zwp_text_input_manager_v3", 1U), + (13U, "zwp_linux_dmabuf_v1", 4U), ] for g in globals { let w = WireWriter::new() @@ -505,6 +526,147 @@ fn emit_shm_formats(c : ClientConn, shm_id : UInt) -> Unit { } } +///| zwp_linux_dmabuf_v1 (version 3): ARGB8888 and XRGB8888, linear only, because the +/// compositor reads a buffer by mapping its dma-buf. Mesa's Wayland EGL needs this global to use +/// the GPU (with v4 feedback naming the render node); without it clients fall back to llvmpipe. +fn emit_dmabuf_formats(c : ClientConn, id : UInt, ver : UInt) -> Unit { + // DRM fourcc codes (ARGB8888, XRGB8888), not the wl_shm 0 and 1. + for fmt in [0x34325241U, 0x34325258U] { + if ver < 3U { + let w = WireWriter::new() + w.u32(fmt) + c.send_msg(w.finish_msg(id, 0U)) + } else { + let w = WireWriter::new() + w.u32(fmt) + w.u32(0U) // modifier_hi + w.u32(0U) // modifier_lo: DRM_FORMAT_MOD_LINEAR + c.send_msg(w.finish_msg(id, 1U)) + } + } +} + +///| The render node's dev_t as 8 native-endian bytes, from /sys/class/drm/renderD*/dev ("226:128"). +fn render_node_dev() -> Array[Byte]? { + for minor = 128; minor < 192; minor = minor + 1 { + let txt = @sys.read_proc_bytes("/sys/class/drm/renderD" + minor.to_string() + "/dev") + if txt.length() == 0 { + continue + } + let mut major = 0 + let mut mnr = 0 + let mut after = false + for i = 0; i < txt.length(); i = i + 1 { + let b = txt[i].to_int() + if b == 58 { + after = true + } else if b >= 48 && b <= 57 { + if after { + mnr = mnr * 10 + (b - 48) + } else { + major = major * 10 + (b - 48) + } + } + } + // glibc makedev() for a 12-bit major and an 8-bit minor (a render node's), as a u64. + let dev = ((major & 0xfff) << 8) | (mnr & 0xff) + let out : Array[Byte] = [] + for i = 0; i < 4; i = i + 1 { + out.push(((dev >> (8 * i)) & 0xff).to_byte()) + } + for _i = 0; _i < 4; _i = _i + 1 { + out.push(b'\x00') + } + return Some(out) + } + None +} + +///| zwp_linux_dmabuf_feedback_v1: one tranche on the render node with the linear formats. Mesa +/// reads the device from here to pick the GPU driver; without it a v3 client uses llvmpipe. +fn emit_dmabuf_feedback(c : ClientConn, id : UInt) -> Unit { + let dev = match render_node_dev() { + Some(d) => d + None => [] + } + // format table: (fourcc u32, padding u32, modifier u64) per entry + let table : Array[Byte] = [] + for fmt in [0x34325241U, 0x34325258U] { + for i = 0; i < 4; i = i + 1 { + table.push(((fmt >> (8 * i)) & 0xffU).to_byte()) + } + for _i = 0; _i < 12; _i = _i + 1 { + table.push(b'\x00') + } + } + let fd = @sys.memfd_create("dmabuf-format-table", table.length()) + if fd >= 0 { + ignore(@sys.pwrite_bytes(fd, Bytes::from_array(table), 0)) + let w = WireWriter::new() + w.u32(table.length().reinterpret_as_uint()) + if c.alive { + let n = @sys.sendmsg_fd(c.fd, w.finish_msg(id, 1U), fd) + if n < 0 { + c.alive = false + } + } + @sys.close_fd(fd) + } + let w1 = WireWriter::new() + w1.array(dev) + c.send_msg(w1.finish_msg(id, 2U)) // main_device + let w2 = WireWriter::new() + w2.array(dev) + c.send_msg(w2.finish_msg(id, 4U)) // tranche_target_device + let w3 = WireWriter::new() + w3.array([b'\x00', b'\x00', b'\x01', b'\x00']) + c.send_msg(w3.finish_msg(id, 5U)) // tranche_formats: indices 0 and 1 + let w4 = WireWriter::new() + w4.u32(0U) + c.send_msg(w4.finish_msg(id, 6U)) // tranche_flags + c.send_msg(WireWriter::new().finish_msg(id, 3U)) // tranche_done + c.send_msg(WireWriter::new().finish_msg(id, 0U)) // done +} + +///| Turn the filled-in params into a wl_buffer; false when they can't be imported. +fn ClientConn::import_dmabuf( + self : ClientConn, + params_id : UInt, + buf_id : UInt, + width : Int, + height : Int, + format : Int, +) -> Bool { + let p = match self.dmabuf_params.get(params_id) { + Some(p) => p + None => return false + } + let format = if format == 0x34325241 { + 0 + } else if format == 0x34325258 { + 1 + } else { + -1 + } + if p.fd < 0 || !p.modifier_ok || format < 0 || width <= 0 || + height <= 0 || p.stride < width * 4 { + return false + } + // The buffer owns the fd, like a one-buffer pool that is already destroyed. + self.shm_pools.set(buf_id, { fd: p.fd, size: p.offset + p.stride * height, destroyed: true }) + p.fd = -1 + self.objects.set(buf_id, ObjBuffer(buf_id)) + self.shm_buffers.set(buf_id, { + pool_id: buf_id, + offset: p.offset, + width, + height, + stride: p.stride, + format, + }) + true +} + ///| fn emit_seat_caps(c : ClientConn, seat_id : UInt, touch : Bool) -> Unit { let w = WireWriter::new() @@ -706,6 +868,12 @@ fn WaylandServer::dispatch_msg( emit_seat_info(c, new_id, ver, self.touch) } else if iface == "wp_cursor_shape_manager_v1" { c.objects.set(new_id, ObjCursorShapeMgr) + } else if iface == "zwp_linux_dmabuf_v1" { + c.objects.set(new_id, ObjDmabuf) + // Version 4 clients get formats from get_default_feedback instead. + if ver < 4U { + emit_dmabuf_formats(c, new_id, ver) + } } else if iface == "wl_data_device_manager" { c.objects.set(new_id, ObjDataManager) c.data_ver = ver @@ -727,7 +895,7 @@ fn WaylandServer::dispatch_msg( c.objects.set(sid, ObjSurface(sid)) c.surfaces.set(sid, { attached_buffer: None, - pending_frame_cb: None, + pending_frame_cbs: [], xdg_surface_id: None, window_id: None, buffer_scale: 1, @@ -776,7 +944,7 @@ fn WaylandServer::dispatch_msg( } else if opcode == 3U { // frame(callback) let cb_id = reader.u32() - surf.pending_frame_cb = Some(cb_id) + surf.pending_frame_cbs.push(cb_id) } else if opcode == 10U { // offset(x, y) (version 5): moves the surface; for a drag icon, its hotspot. surf.pend_dx = surf.pend_dx + reader.i32() @@ -873,17 +1041,14 @@ fn WaylandServer::dispatch_msg( None => () } surf.attached_buffer = None - match surf.pending_frame_cb { - Some(cb_id) => { - surf.pending_frame_cb = None - if self.hold_frames { - self.held_frames.push((c.client_id, cb_id)) - } else { - self.frame_done(c, cb_id) - } + for cb_id in surf.pending_frame_cbs { + if self.hold_frames { + self.held_frames.push((c.client_id, cb_id)) + } else { + self.frame_done(c, cb_id) } - None => () } + surf.pending_frame_cbs.clear() } } ObjSubcompositor => @@ -1142,6 +1307,91 @@ fn WaylandServer::dispatch_msg( None => () } } + ObjDmabuf => + if opcode == 0U { + c.objects.remove(obj_id) + send_delete_id(c, obj_id) + } else if opcode == 1U { + // create_params(params_id: new_id) + let pid = reader.u32() + c.objects.set(pid, ObjDmabufParams(pid)) + c.dmabuf_params.set(pid, { fd: -1, offset: 0, stride: 0, modifier_ok: true }) + } else if opcode == 2U || opcode == 3U { + // get_default_feedback(id) / get_surface_feedback(id, surface) + let fid = reader.u32() + c.objects.set(fid, ObjDmabufFeedback) + emit_dmabuf_feedback(c, fid) + } + ObjDmabufFeedback => + if opcode == 0U { + c.objects.remove(obj_id) + send_delete_id(c, obj_id) + } + ObjDmabufParams(pid) => + if opcode == 0U { + // destroy + match c.dmabuf_params.get(pid) { + Some(p) => + if p.fd >= 0 { + @sys.close_fd(p.fd) + } + None => () + } + c.dmabuf_params.remove(pid) + c.objects.remove(pid) + send_delete_id(c, pid) + } else if opcode == 1U { + // add(fd, plane_idx, offset, stride, modifier_hi, modifier_lo) + let fd = c.take_fd() + let plane = reader.u32() + let offset = reader.u32() + let stride = reader.u32() + let mod_hi = reader.u32() + let mod_lo = reader.u32() + match c.dmabuf_params.get(pid) { + Some(p) => + if plane != 0U || p.fd >= 0 { + if fd >= 0 { + @sys.close_fd(fd) + } + p.modifier_ok = false + } else { + p.fd = fd + p.offset = offset.reinterpret_as_int() + p.stride = stride.reinterpret_as_int() + p.modifier_ok = mod_hi == 0U && mod_lo == 0U + } + None => + if fd >= 0 { + @sys.close_fd(fd) + } + } + } else if opcode == 2U { + // create(width, height, format, flags): answered with created(buffer) or failed + let width = reader.i32() + let height = reader.i32() + let format = reader.u32().reinterpret_as_int() + let _flags = reader.u32() + let buf_id = c.next_offer + c.next_offer = c.next_offer + 1U + if c.import_dmabuf(pid, buf_id, width, height, format) { + let w = WireWriter::new() + w.u32(buf_id) + c.send_msg(w.finish_msg(pid, 0U)) + } else { + c.send_msg(WireWriter::new().finish_msg(pid, 1U)) + } + } else if opcode == 3U { + // create_immed(buffer_id, width, height, format, flags) + let buf_id = reader.u32() + let width = reader.i32() + let height = reader.i32() + let format = reader.u32().reinterpret_as_int() + let _flags = reader.u32() + if !c.import_dmabuf(pid, buf_id, width, height, format) { + c.objects.set(buf_id, ObjBuffer(buf_id)) + } + } ObjShm => if opcode == 0U { // create_pool(id: new_id, fd: out-of-band, size: i32) diff --git a/session/chandra-session b/session/chandra-session index 6be4c67..8732ad5 100755 --- a/session/chandra-session +++ b/session/chandra-session @@ -149,8 +149,15 @@ fi # an earlier session (systemd keeps the user's services between logins) would keep another # desktop's choice, so Chrome and Firefox would not follow the Dark mode switch: restart it if it # is running. Apps start it on demand otherwise. +# Done in the background once the compositor's socket is up: the restart starts the portal +# backends, which connect to WAYLAND_DISPLAY and crash while it doesn't exist, and systemctl +# waits for all of that (about 30 s), which kept the compositor from starting at all. if command -v systemctl >/dev/null 2>&1; then - systemctl --user try-restart xdg-desktop-portal.service >>"$log" 2>&1 || true + ( + i=0 + while [ ! -S "$sock" ] && [ $i -lt 200 ]; do sleep 0.1; i=$((i + 1)); done + systemctl --user --no-block try-restart xdg-desktop-portal.service + ) >>"$log" 2>&1 & fi # Flatpak apps need the document portal's FUSE mount: `flatpak run` binds diff --git a/wasmhost/bin/raster_stub.c b/wasmhost/bin/raster_stub.c index ed53c6f..91bd28a 100644 --- a/wasmhost/bin/raster_stub.c +++ b/wasmhost/bin/raster_stub.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include #include @@ -759,6 +761,12 @@ static const uint8_t *pool_map(int fd, const struct stat *st) { return p; } +/* Wait for the GPU to finish writing a dma-buf before the CPU reads it; harmless on shm files. */ +static int dmabuf_sync(int fd, int start) { + struct dma_buf_sync sync = { .flags = (start ? DMA_BUF_SYNC_START : DMA_BUF_SYNC_END) | DMA_BUF_SYNC_READ }; + return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); +} + /* Copy a client buffer (stride * height bytes at `offset` of the file behind fd, little-endian * B, G, R, A/X) into a surface. 0 on failure. */ uint32_t rs_capture(int32_t fd, int32_t offset, int32_t stride, int32_t w, int32_t h, int32_t format) { @@ -766,11 +774,27 @@ uint32_t rs_capture(int32_t fd, int32_t offset, int32_t stride, int32_t w, int32 int64_t len = (int64_t)stride * h, end = offset + len; struct stat st; if (fstat(fd, &st) < 0 || st.st_size < end) return 0; - const uint8_t *p = pool_map(fd, &st); - if (!p) return 0; + /* A dma-buf is mapped afresh every time: the cache would hand a later buffer the mapping of an + * earlier one that had the same inode and size (the window then shows another app's pixels). */ + int is_dmabuf = dmabuf_sync(fd, 1) == 0; + const uint8_t *p; + if (is_dmabuf) { + p = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (p == MAP_FAILED) { dmabuf_sync(fd, 0); return 0; } + } else { + p = pool_map(fd, &st); + if (!p) return 0; + } uint8_t *rgba = px_alloc((size_t)w * h * 4); - if (!rgba) return 0; + if (!rgba) { + if (is_dmabuf) { munmap((void *)p, (size_t)st.st_size); dmabuf_sync(fd, 0); } + return 0; + } int opaque = swizzle_rows(p + offset, stride, rgba, w, h, format == 1); + if (is_dmabuf) { + dmabuf_sync(fd, 0); + munmap((void *)p, (size_t)st.st_size); + } do { next_surface++; } while (next_surface == 0 || surface(next_surface)); Surface *sf = malloc(sizeof *sf); sf->id = next_surface; sf->w = w; sf->h = h; sf->rgba = rgba; sf->opaque = opaque; From 44bb77871dee7e60e19aea717b19460266dd0e86 Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 11:41:38 -0800 Subject: [PATCH 2/5] 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" From cb81a973f81c6a86be40d18aaf05a15ad5229386 Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 11:48:19 -0800 Subject: [PATCH 3/5] Docs: the host is MoonBit; drop the plan's Rust host recommendation ARCHITECTURE.md's host strategy and open questions still recommended a Rust + wasmtime host; they now record the decision (MoonBit on the wasmtime C API, no Rust in the tree). TOOLCHAIN.md names wasmhost as the embedder. Co-Authored-By: Claude Opus 5.5 --- docs/ARCHITECTURE.md | 6 +++--- docs/TOOLCHAIN.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index cf81e32..a7beeb5 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -210,7 +210,7 @@ WASI-style, deny-by-default: | Option | What it is | Time-to-pixels | Fits the "everything is a component" goal | Main risks | |---|---|---|---|---| | **(a) Browser/Node host with jco** | components transpiled to JS+core wasm; host in JS; Canvas2D now, WebGPU later | **hours — done in M0** | components yes; host = JS runtime (large TCB: browser) | no real windows/devices; JS can't pre-empt a looping component; browser is not a desktop session | -| **(b) Native host embedding wasmtime** | Rust host using `wasmtime::component` + `bindgen!`; software/GPU rendering into a window (winit/SDL) or DRM | days–weeks | best: small native TCB, fuel/epoch limits, real FS/net/devices | host is Rust, not MoonBit; wasmtime's C API cannot instantiate components with host imports as conveniently, so a MoonBit-native host via FFI is **unverified** and probably not worth it | +| **(b) Native host embedding wasmtime** | MoonBit host (`wasmhost/`) linking the prebuilt wasmtime C API; software rendering into a window or DRM | days–weeks | best: small native TCB, fuel/epoch limits, real FS/net/devices | the C API has no bindgen: imports are hand-written handlers over dynamic values (done; a first Rust host on the wasmtime crate was dropped as slow to build and heavy on CPU) | | **(c) Nested compositor in an existing session** | (b) running as a window/Wayland client first, later a real compositor (smithay) hosting foreign Wayland apps | weeks–months | needed to run real apps | scope; Wayland/EGL/input details | **Recommendation:** (a) for M0–M2 (done: it is the fastest way to prove the WIT @@ -265,7 +265,7 @@ Designed next (no WIT yet): `window-registry`/`wm-policy`/`decoration`, `search- | **M0** | Toolchain proof, WIT v0.1 (`widget`/`panel`/`shell`), host (Node+browser), 4 components, tests, CI, swap/theme/permission demos | **done (this PR)** | | M1 | `config-store` + `theme-provider` component; persisted settings; hot reload of `.wasm` on change; `text` interface (measure/fonts) and icon theme | next | | M2 | Move input routing + focus policy into the shell/WM component; more widgets (task manager stub, system tray, notifications toasts); `search-provider` + KRunner component | | -| M3 | Native reference host: Rust + wasmtime (`bindgen!`), software rasteriser into a winit window, fuel/epoch limits, restart supervision; CI runs the *same* integration tests against both hosts | | +| M3 | Native reference host: MoonBit + the wasmtime C API (`wasmhost/`), software rasteriser into a window, fuel/epoch limits, restart supervision; CI runs the *same* integration tests against both hosts | | | M4 | Window-manager world with synthetic windows (no real apps yet): stacking/tiling policies as swappable components, decorations, virtual desktops, activities | | | M5 | Nested compositor (smithay) hosting real Wayland clients; `buffer-surface` resource; GPU rasteriser | | | M6 | Settings (KCM-style) framework, notifications daemon bridge (D-Bus portal), tray (SNI bridge), clipboard, power/session | | @@ -274,7 +274,7 @@ Designed next (no WIT yet): `window-registry`/`wm-policy`/`decoration`, `search- ## 12. Open design questions (with recommendations) -1. **Host language/long-term host** — Rust+wasmtime native host vs trying to keep even the host in MoonBit. *Recommend Rust+wasmtime for M3; revisit MoonBit-native host only if wasmtime's C API gains full component embedding.* Resolved: the host is MoonBit (`wasmhost/`) on the wasmtime C API, whose component model support turned out to be enough; the Rust host was removed on 2026-11-26. +1. **Host language/long-term host** — *Decided: MoonBit (`wasmhost/`) on the wasmtime C API, which does embed components. No Rust in the tree.* 2. **Render-list vs textures** — *Recommend render-list as the default, `buffer-surface` resource only for non-vector content (§4).* 3. **UI toolkit inside components** — adopt `moon-gpui` or a tiny immediate-mode helper (`lib/ui`)? *Recommend `lib/ui` until moon-gpui has a stable scene package and a flatten-to-draw-op adapter, then migrate widget internals; keep the WIT draw-op vocabulary as the stable boundary.* 4. **Text and fonts** — host-provided shaping (`text` interface) vs components bundling a shaper. *Recommend host-provided: layout needs metrics from the same engine that rasterises.* diff --git a/docs/TOOLCHAIN.md b/docs/TOOLCHAIN.md index 9edaeff..a7e0cf3 100644 --- a/docs/TOOLCHAIN.md +++ b/docs/TOOLCHAIN.md @@ -25,7 +25,7 @@ and `wasm-tools` wraps it into a component. | `wasm-tools component embed/new` (1.263.0) | works | `--encoding utf16` (MoonBit strings are UTF-16). | | `wasm-tools component targets` | works | Used as a **WIT conformance test**: asserts each component implements its declared world. | | `jco transpile` (1.42.0) | works | Component → JS + core wasm. Used for the M0 host. `--instantiation async` lets the host pass a *per-instance* import object, which is how capability grants work. | -| `wasmtime` (51.0.0) | validates/compiles | `wasmtime compile` accepts every component. We do **not** run them under wasmtime yet: a component with host imports needs an embedder (Rust/C-API) to supply them — `wasmtime run` cannot. That is M4. | +| `wasmtime` (51.0.0) | validates/compiles | `wasmtime compile` accepts every component. We do **not** run them under wasmtime yet: a component with host imports needs an embedder (now `wasmhost/`, MoonBit on the C API) to supply them — `wasmtime run` cannot. | | mooncakes packages | see below | Nothing needed at M0. | ### Pipeline From e2dc2bb9302bb8a7190afc0b65047e8f34693b12 Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 12:24:33 -0800 Subject: [PATCH 4/5] Tests never change the real screen's brightness Tests that open the Face unlock window or the face auth view turned the fill light on: they read the real /sys/class/backlight, set 90 % and restored it on close, and since the sysfs file is root-owned the write went to logind's SetBrightness over the real system bus. With tests in parallel the screen flickered between levels, and an aborted test left it at 90 %. - The backlight root comes from CHANDRA_BACKLIGHT_ROOT when set (default_backlight_root); test-native.py gives every test its own fake intel_backlight (25 of 100). - Under CHANDRA_TEST_CONFIG=1 the logind SetBrightness fallback is never spawned. - test-native.py drops XDG_SESSION_ID and points DBUS_SYSTEM_BUS_ADDRESS nowhere; tests that want a system bus give their own. - Tests that set a fake root put the default back, not the real /sys/class/backlight. Checked: the face, auth and backlight tests leave /sys/class/backlight/intel_backlight/brightness untouched (value and mtime) while they run. Co-Authored-By: Claude Opus 5.5 --- compositor/host/face_test.mbt | 2 +- compositor/host/input_test.mbt | 2 +- compositor/shell/backlight.mbt | 17 +++++++++++++++-- scripts/test-native.py | 10 ++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/compositor/host/face_test.mbt b/compositor/host/face_test.mbt index 0e70e99..3e5eb33 100644 --- a/compositor/host/face_test.mbt +++ b/compositor/host/face_test.mbt @@ -264,5 +264,5 @@ test "the Face unlock window: screen fill-light boosts backlight and restores on assert_true(comp.shell.face.window is None) assert_eq(@shell.read_backlight_percent(), 50) comp.close() - @shell.set_backlight_root("/sys/class/backlight") + @shell.set_backlight_root(@shell.default_backlight_root()) } diff --git a/compositor/host/input_test.mbt b/compositor/host/input_test.mbt index 0e3a87b..9a258bb 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -1876,5 +1876,5 @@ test "settings Power tab displays and adjusts backlight brightness" { assert_true(bright_row >= 1) click_at(comp, pr.x + 25, pr.y + 40 + bright_row * 28 + 13, 10U) assert_eq(@shell.read_backlight_percent(), 70) - @shell.set_backlight_root("/sys/class/backlight") + @shell.set_backlight_root(@shell.default_backlight_root()) } diff --git a/compositor/shell/backlight.mbt b/compositor/shell/backlight.mbt index 1c90f72..d5ec1ea 100644 --- a/compositor/shell/backlight.mbt +++ b/compositor/shell/backlight.mbt @@ -1,6 +1,17 @@ ///| Linux backlight provider for the `power` capability (sysfs read + logind SetBrightness fallback). -let backlight_root : Ref[String] = { val: "/sys/class/backlight" } +///| Where backlight devices are: /sys/class/backlight, or $CHANDRA_BACKLIGHT_ROOT (the test runner +/// gives every test a fake one, so no test changes the real screen's brightness). +pub fn default_backlight_root() -> String { + let env = @sys.getenv("CHANDRA_BACKLIGHT_ROOT") + if env.length() > 0 { + env + } else { + "/sys/class/backlight" + } +} + +let backlight_root : Ref[String] = { val: default_backlight_root() } let backlight_sample_sec : Ref[Int] = { val: -1 } @@ -124,7 +135,9 @@ pub fn write_backlight_percent( let raw0 = (clamped.to_int64() * dev.max + 50L) / 100L let raw = if raw0 < 1L { 1L } else if raw0 > dev.max { dev.max } else { raw0 } let data = @utf8.encode(raw.to_string() + "\n") - if @sys.write_file_bytes(dev.path + "/brightness", data) < 0 { + // Under test (CHANDRA_TEST_CONFIG=1) never ask logind: that would change the real screen. + if @sys.write_file_bytes(dev.path + "/brightness", data) < 0 && + @sys.getenv("CHANDRA_TEST_CONFIG") != "1" { let sid = @sys.getenv("XDG_SESSION_ID").trim(chars=" \n\r\t").to_string() let sess = if sid.length() > 0 && safe_backlight_name(sid) { "/org/freedesktop/login1/session/" + sid diff --git a/scripts/test-native.py b/scripts/test-native.py index c375258..4721a4c 100755 --- a/scripts/test-native.py +++ b/scripts/test-native.py @@ -18,6 +18,10 @@ BEGIN, END = "----- BEGIN MOON TEST RESULT -----", "----- END MOON TEST RESULT - def environment(): env = dict(os.environ, CHANDRA_TEST_CONFIG="1") + # Nothing reaches the real session through logind (screen brightness, ...). Tests that want a + # system bus give their own address. + env.pop("XDG_SESSION_ID", None) + env["DBUS_SYSTEM_BUS_ADDRESS"] = "unix:path=/nonexistent" env["PATH"] = f"{ROOT}/.tools/bin:{os.path.expanduser('~')}/.moon/bin:" + env["PATH"] wasmer = ROOT + "/.tools/wasmer" if os.path.isdir(wasmer + "/lib"): @@ -42,6 +46,12 @@ def run(test, env, timeout): with open(f"{tmp}/d/applications/test-{n.lower()}.desktop", "w") as f: f.write(f"[Desktop Entry]\nType=Application\nName=Test {n}\nExec=true\nCategories=Utility;\n") os.mkdir(tmp + "/r", 0o700) + # A fake backlight (25 of 100), so a test that changes the brightness can't touch the real screen. + os.makedirs(tmp + "/bl/intel_backlight") + for n, v in (("max_brightness", "100"), ("brightness", "25")): + with open(f"{tmp}/bl/intel_backlight/{n}", "w") as f: + f.write(v + "\n") + e["CHANDRA_BACKLIGHT_ROOT"] = tmp + "/bl" t = time.monotonic() # Output goes to a file: a pipe would stay open as long as anything the test left running. with open(tmp + "/out", "w+b") as out: From 7ce5b79af22cf72c8acaacd617accd0d93eafefd Mon Sep 17 00:00:00 2001 From: nandi Date: Mon, 30 Nov 2026 13:05:40 -0800 Subject: [PATCH 5/5] Drop the screenshot tests and the moon-disc module; just test runs every lib package - Tests that only wrote PNGs to look at are gone: desktop, overview (and its overview_shot helper), editor, emoji picker, launcher/Icon Desktop and dock screenshots. They were among the slowest in the suite; the behaviour they touched has its own tests. - moon-disc never had source in the tree, so every fresh panel said "Module 'moon-disc' not found". It is out of the default panel, and a saved panel drops it (migrate_panel). The settings module's sample rows and labels no longer mention it. - The settings module lists Show Desktop under "Apps and windows", with a description. - just test ran lib/taskbar, lib/layoutpick and lib/modmgr, which no longer exist, so the wasm lib tests failed to start; it now runs every package in lib/ (83 tests). Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +- .../chandra/desktop/plasmoid/stub.mbt | 6 +- compositor/host/annotate_test.mbt | 62 ------------------- compositor/host/desktop_test.mbt | 35 ----------- compositor/host/dock_test.mbt | 43 +------------ compositor/host/emoji_picker_test.mbt | 33 ---------- compositor/host/launcher_icons_test.mbt | 33 ---------- compositor/host/overview_test.mbt | 27 -------- compositor/shell/widgets.mbt | 11 +++- compositor/wasm/wasm_test.mbt | 28 ++------- docs/desktop-modules.md | 2 +- docs/screenshot-editor.md | 4 -- justfile | 2 +- 13 files changed, 20 insertions(+), 270 deletions(-) diff --git a/README.md b/README.md index a0fc642..e72f078 100644 --- a/README.md +++ b/README.md @@ -223,9 +223,7 @@ keep pixels on the host rather than copying them through the component. * Not done yet: lock screen, notifications daemon, system tray, virtual desktops, multi-monitor configuration, idle-inhibit (a playing video doesn't keep the screen on), lid and power-button actions (logind's defaults apply), VPN and enterprise Wi-Fi. -* Desktop Pulse (`compositor/wasm/testdata/pulse.component.wasm`) and the `moon-disc` panel - module have no source in the tree, so `scripts/build-modules.sh` skips moon-disc and a fresh - panel shows a "Module 'moon-disc' not found" notice (remove it in Settings, Panel tab). +* Desktop Pulse (`compositor/wasm/testdata/pulse.component.wasm`) has no source in the tree. ## Layout diff --git a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt index 9532a60..5cf9ada 100644 --- a/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ b/components/session-settings/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -173,9 +173,9 @@ let categories : Array[String] = ["Apps and windows", "System", "Clocks", "Other ///| Which group a module (by id, its file stem) belongs to; modules we don't know go in "Other". fn category_of(id : String) -> String { match id { - "launcher" | "dock" | "layout" => "Apps and windows" + "launcher" | "dock" | "layout" | "show-desktop" => "Apps and windows" "session-settings" | "network" | "battery" | "screenshot" | "rotate" | "osk" => "System" - "clock-digital" | "clock-binary" | "moon-disc" => "Clocks" + "clock-digital" | "clock-binary" => "Clocks" _ => "Other" } } @@ -194,7 +194,7 @@ fn description_of(id : String) -> String { "osk" => "Show or hide the on-screen keyboard" "clock-digital" => "The time, 12 or 24-hour" "clock-binary" => "The time in binary" - "moon-disc" => "Tonight's moon phase" + "show-desktop" => "Hide every window to show the desktop" "inspector" => "Inspect the shell's interface" _ => "" } diff --git a/compositor/host/annotate_test.mbt b/compositor/host/annotate_test.mbt index ecfa052..df29c7b 100644 --- a/compositor/host/annotate_test.mbt +++ b/compositor/host/annotate_test.mbt @@ -426,65 +426,3 @@ test "editor: a region screenshot opens at full size when it fits" { assert_eq((v.w, v.h), (400, 300)) tap(comp, 1U, 30U) } - -///| Headless pictures of the editor for the docs: written when CHANDRA_EDITOR_SHOTS names a folder. -test "editor: headless screenshots" { - let out = @sys.getenv("CHANDRA_EDITOR_SHOTS") - if out.length() == 0 { - return - } - let socket_path = "/tmp/wayland-moon-edshots-" + @sys.getpid().to_string() + ".sock" - let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() - comp.shot_dir = "/tmp/chandra-edshots-" + @sys.getpid().to_string() - ignore(open_and_configure_client(comp, socket_path, "Notes", "notes")) - ignore(open_and_configure_client(comp, socket_path, "Terminal", "term")) - ignore(comp.compose_frame()) - key(comp, 99U, true, 1U) - key(comp, 99U, false, 2U) - ignore(comp.compose_frame()) - // An arrow, a rectangle, a blur, a redaction, a highlight, text and two markers. - tap(comp, 30U, 10U) - edit_drag(comp, 200, 560, 420, 380, 20U) - tap(comp, 19U, 30U) - tap(comp, 6U, 31U) // blue - edit_drag(comp, 430, 200, 760, 360, 40U) - tap(comp, 48U, 50U) - edit_drag(comp, 750, 628, 1275, 674, 60U) // the notification - tap(comp, 32U, 70U) - tap(comp, 8U, 71U) // black - edit_drag(comp, 895, 12, 1025, 42, 80U) // a title - tap(comp, 45U, 85U) - edit_drag(comp, 930, 686, 1060, 719, 86U) // the clock - tap(comp, 35U, 90U) - tap(comp, 4U, 91U) // yellow - let (h0, h1) = on_screen(comp, 436, 590) - let (h2, h3) = on_screen(comp, 640, 590) - drag(comp, h0, h1, h2, h3, 100U) - tap(comp, 49U, 110U) - tap(comp, 2U, 111U) // red - let (m0, m1) = on_screen(comp, 450, 190) - click_at(comp, m0, m1, 120U) - let (m2, m3) = on_screen(comp, 810, 110) - click_at(comp, m2, m3, 130U) - tap(comp, 20U, 140U) - tap(comp, 9U, 141U) // white - let (t0, t1) = on_screen(comp, 440, 590) - click_at(comp, t0, t1, 150U) - for c in [20U, 35U, 18U, 57U, 48U, 22U, 34U, 57U, 23U, 31U, 57U, 35U, 18U, 19U, 18U] { - tap(comp, c, 160U) - } - tap(comp, 28U, 170U) - // A crop being drawn. - tap(comp, 46U, 180U) - let (c0, c1) = on_screen(comp, 60, 60) - let (c2, c3) = on_screen(comp, 1220, 690) - comp.handle_input(@nested.InputEvent::PointerMove(c0.to_double(), c1.to_double()), 190U) - comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 191U) - comp.handle_input(@nested.InputEvent::PointerMove(c2.to_double(), c3.to_double()), 192U) - let frame = comp.compose_frame() - ignore(@sys.mkdir_p(out)) - assert_eq(@sys.write_file_bytes(out + "/screenshot-editor.png", @renderer.encode_png_compressed(frame)), 0) - comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 193U) - let saved = comp.screenshot_editor().unwrap().export() - assert_eq(@sys.write_file_bytes(out + "/screenshot-editor-saved.png", @renderer.encode_png_compressed(saved)), 0) -} diff --git a/compositor/host/desktop_test.mbt b/compositor/host/desktop_test.mbt index 2f5a19e..acfb59a 100644 --- a/compositor/host/desktop_test.mbt +++ b/compositor/host/desktop_test.mbt @@ -264,41 +264,6 @@ test "reload brings the desktop module back from disk with its settings" { assert_eq(comp.shell.desktop_module().unwrap().module_id, "starfield") } -///| -test "desktop screenshots: icons, starfield, the Desktop tab" { - let comp = desk_comp("shots", fake_apps=false) - assert_true(comp.shell.set_desktop("icon-desktop")) - comp.shell.set_module_setting("desktop", "count", "All") - ignore(comp.compose_frame()) - // Hover one icon and select another with the keyboard. - click_at(comp, 900, 300, 10U) - comp.handle_input(@nested.InputEvent::Key(106U, true), 20U) // Right: selects the first - comp.handle_input(@nested.InputEvent::Key(108U, true), 21U) // Down - comp.handle_input(@nested.InputEvent::PointerMove(68.0, 68.0), 22U) - ignore(@sys.write_file_bytes("_build/desktop_icons.png", @renderer.encode_png(comp.compose_frame()))) - assert_true(comp.shell.set_desktop("starfield")) - comp.shell.set_module_setting("desktop", "speed", "Normal") - comp.handle_input(@nested.InputEvent::PointerMove(900.0, 250.0), 30U) - for _ in 0..<6 { - @sys.sleep_ms(34) - ignore(comp.compose_frame()) - } - ignore(@sys.write_file_bytes("_build/desktop_starfield.png", @renderer.encode_png(comp.compose_frame()))) - // Warp pulse: a click streaks the stars. - click_at(comp, 900, 250, 40U) - for _ in 0..<3 { - @sys.sleep_ms(34) - ignore(comp.compose_frame()) - } - ignore(@sys.write_file_bytes("_build/desktop_warp.png", @renderer.encode_png(comp.compose_frame()))) - assert_true(comp.shell.open_settings(Desktop)) - for _ in 0..<10 { - @sys.sleep_ms(40) // the popup slides in - ignore(comp.compose_frame()) - } - ignore(@sys.write_file_bytes("_build/desktop_settings.png", @renderer.encode_png(comp.compose_frame()))) -} - ///| test "mobile tap on desktop icon with finger drift launches without moving any icon" { let socket_path = "/tmp/wayland-moon-desk-mobile-" + @sys.getpid().to_string() + ".sock" diff --git a/compositor/host/dock_test.mbt b/compositor/host/dock_test.mbt index c6d6223..65282a9 100644 --- a/compositor/host/dock_test.mbt +++ b/compositor/host/dock_test.mbt @@ -1,45 +1,4 @@ -///| The dock drawn in a real frame, for a look at it: writes _build/dock_hover.png (an icon under -/// the pointer, magnified, with its name above) and _build/dock_menu.png (an app's right-click -/// menu). Uses the machine's own .desktop files and icon theme, so what it shows varies. - -///| -test "dock screenshots: hover label and an app's menu" { - let socket_path = "/tmp/wayland-moon-dockshot-" + @sys.getpid().to_string() + ".sock" - let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() - ignore(comp.compose_frame()) - let slot = comp.shell.slot_of("dock") - // Room for the dock's running apps on a 1280-wide screen. - for s in comp.shell.slots() { - let m = comp.shell.slot_module(s) - if m == "inspector" || m == "layout" || m == "screenshot" { - ignore(comp.shell.unload_slot(s)) - } - } - comp.shell.set_module_setting( - slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim", - ) - // Icons only, to see the magnification (titles are the default). - comp.shell.set_module_setting(slot, "titles", "off") - let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer") - let _b = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer") - let _c = open_and_configure_client(comp, socket_path, "Terminal", "xterm") - let _e = open_and_configure_client(comp, socket_path, "Notes 2", "org.example.Notes") - let _d = open_and_configure_client(comp, socket_path, "Notes", "org.example.Notes") - ignore(comp.compose_frame()) - ignore(comp.compose_frame()) - let r = comp.shell.slot_rect(slot) - let cy = r.y + r.h / 2 - // Hover the second icon (Calc). - comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 30 + 12).to_double(), cy.to_double()), 1U) - let frame = comp.compose_frame() - assert_true(comp.shell.dock_hover_name().length() > 0) - ignore(@sys.write_file_bytes("_build/dock_hover.png", @renderer.encode_png(frame))) - // Right-click the first (Writer, two windows). - click_at(comp, r.x + 6 + 12, cy, 10U, btn=273U) - assert_true(comp.shell.menu_open) - assert_true(comp.shell.menu_rows.map(m => m.label).contains("Close 2 windows")) - ignore(@sys.write_file_bytes("_build/dock_menu.png", @renderer.encode_png(comp.compose_frame()))) -} +///| The dock as the panel's task manager, driven through real frames. ///| Pick row `label` of the open right-click menu (rows: 26px title, then 28px each). fn dock_pick(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit raise { diff --git a/compositor/host/emoji_picker_test.mbt b/compositor/host/emoji_picker_test.mbt index bebaf62..1b50efb 100644 --- a/compositor/host/emoji_picker_test.mbt +++ b/compositor/host/emoji_picker_test.mbt @@ -218,36 +218,3 @@ test "recent emoji and the skin tone are kept in state.edn" { assert_eq(q.items().map(i => i.text), ["🍕", "👍🏽"]) } } - -///| CHANDRA_EMOJI_SHOTS=: pictures of the picker over a window (docs, the thread). -test "screenshots of the picker" { - let dir = @sys.getenv("CHANDRA_EMOJI_SHOTS") - if dir.length() > 0 { - ignore(@sys.mkdir_p(dir)) - let socket_path = "/tmp/wayland-moon-emojishots-" + @sys.getpid().to_string() + ".sock" - let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() - let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes") - commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) - let (ti, _) = text_input_for(comp, a) - text_input_state(comp, a, ti, true, 120, 90, 18) - let shot = fn(name : String) raise { - let frame = comp.compose_frame() - assert_eq(@sys.write_file_bytes(dir + "/" + name, @renderer.encode_png_compressed(frame)), 0) - } - press_super_period(comp, 10U) - shot("picker-smileys.png") - type_keys(comp, [35U, 18U, 30U, 19U, 20U], 20U) // h e a r t - shot("picker-search.png") - type_keys(comp, [14U, 14U, 14U, 14U, 14U, 15U], 40U) // clear, then Tab: People - comp.handle_input(@nested.InputEvent::Modifiers(4U, 0U, 0U, 0U), 60U) - type_keys(comp, [106U, 106U, 106U], 61U) // Ctrl+Right x3: medium skin tone - comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 70U) - type_keys(comp, [106U, 108U], 71U) - shot("picker-people-tone.png") - // The clipboard notice: the app turns its text field off, then an emoji is chosen. - text_input_state(comp, a, ti, false, 0, 0, 0) - type_keys(comp, [28U], 80U) - shot("picker-copied-notice.png") - comp.close() - } -} diff --git a/compositor/host/launcher_icons_test.mbt b/compositor/host/launcher_icons_test.mbt index 133f25c..f9afe62 100644 --- a/compositor/host/launcher_icons_test.mbt +++ b/compositor/host/launcher_icons_test.mbt @@ -77,36 +77,3 @@ test "the open Applications menu gets its rows' icons and draws them" { assert_false(comp.shell.icon_app_ids().contains("app5")) comp.shell.shutdown() } - -///| For a look: the menu and the Icon Desktop with theme icons (whatever the machine's hicolor -/// theme has for these names; letter tiles or the generic icon where it has nothing). Writes -/// _build/launcher_icons_themed.png and _build/desktop_icons_themed.png. -test "screenshots: Applications menu and Icon Desktop with theme icons" { - let comp = desk_comp("ishot") - let apps = [ - ("org.libreoffice.Writer", "Writer", "Word processor", "libreoffice-writer"), - ("org.libreoffice.Calc", "Calc", "Spreadsheets", "libreoffice-calc"), - ("org.libreoffice.Impress", "Impress", "Presentations", "libreoffice-impress"), - ("org.libreoffice.Draw", "Draw", "Drawings and diagrams", "libreoffice-draw"), - ("xterm", "XTerm", "Terminal emulator", "xterm-color"), - ("gvim", "GVim", "Text editor", "gvim"), - ] - comp.shell.apps.clear() - for a in apps { - comp.shell.apps.push({ id: a.0, name: a.1, comment: a.2, category: "", glyph: "" }) - comp.shell.exec.set(a.0, a.0) - comp.shell.icon_names.set(a.0, a.3) - comp.shell.icon_handles.remove(a.0) - } - comp.shell.apps_dirty = true - assert_true(comp.shell.set_desktop("icon-desktop")) - ignore(comp.compose_frame()) - ignore(@sys.write_file_bytes("_build/desktop_icons_themed.png", @renderer.encode_png(comp.compose_frame()))) - comp.shell.toggle_launcher() - for _ in 0..<10 { - @sys.sleep_ms(30) - ignore(comp.compose_frame()) - } - ignore(@sys.write_file_bytes("_build/launcher_icons_themed.png", @renderer.encode_png(comp.compose_frame()))) - comp.shell.shutdown() -} diff --git a/compositor/host/overview_test.mbt b/compositor/host/overview_test.mbt index 90a8f60..ca60a7f 100644 --- a/compositor/host/overview_test.mbt +++ b/compositor/host/overview_test.mbt @@ -399,33 +399,6 @@ test "middle click closes a window from the overview and it stays open" { assert_true(drain_msgs(clients[ci]).iter().any(m => m.1 == 1U)) } -///| -fn overview_shot(n : Int, dark : Bool) -> Unit raise { - let tag = "ovshot" + n.to_string() + (if dark { "d" } else { "l" }) - let socket_path = "/tmp/wayland-moon-" + tag + "-" + @sys.getpid().to_string() + ".sock" - let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() - comp.shell.dark_mode = dark - comp.apply_theme() - ignore(comp.compose_frame()) - ignore(open_windows(comp, socket_path, n)) - comp.handle_input(@nested.InputEvent::Key(125U, true), 1U) - comp.handle_input(@nested.InputEvent::Key(125U, false), 2U) - ov_settle(comp) - // Hover the first window to show the highlight and close button. - let (_, r) = comp.overview_places()[0] - comp.handle_input(@nested.InputEvent::PointerMove((r.x + r.w / 2).to_double(), (r.y + r.h / 2).to_double()), 3U) - let px = comp.compose_frame() - ignore(@sys.write_file_bytes("_build/overview_" + n.to_string() + (if dark { "_dark" } else { "_light" }) + ".png", @renderer.encode_png(px))) -} - -///| -test "overview screenshots: 1, 4 and 9 windows, dark and light" { - for n in [1, 4, 9] { - overview_shot(n, true) - overview_shot(n, false) - } -} - ///| test "no overview while the Interface Explorer inspects the launcher" { let comp = new_comp("ov-inspect") diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index 5bcae53..15e0577 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -14,8 +14,7 @@ ///| Modules loaded into a fresh panel, in order. The dock (pinned and running apps, the task /// manager) stretches, so what follows it packs right. let default_panel : Array[String] = [ - "launcher", "inspector", "layout", "dock", "moon-disc", "network", "clock-digital", "screenshot", - "session-settings", + "launcher", "inspector", "layout", "dock", "network", "clock-digital", "screenshot", "session-settings", ] ///| A fresh panel's modules: the defaults, plus the battery before the clock on a machine that @@ -334,6 +333,9 @@ fn migrate_panel(entries : Array[String]) -> Array[String] { if !has_settings && !out.contains("session-settings") { out.push("session-settings") } + } else if e == "moon-disc" { + // The moon phase disc never had source in the tree: a saved panel drops it. + continue } else if e == "logout" { if !has_launcher && !out.contains("launcher") { out.push("launcher") @@ -353,6 +355,11 @@ test "a saved panel's wallpaper button becomes the settings module" { assert_eq(migrate_panel(["clock"]), ["clock"]) } +///| +test "a saved panel drops the moon-disc module, which has no source" { + assert_eq(migrate_panel(["launcher", "moon-disc", "clock-digital"]), ["launcher", "clock-digital"]) +} + ///| test "a saved panel's task list and dock become one dock, in the task list's place" { assert_eq(migrate_panel(["launcher", "tasks", "clock-digital", "dock"]), ["launcher", "dock", "clock-digital"]) diff --git a/compositor/wasm/wasm_test.mbt b/compositor/wasm/wasm_test.mbt index 724f2d1..3b480ae 100644 --- a/compositor/wasm/wasm_test.mbt +++ b/compositor/wasm/wasm_test.mbt @@ -69,22 +69,6 @@ fn load_module(name : String) -> Plasmoid { } } -///| Like load_module, for a module that may not be built (e.g. moon-disc, which has no source -/// in the tree): None, with a skip notice, when it isn't in build/components. -fn load_optional_module(name : String) -> Plasmoid? { - match load("build/components/" + name + ".wasm", test_tokens()) { - Ok(p) => Some(p) - Err(_) => - match load("../../build/components/" + name + ".wasm", test_tokens()) { - Ok(p) => Some(p) - Err(_) => { - println("skip: \{name}.wasm is not in build/components (no source in the tree)") - None - } - } - } -} - ///| fn texts_of(ops : Array[@types.DrawOp]) -> Array[String] { let out : Array[String] = [] @@ -199,7 +183,7 @@ test "the settings module's Panel tab lists host modules and asks to load, move, assert_true(p.imports().contains("modules")) let av = Table::new() for m in [ - ("moon-disc", "Moon Phase (disc)", "/m/moon-disc.wasm", 0), + ("clock-binary", "Binary Clock", "/m/clock-binary.wasm", 0), ("tasks", "Task Manager", "/m/tasks.wasm", 1), ("clock-digital", "Digital Clock", "/m/clock-digital.wasm", 1), ] { @@ -224,7 +208,7 @@ test "the settings module's Panel tab lists host modules and asks to load, move, None => fail("popup should be open") Some(ps) => { let ts = texts_of(ps.ops) - assert_true(ts.contains("Moon Phase (disc)")) + assert_true(ts.contains("Binary Clock")) assert_true(ts.contains("Clocks")) // The task manager is in the panel and one is enough: it is not offered again. A clock // can go in twice, so it is. @@ -246,7 +230,7 @@ test "the settings module's Panel tab lists host modules and asks to load, move, FaceUnlock(-1), // opening on the Session tab reads the face unlock status MoveInstance("w1", 1), UnloadInstance("w2"), - LoadModule("/m/moon-disc.wasm"), + LoadModule("/m/clock-binary.wasm"), Browse, ]) // Keys: Backspace removes the highlighted panel module, PageUp moves it. @@ -268,11 +252,7 @@ test "interface explorer module toggles through the inspector capability" { } ///| -test "moon and digital clock modules render from the clock capability" { - if load_optional_module("moon-disc") is Some(m) { - assert_true(m.render(36, 36, test_tokens()).length() > 3) - m.unload() - } +test "the digital clock module renders from the clock capability" { let c = load_module("clock-digital") let ts = texts_of(c.render(120, 36, test_tokens())) assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) // 12-hour by default diff --git a/docs/desktop-modules.md b/docs/desktop-modules.md index a73845e..4148316 100644 --- a/docs/desktop-modules.md +++ b/docs/desktop-modules.md @@ -107,7 +107,7 @@ capability's `desktops`, `current-desktop` and `set-desktop` (`wit/capabilities. `compositor/host/desktop_test.mbt`: choosing and listing, input routing (windows and the panel win, drags stay with the module), the right-click menu, resize, idle and animation pacing, -reload, and screenshots (`_build/desktop_*.png`). Run with: +and reload. Run with: ``` scripts/test-native.py -p compositor/host desktop diff --git a/docs/screenshot-editor.md b/docs/screenshot-editor.md index 67fb387..a3dc517 100644 --- a/docs/screenshot-editor.md +++ b/docs/screenshot-editor.md @@ -76,7 +76,3 @@ overlay, rather than being a separate component window: 52% for the same app on the desktop. - A picture saved unchanged is encoded by the host (`snapshot-png`), as before. An edited one is encoded with `@renderer.encode_png_compressed`. - -Headless pictures of the editor: run the host tests with `CHANDRA_EDITOR_SHOTS=` set, -and the test "editor: headless screenshots" writes `screenshot-editor.png` (the editor) and -`screenshot-editor-saved.png` (what it would save) there. diff --git a/justfile b/justfile index dbf4c26..38a097a 100644 --- a/justfile +++ b/justfile @@ -156,7 +156,7 @@ remote-build *targets: # Compositor + wasm component + lib tests. test: modules emoji-font scripts/test-native.py - moon test --target wasm --warn-list -a lib/shell lib/panel lib/clock lib/launcher lib/wm lib/taskbar lib/layoutpick lib/modmgr + moon test --target wasm --warn-list -a $(ls -d lib/*/ | sed "s,/$,,") # Native tests whose file or name contains one of WORDS (all without any), in parallel: `just t touch`. t *words: