///| 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 } ///| Replace the panel with the compact 9-module handset set (`rotate` and `osk` included). fn load_handset_modules(comp : @host.ChandraCompositor) -> Unit raise { for slot in comp.shell.slots() { ignore(comp.shell.unload_slot(slot)) } for id in [ "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", "rotate", "osk", ] { assert_true(comp.shell.load_module(id)) } ignore(comp.compose_frame()) } ///| 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 panel module 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) ignore(comp.compose_frame()) load_handset_modules(comp) let kr = rect_of(comp, "osk") assert_true(kr.w > 0 && kr.y >= comp.output_h - comp.theme.panel_height) 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()) // No floating "KB" or "Rot" pills are drawn above the panel when hidden. comp.damage.mark_full() let scene = comp.compose_scene().unwrap() for op in scene.panel_ops { match op { @scene.DrawOp::Text(_, y, text, _, _, _, _) if text == "KB" || text == "Rot" => assert_true(y >= comp.output_h - comp.theme.panel_height) _ => () } } // Tapping the "KB" panel module reopens the keyboard, and tapping it again hides it. click_module(comp, "osk", 30U) assert_true(comp.osk_is_visible()) click_module(comp, "osk", 35U) assert_false(comp.osk_is_visible()) // Tap inside the client window with active text input -> reopens. 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 "Rotate panel module rotates CW and rotate control commands update size" { let comp = osk_comp("rotate") load_handset_modules(comp) let rr = rect_of(comp, "rotate") assert_true(rr.w > 0 && rr.y >= comp.output_h - comp.theme.panel_height) // Tap Rotate panel module -> queues 90 deg CW rotation. click_module(comp, "rotate", 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)) // Tap Rotate panel module again -> queues 180 deg rotation. click_module(comp, "rotate", 20U) assert_eq(comp.take_pending_rotation(), Some(2)) assert_eq(comp.current_rotation(), 2) comp.apply_rotated_size(540, 1170) // 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() } ///| test "handset panel loads all 9 modules including rotate and osk inside 540px width" { let comp = osk_comp("handset-fit") load_handset_modules(comp) let ids = comp.shell.loaded_modules().filter(m => m.0 != "desktop").map(m => m.1) assert_eq(ids, [ "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", "rotate", "osk", ]) for id in ids { let r = rect_of(comp, id) assert_true(r.w > 0 && r.x >= 0 && r.x + r.w <= comp.output_w) assert_true(r.y >= comp.output_h - comp.theme.panel_height) } comp.damage.mark_full() let scene = comp.compose_scene().unwrap() for op in scene.panel_ops { match op { @scene.DrawOp::Text(_, y, text, _, _, _, _) if text == "KB" || text == "Rot" => assert_true(y >= comp.output_h - comp.theme.panel_height) _ => () } } comp.close() } ///| test "KB panel module toggles OSK manually even when auto-OSK is disabled" { let socket_path = "/tmp/wayland-moon-osk-manual-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() ignore(comp.compose_frame()) load_handset_modules(comp) 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, kbd) = text_input_for(comp, a) text_input_state(comp, a, ti, true, 50, 50, 16) // Auto-OSK is off, so text-input-v3 does not pop it open on its own. assert_false(comp.osk_is_visible()) ignore(drain_args(a)) // Clicking the KB panel module opens the OSK manually and typing reaches the client. click_module(comp, "osk", 20U) assert_true(comp.osk_is_visible()) let (ax, ay) = comp.osk_key_center("a").unwrap() click_at(comp, ax, ay, 30U) let keys = drain_args(a).filter(m => m.0 == kbd && m.1 == 3U) assert_eq(keys.length(), 2) assert_eq((keys[0].2[2], keys[0].2[3]), (30U, 1U)) // Clicking KB again closes the manually opened OSK. click_module(comp, "osk", 40U) assert_false(comp.osk_is_visible()) comp.close() } ///| test "clicking KB or Rotate panel modules keeps the launcher popup open" { let comp = osk_comp("launcher-keep") load_handset_modules(comp) click_module(comp, "launcher", 10U) assert_true(comp.shell.popup_open()) assert_true(comp.osk_is_visible()) let (hx, hy) = comp.osk_key_center("Hide").unwrap() click_at(comp, hx, hy, 20U) assert_false(comp.osk_is_visible()) assert_true(comp.shell.popup_open()) // Tapping Rotate leaves the Launcher popup open and does not accidentally reopen the OSK. click_module(comp, "rotate", 30U) assert_true(comp.shell.popup_open()) assert_false(comp.osk_is_visible()) assert_eq(comp.take_pending_rotation(), Some(1)) // Tapping KB opens the OSK while keeping the Launcher popup open above it. click_module(comp, "osk", 40U) assert_true(comp.shell.popup_open()) assert_true(comp.osk_is_visible()) let pr = comp.shell.open_popup_rect().unwrap() assert_true(pr.y + pr.h <= comp.osk_rect().y) comp.close() }