Files
chandra/compositor/host/osk_test.mbt
T
nandiandClaude Opus 5.5 444d67ac79
CI / test (push) Failing after 49s
OSK: sit on top of the panel instead of covering it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 23:11:59 -08:00

201 lines
8.0 KiB
MoonBit

///| Built-in on-screen keyboard (osk.mbt): auto-open on text-input-v3 and terminal/launcher
/// focus, work_area resizing, popup lifting, virtual evdev key + Shift delivery, and Hide/reopen.
///|
fn osk_comp(tag : String, enable_osk? : Bool = true) -> @host.ChandraCompositor {
let socket_path = "/tmp/wayland-moon-osk-" + tag + "-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
if enable_osk {
comp.set_osk_enabled(true)
}
ignore(comp.compose_frame())
comp
}
///|
test "OSK stays disabled under CHANDRA_TEST_CONFIG=1 unless explicitly enabled" {
let socket_path = "/tmp/wayland-moon-osk-disabled-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
let (ti, _) = text_input_for(comp, a)
text_input_state(comp, a, ti, true, 50, 50, 16)
assert_false(comp.osk_is_visible())
comp.close()
}
///|
test "OSK auto-opens on zwp_text_input_v3 enable, shrinks work_area, and auto-hides on disable" {
let socket_path = "/tmp/wayland-moon-osk-ti-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
comp.set_osk_enabled(true)
let full_wa_h = comp.work_area.h
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
assert_eq(comp.kbd_win, Some(1UL))
let (ti, _) = text_input_for(comp, a)
assert_false(comp.osk_is_visible())
// Enabling text-input-v3 raises the OSK and shrinks the window work area cleanly above it.
text_input_state(comp, a, ti, true, 50, 50, 16)
assert_true(comp.osk_is_visible())
assert_eq(comp.work_area.h, full_wa_h - comp.osk_height())
// Disabling text-input-v3 hides the OSK and restores the full work area.
text_input_state(comp, a, ti, false, 0, 0, 0)
assert_false(comp.osk_is_visible())
assert_eq(comp.work_area.h, full_wa_h)
comp.close()
}
///|
test "OSK delivers evdev keys and one-shot Shift modifier to focused Wayland client" {
let socket_path = "/tmp/wayland-moon-osk-keys-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
comp.set_osk_enabled(true)
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
let (ti, kbd) = text_input_for(comp, a)
text_input_state(comp, a, ti, true, 50, 50, 16)
assert_true(comp.osk_is_visible())
ignore(drain_args(a))
// Tap 'a' (evdev 30) -> press + release sent via wl_keyboard.key (opcode 3).
let (ax, ay) = comp.osk_key_center("a").unwrap()
click_at(comp, ax, ay, 20U)
let msgs1 = drain_args(a)
let keys1 = msgs1.filter(m => m.0 == kbd && m.1 == 3U)
assert_eq(keys1.length(), 2)
assert_eq((keys1[0].2[2], keys1[0].2[3]), (30U, 1U))
assert_eq((keys1[1].2[2], keys1[1].2[3]), (30U, 0U))
// Tap 'Shift', verify key labels uppercase, tap 'A' -> Shift mod active then released.
let (sx, sy) = comp.osk_key_center("Shift").unwrap()
click_at(comp, sx, sy, 30U)
let (ux, uy) = comp.osk_key_center("A").unwrap()
click_at(comp, ux, uy, 40U)
let msgs2 = drain_args(a)
let mods2 = msgs2.filter(m => m.0 == kbd && m.1 == 4U)
let keys2 = msgs2.filter(m => m.0 == kbd && m.1 == 3U)
assert_true(mods2.length() >= 2)
assert_eq(mods2[0].2[1], 1U) // Shift depressed
assert_eq(mods2[mods2.length() - 1].2[1], 0U) // Restored
assert_eq(keys2.length(), 2)
assert_eq((keys2[0].2[2], keys2[0].2[3]), (30U, 1U))
assert_eq((keys2[1].2[2], keys2[1].2[3]), (30U, 0U))
// One-shot Shift cleared back to lowercase.
assert_true(comp.osk_key_center("a") is Some(_))
comp.close()
}
///|
test "OSK Hide button dismisses keyboard and KB pill or client tap reopens it" {
let socket_path = "/tmp/wayland-moon-osk-hide-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
comp.set_osk_enabled(true)
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes")
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
let (ti, _) = text_input_for(comp, a)
text_input_state(comp, a, ti, true, 50, 50, 16)
assert_true(comp.osk_is_visible())
// Hide button hides the keyboard.
let (hx, hy) = comp.osk_key_center("Hide").unwrap()
click_at(comp, hx, hy, 20U)
assert_false(comp.osk_is_visible())
// Tapping the compact "KB" toggle pill reopens it.
let tr = comp.osk_toggle_rect()
click_at(comp, tr.x + tr.w / 2, tr.y + tr.h / 2, 30U)
assert_true(comp.osk_is_visible())
// Hide again, then tap inside the client window with active text input -> reopens.
let (hx2, hy2) = comp.osk_key_center("Hide").unwrap()
click_at(comp, hx2, hy2, 40U)
assert_false(comp.osk_is_visible())
let g = comp.windows.get(1UL).unwrap().geometry
click_at(comp, g.x + g.w / 2, g.y + g.h / 2, 50U)
assert_true(comp.osk_is_visible())
comp.close()
}
///|
test "OSK auto-opens on launcher popup, lifts popup above OSK, and types into search" {
let comp = osk_comp("launcher")
let (lx, ly) = center_of(comp, "launcher")
click_at(comp, lx.to_int(), ly.to_int(), 10U)
assert_true(comp.shell.popup_open())
assert_true(comp.osk_is_visible())
// The OSK sits on top of the panel, not over it.
let or = comp.osk_rect()
assert_eq(or.y + or.h, comp.output_h - comp.theme.panel_height)
// Launcher popup sits entirely above the OSK.
let pr = comp.shell.open_popup_rect().unwrap()
assert_true(pr.y + pr.h <= comp.osk_rect().y)
// Tapping a letter key updates the launcher search query.
let (tx, ty) = comp.osk_key_center("t").unwrap()
click_at(comp, tx, ty, 20U)
assert_eq(comp.shell.launcher_state.query, "t")
// The panel still takes clicks under the open OSK: its launcher button closes the popup.
click_at(comp, lx.to_int(), ly.to_int(), 30U)
assert_false(comp.shell.popup_open())
assert_false(comp.osk_is_visible())
comp.close()
}
///|
test "OSK reaches the bottom edge in a strict kiosk, which has no panel" {
let comp = osk_comp("kiosk")
comp.start_kiosk("")
let r = comp.osk_rect()
assert_eq(r.y + r.h, comp.output_h)
assert_true(comp.set_kiosk_locked(false))
let r2 = comp.osk_rect()
assert_eq(r2.y + r2.h, comp.output_h - comp.theme.panel_height)
comp.close()
}
///|
test "Rot pill tap rotates CW, right-click flips 180 deg, and rotate control commands update size" {
let comp = osk_comp("rotate")
let rr = comp.osk_rotate_rect()
let rx = rr.x + rr.w / 2
let ry = rr.y + rr.h / 2
// Tap Rot pill -> queues 90 deg CW rotation.
click_at(comp, rx, ry, 10U)
assert_eq(comp.take_pending_rotation(), Some(1))
assert_eq(comp.current_rotation(), 1)
comp.apply_rotated_size(1170, 540)
assert_eq((comp.output_w, comp.output_h), (1170, 540))
// Right-click / long-press Rot pill -> queues 180 deg flip (1 -> 3 = 270 deg).
let rr2 = comp.osk_rotate_rect()
click_at(comp, rr2.x + rr2.w / 2, rr2.y + rr2.h / 2, 20U, btn=273U)
assert_eq(comp.take_pending_rotation(), Some(3))
assert_eq(comp.current_rotation(), 3)
// chandra-ctl rotate 0 / flip / status.
let (out0, ok0) = comp.control_command("rotate 0")
assert_true(ok0)
assert_eq(out0, ["ok rotate 0"])
assert_eq(comp.take_pending_rotation(), Some(0))
comp.apply_rotated_size(540, 1170)
let (out_flip, ok_flip) = comp.control_command("rotate flip")
assert_true(ok_flip)
assert_eq(out_flip, ["ok rotate flip"])
assert_eq(comp.take_pending_rotation(), Some(2))
comp.apply_rotated_size(540, 1170)
assert_true(comp.frame_changed)
let (out_st, ok_st) = comp.control_command("rotate status")
assert_true(ok_st)
assert_eq(out_st, ["ok 180 540x1170"])
comp.close()
}