diff --git a/AGENTS.md b/AGENTS.md index 6a68325..2b4789d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -59,7 +59,10 @@ implementation choices for target packaging and clean-machine acceptance. Open source PDFs read-only. Never rewrite a document as a side effect of presenting. Failed loads retain the working document. Bound renderer memory/cache usage; handle malformed, encrypted and large PDFs explicitly. Keep slow rendering off the UI thread. -Audience outputs must never show operator notes, dialogs, paths or controls. Show presentation output automatically on startup/document open by default, with a +Audience outputs must never show operator notes, source paths or general operator +dialogs/controls. The user-authorized exception is minimal startup display-swap +and timed Keep/Revert recovery controls; disable the startup menu after explicit +navigation/show and never send presenter content to implement this exception. Show presentation output automatically on startup/document open by default, with a saved opt-out. Preserve manual blanking during navigation; topology changes and host failure recovery still blank explicitly and must show an unmistakable operator warning. Display disconnects must not move operator content onto an audience output. diff --git a/Cargo.lock b/Cargo.lock index 104c634..92c005c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2212,7 +2212,7 @@ dependencies = [ [[package]] name = "pdf-presenter" -version = "0.1.20" +version = "0.1.21" dependencies = [ "bytemuck", "chrono", diff --git a/Cargo.toml b/Cargo.toml index e8bacde..157f7ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"] resolver = "3" [workspace.package] -version = "0.1.20" +version = "0.1.21" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter" diff --git a/crates/pdf-presenter/src/native.rs b/crates/pdf-presenter/src/native.rs index cf6aca0..f0a493d 100644 --- a/crates/pdf-presenter/src/native.rs +++ b/crates/pdf-presenter/src/native.rs @@ -1,7 +1,7 @@ //! Native multiwindow host using winit, egui and cached software composition. use crate::{ document::Frame, - output::{Ack, HostState, OutputLink, SleepLease}, + output::{Ack, DisplayAction, HostState, OutputLink, SleepLease}, presenter_ui::{self, UiState}, studio::{Action, Monitor, Studio}, worker::{self, Bridge, Request}, @@ -45,6 +45,7 @@ struct NativeWindow { target: Option<(String, bool)>, transition: Option<(Instant, bool)>, frames: usize, + display_action: Option, } impl NativeWindow { fn create(el: &ActiveEventLoop, role: Role, monitor: String) -> Result { @@ -90,6 +91,7 @@ impl NativeWindow { target: None, transition: None, frames: 0, + display_action: None, }) } fn place(&mut self, handle: &MonitorHandle, id: &str, fullscreen: bool, x11: bool) { @@ -154,6 +156,7 @@ impl NativeWindow { mut studio: Option<&mut Studio>, frame: Option<&Arc>, blank: bool, + setup: Option<&HostState>, ) -> Result<(), Failure> { let size = self.window.inner_size(); if size.width == 0 || size.height == 0 { @@ -170,6 +173,7 @@ impl NativeWindow { let role = self.role; let ui_state = &mut self.ui; let ctx = self.ctx.clone(); + let display_action = &mut self.display_action; let output = ctx.run_ui(input, |ui| match role { Role::Presenter => { presenter_ui::presenter(ui, studio.as_deref_mut().unwrap(), ui_state) @@ -178,6 +182,13 @@ impl NativeWindow { Role::Presentation => { ui.painter() .rect_filled(ui.max_rect(), 0., egui::Color32::BLACK); + if let Some(setup) = setup { + *display_action = presenter_ui::output_display_recovery( + ui, + setup.setup_controls, + setup.route_trial.is_some(), + ); + } if !blank && let Some(frame) = frame { use std::hash::{Hash, Hasher}; let mut hash = std::hash::DefaultHasher::new(); @@ -419,7 +430,7 @@ impl App { let mut desired = vec![]; if let Some(s) = &self.studio { for id in &s.routes.presenter { - desired.push((Role::Presenter, id.clone(), s.settings.presenter_fullscreen)); + desired.push((Role::Presenter, id.clone(), s.presenter_fullscreen())); } if s.browser_open { let id = s @@ -470,6 +481,17 @@ impl App { } fn key(&mut self, role: Role, key: Key, consumed: bool, modifiers: bool) { if role == Role::Presentation { + if matches!(key, Key::Named(NamedKey::Escape)) + && let Some(host) = &self.host + && host.state.route_trial.is_some() + { + let _ = host.acks.try_send(Ack { + display_action: Some(DisplayAction::Revert), + route_trial: host.state.route_trial, + ..Default::default() + }); + return; + } if matches!(key, Key::Named(NamedKey::Escape)) || matches!(&key,Key::Character(c) if c.eq_ignore_ascii_case("b")) { @@ -488,6 +510,10 @@ impl App { let Some(s) = &mut self.studio else { return; }; + if matches!(key, Key::Named(NamedKey::Escape)) && s.route_trial.is_some() { + s.execute(Action::RevertRoutes); + return; + } if modifiers || consumed { return; } @@ -602,6 +628,9 @@ impl App { } if let Some(output) = &self.output { while let Ok(ack) = output.rx.try_recv() { + if let Some(action) = ack.display_action { + s.display_control(action, ack.route_trial); + } if ack.generation == s.buffer_generation() { s.output_buffered = ack.buffered; } @@ -621,6 +650,8 @@ impl App { if s.new_output { s.output_sequence += 1; let state = HostState { + setup_controls: !s.presentation_started, + route_trial: s.route_trial.as_ref().map(|t| t.id), sequence: s.output_sequence, page: s.requested, frame: if s.routes.presentation.is_empty() { @@ -640,7 +671,7 @@ impl App { .collect() }, monitors: s.routes.presentation.clone(), - fullscreen: s.settings.presentation_fullscreen, + fullscreen: s.presentation_fullscreen(), blanked: s.blanked, ..Default::default() }; @@ -672,6 +703,8 @@ impl App { Err(mpsc::TryRecvError::Empty) => break, Err(mpsc::TryRecvError::Disconnected) => { host.parent_connected = false; + host.state.route_trial = None; + host.state.setup_controls = false; break; } }; @@ -897,8 +930,21 @@ impl ApplicationHandler for App { WindowEvent::RedrawRequested => { let frame = self.host.as_ref().and_then(|h| h.frame.clone()); let blank = self.host.as_ref().is_none_or(|h| h.state.blanked); - let result = - self.windows[index].render(self.studio.as_mut(), frame.as_ref(), blank); + let result = self.windows[index].render( + self.studio.as_mut(), + frame.as_ref(), + blank, + self.host.as_ref().map(|h| &h.state), + ); + if let Some(action) = self.windows[index].display_action.take() + && let Some(host) = &self.host + { + let _ = host.acks.try_send(Ack { + display_action: Some(action), + route_trial: host.state.route_trial, + ..Default::default() + }); + } if let Err(e) = result { self.error = Some(e.to_string()); el.exit(); diff --git a/crates/pdf-presenter/src/output.rs b/crates/pdf-presenter/src/output.rs index 6bb97f2..4702199 100644 --- a/crates/pdf-presenter/src/output.rs +++ b/crates/pdf-presenter/src/output.rs @@ -15,8 +15,18 @@ use std::{ }, time::{Duration, Instant}, }; +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum DisplayAction { + Swap, + Keep, + Revert, +} #[derive(Clone, Default, Debug, Serialize, Deserialize)] pub struct HostState { + #[serde(default)] + pub setup_controls: bool, + #[serde(default)] + pub route_trial: Option, pub sequence: u64, #[serde(default)] pub generation: u64, @@ -32,6 +42,10 @@ pub struct HostState { } #[derive(Clone, Default, Debug, Serialize, Deserialize)] pub struct Ack { + #[serde(default)] + pub display_action: Option, + #[serde(default)] + pub route_trial: Option, pub sequence: u64, pub page: Option, pub status: String, diff --git a/crates/pdf-presenter/src/presenter_ui.rs b/crates/pdf-presenter/src/presenter_ui.rs index 8f10f73..0fd096e 100644 --- a/crates/pdf-presenter/src/presenter_ui.rs +++ b/crates/pdf-presenter/src/presenter_ui.rs @@ -132,6 +132,23 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { let footer = s.layout.footer || native.footer_until > now; let background = ui.interact(screen, ui.id().with("context"), Sense::click()); background.context_menu(|ui| { + if !s.presentation_started + && s.route_trial.is_none() + && ui + .button(if s.settings.language.french() { + "Inverser les écrans…" + } else { + "Swap displays…" + }) + .clicked() + { + s.actions.push(Action::SwapRoutes); + ui.close(); + } + if s.route_trial.is_some() && ui.button("Revert display change").clicked() { + s.actions.push(Action::RevertRoutes); + ui.close(); + } ui.checkbox(&mut s.layout.header, tr(&locale, "Keep header visible")); ui.checkbox(&mut s.layout.footer, tr(&locale, "Keep footer visible")); if ui.button(tr(&locale, "Show both")).clicked() { @@ -328,8 +345,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { .map_or("PDF Presenter", |d| d.title.as_str()), ); if ui.button(tr(&locale, "Displays")).clicked() { - s.draft_routes = s.routes.clone(); - s.displays_open = true; + s.begin_display_edit(); } button( ui, @@ -500,6 +516,47 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { }); }); } + if let Some(trial) = &s.route_trial { + let seconds = trial + .deadline + .saturating_duration_since(Instant::now()) + .as_secs() + + 1; + egui::Modal::new(egui::Id::new("confirm-displays")).show(&ctx, |ui| { + ui.heading(if s.settings.language.french() { + "Conserver ces écrans ?" + } else { + "Keep these display settings?" + }); + ui.label(if s.settings.language.french() { + format!("Retour automatique dans {seconds} s. Échap pour annuler.") + } else { + format!("Automatically reverts in {seconds} seconds. Escape to revert.") + }); + ui.horizontal(|ui| { + button( + ui, + if s.settings.language.french() { + "Conserver" + } else { + "Keep changes" + }, + Action::KeepRoutes, + &mut s.actions, + ); + button( + ui, + if s.settings.language.french() { + "Annuler" + } else { + "Revert now" + }, + Action::RevertRoutes, + &mut s.actions, + ); + }); + }); + } if s.layout_open { let mut open = true; egui::Window::new(tr(&locale, "Your presenter view")) @@ -665,16 +722,20 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { ); } ui.checkbox( - &mut s.settings.presenter_fullscreen, + &mut s.draft_presenter_fullscreen, tr(&locale, "Presenter fullscreen"), ); ui.checkbox( - &mut s.settings.presentation_fullscreen, + &mut s.draft_presentation_fullscreen, tr(&locale, "Presentation fullscreen"), ); button( ui, - tr(&locale, "Apply and remember"), + if s.settings.language.french() { + "Tester les écrans (15 s)" + } else { + "Try displays (15 seconds)" + }, Action::ApplyRoutes, &mut s.actions, ); @@ -857,8 +918,7 @@ fn menu(ui: &mut Ui, s: &mut Studio) { &mut s.actions, ); if ui.button(tr(&locale, "Displays")).clicked() { - s.draft_routes = s.routes.clone(); - s.displays_open = true; + s.begin_display_edit(); ui.close(); } if ui.button(tr(&locale, "Layout")).clicked() { @@ -928,3 +988,47 @@ fn menu(ui: &mut Ui, s: &mut Studio) { ui.close(); } } + +/// Minimal setup controls permitted on output windows, without any presenter data. +pub fn output_display_recovery( + ui: &mut egui::Ui, + startup: bool, + trial: bool, +) -> Option { + use crate::output::DisplayAction; + let mut action = None; + if startup && !trial { + ui.interact( + ui.max_rect(), + ui.id().with("startup-display-menu"), + egui::Sense::click(), + ) + .context_menu(|ui| { + if ui + .button("Swap presenter and presentation displays…") + .clicked() + { + action = Some(DisplayAction::Swap); + ui.close(); + } + }); + } + if trial { + egui::Window::new("Keep these display settings?") + .anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO) + .collapsible(false) + .resizable(false) + .show(ui.ctx(), |ui| { + ui.label("Automatically reverts after 15 seconds. Escape to revert."); + ui.horizontal(|ui| { + if ui.button("Keep changes").clicked() { + action = Some(DisplayAction::Keep); + } + if ui.button("Revert now").clicked() { + action = Some(DisplayAction::Revert); + } + }); + }); + } + action +} diff --git a/crates/pdf-presenter/src/studio.rs b/crates/pdf-presenter/src/studio.rs index 0803f32..3049d2d 100644 --- a/crates/pdf-presenter/src/studio.rs +++ b/crates/pdf-presenter/src/studio.rs @@ -27,18 +27,33 @@ pub enum Action { SaveGlobal, UseGlobal, ApplyRoutes, + SwapRoutes, + KeepRoutes, + RevertRoutes, OpenBrowser, CloseBrowser, Refresh, Exit, Windowed, } +pub struct RouteTrial { + pub id: u64, + pub deadline: Instant, + previous: Routes, + presenter_fullscreen: bool, + presentation_fullscreen: bool, +} pub struct Studio { pub settings: Settings, pub layout: Layout, pub monitors: Vec, pub routes: Routes, pub draft_routes: Routes, + pub draft_presenter_fullscreen: bool, + pub draft_presentation_fullscreen: bool, + pub route_trial: Option, + pub presentation_started: bool, + next_route_trial: u64, pub deck: Option, pub requested: usize, pub displayed: Option, @@ -126,6 +141,11 @@ impl Studio { monitors: vec![], routes: Routes::default(), draft_routes: Routes::default(), + draft_presenter_fullscreen: true, + draft_presentation_fullscreen: true, + route_trial: None, + presentation_started: false, + next_route_trial: 0, deck: None, requested: 0, displayed: None, @@ -218,6 +238,7 @@ impl Studio { let recovering = !self.monitors.is_empty(); self.monitors = monitors; if changed { + self.execute(Action::RevertRoutes); self.routes = self.settings.routes.resolve(&ids, primary); // A lost operator screen must not turn a previously public output into a notes window. if recovering { @@ -276,6 +297,9 @@ impl Studio { } } Action::Go(page) => { + if self.route_trial.is_some() { + return; + } if page < self.count() { if page != self.requested && self.fg_busy && !self.loading { self.fg = Bridge::with_program( @@ -285,13 +309,20 @@ impl Studio { self.fg_busy = false; self.fg_job = None; } + self.presentation_started = true; self.requested = page; self.jump.clear(); self.new_output = true; } } Action::Blank => { + if self.route_trial.is_some() { + return; + } self.blanked = !self.blanked; + if !self.blanked { + self.presentation_started = true; + } self.new_output = true; } Action::SaveProject => { @@ -308,19 +339,80 @@ impl Studio { self.layout = self.settings.layout.clone(); self.pending_save = true; } + Action::SwapRoutes => { + if self.route_trial.is_none() + && !self.presentation_started + && !self.routes.presentation.is_empty() + { + self.begin_display_edit(); + std::mem::swap( + &mut self.draft_routes.presenter, + &mut self.draft_routes.presentation, + ); + self.execute(Action::ApplyRoutes); + } + } Action::ApplyRoutes => { + if !self.initialized { + return; + } + if self.route_trial.is_some() { + return; + } if self.draft_routes.presenter.is_empty() { self.status = "Choose at least one presenter screen.".into(); } else if let Err(e) = self.draft_routes.validate() { self.status = e; + } else if self + .draft_routes + .presenter + .iter() + .chain(&self.draft_routes.presentation) + .any(|id| !self.monitors.iter().any(|m| &m.id == id)) + { + self.status = "A selected display is no longer connected.".into(); } else { + self.next_route_trial += 1; + self.route_trial = Some(RouteTrial { + id: self.next_route_trial, + deadline: Instant::now() + Duration::from_secs(15), + previous: self.routes.clone(), + presenter_fullscreen: self.draft_presenter_fullscreen, + presentation_fullscreen: self.draft_presentation_fullscreen, + }); self.routes = self.draft_routes.clone(); - self.settings.routes = self.routes.clone(); self.dirty_routes = true; self.displays_open = false; self.blanked = true; self.new_output = true; + } + } + Action::KeepRoutes => { + if let Some(trial) = self.route_trial.take() { + if Instant::now() >= trial.deadline { + self.route_trial = Some(trial); + self.execute(Action::RevertRoutes); + return; + } + self.settings.routes = self.routes.clone(); + self.settings.presenter_fullscreen = trial.presenter_fullscreen; + self.settings.presentation_fullscreen = trial.presentation_fullscreen; self.pending_save = true; + self.new_output = true; + self.status = + "Display setup confirmed. Output remains blank until shown.".into(); + } + } + Action::RevertRoutes => { + if let Some(trial) = self.route_trial.take() { + self.routes = trial.previous; + self.begin_display_edit(); + self.displays_open = false; + self.dirty_routes = true; + self.blanked = true; + self.new_output = true; + self.status = + "Display change reverted. Output remains blank until shown.".into(); } } Action::OpenBrowser => { @@ -335,6 +427,7 @@ impl Studio { Action::Refresh => self.dirty_routes = true, Action::Exit => self.close_requested = true, Action::Windowed => { + self.execute(Action::RevertRoutes); self.settings.presenter_fullscreen = false; self.settings.presentation_fullscreen = false; self.blanked = true; @@ -343,7 +436,54 @@ impl Studio { } } } + pub fn display_control(&mut self, action: crate::output::DisplayAction, trial: Option) { + use crate::output::DisplayAction; + match action { + DisplayAction::Swap + if trial.is_none() && self.route_trial.is_none() && !self.presentation_started => + { + self.execute(Action::SwapRoutes) + } + DisplayAction::Keep | DisplayAction::Revert + if trial.is_some() && trial == self.route_trial.as_ref().map(|t| t.id) => + { + self.execute(if matches!(action, DisplayAction::Keep) { + Action::KeepRoutes + } else { + Action::RevertRoutes + }); + } + _ => {} + } + } + pub fn begin_display_edit(&mut self) { + self.draft_routes = self.routes.clone(); + self.draft_presenter_fullscreen = self.settings.presenter_fullscreen; + self.draft_presentation_fullscreen = self.settings.presentation_fullscreen; + self.displays_open = true; + } + pub fn presenter_fullscreen(&self) -> bool { + self.route_trial + .as_ref() + .map_or(self.settings.presenter_fullscreen, |t| { + t.presenter_fullscreen + }) + } + pub fn presentation_fullscreen(&self) -> bool { + self.route_trial + .as_ref() + .map_or(self.settings.presentation_fullscreen, |t| { + t.presentation_fullscreen + }) + } pub fn poll(&mut self) { + if self + .route_trial + .as_ref() + .is_some_and(|t| Instant::now() >= t.deadline) + { + self.execute(Action::RevertRoutes); + } while let Ok(c) = self.io.rx.try_recv() { match c.result { Ok(packet) => { @@ -461,6 +601,7 @@ impl Studio { self.ram_blocked = false; self.failed.clear(); self.requested = 0; + self.presentation_started = false; self.displayed = None; self.layout = self.settings.for_project(&info.key); self.status = info.warnings.first().cloned().unwrap_or_else(|| { diff --git a/crates/pdf-presenter/tests/presenter_ui.rs b/crates/pdf-presenter/tests/presenter_ui.rs index f8efe35..e005a9e 100644 --- a/crates/pdf-presenter/tests/presenter_ui.rs +++ b/crates/pdf-presenter/tests/presenter_ui.rs @@ -266,3 +266,188 @@ fn header_click_opens_slide_browser_and_menu_dropdown() { } } } + +#[test] +fn display_changes_require_confirmation_and_timeout_restores_previous_setup() { + let mut s = studio(); + s.settings.routes = s.routes.clone(); + let original = s.routes.clone(); + s.begin_display_edit(); + s.draft_presenter_fullscreen = false; + s.draft_presentation_fullscreen = false; + std::mem::swap( + &mut s.draft_routes.presenter, + &mut s.draft_routes.presentation, + ); + s.execute(Action::ApplyRoutes); + assert_ne!(s.routes, original); + assert_eq!(s.settings.routes, original); + assert!(s.settings.presenter_fullscreen); + assert!(!s.presenter_fullscreen()); + assert!(s.blanked); + s.execute(Action::Blank); + s.execute(Action::Go(5)); + assert!(s.blanked); + assert_eq!(s.requested, 0); + // Render the modal even with the ordinary bars hidden. + s.layout.header = false; + s.layout.footer = false; + let ctx = Context::default(); + let _ = ctx.run_ui(input(Vec2::new(1280., 720.)), |ui| { + presenter_ui::presenter(ui, &mut s, &mut UiState::default()) + }); + s.route_trial.as_mut().unwrap().deadline = std::time::Instant::now(); + s.poll(); + assert!(s.route_trial.is_none()); + assert_eq!(s.routes, original); + assert_eq!(s.settings.routes, original); + assert!(s.presenter_fullscreen()); + assert!(s.blanked); + s.execute(Action::RevertRoutes); // Idempotent recovery. + assert_eq!(s.routes, original); + s.begin_display_edit(); + s.draft_presenter_fullscreen = false; + s.draft_presentation_fullscreen = false; + s.execute(Action::ApplyRoutes); + s.execute(Action::KeepRoutes); + assert!(!s.settings.presenter_fullscreen); + assert!(!s.settings.presentation_fullscreen); +} + +#[test] +fn recovery_commands_are_scoped_to_the_current_trial_and_startup() { + use pdf_presenter::output::DisplayAction; + let mut s = studio(); + s.settings.routes = s.routes.clone(); + let original = s.routes.clone(); + s.display_control(DisplayAction::Swap, None); + let old_id = s.route_trial.as_ref().unwrap().id; + s.display_control(DisplayAction::Keep, Some(old_id + 1)); + assert!(s.route_trial.is_some()); + assert_eq!(s.settings.routes, original); + s.display_control(DisplayAction::Revert, Some(old_id)); + assert_eq!(s.routes, original); + s.display_control(DisplayAction::Swap, None); + let new_id = s.route_trial.as_ref().unwrap().id; + assert_ne!(new_id, old_id); + s.display_control(DisplayAction::Keep, Some(old_id)); + assert!(s.route_trial.is_some()); + s.display_control(DisplayAction::Keep, Some(new_id)); + assert!(s.route_trial.is_none()); + assert_eq!(s.settings.routes, s.routes); + assert_ne!(s.routes, original); + s.execute(Action::Go(0)); + let confirmed = s.routes.clone(); + s.display_control(DisplayAction::Swap, None); + assert!(s.route_trial.is_none()); + assert_eq!(s.routes, confirmed); + // Explicit display editing remains available after startup. + s.begin_display_edit(); + s.draft_routes = original; + s.execute(Action::ApplyRoutes); + s.route_trial.as_mut().unwrap().deadline = std::time::Instant::now(); + s.execute(Action::KeepRoutes); // A late click must revert, never save. + assert!(s.route_trial.is_none()); + assert_eq!(s.settings.routes, confirmed); + assert_eq!(s.routes, confirmed); +} + +#[test] +fn hotplug_cancels_a_display_trial_without_saving_the_proposal() { + let mut s = studio(); + s.settings.routes = s.routes.clone(); + let saved = s.settings.routes.clone(); + s.execute(Action::SwapRoutes); + assert!(s.route_trial.is_some()); + s.set_monitors(vec![s.monitors[0].clone()], 0); + assert!(s.route_trial.is_none()); + assert_eq!(s.settings.routes, saved); + assert!(s.blanked); + assert!(!s.routes.presentation.contains(&"two".to_owned())); +} + +#[test] +fn output_recovery_buttons_dispatch_without_presenter_data() { + fn find(shape: &egui::Shape, label: &str) -> Option { + match shape { + egui::Shape::Text(t) if t.galley.text() == label => Some(t.pos + t.galley.size() * 0.5), + egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)), + _ => None, + } + } + for (label, trial) in [ + ("Keep changes", true), + ("Revert now", true), + ("Swap presenter and presentation displays…", false), + ] { + let ctx = Context::default(); + let size = Vec2::new(1280., 720.); + let mut action = None; + let mut output = ctx.run_ui(input(size), |ui| { + action = presenter_ui::output_display_recovery(ui, true, trial); + }); + if !trial { + for pressed in [true, false] { + let pos = Pos2::new(300., 300.); + let mut raw = input(size); + raw.events = vec![ + egui::Event::PointerMoved(pos), + egui::Event::PointerButton { + pos, + button: egui::PointerButton::Secondary, + pressed, + modifiers: Default::default(), + }, + ]; + output = ctx.run_ui(raw, |ui| { + action = presenter_ui::output_display_recovery(ui, true, false); + }); + } + } + for _ in 0..3 { + output = ctx.run_ui(input(size), |ui| { + action = presenter_ui::output_display_recovery(ui, true, trial); + }); + } + let pos = output + .shapes + .iter() + .find_map(|s| find(&s.shape, label)) + .expect(label); + for pressed in [true, false] { + let mut raw = input(size); + raw.events = vec![ + egui::Event::PointerMoved(pos), + egui::Event::PointerButton { + pos, + button: egui::PointerButton::Primary, + pressed, + modifiers: Default::default(), + }, + ]; + let _ = ctx.run_ui(raw, |ui| { + action = presenter_ui::output_display_recovery(ui, true, trial); + }); + } + use pdf_presenter::output::DisplayAction; + assert!(matches!( + (label, action), + ("Keep changes", Some(DisplayAction::Keep)) + | ("Revert now", Some(DisplayAction::Revert)) + | ( + "Swap presenter and presentation displays…", + Some(DisplayAction::Swap) + ) + )); + let output = ctx.run_ui(input(size), |ui| { + action = presenter_ui::output_display_recovery(ui, false, false); + }); + assert!(action.is_none()); + assert!( + output + .shapes + .iter() + .all(|s| find(&s.shape, label).is_none()) + ); + } +} diff --git a/docs/changelog.md b/docs/changelog.md index 92fa584..5004192 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,15 @@ ## Unreleased +### 0.1.21 + +- Preview display routing/fullscreen changes for 15 seconds before saving. Keep + confirms; Revert, Escape, timeout or hotplug restores the prior setup. +- Provide confirmation on both presenter/output screens and startup right-click + swap on either role, disabled after explicit slide navigation/show. +- Keep output blank during recovery, reject stale confirmations, and leave + unconfirmed assignments out of preference saves. Test rollback and pointer controls. + ### 0.1.20 - Restrict routine agent validation to Linux. Windows/macOS builds and cross-target diff --git a/docs/development/native-implementation.md b/docs/development/native-implementation.md index 40f8452..7df6a4a 100644 --- a/docs/development/native-implementation.md +++ b/docs/development/native-implementation.md @@ -233,3 +233,27 @@ PDF_PRESENTER_STRESS_PDF=/path/to/Ravenous.pdf cargo test --locked --release \ Linux and Windows x86_64 release builds both succeed. The test uses temporary processed files and cleans them up. Real Windows/macOS multiscreen/runtime acceptance remains separate from these regression checks. + + +## 0.1.21 reversible display setup + +Display edits now stage both routes and fullscreen choices in a 15-second trial. +The presenter owns a monotonic deadline and restores the prior setup on timeout, +Revert, Escape or hotplug. Only Keep updates saved preferences; unrelated saves +cannot persist candidate display values. Output remains blank through the trial +and afterward until explicitly shown. Navigation/show actions are held during trials. + +Startup right-click swap is available from either role until explicit navigation +or Show presentation. Opening a source alone does not end startup recovery. Pending +trials expose minimal Keep/Revert on outputs even after startup, without transferring +notes or operator controls. Output commands carry the current trial ID; stale and +late confirmations cannot commit another trial. Orphan outputs clear setup controls +and retain ordinary Close/Escape behavior. + +Validation: 53 Rust tests and 12 Python tests pass, including actual egui pointer +clicks for the output context menu and Keep/Revert, hidden-bar modal rendering, +timeout/late confirmation, stale tokens, confirmed fullscreen settings and hotplug +rollback. The Linux release build succeeds. Linux native window/output smoke, formatting and warnings-denied +Clippy/rustdoc pass. Whole-app line coverage is 84.57%. These tests do not establish +physical dual-monitor acceptance; the user should retest swapping/recovery on their +setup. Windows/macOS builds and checks were not run, per the platform-build policy. diff --git a/docs/interfaces/process-protocol.md b/docs/interfaces/process-protocol.md index 5e7f335..e47fc3a 100644 --- a/docs/interfaces/process-protocol.md +++ b/docs/interfaces/process-protocol.md @@ -81,3 +81,17 @@ Event-loop errors and OutputLink destruction use this cleanup path as well. OS p termination/reaping still relies on OS responsiveness; these bounds are not a promise against kernel/driver failure. Unexpected presenter death deliberately does not use parent-death termination for the audience, to preserve the last usable frame. + + +## Display setup recovery, 0.1.21 + +HostState adds default-false `setup_controls` and optional `route_trial` (u64 trial +identifier). Startup controls allow an output-side right-click swap only before the +first explicit navigation/show action; a pending trial always exposes minimal +Keep/Revert controls. Output ACKs can carry `display_action` (`Swap`, `Keep`, `Revert`) +and `route_trial`. The parent validates startup eligibility and trial identity; +stale confirmations cannot commit a later trial. The parent owns the 15-second +monotonic deadline and does not persist routes/fullscreen flags until confirmed. +A late Keep is treated as rollback. Host EOF clears recovery controls so orphan +Escape/Close remains available. Notes, source paths and operator layout data are +still absent from this control payload. Private same-build IPC only. diff --git a/docs/interfaces/settings.md b/docs/interfaces/settings.md index 82c7032..cc7bad3 100644 --- a/docs/interfaces/settings.md +++ b/docs/interfaces/settings.md @@ -43,7 +43,12 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr persists changes asynchronously. Since 0.1.19, lowering evicts non-active frames while reserving room for outstanding renders; increasing allows RAM refill. -Transient reveals, blank/current/selected slides, elapsed time, loaded document, +Display assignments and fullscreen choices are previewed in a 15-second transient +trial before persistence. Only Keep changes updates their saved values. Timeout, +Escape, Revert now and hotplug discard the trial. Unrelated preference saves during +a trial serialize the previously confirmed display values. No v1 schema change. + +Transient display trials/startup recovery eligibility, reveals, blank/current/selected slides, elapsed time, loaded document, Change on click and worker state are not persisted. HTML prototype localStorage is separate and is not automatically imported. See `examples/settings-v1.toml` and round-trip/invalid-version tests in `tests/settings.rs`. diff --git a/docs/user-guide.md b/docs/user-guide.md index f3c1f8e..3154e9c 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -14,7 +14,21 @@ fullscreen for the session. `--list-monitors` lists CLI display numbers. Both roles default to fullscreen. Displays lists connected screens: assign each Unused, Presenter or Presentation, including several screens per role. Swap groups -exchanges the roles. Apply and remember saves the preferred assignments globally. +exchanges the draft roles. **Try displays (15 seconds)** previews the assignments +and fullscreen choices with output blanked. **Keep changes** confirms and saves; +**Revert now**, Escape, or doing nothing for 15 seconds restores the previous setup. +Confirmation controls appear on presenter and output windows so either screen can +recover the change. Unconfirmed choices are never saved, and a disconnect cancels +the trial. Navigation/show controls are held until the trial is resolved. + +Before the first explicit slide navigation or Show presentation action, right-click +either screen for **Swap displays…** (on output: **Swap presenter and presentation +displays…**). This uses the same timed trial. Merely opening a PDF and automatically +showing its first slide does not disable startup recovery. Once you start navigating +or explicitly showing slides, the output startup menu disappears; use Displays on +the presenter for later changes. Startup swap exchanges whole role groups, including +mirrors. Trial output controls contain no notes, paths or presenter content. +Output remains blank after either confirmation or rollback until explicitly shown. Unavailable screens fall back to surviving assignments and available distinct screens; the preferred saved setup remains available for reconnection. Review the setup after connecting/disconnecting displays: output is blanked until you explicitly show it.