149 lines
5.7 KiB
MoonBit
149 lines
5.7 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
|
|
|
|
// 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: 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)
|
|
assert_eq(comp.desired_cursor(), 4U) // ...but the launcher button always shows a hand
|
|
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
|
|
// Typing fills the search field: evdev 20 = t, 18 = e (key 30 = a was typed above).
|
|
comp.handle_input(@nested.InputEvent::Key(20U, true), 26U)
|
|
comp.handle_input(@nested.InputEvent::Key(18U, true), 27U)
|
|
assert_eq(comp.shell.launcher_state.query, "ate")
|
|
comp.handle_input(@nested.InputEvent::Key(14U, true), 28U)
|
|
assert_eq(comp.shell.launcher_state.query, "at")
|
|
// 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)
|
|
}
|