Preserve output on browser Escape and accelerate held navigation
This commit is contained in:
parent
3724775d30
commit
5294e083ad
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.71"
|
||||
version = "0.1.72"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.71"
|
||||
version = "0.1.72"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -98,3 +98,6 @@ pub mod zoom;
|
|||
|
||||
/// Disk cache retention and worker-only cleanup.
|
||||
pub mod cache;
|
||||
|
||||
/// Bounded held-input slide navigation.
|
||||
pub mod navigation;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ use winit::{
|
|||
monitor::MonitorHandle,
|
||||
window::{Fullscreen, Window, WindowId},
|
||||
};
|
||||
fn navigation_direction(key: &Key, modifiers: egui::Modifiers) -> Option<i32> {
|
||||
if modifiers.ctrl || modifiers.alt || modifiers.command {
|
||||
return None;
|
||||
}
|
||||
match key {
|
||||
Key::Named(NamedKey::Space) if modifiers.shift => Some(-1),
|
||||
Key::Named(NamedKey::ArrowRight | NamedKey::PageDown | NamedKey::Space) => Some(1),
|
||||
Key::Named(NamedKey::ArrowLeft | NamedKey::PageUp) => Some(-1),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
type Failure = Box<dyn std::error::Error>;
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Role {
|
||||
|
|
@ -467,6 +478,7 @@ struct App {
|
|||
windowed: bool,
|
||||
override_presenter: Option<usize>,
|
||||
override_output: Option<usize>,
|
||||
navigation_hold: Option<(WindowId, Key, crate::navigation::Hold)>,
|
||||
}
|
||||
impl App {
|
||||
fn redraw(&self) {
|
||||
|
|
@ -643,12 +655,15 @@ impl App {
|
|||
});
|
||||
return;
|
||||
}
|
||||
if matches!(key, Key::Named(NamedKey::Escape))
|
||||
|| matches!(&key,Key::Character(c) if c.eq_ignore_ascii_case("b"))
|
||||
{
|
||||
if matches!(key, Key::Named(NamedKey::Escape)) {
|
||||
// Focus may move here as All slides closes. Escape must never blank
|
||||
// a connected show; an orphan can still be dismissed safely.
|
||||
if let Some(h) = &mut self.host {
|
||||
h.close_requested = !h.parent_connected;
|
||||
}
|
||||
} else if matches!(&key, Key::Character(c) if c.eq_ignore_ascii_case("b")) {
|
||||
if let Some(h) = &mut self.host {
|
||||
h.state.blanked = true;
|
||||
h.close_requested = matches!(key, Key::Named(NamedKey::Escape));
|
||||
let _ = h.acks.try_send(Ack {
|
||||
request_blank: true,
|
||||
status: "Presentation blanked from output keyboard.".into(),
|
||||
|
|
@ -677,23 +692,21 @@ impl App {
|
|||
// Keep the live show responsive while an operator is using All slides or
|
||||
// has a presenter menu open. Text editors and modified shortcuts above
|
||||
// retain priority; focused controls may still consume all other keys.
|
||||
match key {
|
||||
Key::Named(NamedKey::Space) if modifiers.shift => {
|
||||
s.execute(Action::Go(s.requested.saturating_sub(1)));
|
||||
self.redraw();
|
||||
return;
|
||||
if let Some(delta) = navigation_direction(&key, modifiers) {
|
||||
s.execute(Action::Navigate {
|
||||
delta,
|
||||
repeated: false,
|
||||
});
|
||||
self.redraw();
|
||||
return;
|
||||
}
|
||||
if role == Role::Browser && matches!(key, Key::Named(NamedKey::Escape)) {
|
||||
if !s.jump.is_empty() {
|
||||
s.jump.clear();
|
||||
} else if s.browser_preview.take().is_none() {
|
||||
s.execute(Action::CloseBrowser);
|
||||
}
|
||||
Key::Named(NamedKey::ArrowRight | NamedKey::PageDown | NamedKey::Space) => {
|
||||
s.execute(Action::Go(s.requested + 1));
|
||||
self.redraw();
|
||||
return;
|
||||
}
|
||||
Key::Named(NamedKey::ArrowLeft | NamedKey::PageUp) => {
|
||||
s.execute(Action::Go(s.requested.saturating_sub(1)));
|
||||
self.redraw();
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
return;
|
||||
}
|
||||
if consumed {
|
||||
return;
|
||||
|
|
@ -720,10 +733,6 @@ impl App {
|
|||
Key::Named(NamedKey::Escape) => {
|
||||
if !s.jump.is_empty() {
|
||||
s.jump.clear();
|
||||
} else if role == Role::Browser {
|
||||
if s.browser_preview.take().is_none() {
|
||||
s.execute(Action::CloseBrowser);
|
||||
}
|
||||
} else if s.layout_open || s.displays_open || s.menu_open || s.toolbox.open {
|
||||
s.layout_open = false;
|
||||
s.displays_open = false;
|
||||
|
|
@ -759,6 +768,46 @@ impl App {
|
|||
}
|
||||
self.redraw();
|
||||
}
|
||||
fn stop_navigation(&mut self) {
|
||||
self.navigation_hold = None;
|
||||
if let Some(s) = &mut self.studio {
|
||||
s.execute(Action::FinishNavigation);
|
||||
}
|
||||
}
|
||||
fn repeat_navigation(&mut self, now: Instant) {
|
||||
let Some((id, _, _)) = &self.navigation_hold else {
|
||||
return;
|
||||
};
|
||||
let valid = self
|
||||
.windows
|
||||
.iter()
|
||||
.any(|w| w.window.id() == *id && w.window.has_focus())
|
||||
&& self.studio.as_ref().is_some_and(|s| {
|
||||
s.notes_editor.is_none()
|
||||
&& s.notes_import.is_none()
|
||||
&& !s.dialog_busy
|
||||
&& !s.loading
|
||||
&& s.route_trial.is_none()
|
||||
});
|
||||
if !valid {
|
||||
self.stop_navigation();
|
||||
return;
|
||||
}
|
||||
let s = self.studio.as_mut().unwrap();
|
||||
if let Some(delta) = self
|
||||
.navigation_hold
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.2
|
||||
.tick(now, s.count())
|
||||
{
|
||||
s.execute(Action::Navigate {
|
||||
delta,
|
||||
repeated: true,
|
||||
});
|
||||
self.redraw();
|
||||
}
|
||||
}
|
||||
fn poll(&mut self, el: &ActiveEventLoop) {
|
||||
let mut repaint = false;
|
||||
if let Some(s) = &mut self.studio {
|
||||
|
|
@ -1156,11 +1205,27 @@ impl ApplicationHandler for App {
|
|||
return;
|
||||
};
|
||||
let role = self.windows[index].role;
|
||||
let response = {
|
||||
if matches!(&event, WindowEvent::KeyboardInput { event, is_synthetic: true, .. } if event.state == ElementState::Pressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Navigation belongs to the bounded native hold controller, not also to
|
||||
// egui's focused button activation or the OS repeat stream.
|
||||
let navigation_event = role != Role::Presentation
|
||||
&& self.studio.as_ref().is_some_and(|s| {
|
||||
s.notes_editor.is_none()
|
||||
&& s.notes_import.is_none()
|
||||
&& !s.dialog_busy
|
||||
&& s.route_trial.is_none()
|
||||
})
|
||||
&& matches!(&event, WindowEvent::KeyboardInput { event, .. } if navigation_direction(&event.logical_key, self.windows[index].input.egui_input().modifiers).is_some());
|
||||
let repaint = if navigation_event {
|
||||
false
|
||||
} else {
|
||||
let n = &mut self.windows[index];
|
||||
n.input.on_window_event(&n.window, &event)
|
||||
n.input.on_window_event(&n.window, &event).repaint
|
||||
};
|
||||
if response.repaint {
|
||||
if repaint {
|
||||
self.windows[index].window.request_redraw();
|
||||
}
|
||||
match event {
|
||||
|
|
@ -1200,16 +1265,46 @@ impl ApplicationHandler for App {
|
|||
});
|
||||
}
|
||||
}
|
||||
WindowEvent::KeyboardInput { event, .. }
|
||||
if event.state == ElementState::Pressed && !event.repeat =>
|
||||
{
|
||||
let native = &self.windows[index];
|
||||
self.key(
|
||||
role,
|
||||
event.logical_key,
|
||||
native.ctx.egui_wants_keyboard_input(),
|
||||
native.input.egui_input().modifiers,
|
||||
);
|
||||
WindowEvent::Focused(false) => {
|
||||
self.stop_navigation();
|
||||
self.windows[index].ui.navigation_hold = None;
|
||||
}
|
||||
WindowEvent::ModifiersChanged(_) => self.stop_navigation(),
|
||||
WindowEvent::KeyboardInput {
|
||||
event,
|
||||
is_synthetic,
|
||||
..
|
||||
} => {
|
||||
if event.state == ElementState::Released {
|
||||
if self
|
||||
.navigation_hold
|
||||
.as_ref()
|
||||
.is_some_and(|(owner, key, _)| *owner == id && *key == event.logical_key)
|
||||
{
|
||||
self.stop_navigation();
|
||||
}
|
||||
} else if !event.repeat && !is_synthetic {
|
||||
self.stop_navigation();
|
||||
let native = &self.windows[index];
|
||||
let modifiers = native.input.egui_input().modifiers;
|
||||
let consumed = native.ctx.egui_wants_keyboard_input();
|
||||
let direction = navigation_direction(&event.logical_key, modifiers);
|
||||
let allowed = role != Role::Presentation
|
||||
&& self.studio.as_ref().is_some_and(|s| {
|
||||
s.notes_editor.is_none()
|
||||
&& s.notes_import.is_none()
|
||||
&& !s.dialog_busy
|
||||
&& s.route_trial.is_none()
|
||||
});
|
||||
if allowed && let Some(direction) = direction {
|
||||
self.navigation_hold = Some((
|
||||
id,
|
||||
event.logical_key.clone(),
|
||||
crate::navigation::Hold::new(direction, Instant::now()),
|
||||
));
|
||||
}
|
||||
self.key(role, event.logical_key, consumed, modifiers);
|
||||
}
|
||||
}
|
||||
WindowEvent::Resized(_) | WindowEvent::ScaleFactorChanged { .. } => {
|
||||
self.windows[index].window.request_redraw()
|
||||
|
|
@ -1271,6 +1366,14 @@ impl ApplicationHandler for App {
|
|||
self.next_monitors = now + Duration::from_millis(750);
|
||||
}
|
||||
if now >= self.next_poll {
|
||||
self.repeat_navigation(now);
|
||||
// egui repaint timers alone do not wake this custom native host.
|
||||
// Redraw held mouse controls at their repeat deadline, not at frame rate.
|
||||
for window in &self.windows {
|
||||
if window.ui.navigation_hold.is_some_and(|hold| hold.due(now)) {
|
||||
window.window.request_redraw();
|
||||
}
|
||||
}
|
||||
self.poll(el);
|
||||
self.next_poll = now + Duration::from_millis(8);
|
||||
}
|
||||
|
|
@ -1379,6 +1482,7 @@ pub fn run(options: crate::poc::Options, path: Option<std::path::PathBuf>) -> Re
|
|||
windowed: options.windowed,
|
||||
override_presenter: options.presenter,
|
||||
override_output: options.audience,
|
||||
navigation_hold: None,
|
||||
};
|
||||
let result = el.run_app(&mut app);
|
||||
if let Some(output) = &mut app.output {
|
||||
|
|
@ -1445,6 +1549,7 @@ pub fn run_output() -> Result<(), Failure> {
|
|||
windowed: false,
|
||||
override_presenter: None,
|
||||
override_output: None,
|
||||
navigation_hold: None,
|
||||
};
|
||||
el.run_app(&mut app)?;
|
||||
Ok(())
|
||||
|
|
@ -1485,6 +1590,7 @@ mod buffer_tests {
|
|||
windowed: true,
|
||||
override_presenter: None,
|
||||
override_output: None,
|
||||
navigation_hold: None,
|
||||
};
|
||||
for (role, consumed, modifiers, expected) in [
|
||||
(Role::Presenter, false, egui::Modifiers::NONE, 1),
|
||||
|
|
@ -1534,6 +1640,76 @@ mod buffer_tests {
|
|||
let s = app.studio.as_ref().unwrap();
|
||||
assert!(s.presenter_fullscreen() && s.presentation_fullscreen());
|
||||
assert!(!s.blanked);
|
||||
for consumed in [false, true] {
|
||||
let s = app.studio.as_mut().unwrap();
|
||||
s.browser_open = true;
|
||||
s.browser_preview = Some((s.generation, 1));
|
||||
app.key(
|
||||
Role::Browser,
|
||||
Key::Named(NamedKey::Escape),
|
||||
consumed,
|
||||
egui::Modifiers::NONE,
|
||||
);
|
||||
let s = app.studio.as_ref().unwrap();
|
||||
assert!(s.browser_open && s.browser_preview.is_none() && !s.blanked);
|
||||
app.key(
|
||||
Role::Browser,
|
||||
Key::Named(NamedKey::Escape),
|
||||
consumed,
|
||||
egui::Modifiers::NONE,
|
||||
);
|
||||
let s = app.studio.as_ref().unwrap();
|
||||
assert!(!s.browser_open && !s.blanked && s.presentation_fullscreen());
|
||||
}
|
||||
let (_tx, commands) = mpsc::sync_channel(4);
|
||||
let (acks, rx) = mpsc::sync_channel(8);
|
||||
app.host = Some(Host {
|
||||
parent_connected: true,
|
||||
close_requested: false,
|
||||
commands,
|
||||
acks,
|
||||
state: HostState {
|
||||
blanked: false,
|
||||
..Default::default()
|
||||
},
|
||||
reader: Bridge::new(Duration::from_secs(10)),
|
||||
reading: None,
|
||||
cache: HashMap::new(),
|
||||
frame: None,
|
||||
presented: HashSet::new(),
|
||||
failed_reads: HashSet::new(),
|
||||
preload_cursor: 0,
|
||||
zoom_pending: false,
|
||||
zoom_slow: false,
|
||||
next_zoom_ack: now,
|
||||
});
|
||||
app.key(
|
||||
Role::Presentation,
|
||||
Key::Named(NamedKey::Escape),
|
||||
false,
|
||||
egui::Modifiers::NONE,
|
||||
);
|
||||
assert!(!app.host.as_ref().unwrap().state.blanked);
|
||||
assert!(!app.host.as_ref().unwrap().close_requested);
|
||||
assert!(
|
||||
rx.try_recv().is_err(),
|
||||
"Focus transfer must not request audience blanking"
|
||||
);
|
||||
app.key(
|
||||
Role::Presentation,
|
||||
Key::Character("b".into()),
|
||||
false,
|
||||
egui::Modifiers::NONE,
|
||||
);
|
||||
assert!(rx.try_recv().unwrap().request_blank);
|
||||
app.host.as_mut().unwrap().parent_connected = false;
|
||||
app.key(
|
||||
Role::Presentation,
|
||||
Key::Named(NamedKey::Escape),
|
||||
false,
|
||||
egui::Modifiers::NONE,
|
||||
);
|
||||
assert!(app.host.as_ref().unwrap().close_requested);
|
||||
}
|
||||
fn frame(page: usize) -> Arc<Frame> {
|
||||
Arc::new(Frame {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
//! Constant-memory hold acceleration, independent of OS keyboard repeat rates.
|
||||
use std::time::{Duration, Instant};
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Hold {
|
||||
pub direction: i32,
|
||||
started: Instant,
|
||||
next: Instant,
|
||||
}
|
||||
impl Hold {
|
||||
/// The caller performs the initial single step immediately.
|
||||
pub fn new(direction: i32, now: Instant) -> Self {
|
||||
Self {
|
||||
direction: direction.signum(),
|
||||
started: now,
|
||||
next: now + Duration::from_millis(400),
|
||||
}
|
||||
}
|
||||
/// Native hosts can redraw a held button only when its next step is due.
|
||||
pub fn due(&self, now: Instant) -> bool {
|
||||
now >= self.next
|
||||
}
|
||||
/// At most one step per call; stalled event loops never replay missed steps.
|
||||
pub fn tick(&mut self, now: Instant, count: usize) -> Option<i32> {
|
||||
if !self.due(now) {
|
||||
return None;
|
||||
}
|
||||
let elapsed = now.saturating_duration_since(self.started);
|
||||
let (batch, interval) = if elapsed >= Duration::from_secs(5) {
|
||||
(10, 160)
|
||||
} else if elapsed >= Duration::from_secs(2) {
|
||||
(5, 160)
|
||||
} else {
|
||||
(1, 100)
|
||||
};
|
||||
self.next = now + Duration::from_millis(interval);
|
||||
let batch = batch.min((count / 10).clamp(1, 10));
|
||||
Some(self.direction * batch as i32)
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn delay_acceleration_small_decks_and_stalls_are_bounded() {
|
||||
let t = Instant::now();
|
||||
let mut h = Hold::new(1, t);
|
||||
assert!(!h.due(t + Duration::from_millis(399)));
|
||||
assert!(h.due(t + Duration::from_millis(400)));
|
||||
assert_eq!(h.tick(t + Duration::from_millis(399), 500), None);
|
||||
assert_eq!(h.tick(t + Duration::from_millis(400), 500), Some(1));
|
||||
assert_eq!(h.tick(t + Duration::from_secs(2), 500), Some(5));
|
||||
assert_eq!(h.tick(t + Duration::from_secs(5), 500), Some(10));
|
||||
assert_eq!(h.tick(t + Duration::from_secs(60), 500), Some(10));
|
||||
assert_eq!(h.tick(t + Duration::from_secs(60), 500), None);
|
||||
let mut reverse = Hold::new(-1, t);
|
||||
assert_eq!(reverse.tick(t + Duration::from_secs(6), 15), Some(-1));
|
||||
assert_eq!(reverse.tick(t + Duration::from_secs(7), 30), Some(-3));
|
||||
}
|
||||
}
|
||||
|
|
@ -201,6 +201,7 @@ pub struct UiState {
|
|||
pub textures: HashMap<(u64, usize, u32), TextureHandle>,
|
||||
pub header_until: Instant,
|
||||
pub footer_until: Instant,
|
||||
pub navigation_hold: Option<crate::navigation::Hold>,
|
||||
note_cache: Option<(String, Vec2, Arc<egui::Galley>)>,
|
||||
}
|
||||
impl Default for UiState {
|
||||
|
|
@ -210,6 +211,7 @@ impl Default for UiState {
|
|||
header_until: Instant::now(),
|
||||
footer_until: Instant::now(),
|
||||
note_cache: None,
|
||||
navigation_hold: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -463,6 +465,47 @@ fn slide_tools(ui: &mut Ui, s: &mut Studio, area: Rect, dimensions: [u32; 2]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn navigation_button(
|
||||
ui: &mut Ui,
|
||||
s: &mut Studio,
|
||||
native: &mut UiState,
|
||||
label: &str,
|
||||
direction: i32,
|
||||
) {
|
||||
let response = ui.button(label);
|
||||
let now = Instant::now();
|
||||
let active = response.is_pointer_button_down_on() && response.hovered();
|
||||
let owned = native
|
||||
.navigation_hold
|
||||
.is_some_and(|h| h.direction == direction);
|
||||
if active {
|
||||
if !owned {
|
||||
native.navigation_hold = Some(crate::navigation::Hold::new(direction, now));
|
||||
s.actions.push(Action::Navigate {
|
||||
delta: direction,
|
||||
repeated: false,
|
||||
});
|
||||
} else if let Some(delta) = native
|
||||
.navigation_hold
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.tick(now, s.count())
|
||||
{
|
||||
s.actions.push(Action::Navigate {
|
||||
delta,
|
||||
repeated: true,
|
||||
});
|
||||
}
|
||||
} else if owned {
|
||||
native.navigation_hold = None;
|
||||
s.actions.push(Action::FinishNavigation);
|
||||
} else if response.clicked() {
|
||||
s.actions.push(Action::Navigate {
|
||||
delta: direction,
|
||||
repeated: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
fn button(ui: &mut Ui, label: &str, action: Action, actions: &mut Vec<Action>) {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(action);
|
||||
|
|
@ -797,6 +840,11 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
}
|
||||
let header = s.layout.header || native.header_until > now || s.menu_open;
|
||||
let footer = s.layout.footer || native.footer_until > now;
|
||||
if native.navigation_hold.is_some() && (!footer || !ctx.input(|i| i.focused)) {
|
||||
native.navigation_hold = None;
|
||||
s.actions.push(Action::FinishNavigation);
|
||||
}
|
||||
|
||||
let background = ui.interact(screen, ui.id().with("context"), Sense::click());
|
||||
background.context_menu(|ui| {
|
||||
if !s.presentation_started
|
||||
|
|
@ -1240,18 +1288,8 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
s.layout.footer = !s.layout.footer;
|
||||
native.footer_until = now;
|
||||
}
|
||||
button(
|
||||
ui,
|
||||
tr(&locale, "Previous"),
|
||||
Action::Go(s.requested.saturating_sub(1)),
|
||||
&mut s.actions,
|
||||
);
|
||||
button(
|
||||
ui,
|
||||
tr(&locale, "Next"),
|
||||
Action::Go(s.requested + 1),
|
||||
&mut s.actions,
|
||||
);
|
||||
navigation_button(ui, s, native, tr(&locale, "Previous"), -1);
|
||||
navigation_button(ui, s, native, tr(&locale, "Next"), 1);
|
||||
ui.label(format!(
|
||||
"{} / {}",
|
||||
if s.count() == 0 { 0 } else { s.requested + 1 },
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ pub enum Action {
|
|||
ImportNotes(PathBuf),
|
||||
ApplyNotesImport,
|
||||
Go(usize),
|
||||
Navigate { delta: i32, repeated: bool },
|
||||
FinishNavigation,
|
||||
Blank,
|
||||
SaveProject,
|
||||
SaveGlobal,
|
||||
|
|
@ -121,6 +123,7 @@ pub struct Studio {
|
|||
pub cache_busy: bool,
|
||||
pub cache_status: String,
|
||||
startup_cache_pending: bool,
|
||||
navigation_settle: Option<Instant>,
|
||||
pub fg: Bridge,
|
||||
pub bg: Bridge,
|
||||
pub io: Bridge,
|
||||
|
|
@ -229,6 +232,7 @@ impl Studio {
|
|||
cache_busy: false,
|
||||
cache_status: String::new(),
|
||||
startup_cache_pending: true,
|
||||
navigation_settle: None,
|
||||
fg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
|
||||
bg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
|
||||
io,
|
||||
|
|
@ -365,6 +369,7 @@ impl Studio {
|
|||
self.fg_busy = false;
|
||||
self.fg_job = None;
|
||||
}
|
||||
self.navigation_settle = None;
|
||||
self.loading = true;
|
||||
self.pending_open = Some(path);
|
||||
self.status = "Opening document in an isolated worker…".into();
|
||||
|
|
@ -456,12 +461,49 @@ impl Studio {
|
|||
.into();
|
||||
}
|
||||
}
|
||||
Action::Navigate { delta, repeated } => {
|
||||
if self.notes_editor.is_some()
|
||||
|| self.notes_import.is_some()
|
||||
|| self.dialog_busy
|
||||
|| self.route_trial.is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let page = self
|
||||
.requested
|
||||
.saturating_add_signed(delta as isize)
|
||||
.min(self.count().saturating_sub(1));
|
||||
if page != self.requested {
|
||||
if !repeated {
|
||||
self.navigation_settle = None;
|
||||
}
|
||||
if repeated {
|
||||
self.navigation_settle = Some(Instant::now() + Duration::from_millis(180));
|
||||
}
|
||||
self.execute(Action::Go(page));
|
||||
}
|
||||
}
|
||||
Action::FinishNavigation => {
|
||||
if self.navigation_settle.take().is_some()
|
||||
&& self.fg_job.is_some_and(|(page, _)| page != self.requested)
|
||||
&& !self.loading
|
||||
{
|
||||
self.fg =
|
||||
Bridge::with_program(Duration::from_secs(30), self.worker_program.clone());
|
||||
self.fg_busy = false;
|
||||
self.fg_job = None;
|
||||
}
|
||||
}
|
||||
Action::Go(page) => {
|
||||
if self.route_trial.is_some() {
|
||||
return;
|
||||
}
|
||||
if page < self.count() {
|
||||
if page != self.requested && self.fg_busy && !self.loading {
|
||||
if page != self.requested
|
||||
&& self.fg_busy
|
||||
&& !self.loading
|
||||
&& self.navigation_settle.is_none()
|
||||
{
|
||||
self.fg = Bridge::with_program(
|
||||
Duration::from_secs(30),
|
||||
self.worker_program.clone(),
|
||||
|
|
@ -1031,7 +1073,13 @@ impl Studio {
|
|||
self.pending_open = Some(path);
|
||||
}
|
||||
}
|
||||
if self.deck.is_some() && self.pending_open.is_none() {
|
||||
if self
|
||||
.navigation_settle
|
||||
.is_some_and(|deadline| Instant::now() >= deadline)
|
||||
{
|
||||
self.navigation_settle = None;
|
||||
}
|
||||
if self.deck.is_some() && self.pending_open.is_none() && self.navigation_settle.is_none() {
|
||||
if !self.fg_busy {
|
||||
let edge = self.target_edge;
|
||||
if !self.frames.contains_key(&(self.requested, edge))
|
||||
|
|
@ -1447,6 +1495,54 @@ impl Studio {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn repeated_navigation_coalesces_rendering_and_clamps_without_blanking() {
|
||||
let mut s = Studio::new(true, None);
|
||||
s.deck = Some(DeckInfo {
|
||||
path: "test.pdf".into(),
|
||||
key: "test".into(),
|
||||
title: "Test".into(),
|
||||
names: vec![String::new(); 500],
|
||||
notes: vec![],
|
||||
warnings: vec![],
|
||||
sha256: String::new(),
|
||||
});
|
||||
s.blanked = false;
|
||||
s.fg_busy = true;
|
||||
s.fg_job = Some((0, s.target_edge));
|
||||
for _ in 0..100 {
|
||||
s.execute(Action::Navigate {
|
||||
delta: 10,
|
||||
repeated: true,
|
||||
});
|
||||
}
|
||||
assert_eq!(s.requested, 499);
|
||||
assert!(!s.blanked);
|
||||
assert!(
|
||||
s.fg_busy,
|
||||
"Repeats must not repeatedly replace renderer workers"
|
||||
);
|
||||
assert_eq!(s.fg_job, Some((0, s.target_edge)));
|
||||
s.execute(Action::FinishNavigation);
|
||||
assert!(!s.fg_busy && s.fg_job.is_none());
|
||||
assert!(s.navigation_settle.is_none());
|
||||
s.execute(Action::Navigate {
|
||||
delta: -10,
|
||||
repeated: true,
|
||||
});
|
||||
s.poll();
|
||||
assert!(
|
||||
!s.fg_busy && !s.bg_busy,
|
||||
"Skipped slides must not start render jobs during a hold"
|
||||
);
|
||||
assert_eq!(s.requested, 489);
|
||||
s.execute(Action::Navigate {
|
||||
delta: -1000,
|
||||
repeated: true,
|
||||
});
|
||||
assert_eq!(s.requested, 0);
|
||||
s.execute(Action::FinishNavigation);
|
||||
}
|
||||
#[test]
|
||||
fn absent_frames_report_their_actual_load_state() {
|
||||
let mut studio = Studio::new(true, None);
|
||||
|
|
|
|||
|
|
@ -1385,3 +1385,71 @@ fn zoom_preview_matches_reference_output_crop_and_tracks_window_shape() {
|
|||
s.routes.presentation.clear();
|
||||
assert_eq!(s.presentation_viewport(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn held_navigation_buttons_accelerate_and_release_without_an_extra_step() {
|
||||
fn find(shape: &egui::Shape, label: &str) -> Option<Pos2> {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == label => Some(t.pos + t.galley.size() * 0.5),
|
||||
egui::Shape::Vec(v) => v.iter().find_map(|s| find(s, label)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
let ctx = Context::default();
|
||||
let mut s = studio();
|
||||
s.settings.language = pdf_presenter::localization::Language::En;
|
||||
s.layout.footer = true;
|
||||
s.blanked = false;
|
||||
let mut native = UiState::default();
|
||||
let frame = |s: &mut Studio, native: &mut UiState, events| {
|
||||
let mut raw = input(Vec2::new(1920., 1080.));
|
||||
raw.events = events;
|
||||
let output = ctx.run_ui(raw, |ui| presenter_ui::presenter(ui, s, native));
|
||||
for action in std::mem::take(&mut s.actions) {
|
||||
s.execute(action);
|
||||
}
|
||||
output
|
||||
};
|
||||
for _ in 0..3 {
|
||||
frame(&mut s, &mut native, vec![]);
|
||||
}
|
||||
let output = frame(&mut s, &mut native, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| find(&s.shape, "Next"))
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut s,
|
||||
&mut native,
|
||||
vec![
|
||||
egui::Event::PointerMoved(pos),
|
||||
egui::Event::PointerButton {
|
||||
pos,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: true,
|
||||
modifiers: Default::default(),
|
||||
},
|
||||
],
|
||||
);
|
||||
assert_eq!(s.requested, 1);
|
||||
native.navigation_hold = Some(pdf_presenter::navigation::Hold::new(
|
||||
1,
|
||||
std::time::Instant::now() - std::time::Duration::from_secs(6),
|
||||
));
|
||||
frame(&mut s, &mut native, vec![]);
|
||||
assert_eq!(s.requested, 4); // Batches capped to 10% of this 30-slide deck.
|
||||
frame(
|
||||
&mut s,
|
||||
&mut native,
|
||||
vec![egui::Event::PointerButton {
|
||||
pos,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: Default::default(),
|
||||
}],
|
||||
);
|
||||
assert_eq!(s.requested, 4);
|
||||
assert!(native.navigation_hold.is_none());
|
||||
assert!(!s.blanked);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,18 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.72
|
||||
|
||||
- Preserve the live show when Escape closes All slides, including focused controls
|
||||
and keyboard focus moving to the audience window. Escape still reverts display
|
||||
trials and closes orphan outputs; B remains the explicit blank shortcut.
|
||||
- Accelerate held next/previous buttons and navigation keys from single steps to
|
||||
bounded batches. Coalesce uncached destinations without render-job queues or
|
||||
repeated worker restarts; stop on release/focus loss and retain the last ready frame.
|
||||
Linux formatting, warnings-denied Clippy/rustdoc, workspace/native tests and 13
|
||||
Python tests pass; whole-application coverage is 84.71% (75% floor). The Linux
|
||||
release binary is rebuilt. Windows/macOS and physical-display retesting remain open.
|
||||
|
||||
### 0.1.71
|
||||
|
||||
- Prepare the 0.1.71 preview release with Linux/Windows x86_64 packages; see
|
||||
|
|
|
|||
|
|
@ -358,3 +358,22 @@ of 5.18/4.70 ms at 1080p (4×/8×) and 15.94/15.50 ms at 4K, maximum 16.87 ms.
|
|||
The synthetic texture remains 1920×1080; page metadata supplies A4 proportions to
|
||||
exercise viewport expansion. These are software-drawing measurements, not physical
|
||||
display latency. Windows/macOS were not built or runtime-tested for this change.
|
||||
|
||||
|
||||
## Escape and held navigation — 0.1.72
|
||||
|
||||
Browser Escape dismisses the preview/browser even when a control consumes keyboard
|
||||
input; it preserves audience visibility. Audience Escape can revert a display trial
|
||||
or close an orphan, but cannot blank a connected show. Synthetic focus-transfer key
|
||||
presses are ignored. B and explicit output Close retain their blanking behavior.
|
||||
|
||||
A constant-size monotonic hold state ignores OS repeat frequency. Native keys tick
|
||||
on the existing event loop; held mouse buttons redraw only when a repeat is due.
|
||||
Single steps start after 400 ms at 100 ms intervals, then batches of five/ten at
|
||||
160 ms intervals after two/five seconds (capped to 10% of the deck, minimum one).
|
||||
No missed ticks are replayed. Key release, focus loss or modifier changes cancel
|
||||
keyboard holds. Mouse release, leaving the button or hiding its controls cancels
|
||||
mouse holds. Skipped uncached destinations defer new rendering until input settles
|
||||
for 180 ms or ends; existing workers are not restarted on each repeat. Release can
|
||||
cancel one obsolete foreground job so the final destination gets priority. The
|
||||
last ready audience frame remains visible; RAM-ready destinations can show directly.
|
||||
|
|
|
|||
|
|
@ -70,8 +70,9 @@ No wire fields change. EOF/failed input drops the host command sender; the nativ
|
|||
host detects receiver disconnection instead of treating it as an empty queue forever.
|
||||
An established output keeps its last frame after unexpected connection loss, while
|
||||
Close or Escape requests exit on the next event-loop tick. A disconnected host with
|
||||
no windows exits immediately. B still blanks. With a live presenter, output Close or
|
||||
Escape retains the existing emergency-blank behavior.
|
||||
no windows exits immediately. B still blanks. With a live presenter, output Close
|
||||
retains emergency blanking, but Escape never blanks (since 0.1.72). It can still
|
||||
revert a pending display trial. Focus-transfer synthetic key presses are ignored.
|
||||
|
||||
Normal presenter shutdown signals the supervisor and allows 500 ms for graceful
|
||||
completion, then terminates/reaps the owned child through a separate shared process
|
||||
|
|
|
|||
|
|
@ -83,7 +83,16 @@ Arrow keys and Page Up/Down navigate from the presenter or All slides, including
|
|||
while a presenter menu is open. Space moves forward; Shift+Space moves back. Notes
|
||||
editors and Ctrl/Alt/Command combinations retain keyboard priority. Type a 1-based slide
|
||||
number then Enter to jump; Backspace edits and Escape cancels. Out-of-range numbers
|
||||
do not navigate. Output windows accept B/Escape for emergency blanking.
|
||||
do not navigate. Output windows accept B for emergency blanking. Escape never blanks a connected
|
||||
show; it only reverts a display trial or closes an orphaned output.
|
||||
|
||||
Hold Next/Previous, an arrow key, Page Up/Down or Space (Shift+Space backwards)
|
||||
to accelerate. The first step is immediate; after 400 ms, single steps repeat every
|
||||
100 ms. After two seconds, steps become batches of up to five; after five seconds,
|
||||
up to ten, every 160 ms. Batches never exceed 10% of the deck (minimum one slide).
|
||||
Release or change focus to stop. Missed repeats are never queued or replayed.
|
||||
Buffered slides display immediately; uncached intermediate destinations are skipped,
|
||||
with rendering resumed at the latest destination on release or after input settles.
|
||||
|
||||
## Pointer and drawing tools
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue