CI / test (push) Successful in 25s
- server: wl_pointer/wl_keyboard events (enter/leave/motion/button/key/modifiers), host keymap shared with client keyboards - nested: receives host pointer + keyboard + keymap, queues InputEvents - host: routes input to the launcher popup or the window under the pointer; click-to-focus moves keyboard focus - shell: launcher button opens lib/launcher popup; entries start real apps (foot, konsole, dolphin, firefox, kate, systemsettings if installed) with WAYLAND_DISPLAY pointed at the compositor - sys: has_exe + spawn - e2e test for input delivery and the launcher popup Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
95 lines
3.3 KiB
MoonBit
95 lines
3.3 KiB
MoonBit
///| Input routing: host pointer/keyboard events reach the focused client window,
|
|
/// and the launcher button opens the shell's launcher popup.
|
|
|
|
///| 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
|
|
|
|
// Launcher: click the button -> popup opens and swallows keys.
|
|
ignore(comp.compose_frame()) // lays out the panel
|
|
comp.handle_input(@nested.InputEvent::PointerMove(60.0, 700.0), 20U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 21U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 22U)
|
|
assert_true(comp.shell.popup_open())
|
|
comp.handle_input(@nested.InputEvent::Key(30U, true), 23U)
|
|
let after = drain_msgs(c)
|
|
assert_false(has_msg(after, kbd_id, 3U)) // swallowed by the launcher
|
|
// Escape closes it.
|
|
comp.handle_input(@nested.InputEvent::Key(1U, true), 24U)
|
|
assert_false(comp.shell.popup_open())
|
|
comp.close()
|
|
}
|