From 819778f292ee4e1294603b98662e083e49e23463 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 19:52:05 +0200 Subject: rsnix v0.5.0: graphics layer + cursor compositor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first visible GUI surface: real rect primitives, a single shadow→display push path, and an on-screen mouse cursor that can never race the text surface. gop: - fill_rect + push_rect(x,y,w,h): every raster op rasterises into the RAM shadow, then push_rect copies the rect to the display (write-only, still never read) and composites the cursor on top. blit_glyph and scroll shifts now route through it. - cursor overlay: 12x16 pointer (const-fn built from column lists) drawn white with a black offset outline; position in one AtomicU64 (x:high 32, y:low 32) — unpack masks the low word (a bare 'as usize' cast is a no-op on 64-bit). The cursor never enters the shadow, so erasing is just a shadow push of the old rect. - cursor_redraw after scroll shifts and once at spawn (the vt diff never re-blits idle cells). cursor task (task 2, spawned at boot when a mouse is present): - owns the PS/2 ring; polls every 10 ms, moves the cursor (clamped), tracks buttons, and forwards every event to a task's queue when 'mouse ' armed it (the window-manager input path). - /dev/mouse is now a position device (x/y/buttons snapshot); 'mouse' watches the cursor live (prints on change); 'cursor' prints one-shot state; 'gfx' draws a status-bar demo; 'gfx check' is an in-kernel pixel self-test (shadow readback, display readback, cursor overlay purity) — PASS/FAIL per stage. Tests (headless QEMU + monitor injection): - make test-gfx (new): all four compositor checks PASS. - make test-mouse (rewritten): cursor tracks mouse_move deltas, buttons ride along, /dev/mouse snapshot, live watch, real-event queue routing. - make test-msg: task numbering shifted (cursor is task 2; msgrecv is task 3) — updated, still PASS. - make test-disk regression re-passes. 0 build warnings. --- shell/src/lib.rs | 194 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 158 insertions(+), 36 deletions(-) (limited to 'shell/src/lib.rs') diff --git a/shell/src/lib.rs b/shell/src/lib.rs index c18d319..e1d54c8 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -704,6 +704,8 @@ write `{} TIL `", "pci" => cmd_pci(&parsed), "rescan" => cmd_rescan(&parsed), "mouse" => cmd_mouse(&parsed), + "cursor" => cmd_cursor(&parsed), + "gfx" => cmd_gfx(&parsed), "ls" => cmd_ls(&parsed), "cat" => cmd_cat(&parsed), "klog" => cmd_klog(&parsed), @@ -741,8 +743,11 @@ fn cmd_help(_p: &Parsed) { date — show current date/time (RTC) pci — list PCI devices rescan — re-scan for hotplugged/removed disks (also runs automatically) - mouse — live mouse events (dx/dy/buttons); ^C stops - mouse — post decoded mouse events to task 's queue (input routing) + cursor — report the on-screen mouse cursor (x, y, buttons) + mouse — watch the cursor live (x/y/buttons); ^C stops + mouse — route mouse events to task 's queue (cursor still tracks) + gfx — demo: draw a status bar + RGB boxes (bottom strip) + gfx check — pixel self-test: shadow, display push, cursor overlay bg — spawn a background task (spinner, ticker, counter, boom, overflow) msgrecv — spawn a task that blocks on its message queue and logs every message to serial (ids from `jobs`) @@ -1546,13 +1551,11 @@ fn cmd_rescan(_p: &Parsed) { } } -/// Live mouse event stream: print each decoded packet (dx/dy/buttons) as -/// it arrives until ^C. With an optional task id, events are **posted to -/// that task's message queue** instead of printed — the input-routing -/// path the window manager will use (`mouse ` + `msgrecv` proves the -/// whole chain: IRQ12 → ring → decoder → queue → blocked task). Polls -/// the PS/2 ring every 10 ms (via `sleep_ms`, which only blocks the -/// shell task) so background tasks keep running. +/// Mouse front-end. The cursor task owns the PS/2 ring, so this +/// command *watches the on-screen cursor* (position + buttons, printed +/// only on change) until ^C. With a task id it also routes every event +/// to that task's queue — the window-manager input path — clearing the +/// route on exit. fn cmd_mouse(p: &Parsed) { let target: Option = p.args.first().and_then(|s| s.parse::().ok()); if let Some(id) = target { @@ -1560,48 +1563,167 @@ fn cmd_mouse(p: &Parsed) { term_err(&alloc::format!("mouse: no such task {}", id)); return; } + rsnix::cursor::set_forward(Some(id)); term_println(&alloc::format!( - "mouse: posting events to task {} — ^C to stop", + "mouse: routing events to task {} (cursor still tracks) — ^C to stop", id )); + } else if !rsnix::ps2::mouse_present() { + term_err("mouse: no PS/2 mouse at boot — cat /dev/mouse still works"); + return; } else { - if !rsnix::ps2::mouse_present() { - term_err("mouse: no PS/2 mouse at boot — cat /dev/mouse still works"); - return; - } - term_println("mouse: streaming events — ^C to stop"); + term_println("mouse: watching cursor — move the mouse, ^C to stop"); } + let mut last = (usize::MAX, usize::MAX, u8::MAX); loop { if tty::interrupt_pressed() { + rsnix::cursor::set_forward(None); term_println("mouse: stopped"); return; } - while let Some(ev) = rsnix::ps2::try_poll_mouse() { - match target { - Some(id) => { - if let Err(e) = rsnix::sched::send(id, rsnix::sched::TaskMsg::Mouse(ev)) { - term_err(&alloc::format!("mouse: {}", e)); - return; - } - } - None => { - let mut b = String::new(); - b.push(if ev.left { 'L' } else { '-' }); - b.push(if ev.right { 'R' } else { '-' }); - b.push(if ev.middle { 'M' } else { '-' }); - term_println(&alloc::format!( - "dx={:+} dy={:+} buttons={}", - ev.dx, - ev.dy, - b - )); - } - } + let (x, y, b) = ( + rsnix::gop::cursor_pos().0, + rsnix::gop::cursor_pos().1, + rsnix::gop::cursor_buttons(), + ); + if (x, y, b) != last { + last = (x, y, b); + term_println(&alloc::format!( + "mouse: x={} y={} buttons={}{}{}", + x, + y, + if b & 1 != 0 { 'L' } else { '-' }, + if b & 2 != 0 { 'R' } else { '-' }, + if b & 4 != 0 { 'M' } else { '-' } + )); } rsnix::sched::sleep_ms(10); } } +/// One-shot cursor state (parseable; used by the test harness). +fn cmd_cursor(_p: &Parsed) { + let (x, y) = rsnix::gop::cursor_pos(); + let b = rsnix::gop::cursor_buttons(); + term_println(&alloc::format!( + "cursor: x={} y={} buttons={}{}{}", + x, + y, + if b & 1 != 0 { 'L' } else { '-' }, + if b & 2 != 0 { 'R' } else { '-' }, + if b & 4 != 0 { 'M' } else { '-' } + )); +} + +/// Graphics primitives demo + pixel self-test (shadow + display + cursor +/// overlay readbacks). `gfx` / `gfx demo` draws a status-bar scene; +/// `gfx check` runs the readback assertions (run after `clear` for a +/// predictable background). +fn cmd_gfx(p: &Parsed) { + match p.args.first().map(|s| s.as_str()) { + Some("check") => gfx_check(), + _ => gfx_demo(), + } +} + +fn gfx_demo() { + let (w, h) = rsnix::gop::pixel_dims(); + if w == 0 { + term_err("gfx: no framebuffer"); + return; + } + // Status-bar strip across the bottom, with three RGB boxes. + rsnix::gop::fill_rect(0, h - 40, w, 40, rsnix::gop::rgb(0, 0, 128)); + rsnix::gop::fill_rect(20, h - 32, 60, 24, rsnix::gop::rgb(255, 0, 0)); + rsnix::gop::fill_rect(90, h - 32, 60, 24, rsnix::gop::rgb(0, 255, 0)); + rsnix::gop::fill_rect(160, h - 32, 60, 24, rsnix::gop::rgb(255, 255, 0)); + term_println(&alloc::format!( + "gfx: drew status bar + RGB boxes ({}x{} px bottom strip)", + w, + h + )); +} + +fn gfx_check() { + let (w, _h) = rsnix::gop::pixel_dims(); + if w == 0 { + term_err("gfx: no framebuffer"); + return; + } + let mut ok = true; + let mut report = String::new(); + + // 1. fill_rect lands in the shadow. + let (rx, ry, rw, rh) = (8usize, 8usize, 40usize, 16usize); + let red = rsnix::gop::rgb(255, 0, 0); + rsnix::gop::fill_rect(rx, ry, rw, rh, red); + match rsnix::gop::shadow_pixel(rx + rw / 2, ry + rh / 2) { + Some(p) if p == red => report.push_str("fill_rect/shadow: OK\n"), + Some(p) => { + ok = false; + report.push_str(&alloc::format!("fill_rect/shadow: FAIL ({:#x})\n", p)); + } + None => { + ok = false; + report.push_str("fill_rect/shadow: FAIL (no shadow)\n"); + } + } + // 2. the push reached the display. + match rsnix::gop::display_pixel(rx + rw / 2, ry + rh / 2) { + Some(p) if p == red => report.push_str("display push: OK\n"), + Some(p) => { + ok = false; + report.push_str(&alloc::format!("display push: FAIL ({:#x})\n", p)); + } + None => { + ok = false; + report.push_str("display push: FAIL (readback)\n"); + } + } + // 3. cursor overlay: the arrow tip is white on the display… + let (cx, cy) = rsnix::gop::cursor_pos(); + let (dw, dh) = rsnix::gop::pixel_dims(); + let white = rsnix::gop::rgb(255, 255, 255); + let tip = rsnix::gop::display_pixel(cx + 2, cy); + let out = rsnix::gop::display_pixel(cx, cy); + match (tip, out) { + (Some(t), Some(o)) if t == white && o != white => report.push_str("cursor overlay: OK\n"), + (Some(t), Some(o)) => { + ok = false; + report.push_str(&alloc::format!( + "cursor overlay: FAIL (tip={:#x} outside={:#x})\n", + t, + o + )); + } + _ => { + ok = false; + report.push_str(&alloc::format!( + "cursor overlay: FAIL (readback cx={} cy={} dims={}x{})\n", + cx, + cy, + dw, + dh + )); + } + } + // …and it must NOT be in the shadow (pure overlay). + match rsnix::gop::shadow_pixel(cx + 2, cy) { + Some(p) if p != white => report.push_str("cursor not in shadow: OK\n"), + p => { + ok = false; + report.push_str(&alloc::format!("cursor in shadow: FAIL ({:?})\n", p)); + } + } + + term_println(&report); + term_println(if ok { + "gfx check: PASS" + } else { + "gfx check: FAIL" + }); +} + // --------------------------------------------------------------------------- // Multitasking: bg / jobs / sleep / kill / demo // -- cgit v1.2.3