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.
This commit is contained in:
nandi committed 2026-11-30 12:24:01 -08:00
1 parent 51852f0dac
commit 44bb77871d
31 files changed
+869 -49

No files matched your search

+2
View File
@@ -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)
+35
View File
@@ -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)
+6
View File
@@ -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,
+4
View File
@@ -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)
+8
View File
@@ -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)
}
}
+8
View File
@@ -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 => {
+9 -2
View File
@@ -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;