From b418c26050870b900ff56d5a47f32209795aaf4a Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 21 Aug 2026 03:30:35 +0200 Subject: v0.5.11: fix terminal focus — toggle ACTIVE on Focus messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tty: read_line_from_queue() now takes &mut Terminal and handles TaskMsg::Focus: Focus(true) sets ACTIVE to the terminal, Focus(false) clears it. This fixes the bug where the console shell's gop_print! output was redirected to the soft terminal even after focus switched away from it. - shell: run_windowed() passes the terminal through to read_line_from_queue. - wm: remove noisy per-key debug logging from pump_main. --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- rsdos/src/main.rs | 2 +- rsnix/src/tty.rs | 16 +++++++++++++++- rsnix/src/wm.rs | 8 +++----- shell/src/lib.rs | 4 ++-- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76b5a2a..24b6a35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "rsdos" -version = "0.5.10" +version = "0.5.11" dependencies = [ "rsnix", "shell", @@ -19,7 +19,7 @@ dependencies = [ [[package]] name = "rsnix" -version = "0.5.10" +version = "0.5.11" [[package]] name = "rspaint" @@ -30,7 +30,7 @@ dependencies = [ [[package]] name = "shell" -version = "0.5.10" +version = "0.5.11" dependencies = [ "rsdosedit", "rsnix", diff --git a/Cargo.toml b/Cargo.toml index 90d28c7..26e5874 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["rsnix", "shell", "rsdos", "rsdosedit", "rspaint"] [workspace.package] -version = "0.5.10" +version = "0.5.11" edition = "2024" # no_std UEFI kernel: no unwinder available, so panic must abort. diff --git a/rsdos/src/main.rs b/rsdos/src/main.rs index e5fb6dd..d1ed506 100644 --- a/rsdos/src/main.rs +++ b/rsdos/src/main.rs @@ -483,7 +483,7 @@ fn terminal_entry() { rsnix::vt::set_active(&mut term as *mut Terminal); // Run the shell — it owns input, line editing, and command execution. - shell::run_windowed(); + shell::run_windowed(&mut term); // Shell exited (^D or window close). Clean up. rsnix::serial_println!("term: shell exited, cleaning up"); diff --git a/rsnix/src/tty.rs b/rsnix/src/tty.rs index 918f6e0..c44dca8 100644 --- a/rsnix/src/tty.rs +++ b/rsnix/src/tty.rs @@ -139,7 +139,14 @@ pub fn read_line() -> LineInput { /// windowed shells). Same semantics as `read_line` but keys arrive as /// `TaskMsg::Key` instead of from the global PS/2 queue. Returns `None` /// on `TaskMsg::Close` (window was closed). -pub fn read_line_from_queue() -> Option { +/// Read one line in canonical mode from the task's message queue (for +/// windowed shells). Same semantics as `read_line` but keys arrive as +/// `TaskMsg::Key` instead of from the global PS/2 queue. Returns `None` +/// on `TaskMsg::Close` (window was closed). +/// +/// Handles `TaskMsg::Focus` to toggle the global `ACTIVE` redirect so +/// gop_print! goes to the right terminal buffer. +pub fn read_line_from_queue(term: &mut crate::vt::Terminal) -> Option { crate::vt::sync_scroll(); let mut buf = strbuf::String::::new(); loop { @@ -191,6 +198,13 @@ pub fn read_line_from_queue() -> Option { } _ => {} }, + crate::sched::TaskMsg::Focus(gained) => { + if gained { + crate::vt::set_active(term as *mut crate::vt::Terminal); + } else { + crate::vt::set_active(core::ptr::null_mut()); + } + } crate::sched::TaskMsg::Close => return None, _ => {} } diff --git a/rsnix/src/wm.rs b/rsnix/src/wm.rs index 05781e8..71c310f 100644 --- a/rsnix/src/wm.rs +++ b/rsnix/src/wm.rs @@ -617,12 +617,10 @@ pub fn spawn_input_pump() -> Option { fn pump_main() { loop { - if focused().is_some() { + if let Some(id) = focused() { + let o = owner(id).unwrap_or(0); while let Some(ev) = crate::ps2::try_poll_key().or_else(crate::uhci::try_poll_key) { - if !handle_key(ev) - && let Some(id) = focused() - && let Some(o) = owner(id) - { + if !handle_key(ev) { let _ = crate::sched::send(o, TaskMsg::Key(ev)); } } diff --git a/shell/src/lib.rs b/shell/src/lib.rs index 6077f35..f2a0e6e 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -97,12 +97,12 @@ pub fn run() -> ! { /// reads from the task's message queue (Fed by the WM input pump) and /// writes to the active terminal (set by the caller via `vt::set_active`). /// Returns when the window is closed (Close message or ^D on empty line). -pub fn run_windowed() { +pub fn run_windowed(term: &mut rsnix::vt::Terminal) { term_println(&alloc::format!("rs-dos v{}", env!("CARGO_PKG_VERSION"))); loop { rsnix::vt::sync_scroll(); term_print("> "); - match tty::read_line_from_queue() { + match tty::read_line_from_queue(term) { None => return, // window closed Some(LineInput::Interrupted) => continue, Some(LineInput::Eof) => return, // ^D in windowed mode = close -- cgit v1.2.3