Files
chandra/compositor/host/input_test.mbt
T
nandiandClaude Sonnet 5.5 bca69d8c90 Desktop card: click and drag it around the wallpaper
Press on the card (when no window covers it) to grab it; it follows the pointer,
clamped to the screen, with a hand cursor on hover and grabbing while dragged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-24 23:41:31 -08:00

556 lines
23 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
// 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: the visible window first, the minimized one second (140 wide, 6 apart)
click((tasks.x + 146 + 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())
}