diff --git a/src/console_session/console_takeover.rs b/src/console_session/console_takeover.rs index ae0cebf..6818655 100644 --- a/src/console_session/console_takeover.rs +++ b/src/console_session/console_takeover.rs @@ -58,14 +58,16 @@ impl Console { self.foreground.is_some() } - pub fn keep_up(&mut self) { - if let Some(quiet_kernel) = &mut self.quiet_kernel { - quiet_kernel.keep_quiet(); - } - if let Some(foreground) = &self.foreground { - foreground.insist(); - } - self.glyphs = font_glyphs(); + pub fn keep_up(&mut self) -> bool { + let kernel_got_loud = self + .quiet_kernel + .as_mut() + .is_some_and(QuietKernelConsole::keep_quiet); + let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist); + let glyphs = font_glyphs(); + let font_changed = glyphs != self.glyphs; + self.glyphs = glyphs; + kernel_got_loud || terminal_was_taken || font_changed } } @@ -85,13 +87,15 @@ impl QuietKernelConsole { Some(Self { previous_level }) } - fn keep_quiet(&mut self) { + fn keep_quiet(&mut self) -> bool { let Some(level) = console_level() else { - return; + return false; }; - if level != ALERTS_ONLY && fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_ok() { - self.previous_level = level; + if level == ALERTS_ONLY || fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_err() { + return false; } + self.previous_level = level; + true } } @@ -185,10 +189,8 @@ impl ForegroundVt { Some(Self { own, previous }) } - fn insist(&self) { - if active_vt().is_some_and(|active| active != self.own) { - let _ = activate(self.own); - } + fn insist(&self) -> bool { + active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok() } } diff --git a/src/console_session/live_desk.rs b/src/console_session/live_desk.rs index 294b9b5..c46a1f7 100644 --- a/src/console_session/live_desk.rs +++ b/src/console_session/live_desk.rs @@ -16,7 +16,8 @@ use crate::{ screen_settings::font_glyphs::Glyphs, }; -const FULL_REPAINT_INTERVAL: Duration = Duration::from_secs(1); +const CONSOLE_UPKEEP_INTERVAL: Duration = Duration::from_secs(1); +const FULL_REPAINT_INTERVAL: Duration = Duration::from_secs(5); pub struct LiveDesk { console: Console, @@ -83,8 +84,8 @@ impl ConsoleDesk for LiveDesk { self.follow_requests(true); } - fn keep_console_up(&mut self) { - self.console.keep_up(); + fn keep_console_up(&mut self) -> bool { + self.console.keep_up() } fn take_clear_request(&mut self) -> bool { @@ -96,6 +97,10 @@ impl ConsoleDesk for LiveDesk { } } +pub fn console_upkeep_inputs() -> impl Stream { + periodic_inputs(CONSOLE_UPKEEP_INTERVAL, || ScreenInput::ConsoleUpkeep) +} + pub fn full_repaint_inputs() -> impl Stream { periodic_inputs(FULL_REPAINT_INTERVAL, || ScreenInput::FullRepaint) } diff --git a/src/console_session/watch_loop.rs b/src/console_session/watch_loop.rs index bdfe05c..5a9feed 100644 --- a/src/console_session/watch_loop.rs +++ b/src/console_session/watch_loop.rs @@ -8,7 +8,9 @@ use crate::{ console_session::{ ask_password::RequestWatch, console_takeover::Console, - live_desk::{LiveDesk, full_repaint_inputs, password_request_inputs}, + live_desk::{ + LiveDesk, console_upkeep_inputs, full_repaint_inputs, password_request_inputs, + }, stream_sources::{frame_inputs, key_inputs, termination_inputs}, watch_screen::{WatchEnding, WatchScreen, watch_until_ending}, }, @@ -88,7 +90,10 @@ async fn watch_live_boot(settings: &Settings, phase: Phase) -> Result<(), Error> key_inputs()?, ), stream::select( - stream::select(frame_inputs(), full_repaint_inputs()), + stream::select( + frame_inputs(), + stream::select(console_upkeep_inputs(), full_repaint_inputs()), + ), stream::select( termination_inputs()?, stream::iter(password_inputs).flatten(), diff --git a/src/console_session/watch_screen.rs b/src/console_session/watch_screen.rs index 05eb2f2..34bad54 100644 --- a/src/console_session/watch_screen.rs +++ b/src/console_session/watch_screen.rs @@ -21,9 +21,9 @@ const PROJECTION_REFRESH: Duration = Duration::from_millis(100); pub enum ScreenInput { Boot(Vec), - Reconnected, Key(Event), Frame, + ConsoleUpkeep, FullRepaint, PasswordRequests, Terminate, @@ -45,7 +45,9 @@ pub trait ConsoleDesk { fn password_requests_changed(&mut self) {} - fn keep_console_up(&mut self) {} + fn keep_console_up(&mut self) -> bool { + false + } fn take_clear_request(&mut self) -> bool { false @@ -102,14 +104,13 @@ impl WatchScreen { let now = self.now(); match input { ScreenInput::Boot(changes) => self.apply_boot_changes(changes), - ScreenInput::Reconnected => { - self.full_repaint_due = true; - ControlFlow::Continue(()) - } ScreenInput::Key(event) => self.desk.press_key(&event, now), ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now), + ScreenInput::ConsoleUpkeep => { + self.full_repaint_due |= self.desk.keep_console_up(); + ControlFlow::Continue(()) + } ScreenInput::FullRepaint => { - self.desk.keep_console_up(); self.full_repaint_due = true; ControlFlow::Continue(()) } diff --git a/src/systemd_link/boot_feed.rs b/src/systemd_link/boot_feed.rs index 8e9c222..3425912 100644 --- a/src/systemd_link/boot_feed.rs +++ b/src/systemd_link/boot_feed.rs @@ -133,7 +133,7 @@ impl BusFeed { match self.open_watched().await { Ok(watched) => { self.link = Link::Connected(watched.connection); - vec![ScreenInput::Boot(watched.changes), ScreenInput::Reconnected] + vec![ScreenInput::Boot(watched.changes), ScreenInput::FullRepaint] } Err(_) if Instant::now() < deadline => { sleep(FRAME_INTERVAL).await;