CI / test (push) Failing after 18s
clock-digital12 and clock-digital had become the same module (same lib/clock code, same right-click settings), differing only in the starting format. Keep one: the Digital Clock now starts in 12-hour mode with AM/PM, and its "Time format" setting switches to 24-hour. - components/clock-digital12 is gone (and from scripts/components.txt); lib/clock drops digital12_info/digital12_config. - The default panel loads clock-digital. - "clock-digital12" stays an alias (find_module, slot_of, saved panels) and is never listed in the module picker, even if an old .wasm is still installed. - panel.edn gets :version 2. A version-1 panel is migrated once: the old 12-hour clock becomes the Digital Clock with its settings (state.edn :module-config) moved over in 12-hour mode; a panel that had the old 24-hour Digital Clock keeps 24-hour. The file is rewritten afterwards. - Tests updated, plus a migration test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgnZsS91fwCreut8FL
1626 lines
66 KiB
MoonBit
1626 lines
66 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.ChandraCompositor, id : String) -> @scene.Rect {
|
|
comp.shell.slot_rect(comp.shell.slot_of(id))
|
|
}
|
|
|
|
///| Centre of the panel module `id`.
|
|
fn center_of(comp : @host.ChandraCompositor, 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.ChandraCompositor, 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.ChandraCompositor, 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.ChandraCompositor {
|
|
let socket_path = "/tmp/wayland-moon-" + tag + "-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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 task-bar pill for the window's menu: Minimize, Maximize, Quit" {
|
|
let socket_path = "/tmp/wayland-moon-taskmenu-" +
|
|
@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, "A", "a")
|
|
let _b = open_and_configure_client(comp, socket_path, "B", "b")
|
|
ignore(comp.compose_frame())
|
|
let tasks = rect_of(comp, "tasks")
|
|
let cy = tasks.y + tasks.h / 2
|
|
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
|
|
// Pick menu row `label` (rows: 26px title, then 28px each).
|
|
let pick = fn(label : String, t : UInt) raise {
|
|
let i = labels().search(label).unwrap()
|
|
let m = comp.shell.menu_rect
|
|
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
|
|
}
|
|
// Pill 0 is window 1 (opening order): its menu, titled with its title.
|
|
click_at(comp, tasks.x + 20, cy, 1U, btn=273U)
|
|
assert_true(comp.shell.menu_open)
|
|
assert_eq(comp.shell.menu_title, "A")
|
|
assert_eq(labels(), ["Minimize", "Maximize", "Quit"])
|
|
// Minimize, then the same pill's menu offers Restore, which brings it back.
|
|
pick("Minimize", 10U)
|
|
assert_true(!comp.shell.menu_open)
|
|
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
|
|
click_at(comp, tasks.x + 20, cy, 20U, btn=273U)
|
|
assert_eq(labels(), ["Restore", "Maximize", "Quit"])
|
|
pick("Restore", 30U)
|
|
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
|
|
// Maximize, then Restore size.
|
|
let w0 = comp.windows.get(1UL).unwrap().geometry.w
|
|
click_at(comp, tasks.x + 20, cy, 40U, btn=273U)
|
|
pick("Maximize", 50U)
|
|
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
|
|
click_at(comp, tasks.x + 20, cy, 60U, btn=273U)
|
|
assert_eq(labels(), ["Minimize", "Restore size", "Quit"])
|
|
pick("Restore size", 70U)
|
|
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
|
|
// Pill 1 is window 2.
|
|
click_at(comp, tasks.x + 146 + 20, cy, 80U, btn=273U)
|
|
assert_eq(comp.shell.menu_title, "B")
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 85U) // Escape
|
|
assert_true(!comp.shell.menu_open)
|
|
// Quit asks the app to close its window (xdg_toplevel.close, opcode 1 on its toplevel).
|
|
ignore(drain_msgs(c))
|
|
click_at(comp, tasks.x + 20, cy, 90U, btn=273U)
|
|
pick("Quit", 100U)
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_true(has_msg(drain_msgs(c), tl, 1U))
|
|
// Empty task-bar space keeps the module's own menu.
|
|
click_at(comp, tasks.x + tasks.w - 10, cy, 110U, btn=273U)
|
|
assert_eq(comp.shell.menu_title, "Task Manager")
|
|
assert_true(labels().contains("Remove widget"))
|
|
}
|
|
|
|
///|
|
|
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-digital")
|
|
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("System settings...") >= 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-digital"), "")
|
|
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 "right-click a module for its own settings: they apply at once and are remembered" {
|
|
let comp = new_comp("modcfg")
|
|
// A fresh instance next to nothing else: drop the default panel's clock first.
|
|
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
|
assert_true(comp.shell.load_module("clock-digital"))
|
|
ignore(comp.compose_frame())
|
|
let clock = rect_of(comp, "clock-digital")
|
|
assert_true(clock.w > 0)
|
|
let row_y = fn(k : Int) { comp.shell.menu_rect.y + 26 + 28 * k + 14 }
|
|
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
|
|
}
|
|
let time_text = fn() {
|
|
let mut t = ""
|
|
for op in comp.shell.slot_ops(comp.shell.slot_of("clock-digital")) {
|
|
match op {
|
|
Text(x) => if t == "" { t = x.text }
|
|
_ => ()
|
|
}
|
|
}
|
|
t
|
|
}
|
|
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) // 12-hour by default
|
|
click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U)
|
|
assert_true(comp.shell.menu_open)
|
|
assert_eq(comp.shell.menu_rows[0].label, "Module settings...")
|
|
assert_eq(comp.shell.menu_rows[1].label, "System settings...")
|
|
click_at(comp, comp.shell.menu_rect.x + 60, row_y(0), 10U)
|
|
// The module's own menu: a "Time format" heading, its two choices, then the switches.
|
|
assert_true(comp.shell.menu_open)
|
|
assert_eq(comp.shell.menu_title, "Digital Clock settings")
|
|
let h24 = find_row("24-hour")
|
|
assert_true(h24 > 0 && find_row("Time format") == h24 - 1)
|
|
assert_true(comp.shell.menu_rows[h24 + 1].ticked) // 12-hour
|
|
assert_true(find_row("Show AM/PM") >= 0)
|
|
click_at(comp, comp.shell.menu_rect.x + 60, row_y(h24), 20U)
|
|
assert_true(comp.shell.menu_open) // stays open, now ticking 24-hour
|
|
assert_true(comp.shell.menu_rows[find_row("24-hour")].ticked)
|
|
assert_eq(find_row("Show AM/PM"), -1) // only offered in 12-hour mode
|
|
assert_false(time_text().has_suffix("M"))
|
|
assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("24-hour"))
|
|
// A heading does nothing; Escape closes.
|
|
click_at(comp, comp.shell.menu_rect.x + 60, row_y(find_row("Time format")), 30U)
|
|
assert_true(comp.shell.menu_open)
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 40U)
|
|
assert_false(comp.shell.menu_open)
|
|
// A second instance of the module starts with the chosen setting.
|
|
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
|
assert_true(comp.shell.load_module("clock-digital"))
|
|
ignore(comp.compose_frame())
|
|
assert_false(time_text().has_suffix("M"))
|
|
}
|
|
|
|
///|
|
|
test "module settings are saved in state.edn and handed back at the next start" {
|
|
if @sys.getenv("CHANDRA_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.load_module("clock-binary"))
|
|
a.set_module_setting(a.slot_of("clock-binary"), "seconds", "off")
|
|
a.save_state() // the rest of state.edn is rewritten: :module-config stays
|
|
let b = @shell.DesktopShell::new("x")
|
|
b.persist = true
|
|
b.set_output(theme, 1280, 720)
|
|
assert_eq(b.module_setting("clock-binary", "seconds"), Some("off"))
|
|
let slot = b.slot_of("clock-binary")
|
|
assert_true(slot != "")
|
|
assert_eq(b.slot_config(slot)[0].value, "off")
|
|
}
|
|
}
|
|
|
|
///|
|
|
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("CHANDRA_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 "a panel saved with the old 12-hour clock gets the Digital Clock with the same settings" {
|
|
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
|
let dir = @sys.getenv("XDG_CONFIG_HOME") + "/chandra"
|
|
assert_true(@sys.mkdir_p(dir))
|
|
let state0 = @sys.read_file_bytes(dir + "/state.edn")
|
|
let write = fn(name : String, text : String) {
|
|
ignore(@sys.write_file_bytes(dir + "/" + name, @utf8.encode(text)))
|
|
}
|
|
let boot = fn() {
|
|
let s = @shell.DesktopShell::new("x")
|
|
s.persist = true
|
|
s.set_output(@scene.ThemeTokens::moon_night(), 1280, 720)
|
|
ignore(s.slots())
|
|
s
|
|
}
|
|
// The default panel's 12-hour clock, its date line switched off.
|
|
write("panel.edn", "{:panel [\"tasks\" \"clock-digital12\" \"logout\"]}\n")
|
|
write("state.edn", "{:module-config {\"clock-digital12\" {\"date\" \"off\"} \"clock-digital\" {\"format\" \"24-hour\"}}}\n")
|
|
let a = boot()
|
|
assert_true(a.slot_of("clock-digital") != "")
|
|
assert_eq(a.slot_of("clock-digital12"), a.slot_of("clock-digital")) // the old id is an alias
|
|
assert_eq(a.module_setting("clock-digital", "format"), Some("12-hour"))
|
|
assert_eq(a.module_setting("clock-digital", "date"), Some("off"))
|
|
assert_eq(a.module_setting("clock-digital12", "date"), None)
|
|
let panel = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/panel.edn"))
|
|
assert_true(panel.contains("\"clock-digital\"") && !panel.contains("clock-digital12"))
|
|
assert_true(panel.contains(":version 2"))
|
|
// Only once: a format chosen afterwards sticks across restarts.
|
|
a.set_module_setting(a.slot_of("clock-digital"), "format", "24-hour")
|
|
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
|
// A panel that had the (then 24-hour) Digital Clock keeps it in 24-hour mode.
|
|
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]}\n")
|
|
write("state.edn", "{}\n")
|
|
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
|
// A panel saved since then is left alone.
|
|
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]\n :version 2}\n")
|
|
write("state.edn", "{}\n")
|
|
assert_eq(boot().module_setting("clock-digital", "format"), None)
|
|
write("panel.edn", "")
|
|
ignore(@sys.write_file_bytes(dir + "/state.edn", state0))
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the wasm picker opens the settings module's Panel tab, which loads and unloads modules" {
|
|
let comp = new_comp("manager")
|
|
// The settings module is in the default panel; the standalone module manager is gone.
|
|
assert_eq(comp.shell.slot_of("module-manager"), "")
|
|
let mgr = comp.shell.slot_of("session-settings")
|
|
assert_true(mgr != "")
|
|
let n0 = comp.shell.slots().length()
|
|
// Right-click empty panel space (the margin): the menu offers the module list.
|
|
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, "System settings...")
|
|
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) // nothing new was loaded for it
|
|
ignore(comp.compose_frame())
|
|
let pr = comp.shell.slot_popup_rect(mgr)
|
|
assert_true(pr.w > 0) // the picker opened the popup
|
|
// Rows below the tab bar (40): heading, one per loaded module, heading, one per available
|
|
// module, browse; 28 each.
|
|
let loaded = comp.shell.slots().length()
|
|
assert_true(pr.h >= 40 + (loaded + 3) * 28)
|
|
let avail_y = fn(pr : @scene.Rect, k : Int) { pr.y + 40 + (loaded + 2 + k) * 28 + 13 }
|
|
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(pr, 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 (it grew a row); click the loaded module's row to unload it again.
|
|
ignore(comp.compose_frame())
|
|
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 + 40 + (1 + idx) * 28 + 13, 30U)
|
|
assert_eq(comp.shell.slot_of("clock-binary"), "")
|
|
assert_eq(comp.shell.slots().length(), loaded)
|
|
// The settings module 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("session-settings"), "")
|
|
assert_true(comp.shell.open_module_manager())
|
|
assert_true(comp.shell.slot_of("session-settings") != "")
|
|
}
|
|
|
|
///|
|
|
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-digital")
|
|
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-digital"))
|
|
assert_true(rect_of(comp, "clock-digital").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 draws no task icons" {
|
|
let socket_path = "/tmp/wayland-moon-pulse-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.ChandraCompositor::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)
|
|
// Pulse no longer draws a chip (task icon) per window: clicking where the chips used to be
|
|
// (from x = 280) focuses nothing.
|
|
let before = comp.windows.iter().filter(kv => kv.1.focused).map(kv => kv.0).collect()
|
|
for i = 0; i < 2; i = i + 1 {
|
|
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())
|
|
let now : Array[UInt64] = comp.windows.iter().filter(kv => kv.1.focused).map(kv => kv.0).collect()
|
|
assert_eq(now, before)
|
|
}
|
|
}
|
|
|
|
///|
|
|
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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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 + "/chandra/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 + "/chandra"))
|
|
ignore(@sys.write_file_bytes(dir + "/chandra/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("CHANDRA_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("CHANDRA_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.ChandraCompositor::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("CHANDRA_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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor::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.ChandraCompositor, 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 settings module lists the wallpapers and switches the desktop to the one clicked" {
|
|
let comp = new_comp("wallpaper")
|
|
let slot = comp.shell.slot_of("session-settings")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
assert_eq(comp.shell.slot_of("wallpaper"), "") // the standalone chooser is gone
|
|
assert_eq(comp.shell.wallpaper_sel, 0)
|
|
// A click opens the popup on its Session tab; the Desktop tab (the second of three 96 px
|
|
// tabs; four 72 px tabs) lists the wallpapers below a heading. Nothing changes yet.
|
|
click_module(comp, "session-settings", 1U)
|
|
let p0 = comp.shell.slot_popup_rect(slot)
|
|
click_at(comp, p0.x + 6 + 72 + 36, p0.y + 6 + 14, 3U)
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.h >= 40 + 6 * 28) // heading and one row per wallpaper below the tab bar
|
|
assert_eq(comp.shell.wallpaper_sel, 0)
|
|
// Third wallpaper: Starfield. The list stays open and the backdrop is drawn anew.
|
|
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 40 + 3 * 28 + 13, 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 + 40 + 5 * 28 + 13, 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("CHANDRA_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)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "state saved by a build from before the rename to Chandra is still read" {
|
|
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
|
let dir = match @sys.getenv("XDG_CONFIG_HOME") {
|
|
"" => @sys.getenv("HOME") + "/.config"
|
|
c => c
|
|
}
|
|
@sys.unlink(dir + "/chandra/state.edn")
|
|
ignore(@sys.mkdir_p(dir + "/moon-plasma"))
|
|
ignore(
|
|
@sys.write_file_bytes(
|
|
dir + "/moon-plasma/state.edn",
|
|
@sys.str_to_utf8_bytes("{:layout :monocle}\n"),
|
|
),
|
|
)
|
|
let c = new_comp("state-legacy")
|
|
c.shell.persist = true
|
|
c.restore_state()
|
|
assert_eq(c.layout_mode, @wm.LayoutMode::Monocle)
|
|
// The next save goes to the new place.
|
|
c.shell.save_state()
|
|
assert_true(read_state_edn().contains(":layout :monocle"))
|
|
@sys.unlink(dir + "/moon-plasma/state.edn")
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the open windows are saved as the session and a restored app's window gets its state back" {
|
|
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\"}\n")
|
|
let sock1 = "/tmp/wayland-moon-ss1-" + @sys.getpid().to_string() + ".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let a = @host.ChandraCompositor::new(sock1, theme, 1280, 720).unwrap()
|
|
a.shell.persist = true
|
|
ignore(open_and_configure_client(a, sock1, "A", "org.test.alpha"))
|
|
ignore(open_and_configure_client(a, sock1, "B", "org.test.beta"))
|
|
ignore(a.compose_frame())
|
|
ignore(a.wm.handle_request(2UL, @wm.WindowRequest::Minimize(true), a.work_area))
|
|
a.save_session()
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":session"))
|
|
assert_true(text.contains("\"org.test.alpha\"") && text.contains("\"org.test.beta\""))
|
|
assert_true(text.contains(":minimized true"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
// Saving the other state keeps the session, and the session reads back in order.
|
|
a.shell.save_state()
|
|
let saved = a.shell.load_session()
|
|
assert_eq(saved.length(), 2)
|
|
assert_eq(saved[0], { app: "org.test.alpha", minimized: false, maximized: false })
|
|
assert_eq(saved[1], { app: "org.test.beta", minimized: true, maximized: false })
|
|
// A new session: beta was launched and is waiting for its window. Until it shows up it still
|
|
// counts as part of the session; when it opens it is minimized again.
|
|
let sock2 = "/tmp/wayland-moon-ss2-" + @sys.getpid().to_string() + ".sock"
|
|
let b = @host.ChandraCompositor::new(sock2, theme, 1280, 720).unwrap()
|
|
b.shell.persist = true
|
|
b.restore_pending.push(saved[1])
|
|
b.restore_until = @sys.monotonic_ms() + 30000UL
|
|
assert_eq(b.session_snapshot(@sys.monotonic_ms()), [saved[1]])
|
|
ignore(open_and_configure_client(b, sock2, "B", "org.test.beta"))
|
|
ignore(b.compose_frame())
|
|
assert_eq(b.restore_pending.length(), 0)
|
|
assert_true(b.wm.windows.get(1UL).unwrap().minimized)
|
|
assert_eq(b.session_snapshot(@sys.monotonic_ms()), [saved[1]])
|
|
// :restore-session false turns reopening off.
|
|
write_state_edn("{:restore-session false :session [{:app \"foot\"}]}\n")
|
|
assert_eq(b.shell.load_session().length(), 0)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "the settings module flips the session settings from its popup" {
|
|
let comp = new_comp("sessset")
|
|
let slot = comp.shell.slot_of("session-settings")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
assert_true(comp.shell.restore_session)
|
|
assert_true(comp.shell.remember_windows)
|
|
// A click opens the list of switches; nothing changes yet.
|
|
click_module(comp, "session-settings", 1U)
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.h >= 40 + 3 * 28) // one row per setting below the tab bar
|
|
assert_true(comp.shell.restore_session)
|
|
// First row: "Reopen windows at login" goes off, and on again with a second click.
|
|
click_at(comp, pr.x + 40, pr.y + 40 + 13, 5U)
|
|
assert_false(comp.shell.restore_session)
|
|
assert_true(comp.shell.remember_windows)
|
|
assert_true(comp.shell.slot_popup_rect(slot).w > 0) // the list stays open
|
|
click_at(comp, pr.x + 40, pr.y + 40 + 13, 10U)
|
|
assert_true(comp.shell.restore_session)
|
|
// Second row: "Remember window positions"; then Down and Enter flip it back from the keyboard.
|
|
click_at(comp, pr.x + 40, pr.y + 40 + 28 + 13, 15U)
|
|
assert_false(comp.shell.remember_windows)
|
|
comp.shell.key_down("Enter")
|
|
ignore(comp.compose_frame())
|
|
assert_true(comp.shell.remember_windows)
|
|
assert_true(comp.shell.restore_session)
|
|
// Third row: Dark mode. Off switches the shell, panel and decorations to the light theme.
|
|
assert_eq(comp.theme.name, "Moon Night")
|
|
click_at(comp, pr.x + 40, pr.y + 40 + 2 * 28 + 13, 20U)
|
|
assert_false(comp.shell.dark_mode)
|
|
assert_eq(comp.theme.name, "Moon Day")
|
|
assert_eq(comp.shell.tokens.name, "Moon Day")
|
|
comp.shell.key_down("Enter") // the highlight stayed on Dark mode
|
|
ignore(comp.compose_frame())
|
|
assert_true(comp.shell.dark_mode)
|
|
assert_eq(comp.theme.name, "Moon Night")
|
|
comp.shell.key_down("Escape")
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
// Out-of-range settings are ignored.
|
|
comp.shell.set_session_setting(7, false)
|
|
assert_true(comp.shell.restore_session && comp.shell.remember_windows)
|
|
}
|
|
|
|
///|
|
|
test "session settings are saved to state.edn and restored, and take effect" {
|
|
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\" :session [{:app \"foot\"}]}\n")
|
|
let a = new_comp("sess-a")
|
|
a.shell.persist = true
|
|
a.restore_state()
|
|
assert_true(a.shell.restore_session) // absent: on
|
|
assert_eq(a.shell.load_session().length(), 1)
|
|
a.shell.remember_window("foot", 10, 20, 300, 200)
|
|
assert_eq(a.shell.saved_window("foot"), Some((10, 20, 300, 200)))
|
|
// Turning them off writes them, keeps the other keys, and stops reopening and placing.
|
|
a.shell.set_session_setting(0, false)
|
|
a.shell.set_session_setting(1, false)
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":restore-session false"))
|
|
assert_true(text.contains(":remember-windows false"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
assert_true(text.contains(":session"))
|
|
assert_eq(a.shell.load_session().length(), 0)
|
|
assert_eq(a.shell.saved_window("foot"), None)
|
|
a.shell.remember_window("foot", 50, 60, 300, 200) // not recorded while off
|
|
let b = new_comp("sess-b")
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
assert_false(b.shell.restore_session)
|
|
assert_false(b.shell.remember_windows)
|
|
// On again: the keys go away (absent means on), and the old place is still known.
|
|
b.shell.set_session_setting(0, true)
|
|
b.shell.set_session_setting(1, true)
|
|
let text2 = read_state_edn()
|
|
assert_false(text2.contains(":restore-session"))
|
|
assert_false(text2.contains(":remember-windows"))
|
|
assert_eq(b.shell.load_session().length(), 1)
|
|
assert_eq(b.shell.saved_window("foot"), Some((10, 20, 300, 200)))
|
|
// Dark mode off is saved as :theme :light and the next start comes up light.
|
|
b.shell.set_session_setting(2, false)
|
|
assert_true(read_state_edn().contains(":theme :light"))
|
|
let c = new_comp("sess-c")
|
|
c.shell.persist = true
|
|
assert_eq(c.theme.name, "Moon Night")
|
|
c.restore_state()
|
|
assert_false(c.shell.dark_mode)
|
|
assert_eq(c.theme.name, "Moon Day")
|
|
c.shell.set_session_setting(2, true)
|
|
assert_false(read_state_edn().contains(":theme"))
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "open_settings opens the settings module on the tab asked for" {
|
|
let comp = new_comp("opensettings")
|
|
let slot = comp.shell.slot_of("session-settings")
|
|
assert_true(comp.shell.open_settings(Desktop))
|
|
ignore(comp.compose_frame())
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_eq(pr.h, 40 + 6 * 28 + 6) // the Wallpaper heading and the five wallpapers
|
|
assert_true(comp.shell.open_settings(Session))
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 40 + 3 * 28 + 6) // the three settings
|
|
}
|
|
|
|
///|
|
|
test "idle timeouts turn the screen off, suspend once per idle spell, and input wakes the screen" {
|
|
let comp = new_comp("powertick")
|
|
comp.shell.screen_off_min = 1
|
|
comp.shell.suspend_min = 2
|
|
comp.note_activity(0UL)
|
|
assert_eq(comp.power_tick(30000UL), NoChange)
|
|
assert_eq(comp.power_tick(60000UL), ScreenOff)
|
|
assert_eq(comp.power_tick(61000UL), NoChange)
|
|
assert_eq(comp.power_tick(120000UL), Suspend)
|
|
assert_eq(comp.power_tick(200000UL), NoChange) // not again in the same idle spell
|
|
comp.note_activity(210000UL)
|
|
assert_eq(comp.power_tick(210500UL), ScreenOn)
|
|
assert_eq(comp.power_tick(250000UL), NoChange)
|
|
// A new idle spell suspends again; 0 means never.
|
|
assert_eq(comp.power_tick(270000UL), ScreenOff)
|
|
assert_eq(comp.power_tick(330000UL), Suspend)
|
|
comp.shell.screen_off_min = 0
|
|
comp.shell.suspend_min = 0
|
|
comp.note_activity(400000UL)
|
|
assert_eq(comp.power_tick(400100UL), ScreenOn)
|
|
assert_eq(comp.power_tick(99999999UL), NoChange)
|
|
}
|
|
|
|
///|
|
|
test "the settings module's Power tab steps the timeouts and confirms power off" {
|
|
let comp = new_comp("powertab")
|
|
let slot = comp.shell.slot_of("session-settings")
|
|
assert_true(comp.shell.open_settings(Power))
|
|
ignore(comp.compose_frame())
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
// Rows of 28 below the tab bar (40): [Battery heading, battery,] When idle, screen off,
|
|
// suspend, Now, Suspend, Restart, Power off.
|
|
let n = (pr.h - 40 - 6) / 28
|
|
assert_true(n == 7 || n == 9)
|
|
let first = n - 7
|
|
let row_y = fn(i : Int) { pr.y + 40 + (first + i) * 28 + 13 }
|
|
assert_eq(comp.shell.screen_off_min, 10)
|
|
click_at(comp, pr.x + 40, row_y(1), 5U) // screen off: 10 -> 15 min
|
|
assert_eq(comp.shell.screen_off_min, 15)
|
|
click_at(comp, pr.x + 40, row_y(2), 10U) // suspend: never -> 5 min
|
|
assert_eq(comp.shell.suspend_min, 5)
|
|
// Power off asks for a second click; outside the login session it only says so.
|
|
comp.shell.notice = ""
|
|
click_at(comp, pr.x + 40, row_y(6), 15U)
|
|
assert_eq(comp.shell.notice, "")
|
|
click_at(comp, pr.x + 40, row_y(6), 20U)
|
|
assert_true(comp.shell.notice.contains("login session"))
|
|
}
|
|
|
|
///|
|
|
test "power timeouts are saved to state.edn and restored" {
|
|
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
|
write_state_edn("{:note \"keep\"}\n")
|
|
let a = new_comp("pow-a")
|
|
a.shell.persist = true
|
|
a.restore_state()
|
|
assert_eq((a.shell.screen_off_min, a.shell.suspend_min), (10, 0)) // the defaults
|
|
a.shell.set_power_timeouts(5, 30)
|
|
let text = read_state_edn()
|
|
assert_true(text.contains(":power {:screen-off 5 :suspend 30}"))
|
|
assert_true(text.contains(":note \"keep\""))
|
|
let b = new_comp("pow-b")
|
|
b.shell.persist = true
|
|
b.restore_state()
|
|
assert_eq((b.shell.screen_off_min, b.shell.suspend_min), (5, 30))
|
|
b.shell.set_power_timeouts(10, 0)
|
|
assert_false(read_state_edn().contains(":power"))
|
|
}
|
|
}
|