Files
chandra/compositor/host/dock_test.mbt
T
nandiandClaude Opus 5.5 68baf1a467
CI / test (push) Failing after 49s
Launcher: pick up web apps as they are installed, categories, scrolling
- Read the app catalog again when the Applications menu opens if .desktop files were added or removed (and on Reload); it was only read at login, so a PWA installed during the session was missing from the menu and its search
- List a Chromium browser's web apps in their own category ("Chrome Apps", "Chromium Apps", ...), as Plasma does; don't take one for the default browser
- Category column and a scrollable list (wheel, scrollbar) when the catalog doesn't fit the menu
- Show menu-spec main category names instead of the first Categories= entry; sort apps A-Z (they were sorted shortest name first)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 23:42:10 -08:00

138 lines
7.3 KiB
MoonBit

///| The dock drawn in a real frame, for a look at it: writes _build/dock_hover.png (an icon under
/// the pointer, magnified, with its name above) and _build/dock_menu.png (an app's right-click
/// menu). Uses the machine's own .desktop files and icon theme, so what it shows varies.
///|
test "dock screenshots: hover label and an app's menu" {
let socket_path = "/tmp/wayland-moon-dockshot-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
ignore(comp.compose_frame())
let slot = comp.shell.slot_of("dock")
// Room for the dock's running apps on a 1280-wide screen.
for s in comp.shell.slots() {
let m = comp.shell.slot_module(s)
if m == "inspector" || m == "layout" || m == "screenshot" {
ignore(comp.shell.unload_slot(s))
}
}
comp.shell.set_module_setting(
slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim",
)
// Icons only, to see the magnification (titles are the default).
comp.shell.set_module_setting(slot, "titles", "off")
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
let _b = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
let _c = open_and_configure_client(comp, socket_path, "Terminal", "xterm")
let _e = open_and_configure_client(comp, socket_path, "Notes 2", "org.example.Notes")
let _d = open_and_configure_client(comp, socket_path, "Notes", "org.example.Notes")
ignore(comp.compose_frame())
ignore(comp.compose_frame())
let r = comp.shell.slot_rect(slot)
let cy = r.y + r.h / 2
// Hover the second icon (Calc).
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 30 + 12).to_double(), cy.to_double()), 1U)
let frame = comp.compose_frame()
assert_true(comp.shell.dock_hover_name().length() > 0)
ignore(@sys.write_file_bytes("_build/dock_hover.png", @renderer.encode_png(frame)))
// Right-click the first (Writer, two windows).
click_at(comp, r.x + 6 + 12, cy, 10U, btn=273U)
assert_true(comp.shell.menu_open)
assert_true(comp.shell.menu_rows.map(m => m.label).contains("Close 2 windows"))
ignore(@sys.write_file_bytes("_build/dock_menu.png", @renderer.encode_png(comp.compose_frame())))
}
///| Pick row `label` of the open right-click menu (rows: 26px title, then 28px each).
fn dock_pick(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit raise {
let i = comp.shell.menu_rows.map(r => r.label).search(label).unwrap()
let m = comp.shell.menu_rect
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
}
///| A key pressed and released with Super held (evdev codes).
fn super_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
comp.handle_input(@nested.InputEvent::Key(code, true), t + 1U)
comp.handle_input(@nested.InputEvent::Key(code, false), t + 2U)
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 3U)
ignore(comp.compose_frame())
}
///|
test "the dock is the panel's task manager: empty + opens Applications, pin from there, Super+number" {
let socket_path = "/tmp/wayland-moon-dockbar-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
ignore(comp.compose_frame())
// A fresh panel has the dock where the task list was; the old id is an alias of it.
let slot = comp.shell.slot_of("dock")
assert_true(slot.length() > 0)
assert_eq(comp.shell.slot_of("tasks"), slot)
// It stretches: the clock still packs against the right edge.
let r = comp.shell.slot_rect(slot)
assert_true(r.w > 300)
let clock = comp.shell.slot_rect(comp.shell.slot_of("clock-digital"))
assert_true(clock.x > 900)
// Nothing pinned, nothing running: a "+" that opens the Applications menu.
comp.shell.set_module_setting(slot, "pinned", ";")
ignore(comp.compose_frame())
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 14).to_double(), (r.y + r.h / 2).to_double()), 8U)
ignore(@sys.write_file_bytes("_build/dock_empty.png", @renderer.encode_png(comp.compose_frame())))
click_at(comp, r.x + 14, r.y + r.h / 2, 10U)
let launcher = comp.shell.slot_of("launcher")
let pr = comp.shell.slot_popup_rect(launcher)
assert_true(pr.w > 0)
// (The apps are right of the category column, when the machine has enough of them for one.)
// Right-click the first app there: Open, Pin to dock. Pinning keeps the menu open.
click_at(comp, pr.x + pr.w - 60, pr.y + 60, 20U, btn=273U)
assert_true(comp.shell.menu_open)
assert_eq(comp.shell.menu_rows.map(r => r.label), ["Open", "Pin to dock"])
let first = comp.shell.menu_title
ignore(@sys.write_file_bytes("_build/dock_pin_from_menu.png", @renderer.encode_png(comp.compose_frame())))
dock_pick(comp, "Pin to dock", 25U)
assert_true(comp.shell.slot_popup_rect(launcher).w > 0)
let pinned = comp.shell.module_setting("dock", "pinned").unwrap_or("")
assert_true(pinned.length() > 1 && pinned != ";")
// The same app's menu now offers Unpin.
click_at(comp, pr.x + pr.w - 60, pr.y + 60, 30U, btn=273U)
assert_eq(comp.shell.menu_title, first)
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Unpin from dock"))
comp.handle_input(@nested.InputEvent::Key(1U, true), 35U) // Escape closes the menu
comp.handle_input(@nested.InputEvent::Key(1U, false), 36U)
comp.handle_input(@nested.InputEvent::Key(1U, true), 37U) // and the Applications menu
comp.handle_input(@nested.InputEvent::Key(1U, false), 38U)
// Two running apps pinned in front: Super+2 brings the second one's window forward.
comp.shell.set_module_setting(slot, "pinned", "libreoffice-writer;libreoffice-calc;vim")
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
let _b = open_and_configure_client(comp, socket_path, "Budget.ods", "libreoffice-calc")
let _c = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
ignore(comp.compose_frame())
let focused = fn() {
let mut f = ""
for _, w in comp.windows {
if w.focused {
f = w.title
}
}
f
}
// Vim isn't running, so its icon comes first, then the tasks: Writer, Calc (pin order).
assert_eq(comp.shell.dock_item_ids(), ["vim", "libreoffice-writer", "libreoffice-calc"])
super_key(comp, 4U, 40U) // Super+3
assert_eq(focused(), "Budget.ods")
super_key(comp, 3U, 50U) // Super+2: Writer's newest window, then its other one
assert_eq(focused(), "Notes.odt")
super_key(comp, 3U, 60U)
assert_eq(focused(), "Report.odt")
// Writer's menu lists its two windows by title; picking one brings it forward.
let r = comp.shell.slot_rect(slot)
let writer_x = r.x + 6 + 24 + 6 + 11 + 20 // after Vim's icon and the divider
click_at(comp, writer_x, r.y + r.h / 2, 70U, btn=273U)
let labels = comp.shell.menu_rows.map(r => r.label)
assert_true(labels.contains("Report.odt") && labels.contains("Notes.odt"))
ignore(@sys.write_file_bytes("_build/dock_bar_menu.png", @renderer.encode_png(comp.compose_frame())))
dock_pick(comp, "Notes.odt", 80U)
ignore(comp.compose_frame())
assert_eq(focused(), "Notes.odt")
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 12).to_double(), (r.y + r.h / 2).to_double()), 90U)
ignore(@sys.write_file_bytes("_build/dock_bar.png", @renderer.encode_png(comp.compose_frame())))
}