Start the timer on the first presentation action

This commit is contained in:
Dandaedre 2026-11-20 08:46:02 +01:00
parent f5b3a6cce8
commit 8f361c70c5
12 changed files with 95 additions and 73 deletions

2
Cargo.lock generated
View File

@ -2245,7 +2245,7 @@ dependencies = [
[[package]]
name = "pdf-presenter"
version = "0.1.61"
version = "0.1.62"
dependencies = [
"bytemuck",
"chrono",

View File

@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
resolver = "3"
[workspace.package]
version = "0.1.61"
version = "0.1.62"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"

View File

@ -214,18 +214,18 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
" · CURRENT" => " · ACTUELLE",
"Open PDF…" => "Ouvrir un PDF…",
"Open picture folder…" => "Ouvrir un dossier d’images…",
"Restart timer" => "Redémarrer le chronomètre",
"Reset timer" => "Réinitialiser le chronomètre",
"Start timer" => "Démarrer le chronomètre",
"Pause timer" => "Mettre en pause",
"Countdown" => "Compte à rebours",
"Duration" => "Durée",
"Start on first slide" => "Démarrer à la première diapositive",
"Or use Start timer. Restart resets and starts immediately." => {
"Ou utilisez Démarrer. Redémarrer remet à zéro et démarre immédiatement."
"Start on first action" => "Démarrer à la première action",
"Start begins immediately. Reset waits for the next presentation action." => {
"Démarrer lance immédiatement. Réinitialiser attend la prochaine action de présentation."
}
"Running" => "En cours",
"Stopped" => "Arrêté",
"Waiting for first slide" => "En attente de la première diapositive",
"Waiting for first action" => "En attente de la première action",
"Time is up" => "Temps écoulé",
"Bar height" => "Hauteur de la barre",
"Exit fullscreen" => "Quitter le plein écran",

View File

@ -789,6 +789,7 @@ impl App {
if ack.generation == s.buffer_generation() && ack.page == Some(s.requested)
{
if s.zoom.accept_output(zoom) {
s.presentation_action();
repaint = true;
}
if zoom.epoch == s.zoom.epoch {
@ -814,17 +815,12 @@ impl App {
s.new_output = true;
}
if ack.request_blank {
s.presentation_action();
s.blanked = true;
s.new_output = true;
}
if ack.sequence == s.output_sequence {
s.displayed = ack.page;
if ack.page.is_some()
&& !s.blanked
&& ack.generation == s.buffer_generation()
{
s.slide_played();
}
}
}
if s.new_output {

View File

@ -382,8 +382,8 @@ fn timer_buttons(ui: &mut Ui, s: &mut Studio) {
{
s.execute(Action::ToggleTimer);
}
if ui.button(tr(&locale, "Restart timer")).clicked() {
s.execute(Action::RestartTimer);
if ui.button(tr(&locale, "Reset timer")).clicked() {
s.execute(Action::ResetTimer);
}
}
fn timer_controls(ui: &mut Ui, s: &mut Studio) {
@ -392,8 +392,8 @@ fn timer_controls(ui: &mut Ui, s: &mut Studio) {
let running = s.timer.running(Instant::now(), s.timer_limit());
let state = if running {
"Running"
} else if s.timer.waiting_for_slide && s.layout.timer_autostart {
"Waiting for first slide"
} else if s.timer.waiting_for_action && s.layout.timer_autostart {
"Waiting for first action"
} else if s.timer_limit().is_some() && s.timer.seconds(Instant::now(), s.timer_limit()) == 0 {
"Time is up"
} else {
@ -440,11 +440,11 @@ fn timer_settings(ui: &mut Ui, s: &mut Studio) {
}
ui.checkbox(
&mut s.layout.timer_autostart,
tr(&locale, "Start on first slide"),
tr(&locale, "Start on first action"),
);
ui.small(tr(
&locale,
"Or use Start timer. Restart resets and starts immediately.",
"Start begins immediately. Reset waits for the next presentation action.",
));
if before
!= (
@ -856,7 +856,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
"Scroll to zoom · drag to pan · double-click to fit width / reset",
));
if view != s.zoom.view {
s.set_zoom(view);
s.set_zoom_from_action(view);
}
}
} else {
@ -1523,7 +1523,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
.collapsible(false).resizable(false).show(&ctx, |ui| {
ui.set_max_width(420.);
ui.label(tr(&ctx, "Zoomed frames are taking over 33 ms to draw. Panning may feel slow on this display. Reset or disable zoom to return to normal viewing."));
if ui.button(tr(&ctx, "Reset zoom")).clicked() { s.set_zoom(Default::default()); s.zoom_warning_dismissed = true; }
if ui.button(tr(&ctx, "Reset zoom")).clicked() { s.set_zoom_from_action(Default::default()); s.zoom_warning_dismissed = true; }
if ui.button(tr(&ctx, "Disable zoom")).clicked() { s.enable_zoom(false); }
if ui.button(tr(&ctx, "Keep zoom enabled")).clicked() { s.zoom_warning_dismissed = true; }
});
@ -2116,9 +2116,9 @@ fn menu(ui: &mut Ui, s: &mut Studio) {
ui.menu_button(tr(&locale, "Page zoom"), |ui| {
let mut scale = s.zoom.view.scale;
if ui.add(egui::Slider::new(&mut scale, 1.0..=8.0).text("×")).changed() {
s.set_zoom(s.zoom.view.zoom_at(scale, [0.5; 2]));
s.set_zoom_from_action(s.zoom.view.zoom_at(scale, [0.5; 2]));
}
if ui.button(tr(&locale, "Reset zoom")).clicked() { s.set_zoom(Default::default()); }
if ui.button(tr(&locale, "Reset zoom")).clicked() { s.set_zoom_from_action(Default::default()); }
ui.small(tr(&locale, "Scroll to zoom · drag to pan · double-click to fit width / reset"));
ui.small(tr(&locale, "Use the current slide preview or a presentation screen. Changing slides resets zoom."));
});

View File

@ -39,7 +39,7 @@ pub enum Action {
Exit,
ToggleFullscreen,
ToggleTimer,
RestartTimer,
ResetTimer,
EditNotes,
ReloadNotes,
SaveNotes,
@ -312,9 +312,9 @@ impl Studio {
(self.layout.timer_mode == settings::TimerMode::Countdown)
.then(|| Duration::from_secs(self.layout.countdown_seconds as u64))
}
pub fn slide_played(&mut self) {
pub fn presentation_action(&mut self) {
self.timer
.first_slide(Instant::now(), self.layout.timer_autostart);
.presentation_action(Instant::now(), self.layout.timer_autostart);
}
pub fn execute(&mut self, action: Action) {
match action {
@ -435,11 +435,9 @@ impl Studio {
self.fg_job = None;
}
self.presentation_started = true;
if !self.blanked && self.routes.presentation.is_empty() {
self.slide_played();
}
if self.requested != page {
self.set_zoom(crate::zoom::View::default());
self.presentation_action();
}
self.requested = page;
self.jump.clear();
@ -448,11 +446,9 @@ impl Studio {
}
Action::Blank => {
self.blanked = !self.blanked;
self.presentation_action();
if !self.blanked {
self.presentation_started = true;
if self.count() > 0 && self.routes.presentation.is_empty() {
self.slide_played();
}
}
self.new_output = true;
}
@ -630,7 +626,7 @@ impl Studio {
}
}
Action::ToggleTimer => self.timer.toggle(Instant::now(), self.timer_limit()),
Action::RestartTimer => self.timer.restart(Instant::now()),
Action::ResetTimer => self.timer.reset(),
Action::ToggleFullscreen => {
if self.route_trial.is_some() {
return;
@ -1140,6 +1136,12 @@ impl Studio {
self.zoom.set(self.settings.zoom_enabled, view);
self.new_zoom = true;
}
pub fn set_zoom_from_action(&mut self, view: crate::zoom::View) {
if self.settings.zoom_enabled && view.normalized() != self.zoom.view.normalized() {
self.presentation_action();
}
self.set_zoom(view);
}
pub fn enable_zoom(&mut self, enabled: bool) {
self.settings.zoom_enabled = enabled;
self.set_zoom(crate::zoom::View::default());

View File

@ -5,14 +5,14 @@ use std::time::{Duration, Instant};
pub struct Timer {
accumulated: Duration,
running_since: Option<Instant>,
pub waiting_for_slide: bool,
pub waiting_for_action: bool,
}
impl Default for Timer {
fn default() -> Self {
Self {
accumulated: Duration::ZERO,
running_since: None,
waiting_for_slide: true,
waiting_for_action: true,
}
}
}
@ -36,25 +36,27 @@ impl Timer {
None => elapsed.as_secs(),
}
}
pub fn restart(&mut self, now: Instant) {
/// Return to zero and wait for the next presentation action.
pub fn reset(&mut self) {
self.accumulated = Duration::ZERO;
self.running_since = Some(now);
self.waiting_for_slide = false;
self.running_since = None;
self.waiting_for_action = true;
}
pub fn toggle(&mut self, now: Instant, limit: Option<Duration>) {
self.waiting_for_slide = false;
self.waiting_for_action = false;
if self.running(now, limit) {
self.accumulated = self.elapsed(now);
self.running_since = None;
} else if limit.is_some_and(|limit| self.elapsed(now) >= limit) {
self.restart(now);
self.accumulated = Duration::ZERO;
self.running_since = Some(now);
} else {
self.running_since = Some(now);
}
}
pub fn first_slide(&mut self, now: Instant, automatic: bool) {
if self.waiting_for_slide {
self.waiting_for_slide = false;
pub fn presentation_action(&mut self, now: Instant, automatic: bool) {
if self.waiting_for_action {
self.waiting_for_action = false;
if automatic {
self.running_since = Some(now);
}

View File

@ -528,16 +528,16 @@ fn nested_settings_remain_interactive_and_menu_still_dismisses() {
assert!(s.menu_open);
click(&mut s, "Storage locations");
assert!(s.menu_open);
click(&mut s, "Restart timer");
assert!(s.timer.running(std::time::Instant::now(), s.timer_limit()));
click(&mut s, "Reset timer");
assert!(!s.timer.running(std::time::Instant::now(), s.timer_limit()));
assert!(
!s.menu_open,
"Clicking the header command should dismiss the dropdown"
);
click(&mut s, "Pause timer");
assert!(!s.timer.running(std::time::Instant::now(), s.timer_limit()));
click(&mut s, "Start timer");
assert!(s.timer.running(std::time::Instant::now(), s.timer_limit()));
click(&mut s, "Pause timer");
assert!(!s.timer.running(std::time::Instant::now(), s.timer_limit()));
click(&mut s, "Menu");
click(&mut s, "Demo");
assert!(!s.menu_open, "Outside click should dismiss the dropdown");
@ -924,28 +924,35 @@ fn fullscreen_button_trials_both_directions_and_can_revert() {
}
#[test]
fn timer_actions_and_slide_triggers_do_not_restart_paused_timers() {
fn timer_waits_for_activity_reset_rearms_and_pause_stays_paused() {
use std::time::Instant;
let mut s = studio();
s.blanked = true;
s.execute(Action::Go(1));
assert!(!s.timer.running(Instant::now(), s.timer_limit()));
assert!(s.timer.running(Instant::now(), s.timer_limit()));
s.blanked = false;
s.slide_played();
assert!(s.timer.running(Instant::now(), s.timer_limit()));
s.execute(Action::ToggleTimer);
s.slide_played();
s.presentation_action();
assert!(!s.timer.running(Instant::now(), s.timer_limit()));
s.execute(Action::RestartTimer);
s.execute(Action::ResetTimer);
assert!(!s.timer.running(Instant::now(), s.timer_limit()));
s.settings.zoom_enabled = true;
s.set_zoom_from_action(pdf_presenter::zoom::View {
scale: 2.,
center: [0.5; 2],
});
assert!(s.timer.running(Instant::now(), s.timer_limit()));
s.timer = Default::default();
s.layout.timer_autostart = false;
s.slide_played();
s.presentation_action();
assert!(!s.timer.running(Instant::now(), s.timer_limit()));
s.timer = Default::default();
s.layout.timer_autostart = true;
s.routes.presentation.clear();
s.execute(Action::Go(0));
s.execute(Action::Go(s.requested));
assert!(!s.timer.running(Instant::now(), s.timer_limit()));
s.execute(Action::Blank);
assert!(s.timer.running(Instant::now(), s.timer_limit()));
}

View File

@ -2,22 +2,25 @@ use pdf_presenter::timer::Timer;
use std::time::{Duration, Instant};
#[test]
fn elapsed_autostart_pause_resume_restart_use_monotonic_time() {
fn elapsed_action_start_pause_resume_and_reset_use_monotonic_time() {
let now = Instant::now();
let mut timer = Timer::default();
assert_eq!(timer.seconds(now + Duration::from_secs(50), None), 0);
timer.first_slide(now, true);
timer.presentation_action(now, true);
assert!(timer.running(now, None));
timer.first_slide(now + Duration::from_secs(4), true);
timer.presentation_action(now + Duration::from_secs(4), true);
assert_eq!(timer.seconds(now + Duration::from_secs(5), None), 5);
timer.toggle(now + Duration::from_secs(5), None);
assert!(!timer.running(now + Duration::from_secs(20), None));
timer.first_slide(now + Duration::from_secs(10), true);
timer.presentation_action(now + Duration::from_secs(10), true);
assert_eq!(timer.seconds(now + Duration::from_secs(20), None), 5);
timer.toggle(now + Duration::from_secs(20), None);
assert_eq!(timer.seconds(now + Duration::from_secs(23), None), 8);
timer.restart(now + Duration::from_secs(23));
assert_eq!(timer.seconds(now + Duration::from_secs(25), None), 2);
timer.reset();
assert_eq!(timer.seconds(now + Duration::from_secs(25), None), 0);
assert!(!timer.running(now + Duration::from_secs(25), None));
timer.presentation_action(now + Duration::from_secs(25), true);
assert!(timer.running(now + Duration::from_secs(25), None));
}
#[test]
@ -25,7 +28,7 @@ fn countdown_manual_start_preserves_fractional_seconds_and_stops_at_zero() {
let now = Instant::now();
let limit = Some(Duration::from_secs(90));
let mut timer = Timer::default();
timer.first_slide(now, false);
timer.presentation_action(now, false);
assert!(!timer.running(now, limit));
assert_eq!(timer.seconds(now + Duration::from_secs(5), limit), 90);
timer.toggle(now, limit);

View File

@ -2,6 +2,15 @@
## Unreleased
### 0.1.62
- Keep the default timer at zero when a deck's initial slide is merely displayed.
Start it on the first navigation, zoom or output visibility action. Rename Restart
to Reset: it now returns to zero and rearms this action trigger, while explicit
Start still begins immediately and Pause cannot be undone by later activity.
Linux checks pass with 86.54% whole-application coverage; the release binary
is rebuilt. Physical presentation timing remains a separate acceptance check.
### 0.1.61
- Keep Displays, Layout and fullscreen as header buttons and remove their Menu

View File

@ -69,11 +69,12 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr
Running/paused state, monotonic timestamps and elapsed time are transient,
never saved. Successful source loads reset the timer to its waiting state;
failed loads preserve the current timer. Mode/duration/autostart edits reset it.
Automatic start uses the first matching, unblanked output frame acknowledgement;
without output monitors, explicit navigation/show starts rehearsal timing.
Pause disables pending autostart; later slide changes never resume a paused timer.
Restart resets and runs immediately. Countdown uses ceiling seconds, stops at
zero and never wraps; Start after expiry restarts the configured duration.
Automatic start uses the first explicit navigation, zoom or output-visibility
action; passively displaying the initial output frame does not start timing.
Pause disables pending autostart; later actions never resume a paused timer. Reset
returns to the configured initial value and arms autostart for the next navigation,
zoom or visibility action. Countdown uses ceiling seconds, stops at zero and never wraps; explicit
Start after expiry restarts the configured duration immediately.
- `projects`: at most 4096 SHA-256 canonical-path keys mapping to full layouts.
Path identity uses OS encoded bytes, not source content. Moving files or switching
platforms may therefore select a different layout. Project overrides win globally.

View File

@ -91,7 +91,7 @@ time and the local HH:MM clock. Hidden widgets release their space. Notes wrap a
automatically shrink to fit; extremely long notes can become too small to read.
The previous-slide preview is off by default; enable **Previous slide** in Layout
when you want it. Saved layouts keep their chosen visibility.
The header’s **Restart timer** button starts elapsed time again. Bundled UI fonts cover their supplied
The header's **Reset timer** button returns elapsed time to zero and arms it for the next presentation action. Bundled UI fonts cover their supplied
character sets; broad CJK text coverage remains a packaging acceptance item.
Save layout (this project) stores an override for the canonical document/folder path.
@ -224,14 +224,16 @@ Header, Above slides, Below notes, or left/right of the notes or slides.
Timer text can be set up to 320 logical pixels; it scales down only to fit its
allocated space. Timers on the same side stack vertically. Timers have separate labeled boxes; size and
visibility controls still apply. Body positions remain visible when bars are hidden.
Use **Start timer**, **Pause timer** and **Restart timer** in the presenter header or Layout.
Pause preserves the time; Restart resets and starts immediately. Under Layout →
Use **Start timer**, **Pause timer** and **Reset timer** in the presenter header or Layout.
Pause preserves the time. Reset returns to zero and waits for the next slide navigation,
zoom change or output visibility action. Start always begins immediately. Under Layout →
Timers and progress, choose **Elapsed time** or **Countdown** and set a countdown
in minutes and seconds (up to 24 hours). **Start on first slide** is enabled by
default: timing begins when the first slide reaches the presentation output,
including automatic output after opening a document. Turn it off for manual start.
in minutes and seconds (up to 24 hours). **Start on first action** is enabled by
default: timing begins on the first presentation action after opening or resetting.
Automatic output after opening a document does not count. Turn it off for manual start.
Rehearsal without an output screen starts on explicit navigation or Show presentation.
Loading a new source resets the timer; pausing is never undone by slide navigation.
Merely displaying the initial slide does not start it. Loading a new source resets the
timer; pausing is never undone by slide navigation.
Countdown stops at zero. Changing mode, duration or autostart resets the timer.
Save the layout for this project or all projects to remember these preferences.