CI / test (push) Failing after 17s
- New 'wallpaper' capability (wit/capabilities.wit: wallpapers, current-wallpaper, set-wallpaper) and 'wallpaper' panel module: a button whose popup lists the wallpapers with the current one ticked. Clicking a row switches the desktop at once (the list stays open to compare); Enter picks the highlighted row, Escape or a click elsewhere closes. In the default panel, before Log out. - lib/shell: render_wallpaper(screen, tokens, index) with Plasma glow (the old background), Aurora, Starfield, Dusk and Solid, all draw ops; the themed ones follow a theme swap. - The shell draws the chosen one (the renderer's wallpaper cache redraws it on change) and saves it in state.edn as :wallpaper (:aurora, ...); unknown names fall back to the default. - Served by both hosts: wasmer stub (native) and host-wasm (publish-wallpaper, wallpapers table 5, set-wallpaper request). - Tests: lib/shell wallpaper test, host-wasm module test, native end-to-end test (open, pick, Escape) and a state.edn round trip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hhM8CTYpe2XVYTFQGn
1187 lines
47 KiB
MoonBit
1187 lines
47 KiB
MoonBit
///| Input routing: host pointer/keyboard events reach the focused client window, and the
|
|
/// panel (made entirely of wasm modules) responds to the mouse and keyboard.
|
|
/// Needs the modules: run scripts/build-modules.sh (just test does).
|
|
|
|
///| Rectangle of the panel module `id` (file stem), as last drawn.
|
|
fn rect_of(comp : @host.MoonPlasmaCompositor, id : String) -> @scene.Rect {
|
|
comp.shell.slot_rect(comp.shell.slot_of(id))
|
|
}
|
|
|
|
///| Centre of the panel module `id`.
|
|
fn center_of(comp : @host.MoonPlasmaCompositor, id : String) -> (Double, Double) raise {
|
|
let r = rect_of(comp, id)
|
|
assert_true(r.w > 0)
|
|
((r.x + r.w / 2).to_double(), (r.y + r.h / 2).to_double())
|
|
}
|
|
|
|
///| Move to (x, y), press and release `btn`, then draw a frame.
|
|
fn click_at(comp : @host.MoonPlasmaCompositor, x : Int, y : Int, t : UInt, btn? : UInt = 272U) -> Unit {
|
|
comp.handle_input(@nested.InputEvent::PointerMove(x.to_double(), y.to_double()), t)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(btn, true), t + 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(btn, false), t + 2U)
|
|
ignore(comp.compose_frame())
|
|
}
|
|
|
|
///| Click the centre of panel module `id`.
|
|
fn click_module(comp : @host.MoonPlasmaCompositor, id : String, t : UInt) -> Unit raise {
|
|
let (x, y) = center_of(comp, id)
|
|
click_at(comp, x.to_int(), y.to_int(), t)
|
|
}
|
|
|
|
///| A fresh compositor with the default panel and a first frame drawn.
|
|
fn new_comp(tag : String) -> @host.MoonPlasmaCompositor {
|
|
let socket_path = "/tmp/wayland-moon-" + tag + "-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(comp.compose_frame())
|
|
comp
|
|
}
|
|
|
|
///| Drain everything the compositor sent this client as (object, opcode) pairs.
|
|
fn drain_msgs(c : TestWaylandClient) -> Array[(UInt, UInt)] {
|
|
let scratch : FixedArray[Byte] = FixedArray::make(65536, b'\x00')
|
|
let raw : Array[Byte] = []
|
|
while @sys.poll_read(c.fd, 5) > 0 {
|
|
let (n, rfd) = @sys.recvmsg_fd(c.fd, scratch, 65536)
|
|
if rfd >= 0 {
|
|
@sys.close_fd(rfd)
|
|
}
|
|
if n <= 0 {
|
|
break
|
|
}
|
|
for i = 0; i < n; i = i + 1 {
|
|
raw.push(scratch[i])
|
|
}
|
|
}
|
|
let out : Array[(UInt, UInt)] = []
|
|
let mut off = 0
|
|
while off + 8 <= raw.length() {
|
|
let obj = @wayland.read_u32_le(raw, off)
|
|
let w2 = @wayland.read_u32_le(raw, off + 4)
|
|
let size = ((w2 >> 16) & 0xFFFFU).reinterpret_as_int()
|
|
if size < 8 {
|
|
break
|
|
}
|
|
out.push((obj, w2 & 0xFFFFU))
|
|
off = off + size
|
|
}
|
|
out
|
|
}
|
|
|
|
///|
|
|
fn has_msg(msgs : Array[(UInt, UInt)], obj : UInt, op : UInt) -> Bool {
|
|
msgs.iter().any(m => m.0 == obj && m.1 == op)
|
|
}
|
|
|
|
|
|
///|
|
|
test "host input reaches the focused client and the launcher popup opens" {
|
|
let socket_path = "/tmp/wayland-moon-input-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(
|
|
comp, socket_path, "T", "t",
|
|
)
|
|
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
|
|
|
|
// Bind the seat and fetch its pointer + keyboard.
|
|
let reg_id = 2U
|
|
let seat_id = bind_global(c, reg_id, "wl_seat", 7U)
|
|
let ptr_id = c.alloc_id()
|
|
let w1 = @wayland.WireWriter::new()
|
|
w1.u32(ptr_id)
|
|
c.send(w1.finish_msg(seat_id, 0U))
|
|
let kbd_id = c.alloc_id()
|
|
let w2 = @wayland.WireWriter::new()
|
|
w2.u32(kbd_id)
|
|
c.send(w2.finish_msg(seat_id, 1U))
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
ignore(drain_msgs(c))
|
|
|
|
// Pointer over the window: enter + motion; press goes through as a button.
|
|
comp.handle_input(@nested.InputEvent::PointerMove(640.0, 300.0), 10U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 11U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 12U)
|
|
// Keyboard goes to the focused window.
|
|
comp.handle_input(@nested.InputEvent::Key(30U, true), 13U)
|
|
let msgs = drain_msgs(c)
|
|
assert_true(has_msg(msgs, ptr_id, 0U)) // wl_pointer.enter
|
|
assert_true(has_msg(msgs, ptr_id, 2U)) // motion
|
|
assert_true(has_msg(msgs, ptr_id, 3U)) // button
|
|
assert_true(has_msg(msgs, kbd_id, 3U)) // wl_keyboard.key
|
|
|
|
// The mouse wheel over the window scrolls it: axis_source + axis_discrete + axis.
|
|
comp.handle_input(@nested.InputEvent::Scroll(0U, 15.0, 1), 14U)
|
|
let wheel = drain_msgs(c)
|
|
assert_true(has_msg(wheel, ptr_id, 6U)) // wl_pointer.axis_source
|
|
assert_true(has_msg(wheel, ptr_id, 8U)) // wl_pointer.axis_discrete
|
|
assert_true(has_msg(wheel, ptr_id, 4U)) // wl_pointer.axis
|
|
// A touchpad (no notches) sends only the continuous axis.
|
|
comp.handle_input(@nested.InputEvent::Scroll(1U, -3.5, 0), 15U)
|
|
let pad = drain_msgs(c)
|
|
assert_true(has_msg(pad, ptr_id, 4U))
|
|
assert_false(has_msg(pad, ptr_id, 8U))
|
|
|
|
// Cursor: a client that asks for a text cursor gets it inside its window...
|
|
let shape_mgr = bind_global(c, reg_id, "wp_cursor_shape_manager_v1", 1U)
|
|
let shape_dev = c.alloc_id()
|
|
let w3 = @wayland.WireWriter::new()
|
|
w3.u32(shape_dev)
|
|
w3.u32(ptr_id)
|
|
c.send(w3.finish_msg(shape_mgr, 1U))
|
|
let w4 = @wayland.WireWriter::new()
|
|
w4.u32(1U) // serial
|
|
w4.u32(9U) // text
|
|
c.send(w4.finish_msg(shape_dev, 1U))
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_eq(comp.desired_cursor(), 9U)
|
|
|
|
// Launcher module: click the button -> its popup opens and swallows keys.
|
|
ignore(comp.compose_frame()) // lays out the panel
|
|
let (lx, ly) = center_of(comp, "launcher")
|
|
comp.handle_input(@nested.InputEvent::PointerMove(lx, ly), 20U)
|
|
assert_eq(comp.desired_cursor(), 4U) // ...but panel modules always show a hand
|
|
click_at(comp, lx.to_int(), ly.to_int(), 21U)
|
|
assert_true(comp.shell.popup_open())
|
|
assert_true(comp.shell.slot_popup_rect(comp.shell.slot_of("launcher")).w > 0)
|
|
comp.handle_input(@nested.InputEvent::Key(30U, true), 23U)
|
|
assert_false(has_msg(drain_msgs(c), kbd_id, 3U)) // swallowed by the launcher
|
|
// Off the shell and off any window: default arrow.
|
|
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 25U)
|
|
assert_eq(comp.desired_cursor(), 1U)
|
|
// Escape closes it.
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 24U)
|
|
assert_false(comp.shell.popup_open())
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "dragging the divider between two tiled windows resizes them" {
|
|
let socket_path = "/tmp/wayland-moon-split-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
let left = comp.windows.get(1UL).unwrap().geometry
|
|
let right = comp.windows.get(2UL).unwrap().geometry
|
|
// The divider is the gap between the two windows.
|
|
let gx = left.x + left.w + 2
|
|
let gy = left.y + left.h / 2
|
|
assert_true(right.x > left.x + left.w)
|
|
comp.handle_input(@nested.InputEvent::PointerMove(gx.to_double(), gy.to_double()), 1U)
|
|
assert_eq(comp.desired_cursor(), 26U) // ew-resize over the divider
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove(400.0, gy.to_double()), 3U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
|
let left2 = comp.windows.get(1UL).unwrap().geometry
|
|
let right2 = comp.windows.get(2UL).unwrap().geometry
|
|
assert_true(left2.w < left.w - 200)
|
|
assert_true(right2.w > right.w + 200)
|
|
assert_true(right2.x > left2.x + left2.w)
|
|
}
|
|
|
|
///|
|
|
test "the layout module opens a popup to pick Tiling, Monocle or Floating" {
|
|
let socket_path = "/tmp/wayland-moon-layout-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
ignore(comp.compose_frame())
|
|
let slot = comp.shell.slot_of("layout")
|
|
let (cx, cy) = center_of(comp, "layout")
|
|
comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 1U)
|
|
assert_eq(comp.desired_cursor(), 4U) // it is a button: hand cursor
|
|
// Pick row `i` from the popup the button opens.
|
|
let pick = fn(i : Int, t : UInt) raise {
|
|
click_at(comp, cx.to_int(), cy.to_int(), t) // open
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.w > 0)
|
|
click_at(comp, pr.x + pr.w / 2, pr.y + 4 + i * 28 + 14, t + 3U)
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
}
|
|
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
|
|
let tiled_w = comp.windows.get(1UL).unwrap().geometry.w
|
|
// Opening alone changes nothing.
|
|
click_at(comp, cx.to_int(), cy.to_int(), 2U)
|
|
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
|
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
|
|
// Escape closes without picking.
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 3U)
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
pick(1, 10U)
|
|
assert_eq(comp.layout_mode, @wm.LayoutMode::Monocle)
|
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > tiled_w + 100)
|
|
pick(2, 20U)
|
|
assert_eq(comp.layout_mode, @wm.LayoutMode::Floating)
|
|
pick(0, 30U)
|
|
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
|
|
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, tiled_w)
|
|
}
|
|
|
|
///|
|
|
test "title-bar buttons minimize, maximize and close windows" {
|
|
let socket_path = "/tmp/wayland-moon-btn-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let (c, _shm, _surf, _xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
ignore(comp.compose_frame())
|
|
// Button centres, from the decoration layout (18px buttons, 10px from the right edge).
|
|
let btn = fn(wid : UInt64, n : Int) {
|
|
let g = comp.windows.get(wid).unwrap().geometry
|
|
let outer_w = g.w + 4
|
|
let x = g.x - 2 + outer_w - 10 - 9 - (3 - n) * 26
|
|
let y = g.y - 32 + 16
|
|
(x, y)
|
|
}
|
|
let click = fn(p : (Int, Int), t : UInt) {
|
|
click_at(comp, p.0, p.1, t)
|
|
}
|
|
// Maximize window 1: it grows.
|
|
let w0 = comp.windows.get(1UL).unwrap().geometry.w
|
|
click(btn(1UL, 2), 1U)
|
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
|
|
click(btn(1UL, 2), 10U)
|
|
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
|
|
// Minimize window 1: it leaves the stacking order, then its pill in the task list restores it.
|
|
click(btn(1UL, 1), 20U)
|
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
|
assert_true(!comp.wm.stacking_order().contains(1UL))
|
|
let tasks = rect_of(comp, "tasks")
|
|
// pills are in opening order (140 wide, 6 apart): window 1, the minimized one, is first
|
|
click((tasks.x + 20, tasks.y + tasks.h / 2), 30U)
|
|
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
|
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
|
|
ignore(drain_msgs(c))
|
|
click(btn(1UL, 3), 40U)
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_true(has_msg(drain_msgs(c), tl, 1U))
|
|
}
|
|
|
|
///|
|
|
test "the task list module focuses the window whose pill is clicked" {
|
|
let socket_path = "/tmp/wayland-moon-tasks-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
ignore(comp.compose_frame())
|
|
let focused = fn() {
|
|
let mut f = 0UL
|
|
for id, w in comp.windows {
|
|
if w.focused {
|
|
f = id
|
|
}
|
|
}
|
|
f
|
|
}
|
|
let tasks = rect_of(comp, "tasks")
|
|
assert_true(tasks.w > 300) // the stretching module takes the free space
|
|
let first = comp.wm.stacking_order()[0]
|
|
click_at(comp, tasks.x + 20, tasks.y + tasks.h / 2, 1U) // pill 0
|
|
assert_eq(focused(), first)
|
|
let other = comp.wm.stacking_order()
|
|
click_at(comp, tasks.x + 146 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
|
|
assert_true(focused() != first || other.length() == 1)
|
|
}
|
|
|
|
///|
|
|
test "right-click a panel module to replace it in place, or remove it" {
|
|
let comp = new_comp("swap")
|
|
let before = comp.shell.slots()
|
|
let clock = rect_of(comp, "clock-digital12")
|
|
assert_true(clock.w > 0)
|
|
let find_row = fn(label : String) {
|
|
let mut i = -1
|
|
for k = 0; k < comp.shell.menu_rows.length(); k = k + 1 {
|
|
if comp.shell.menu_rows[k].label == label {
|
|
i = k
|
|
}
|
|
}
|
|
i
|
|
}
|
|
click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U)
|
|
assert_true(comp.shell.menu_open)
|
|
let m = comp.shell.menu_rect
|
|
assert_true(m.w > 0 && m.y + m.h <= clock.y) // above the panel, not off-screen
|
|
let bin = find_row("Replace with Binary Clock")
|
|
assert_true(bin >= 0)
|
|
assert_true(find_row("Remove widget") >= 0)
|
|
assert_true(find_row("Module manager...") >= 0)
|
|
// Hover the row (hand cursor), click it: the binary clock takes the digital clock's place.
|
|
let ix = m.x + m.w / 2
|
|
let iy = m.y + 26 + 28 * bin + 14
|
|
comp.handle_input(@nested.InputEvent::PointerMove(ix.to_double(), iy.to_double()), 10U)
|
|
assert_eq(comp.desired_cursor(), 4U)
|
|
click_at(comp, ix, iy, 11U)
|
|
assert_true(!comp.shell.menu_open)
|
|
assert_eq(comp.shell.slot_of("clock-digital12"), "")
|
|
let after = comp.shell.slots()
|
|
assert_eq(after.length(), before.length())
|
|
assert_eq(after[after.length() - 1], comp.shell.slot_of("clock-binary")) // same place in the panel
|
|
assert_true(rect_of(comp, "clock-binary").w > 0)
|
|
// Escape dismisses the menu; "Remove widget" unloads the module.
|
|
let moon = rect_of(comp, "moon-disc")
|
|
click_at(comp, moon.x + moon.w / 2, moon.y + moon.h / 2, 20U, btn=273U)
|
|
assert_true(comp.shell.menu_open)
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 30U)
|
|
assert_true(!comp.shell.menu_open)
|
|
click_at(comp, moon.x + moon.w / 2, moon.y + moon.h / 2, 40U, btn=273U)
|
|
let m2 = comp.shell.menu_rect
|
|
click_at(comp, m2.x + m2.w / 2, m2.y + 26 + 28 * find_row("Remove widget") + 14, 50U)
|
|
assert_eq(comp.shell.slot_of("moon-disc"), "")
|
|
assert_eq(comp.shell.slots().length(), before.length() - 1)
|
|
}
|
|
|
|
///|
|
|
test "tapping Super toggles the launcher; Super+key does not" {
|
|
let comp = new_comp("super")
|
|
let tap = fn(t : UInt) {
|
|
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
|
|
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 1U)
|
|
}
|
|
assert_false(comp.shell.popup_open())
|
|
tap(1U)
|
|
assert_true(comp.shell.popup_open())
|
|
tap(3U)
|
|
assert_false(comp.shell.popup_open())
|
|
// Super held while another key is pressed: not a tap.
|
|
comp.handle_input(@nested.InputEvent::Key(125U, true), 5U)
|
|
comp.handle_input(@nested.InputEvent::Key(30U, true), 6U)
|
|
comp.handle_input(@nested.InputEvent::Key(30U, false), 7U)
|
|
comp.handle_input(@nested.InputEvent::Key(125U, false), 8U)
|
|
assert_false(comp.shell.popup_open())
|
|
}
|
|
|
|
///|
|
|
test "the panel is saved to panel.edn and restored" {
|
|
// Never touch the user's real config: only run when a scratch dir is provided.
|
|
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let a = @shell.DesktopShell::new("x")
|
|
a.persist = true
|
|
a.set_output(theme, 1280, 720)
|
|
assert_true(a.unload_slot(a.slot_of("moon-disc")))
|
|
assert_true(a.load_module("clock-binary"))
|
|
let b = @shell.DesktopShell::new("x")
|
|
b.persist = true
|
|
b.set_output(theme, 1280, 720)
|
|
assert_eq(b.slot_of("moon-disc"), "")
|
|
assert_true(b.slot_of("clock-binary") != "")
|
|
assert_eq(b.slots().length(), a.slots().length())
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the wasm picker opens the module manager, which loads and unloads modules" {
|
|
let comp = new_comp("manager")
|
|
// The manager is not in the default panel: the picker loads it on demand.
|
|
assert_eq(comp.shell.slot_of("module-manager"), "")
|
|
let n0 = comp.shell.slots().length()
|
|
// Right-click empty panel space (the margin): the menu offers the module manager.
|
|
let panel = comp.shell.panel_rect
|
|
click_at(comp, 1, panel.y + 5, 1U, btn=273U)
|
|
assert_true(comp.shell.menu_open)
|
|
assert_eq(comp.shell.menu_rows[0].label, "Module manager...")
|
|
let m = comp.shell.menu_rect
|
|
click_at(comp, m.x + m.w / 2, m.y + 26 + 14, 10U)
|
|
assert_eq(comp.shell.slots().length(), n0 + 1)
|
|
let mgr = comp.shell.slot_of("module-manager")
|
|
assert_true(mgr != "")
|
|
ignore(comp.compose_frame())
|
|
let pr = comp.shell.slot_popup_rect(mgr)
|
|
assert_true(pr.w > 0) // the picker opened the app's popup
|
|
// Rows: header(24), one per loaded module (28), header(24), one per available module (28), browse.
|
|
let loaded = comp.shell.slots().length()
|
|
let avail_y = fn(k : Int) { pr.y + 4 + 24 + loaded * 28 + 24 + k * 28 + 14 }
|
|
let mut k_bin = -1
|
|
for k = 0; k < comp.shell.catalog.length(); k = k + 1 {
|
|
if comp.shell.catalog[k].id == "clock-binary" {
|
|
k_bin = k
|
|
}
|
|
}
|
|
assert_true(k_bin >= 0)
|
|
assert_eq(comp.shell.slot_of("clock-binary"), "")
|
|
click_at(comp, pr.x + 40, avail_y(k_bin), 20U) // select it: it is loaded into the panel
|
|
assert_true(comp.shell.slot_of("clock-binary") != "")
|
|
assert_eq(comp.shell.slots().length(), loaded + 1)
|
|
// The popup stays open; click the loaded module's row to unload it again.
|
|
let pr2 = comp.shell.slot_popup_rect(mgr)
|
|
assert_true(pr2.w > 0)
|
|
let slots = comp.shell.slots()
|
|
let mut idx = -1
|
|
for i = 0; i < slots.length(); i = i + 1 {
|
|
if slots[i] == comp.shell.slot_of("clock-binary") {
|
|
idx = i
|
|
}
|
|
}
|
|
click_at(comp, pr2.x + 40, pr2.y + 4 + 24 + idx * 28 + 14, 30U)
|
|
assert_eq(comp.shell.slot_of("clock-binary"), "")
|
|
assert_eq(comp.shell.slots().length(), loaded)
|
|
// The manager is just another module: it can be removed too, and the picker brings it back.
|
|
assert_true(comp.shell.unload_slot(mgr))
|
|
assert_eq(comp.shell.slot_of("module-manager"), "")
|
|
assert_true(comp.shell.open_module_manager())
|
|
assert_true(comp.shell.slot_of("module-manager") != "")
|
|
}
|
|
|
|
///|
|
|
test "dragging a panel module reorders it" {
|
|
let comp = new_comp("wdrag")
|
|
let order0 = comp.shell.slots()
|
|
let moon = rect_of(comp, "moon-disc")
|
|
let clock = rect_of(comp, "clock-digital12")
|
|
assert_true(moon.x < clock.x)
|
|
let cy = (clock.y + clock.h / 2).to_double()
|
|
comp.handle_input(@nested.InputEvent::PointerMove((clock.x + clock.w / 2).to_double(), cy), 1U)
|
|
assert_eq(comp.desired_cursor(), 4U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
// Drag the clock left past the moon.
|
|
comp.handle_input(@nested.InputEvent::PointerMove((moon.x + 2).to_double(), cy), 3U)
|
|
assert_eq(comp.desired_cursor(), 17U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
|
ignore(comp.compose_frame())
|
|
let order1 = comp.shell.slots()
|
|
assert_eq(order1.length(), order0.length())
|
|
assert_true(order1 != order0)
|
|
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital12"))
|
|
assert_true(rect_of(comp, "clock-digital12").x < rect_of(comp, "moon-disc").x)
|
|
assert_true(comp.desired_cursor() != 17U)
|
|
}
|
|
|
|
///|
|
|
test "any .wasm plasmoid can be loaded from a path and unloaded again" {
|
|
let comp = new_comp("path")
|
|
let n0 = comp.shell.slots().length()
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
ignore(theme)
|
|
assert_true(comp.shell.load_path("compositor/wasm/testdata/clock-digital.component.wasm") is Some(_))
|
|
assert_eq(comp.shell.slots().length(), n0 + 1)
|
|
ignore(comp.compose_frame())
|
|
let slot = comp.shell.slots()[n0]
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it got a panel placement and was drawn
|
|
assert_true(comp.shell.load_path("compositor/wasm/testdata/missing.wasm") is None)
|
|
assert_eq(comp.shell.slots().length(), n0 + 1)
|
|
// It unloads like any module.
|
|
assert_true(comp.shell.unload_slot(slot))
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_rect(slot).w, 0)
|
|
}
|
|
|
|
///|
|
|
test "modules are added until the panel is full" {
|
|
let comp = new_comp("full")
|
|
let n0 = comp.shell.slots().length()
|
|
let mut added = 0
|
|
for _i = 0; _i < 40; _i = _i + 1 {
|
|
if comp.shell.load_module("moon-disc") {
|
|
added = added + 1
|
|
}
|
|
}
|
|
assert_true(added > 2 && added < 40)
|
|
assert_eq(comp.shell.slots().length(), n0 + added)
|
|
ignore(comp.compose_frame())
|
|
assert_true(rect_of(comp, "moon-disc").w > 0)
|
|
}
|
|
|
|
///|
|
|
test "Desktop Pulse reads live machine and window state through its granted interfaces and can raise a window" {
|
|
let socket_path = "/tmp/wayland-moon-pulse-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
ignore(comp.compose_frame())
|
|
let n0 = comp.shell.slots().length()
|
|
assert_true(comp.shell.load_path("compositor/wasm/testdata/pulse.component.wasm") is Some(_))
|
|
// Its capability grant is exactly what the component imports; nothing else is reachable.
|
|
let slot = comp.shell.slots()[n0]
|
|
let w = comp.shell.widgets[n0]
|
|
assert_eq(w.slot, slot)
|
|
assert_eq(w.caps.length(), 3)
|
|
assert_true(w.caps.contains("system") && w.caps.contains("theme") && w.caps.contains("windows"))
|
|
ignore(comp.compose_frame())
|
|
// The host provider fed it real numbers and the window list.
|
|
assert_true(comp.shell.sampler.cur.mem_total_kib > 0L)
|
|
assert_true(comp.shell.sampler.cur.uptime_secs > 0L)
|
|
assert_eq(comp.shell.win_list.length(), 2)
|
|
let r = comp.shell.slot_rect(slot)
|
|
assert_true(r.w >= 300)
|
|
// Clicking each window's chip raises that window (first chip starts at x = 280).
|
|
for i = 0; i < 2; i = i + 1 {
|
|
let id = comp.shell.win_list[i].id
|
|
let cx = r.x + 280 + i * 23 + 10
|
|
let cy = r.y + r.h / 2
|
|
comp.handle_input(@nested.InputEvent::PointerMove(cx.to_double(), cy.to_double()), (10 + i * 4).reinterpret_as_uint())
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), (11 + i * 4).reinterpret_as_uint())
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), (12 + i * 4).reinterpret_as_uint())
|
|
ignore(comp.compose_frame())
|
|
assert_true(comp.windows.get(id).unwrap().focused)
|
|
let others_focused = comp.windows.iter().filter(kv => kv.0 != id && kv.1.focused).count()
|
|
assert_eq(others_focused, 0)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the desktop card can be dragged across the wallpaper" {
|
|
let socket_path = "/tmp/wayland-moon-desk-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(comp.compose_frame())
|
|
// Default: top-right, 24px in. Grab it by its body.
|
|
let gx = 1280 - 260 - 24 + 40
|
|
let gy = 24 + 30
|
|
assert_true(comp.shell.desk_hit(gx, gy))
|
|
comp.handle_input(@nested.InputEvent::PointerMove(gx.to_double(), gy.to_double()), 1U)
|
|
assert_eq(comp.desired_cursor(), 4U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove(300.0, 300.0), 3U)
|
|
assert_eq(comp.desired_cursor(), 17U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
|
// It moved: new top-left is pointer minus the grab offset.
|
|
assert_true(comp.shell.desk_hit(300, 300))
|
|
assert_true(!comp.shell.desk_hit(gx, gy))
|
|
assert_true(!comp.shell.desk_dragging())
|
|
}
|
|
|
|
///|
|
|
test "an xdg_popup (right-click menu) is placed, drawn, clickable and dismissed from outside" {
|
|
let socket_path = "/tmp/wayland-moon-popup-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(comp, socket_path, "T", "t")
|
|
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
|
|
let win = comp.windows.get(1UL).unwrap().geometry
|
|
|
|
let reg_id = 2U
|
|
let seat_id = bind_global(c, reg_id, "wl_seat", 7U)
|
|
let ptr_id = c.alloc_id()
|
|
let w1 = @wayland.WireWriter::new()
|
|
w1.u32(ptr_id)
|
|
c.send(w1.finish_msg(seat_id, 0U))
|
|
let comp_id = bind_global(c, reg_id, "wl_compositor", 5U)
|
|
let wm_id = bind_global(c, reg_id, "xdg_wm_base", 5U)
|
|
|
|
// Positioner: 100x60 popup whose top-left sits at (50, 60) in the window.
|
|
let pos_id = c.alloc_id()
|
|
let a = @wayland.WireWriter::new()
|
|
a.u32(pos_id)
|
|
c.send(a.finish_msg(wm_id, 1U))
|
|
let b = @wayland.WireWriter::new()
|
|
b.i32(100)
|
|
b.i32(60)
|
|
c.send(b.finish_msg(pos_id, 1U))
|
|
let d = @wayland.WireWriter::new()
|
|
d.i32(50)
|
|
d.i32(60)
|
|
d.i32(1)
|
|
d.i32(1)
|
|
c.send(d.finish_msg(pos_id, 2U))
|
|
let e = @wayland.WireWriter::new()
|
|
e.u32(2U) // anchor: top-left of the rect (bottom edge); use top_left below
|
|
c.send(e.finish_msg(pos_id, 3U))
|
|
let f = @wayland.WireWriter::new()
|
|
f.u32(8U) // gravity bottom_right: popup extends right and down from the anchor point
|
|
c.send(f.finish_msg(pos_id, 4U))
|
|
|
|
let psurf = c.alloc_id()
|
|
let g = @wayland.WireWriter::new()
|
|
g.u32(psurf)
|
|
c.send(g.finish_msg(comp_id, 0U))
|
|
let pxdg = c.alloc_id()
|
|
let h = @wayland.WireWriter::new()
|
|
h.u32(pxdg)
|
|
h.u32(psurf)
|
|
c.send(h.finish_msg(wm_id, 2U))
|
|
let popup_id = c.alloc_id()
|
|
let i = @wayland.WireWriter::new()
|
|
i.u32(popup_id)
|
|
i.u32(xdg)
|
|
i.u32(pos_id)
|
|
c.send(i.finish_msg(pxdg, 2U))
|
|
c.send(@wayland.WireWriter::new().finish_msg(psurf, 6U))
|
|
for _n = 0; _n < 5; _n = _n + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_eq(comp.popups.length(), 1)
|
|
let msgs = drain_msgs(c)
|
|
assert_true(has_msg(msgs, popup_id, 0U)) // xdg_popup.configure
|
|
|
|
// Attach a 100x60 buffer.
|
|
let bytes = 100 * 60 * 4
|
|
let pixels : Array[Byte] = Array::make(bytes, b'\xff')
|
|
let memfd = @sys.memfd_create("popup-shm", bytes)
|
|
ignore(@sys.pwrite_bytes(memfd, Bytes::from_array(pixels), 0))
|
|
let pool = c.alloc_id()
|
|
let j = @wayland.WireWriter::new()
|
|
j.u32(pool)
|
|
j.i32(bytes)
|
|
c.send(j.finish_msg(shm, 0U), send_fd=memfd)
|
|
@sys.close_fd(memfd)
|
|
let buf = c.alloc_id()
|
|
let k = @wayland.WireWriter::new()
|
|
k.u32(buf)
|
|
k.i32(0)
|
|
k.i32(100)
|
|
k.i32(60)
|
|
k.i32(400)
|
|
k.u32(0U)
|
|
c.send(k.finish_msg(pool, 0U))
|
|
let l = @wayland.WireWriter::new()
|
|
l.u32(buf)
|
|
l.i32(0)
|
|
l.i32(0)
|
|
c.send(l.finish_msg(psurf, 1U))
|
|
c.send(@wayland.WireWriter::new().finish_msg(psurf, 6U))
|
|
for _n = 0; _n < 10; _n = _n + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
let p = comp.popups[0]
|
|
assert_true(p.surface is Some(_))
|
|
let px = win.x + 50 + 5
|
|
let py = win.y + 60 + 5
|
|
|
|
// Clicking inside the popup reaches the client (not the window beneath).
|
|
drain_msgs(c) |> ignore
|
|
click_at(comp, px, py, 10U)
|
|
let msgs2 = drain_msgs(c)
|
|
assert_true(has_msg(msgs2, ptr_id, 0U)) // pointer enter on the popup surface
|
|
assert_true(has_msg(msgs2, ptr_id, 3U)) // button
|
|
|
|
// The popup is drawn above the window.
|
|
let pm = comp.compose_frame()
|
|
let (_, _, _, _) = (pm.width, pm.height, 0, 0)
|
|
|
|
// Clicking outside asks it to close.
|
|
click_at(comp, win.x + win.w - 20, win.y + win.h - 20, 20U)
|
|
let msgs3 = drain_msgs(c)
|
|
assert_true(has_msg(msgs3, popup_id, 1U)) // xdg_popup.popup_done
|
|
|
|
// The client destroys it: gone from the compositor.
|
|
c.send(@wayland.WireWriter::new().finish_msg(popup_id, 0U))
|
|
for _n = 0; _n < 5; _n = _n + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_eq(comp.popups.length(), 0)
|
|
}
|
|
|
|
///|
|
|
test "the dock module magnifies the tile under the pointer and shows nothing when the pointer leaves" {
|
|
let comp = new_comp("dock")
|
|
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
|
|
ignore(comp.compose_frame())
|
|
let slot = comp.shell.slots()[comp.shell.slots().length() - 1]
|
|
let r = comp.shell.slot_rect(slot)
|
|
assert_true(r.w > 0)
|
|
let frame = fn() {
|
|
ignore(comp.compose_frame())
|
|
}
|
|
// Pointer over the dock: it becomes the hovered widget.
|
|
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 14).to_double(), (r.y + r.h / 2).to_double()), 1U)
|
|
frame()
|
|
assert_eq(comp.shell.hover_slot, slot)
|
|
// Off the panel: the dock gets a leave.
|
|
comp.handle_input(@nested.InputEvent::PointerMove(640.0, 300.0), 2U)
|
|
assert_eq(comp.shell.hover_slot, "")
|
|
}
|
|
|
|
///| Bind wl_data_device_manager and get a data device; returns (manager, device).
|
|
fn data_device_for(c : TestWaylandClient) -> (UInt, UInt) {
|
|
let mgr = bind_global(c, 2U, "wl_data_device_manager", 3U)
|
|
let seat = bind_global(c, 2U, "wl_seat", 7U)
|
|
let dev = c.alloc_id()
|
|
let w = @wayland.WireWriter::new()
|
|
w.u32(dev)
|
|
w.u32(seat)
|
|
c.send(w.finish_msg(mgr, 1U))
|
|
(mgr, dev)
|
|
}
|
|
|
|
///|
|
|
test "copy in one client, paste in another" {
|
|
let socket_path = "/tmp/wayland-moon-clip-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let (a, _, _, _, _, _) = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let (b, _, _, _, _, _) = open_and_configure_client(comp, socket_path, "B", "b")
|
|
let (mgr_a, dev_a) = data_device_for(a)
|
|
let (_, dev_b) = data_device_for(b)
|
|
// A creates a source offering text and makes it the selection.
|
|
let src = a.alloc_id()
|
|
let w1 = @wayland.WireWriter::new()
|
|
w1.u32(src)
|
|
a.send(w1.finish_msg(mgr_a, 0U))
|
|
let w2 = @wayland.WireWriter::new()
|
|
w2.str("text/plain;charset=utf-8")
|
|
a.send(w2.finish_msg(src, 0U))
|
|
let w3 = @wayland.WireWriter::new()
|
|
w3.u32(src)
|
|
w3.u32(1U)
|
|
a.send(w3.finish_msg(dev_a, 1U))
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
// Focus B's window by clicking it; B is then offered the clipboard.
|
|
let bg = comp.windows.get(2UL).unwrap().geometry
|
|
comp.handle_input(
|
|
@nested.InputEvent::PointerMove((bg.x + bg.w / 2).to_double(), (bg.y + bg.h / 2).to_double()),
|
|
1U,
|
|
)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
let msgs_b = drain_msgs(b)
|
|
assert_true(has_msg(msgs_b, dev_b, 0U)) // data_offer
|
|
assert_true(has_msg(msgs_b, 0xff000000U, 0U)) // offer(mime) on the new wl_data_offer
|
|
assert_true(has_msg(msgs_b, dev_b, 5U)) // selection
|
|
// B pastes: receive(mime, fd) on the offer reaches A as source.send.
|
|
let fd = @sys.memfd_create("paste", 16)
|
|
let w4 = @wayland.WireWriter::new()
|
|
w4.str("text/plain;charset=utf-8")
|
|
b.send(w4.finish_msg(0xff000000U, 1U), send_fd=fd)
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_true(has_msg(drain_msgs(a), src, 1U))
|
|
@sys.close_fd(fd)
|
|
}
|
|
|
|
///|
|
|
test "dragging a title bar moves the window and floats it" {
|
|
let socket_path = "/tmp/wayland-moon-wdrag-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
let g0 = comp.windows.get(2UL).unwrap().geometry
|
|
let sx = g0.x + g0.w / 3
|
|
let sy = g0.y - 16 // inside the title bar, clear of the buttons
|
|
comp.handle_input(@nested.InputEvent::PointerMove(sx.to_double(), sy.to_double()), 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove((sx - 120).to_double(), (sy + 60).to_double()), 3U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
|
let g1 = comp.windows.get(2UL).unwrap().geometry
|
|
assert_eq(g1.x, g0.x - 120)
|
|
assert_eq(g1.y, g0.y + 60)
|
|
assert_eq(g1.w, g0.w)
|
|
// The other window now has the whole tiling area.
|
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > g0.w)
|
|
}
|
|
|
|
///|
|
|
test "dragging a floating window's corner resizes it" {
|
|
let socket_path = "/tmp/wayland-moon-rsz-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
let _a = open_and_configure_client(comp, socket_path, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
// Float window 2 by dragging its title bar a little.
|
|
let g = comp.windows.get(2UL).unwrap().geometry
|
|
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y - 16).to_double()), 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y - 6).to_double()), 3U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
|
let g0 = comp.windows.get(2UL).unwrap().geometry
|
|
let cx = g0.x + g0.w - 1
|
|
let cy = g0.y + g0.h - 1
|
|
comp.handle_input(@nested.InputEvent::PointerMove(cx.to_double(), cy.to_double()), 5U)
|
|
assert_eq(comp.desired_cursor(), 29U) // nwse-resize on the bottom-right corner
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 6U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove((cx - 50).to_double(), (cy - 40).to_double()), 7U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 8U)
|
|
let g1 = comp.windows.get(2UL).unwrap().geometry
|
|
assert_eq(g1.x, g0.x)
|
|
assert_eq(g1.y, g0.y)
|
|
assert_eq(g1.w, g0.w - 50)
|
|
assert_eq(g1.h, g0.h - 40)
|
|
}
|
|
|
|
///|
|
|
test "the logout button asks first, then ends the session" {
|
|
let comp = new_comp("logout")
|
|
let slot = comp.shell.slot_of("logout")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
assert_false(comp.quit_requested)
|
|
// A click opens the popup; nothing is requested yet.
|
|
click_module(comp, "logout", 1U)
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.w > 0)
|
|
ignore(comp.compose_frame())
|
|
assert_false(comp.quit_requested)
|
|
// Cancel (second row) closes it without logging out.
|
|
click_at(comp, pr.x + 20, pr.y + 6 + 30 + 5, 5U)
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
assert_false(comp.quit_requested)
|
|
// Open again and choose Log out (first row).
|
|
click_module(comp, "logout", 10U)
|
|
let pr2 = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr2.w > 0)
|
|
click_at(comp, pr2.x + 20, pr2.y + 6 + 5, 15U)
|
|
ignore(comp.compose_frame())
|
|
assert_true(comp.quit_requested)
|
|
}
|
|
|
|
///| Contents of state.edn in the scratch config dir.
|
|
fn read_state_edn() -> String {
|
|
let dir = match @sys.getenv("XDG_CONFIG_HOME") {
|
|
"" => @sys.getenv("HOME") + "/.config"
|
|
c => c
|
|
}
|
|
let raw = @sys.read_file_bytes(dir + "/moon-plasma/state.edn")
|
|
let sb = StringBuilder::new()
|
|
for i = 0; i < raw.length(); i = i + 1 {
|
|
sb.write_char(Int::unsafe_to_char(raw[i].to_int())) // the file is ASCII
|
|
}
|
|
sb.to_string()
|
|
}
|
|
|
|
///|
|
|
fn write_state_edn(text : String) -> Unit {
|
|
let dir = match @sys.getenv("XDG_CONFIG_HOME") {
|
|
"" => @sys.getenv("HOME") + "/.config"
|
|
c => c
|
|
}
|
|
ignore(@sys.mkdir_p(dir + "/moon-plasma"))
|
|
ignore(@sys.write_file_bytes(dir + "/moon-plasma/state.edn", @sys.str_to_utf8_bytes(text)))
|
|
}
|
|
|
|
///|
|
|
test "the layout mode and recent apps are saved to state.edn and restored; other keys survive" {
|
|
// Never touch the user's real config: only run when the test runner gave us a scratch dir.
|
|
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
|
write_state_edn(";; hand-written\n{:note \"keep me\" :layout :tiling}\n")
|
|
let a = new_comp("state-a")
|
|
a.shell.persist = true
|
|
a.restore_state() // nothing but :layout :tiling saved: stays tiling
|
|
assert_eq(a.layout_mode, @wm.LayoutMode::Tiling)
|
|
// Changing the layout writes it (and keeps the key we don't own).
|
|
a.set_layout_mode(@wm.LayoutMode::Floating)
|
|
a.shell.recents.push("konsole")
|
|
a.shell.recents.push("foot")
|
|
a.shell.save_state()
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":layout :floating"))
|
|
assert_true(text.contains("\"konsole\"") && text.contains("\"foot\""))
|
|
assert_true(text.contains(":note \"keep me\""))
|
|
// A new compositor starts where the last one left off.
|
|
let b = new_comp("state-b")
|
|
assert_eq(b.layout_mode, @wm.LayoutMode::Tiling) // persistence is off until asked
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
assert_eq(b.layout_mode, @wm.LayoutMode::Floating)
|
|
assert_eq(b.shell.recents, ["konsole", "foot"])
|
|
// Garbage in the file is ignored, not fatal.
|
|
write_state_edn("{:layout")
|
|
let c = new_comp("state-c")
|
|
c.shell.persist = true
|
|
c.restore_state()
|
|
assert_eq(c.layout_mode, @wm.LayoutMode::Tiling)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the desktop card position is saved when dropped and restored" {
|
|
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\"}\n")
|
|
let a = new_comp("card-a")
|
|
a.shell.persist = true
|
|
ignore(a.compose_frame())
|
|
assert_true(a.shell.desk_press(a.shell.screen_w - 100, 40))
|
|
ignore(a.shell.pointer_move(300, 200))
|
|
assert_true(a.shell.pointer_up())
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":desktop-card"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
let b = new_comp("card-b")
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
assert_true(b.shell.desk_set)
|
|
assert_eq(b.shell.desk_x, a.shell.desk_x)
|
|
assert_eq(b.shell.desk_y, a.shell.desk_y)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "clicking a floating window brings it in front of the others" {
|
|
let socket_path = "/tmp/wayland-moon-z-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
comp.set_layout_mode(@wm.LayoutMode::Floating)
|
|
ignore(comp.compose_frame())
|
|
let order = comp.wm.stacking_order()
|
|
assert_eq(order.length(), 2)
|
|
let (back, front) = (order[0], order[1])
|
|
// Click the window in back (its title bar, away from any overlap): it comes to the front.
|
|
let g = comp.windows.get(back).unwrap().geometry
|
|
click_at(comp, g.x + 20, g.y - 16, 1U)
|
|
ignore(comp.compose_frame())
|
|
let after = comp.wm.stacking_order()
|
|
assert_eq(after[1], back)
|
|
assert_eq(after[0], front)
|
|
}
|
|
|
|
///|
|
|
test "a window dragged somewhere reopens there, saved per app in state.edn" {
|
|
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\"}\n")
|
|
let sock1 = "/tmp/wayland-moon-wp1-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let a = @host.MoonPlasmaCompositor::new(sock1, theme, 1280, 720).unwrap()
|
|
a.shell.persist = true
|
|
a.set_layout_mode(@wm.LayoutMode::Floating)
|
|
ignore(open_and_configure_client(a, sock1, "T", "org.test.app"))
|
|
ignore(a.compose_frame())
|
|
let g0 = a.windows.get(1UL).unwrap().geometry
|
|
// Drag its title bar 120px right and 60px down.
|
|
a.handle_input(@nested.InputEvent::PointerMove((g0.x + 20).to_double(), (g0.y - 16).to_double()), 10U)
|
|
a.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
|
|
a.handle_input(@nested.InputEvent::PointerMove((g0.x + 140).to_double(), (g0.y + 44).to_double()), 12U)
|
|
a.handle_input(@nested.InputEvent::PointerButton(272U, false), 13U)
|
|
let g1 = a.windows.get(1UL).unwrap().geometry
|
|
assert_true(g1.x != g0.x || g1.y != g0.y)
|
|
let text = read_state_edn()
|
|
assert_true(text.contains("\"org.test.app\"") && text.contains(":windows"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
// A new session: the same app opens where it was left.
|
|
let sock2 = "/tmp/wayland-moon-wp2-" + @sys.getpid().to_string() + ".sock"
|
|
let b = @host.MoonPlasmaCompositor::new(sock2, theme, 1280, 720).unwrap()
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
ignore(open_and_configure_client(b, sock2, "T", "org.test.app"))
|
|
ignore(b.compose_frame())
|
|
let g2 = b.windows.get(1UL).unwrap().geometry
|
|
assert_eq(g2.x, g1.x)
|
|
assert_eq(g2.y, g1.y)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "alt-tab switches to the previous window, tab again goes further back, escape cancels" {
|
|
let socket_path = "/tmp/wayland-moon-alt-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
ignore(open_and_configure_client(comp, socket_path, "C", "c"))
|
|
ignore(comp.compose_frame())
|
|
let focused = fn() {
|
|
let mut f = 0UL
|
|
for id, w in comp.windows {
|
|
if w.focused {
|
|
f = id
|
|
}
|
|
}
|
|
f
|
|
}
|
|
let key = fn(code : UInt, down : Bool, t : UInt) {
|
|
comp.handle_input(@nested.InputEvent::Key(code, down), t)
|
|
}
|
|
assert_eq(focused(), 3UL)
|
|
// Alt+Tab, release Alt: the window used before this one.
|
|
key(56U, true, 1U)
|
|
key(15U, true, 2U)
|
|
key(15U, false, 3U)
|
|
assert_true(comp.switcher_open())
|
|
ignore(comp.compose_frame())
|
|
assert_true(comp.frame_changed) // the switcher is drawn
|
|
assert_eq(focused(), 3UL) // nothing switches until Alt is released
|
|
key(56U, false, 4U)
|
|
assert_false(comp.switcher_open())
|
|
assert_eq(focused(), 2UL)
|
|
// Alt+Tab+Tab: two back in use order (3 was used before 2, then 1).
|
|
key(56U, true, 10U)
|
|
key(15U, true, 11U)
|
|
key(15U, true, 12U)
|
|
key(56U, false, 13U)
|
|
assert_eq(focused(), 1UL)
|
|
// Escape closes it without switching.
|
|
key(56U, true, 20U)
|
|
key(15U, true, 21U)
|
|
assert_true(comp.switcher_open())
|
|
key(1U, true, 22U)
|
|
assert_false(comp.switcher_open())
|
|
key(56U, false, 23U)
|
|
assert_eq(focused(), 1UL)
|
|
// With the Alt not held, Tab is an ordinary key.
|
|
key(15U, true, 30U)
|
|
assert_false(comp.switcher_open())
|
|
}
|
|
|
|
///|
|
|
test "compose_scene hands the host a scene only when something changed" {
|
|
let socket_path = "/tmp/wayland-moon-scene-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
// The first scene is always drawn; the wallpaper and the desktop card are split out of it.
|
|
match comp.compose_scene() {
|
|
Some(sg) => {
|
|
assert_true(sg.wallpaper_ops.length() > 0)
|
|
assert_true(sg.panel_ops.length() > 0)
|
|
}
|
|
None => abort("the first scene must be drawn")
|
|
}
|
|
// Nothing happened: nothing to draw.
|
|
assert_true(comp.compose_scene() is None)
|
|
assert_false(comp.frame_changed)
|
|
// A new window changes the scene, then it settles again.
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
match comp.compose_scene() {
|
|
Some(sg) => assert_eq(sg.windows.length(), 1)
|
|
None => abort("a new window must change the scene")
|
|
}
|
|
assert_true(comp.compose_scene() is None)
|
|
// The switcher overlay is part of the scene too.
|
|
comp.handle_input(@nested.InputEvent::Key(56U, true), 1U)
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
ignore(comp.compose_scene())
|
|
comp.handle_input(@nested.InputEvent::Key(15U, true), 2U)
|
|
assert_true(comp.switcher_open())
|
|
assert_true(comp.compose_scene() is Some(_))
|
|
}
|
|
|
|
///|
|
|
test "super+d minimizes every window to show the desktop, and again brings them back" {
|
|
let socket_path = "/tmp/wayland-moon-supd-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
ignore(comp.compose_frame())
|
|
let key = fn(code : UInt, down : Bool, t : UInt) {
|
|
comp.handle_input(@nested.InputEvent::Key(code, down), t)
|
|
}
|
|
let focused = fn() {
|
|
let mut f = 0UL
|
|
for id, w in comp.windows {
|
|
if w.focused {
|
|
f = id
|
|
}
|
|
}
|
|
f
|
|
}
|
|
assert_eq(focused(), 2UL)
|
|
// Super+D: both windows are minimized and the launcher does not open.
|
|
key(125U, true, 1U)
|
|
key(32U, true, 2U)
|
|
key(32U, false, 3U)
|
|
key(125U, false, 4U)
|
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
|
assert_true(comp.wm.windows.get(2UL).unwrap().minimized)
|
|
assert_eq(comp.wm.stacking_order().length(), 0)
|
|
assert_true(comp.desktop_shown())
|
|
assert_false(comp.shell.popup_open())
|
|
// Super+D again: they come back, the one that was on top focused.
|
|
key(125U, true, 10U)
|
|
key(32U, true, 11U)
|
|
key(32U, false, 12U)
|
|
key(125U, false, 13U)
|
|
assert_false(comp.wm.windows.get(1UL).unwrap().minimized)
|
|
assert_false(comp.wm.windows.get(2UL).unwrap().minimized)
|
|
assert_false(comp.desktop_shown())
|
|
assert_false(comp.shell.popup_open())
|
|
assert_eq(focused(), 2UL)
|
|
// D without Super is an ordinary key.
|
|
key(32U, true, 20U)
|
|
key(32U, false, 21U)
|
|
assert_false(comp.wm.windows.get(2UL).unwrap().minimized)
|
|
}
|
|
|
|
///| Click (x, y) without drawing, then return the next scene's wallpaper op count (0: no new scene).
|
|
fn click_wallpaper_ops(comp : @host.MoonPlasmaCompositor, x : Int, y : Int, t : UInt) -> Int {
|
|
comp.handle_input(@nested.InputEvent::PointerMove(x.to_double(), y.to_double()), t)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t + 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 2U)
|
|
match comp.compose_scene() {
|
|
Some(sg) => sg.wallpaper_ops.length()
|
|
None => 0
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the wallpaper module lists the wallpapers and switches the desktop to the one clicked" {
|
|
let comp = new_comp("wallpaper")
|
|
let slot = comp.shell.slot_of("wallpaper")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
assert_eq(comp.shell.wallpaper_sel, 0)
|
|
// A click opens the list; nothing changes yet.
|
|
click_module(comp, "wallpaper", 1U)
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.h >= 6 * 2 + 5 * 30) // one row per wallpaper
|
|
assert_eq(comp.shell.wallpaper_sel, 0)
|
|
// Third row: Starfield. The list stays open and the backdrop is drawn anew.
|
|
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 5U)
|
|
assert_eq(comp.shell.wallpaper_sel, 2)
|
|
assert_true(star > 0)
|
|
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
|
// Last row: Solid, a single fill. Escape then closes the list.
|
|
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 4 * 30 + 5, 10U), 1)
|
|
assert_eq(comp.shell.wallpaper_sel, 4)
|
|
comp.shell.key_down("Escape")
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
// Out-of-range choices are ignored.
|
|
comp.shell.set_wallpaper(99)
|
|
assert_eq(comp.shell.wallpaper_sel, 4)
|
|
}
|
|
|
|
///|
|
|
test "the chosen wallpaper is saved to state.edn and restored" {
|
|
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\"}\n")
|
|
let a = new_comp("wall-a")
|
|
a.shell.persist = true
|
|
a.restore_state()
|
|
assert_eq(a.shell.wallpaper_sel, 0) // nothing saved: the default
|
|
a.shell.set_wallpaper(1)
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":wallpaper :aurora"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
let b = new_comp("wall-b")
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
assert_eq(b.shell.wallpaper_sel, 1)
|
|
// An unknown name falls back to the default.
|
|
write_state_edn("{:wallpaper :lava-lamp}\n")
|
|
let c = new_comp("wall-c")
|
|
c.shell.persist = true
|
|
c.restore_state()
|
|
assert_eq(c.shell.wallpaper_sel, 0)
|
|
}
|
|
}
|