Files
chandra/compositor/host/osk_test.mbt
T
nandi 905dab8725
CI / test (push) Failing after 52s
Add a built-in on-screen keyboard for handset sessions
- Opens for text-input-v3 fields, terminals, launcher search, Network password, emoji picker and the password dialog; a KB pill summons it manually.
- Enabled on CHASSIS=handset; CHANDRA_OSK=1|0 overrides, and it stays off under CHANDRA_TEST_CONFIG.
- Work area and panel popups shrink above the keyboard so focused content stays visible.
- Keys send evdev codes with Shift, Ctrl and Alt modifiers.
- chandra-ctl: `screenshot [PATH]` saves a PNG without opening the editor.
- Key names cover the full punctuation set and shifted symbols.
- Launcher plasmoid min width drops from 60 to 36.
2026-11-28 00:18:32 -08:00

140 lines
5.9 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() - comp.theme.panel_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())
// 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")
comp.close()
}