feat: confirm quit requests from Escape and Ctrl+Q

This commit is contained in:
Dandaedre 2026-11-21 07:17:12 +01:00
parent fbdd1d2654
commit 0cbd6f2607
12 changed files with 282 additions and 120 deletions

2
Cargo.lock generated
View File

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

View File

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

View File

@ -134,7 +134,7 @@ Useful controls:
- **Hold S for one second** — swap Presenter and Slides screens, then Keep or Revert
- **B** — blank or restore Slides
- **P / A / H** — pointer, arrow or highlighter
- **Escape** — cancel the current popup or display proposal; fullscreen has its own button
- **Escape / Ctrl+Q** — request quit confirmation (Escape first reverts an active display trial)
[Notes, layouts and controls →](docs/user-guide.md) ·
[Notes file formats →](docs/interfaces/presentation-notes.md) ·

View File

@ -276,6 +276,17 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
"Afficher automatiquement les diapositives à l’ouverture d’un document"
}
"Quit" => "Quitter",
"Quit presentation?" => "Quitter la présentation ?",
"Quit presentation" => "Quitter la présentation",
"This closes Presenter and all Slides windows." => {
"Ferme le présentateur et toutes les fenêtres de diapositives."
}
"Wait for notes import to finish before closing." => {
"Attendez la fin de l’importation des notes avant de quitter."
}
"Save or discard notes before closing the presentation." => {
"Enregistrez ou abandonnez les notes avant de quitter la présentation."
}
"Theme" => "Thème",
"Language" => "Langue",
_ => text,

View File

@ -937,8 +937,14 @@ impl App {
Ok(())
}
fn key(&mut self, role: Role, key: Key, consumed: bool, modifiers: egui::Modifiers) {
let escape = matches!(key, Key::Named(NamedKey::Escape)) && modifiers.is_none();
let quit = escape
|| (matches!(&key, Key::Character(c) if c.eq_ignore_ascii_case("q"))
&& modifiers.ctrl
&& !modifiers.alt
&& !modifiers.shift);
if role == Role::Presentation {
if matches!(key, Key::Named(NamedKey::Escape))
if escape
&& let Some(host) = &self.host
&& host.state.route_trial.is_some()
{
@ -949,7 +955,16 @@ impl App {
});
return;
}
if matches!(key, Key::Named(NamedKey::Escape)) {
if quit {
if let Some(h) = &self.host
&& h.parent_connected
{
let _ = h.acks.try_send(Ack {
request_quit: true,
..Default::default()
});
return;
}
// 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 {
@ -971,10 +986,22 @@ impl App {
let Some(s) = &mut self.studio else {
return;
};
if matches!(key, Key::Named(NamedKey::Escape)) && s.route_trial.is_some() {
if s.quit_confirmation {
if escape {
s.execute(Action::CancelExit);
}
self.redraw();
return;
}
if escape && s.route_trial.is_some() {
s.execute(Action::RevertRoutes);
return;
}
if quit {
s.execute(Action::Exit);
self.redraw();
return;
}
// Notes editing must never turn typing or Escape into presentation commands.
// Unsaved text is only discarded through the explicit editor control.
if s.notes_editor.is_some() || s.notes_import.is_some() {
@ -994,14 +1021,6 @@ impl App {
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);
}
return;
}
if consumed {
return;
}
@ -1024,16 +1043,6 @@ impl App {
Key::Named(NamedKey::Backspace) if !s.jump.is_empty() => {
s.jump.pop();
}
Key::Named(NamedKey::Escape) => {
if !s.jump.is_empty() {
s.jump.clear();
} else if s.layout_open || s.displays_open || s.menu_open || s.toolbox.open {
s.layout_open = false;
s.displays_open = false;
s.menu_open = false;
s.toolbox.open = false;
}
}
Key::Character(c) if c.eq_ignore_ascii_case("p") => {
let tool = if s.toolbox.tool == crate::tools::Tool::Pointer {
crate::tools::Tool::Off
@ -1089,7 +1098,8 @@ impl App {
.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.quit_confirmation
&& s.notes_editor.is_none()
&& s.notes_import.is_none()
&& !s.dialog_busy
&& !s.loading
@ -1126,6 +1136,7 @@ impl App {
s.status.clone(),
s.layout_open,
s.browser_open,
s.quit_confirmation,
s.route_trial.as_ref().map(|trial| trial.id),
);
let chooser_was_open = s.dialog_busy;
@ -1206,6 +1217,9 @@ impl App {
}
continue;
}
if ack.request_quit {
s.execute(Action::Exit);
}
if let Some(action) = ack.display_action {
s.display_control(action, ack.route_trial);
}
@ -1311,6 +1325,7 @@ impl App {
s.status.clone(),
s.layout_open,
s.browser_open,
s.quit_confirmation,
s.route_trial.as_ref().map(|trial| trial.id),
);
}
@ -1553,7 +1568,8 @@ impl ApplicationHandler for App {
// 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.quit_confirmation
&& s.notes_editor.is_none()
&& s.notes_import.is_none()
&& !s.dialog_busy
&& s.route_trial.is_none()
@ -1651,7 +1667,8 @@ impl ApplicationHandler for App {
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.quit_confirmation
&& s.notes_editor.is_none()
&& s.notes_import.is_none()
&& !s.dialog_busy
&& s.route_trial.is_none()
@ -1663,34 +1680,7 @@ impl ApplicationHandler for App {
crate::navigation::Hold::new(direction, Instant::now()),
));
}
let local_dismissed = matches!(event.logical_key, Key::Named(NamedKey::Escape))
&& !modifiers.ctrl
&& !modifiers.alt
&& !modifiers.command
&& role == Role::Presenter
&& self.studio.as_mut().is_some_and(|s| {
if s.route_trial.is_some()
|| s.notes_editor.is_some()
|| s.notes_import.is_some()
|| !s.jump.is_empty()
{
return false;
}
let Some(view) =
s.presenter_views.get_mut(&self.windows[index].monitor)
else {
return false;
};
let open = view.layout_open || view.menu_open;
view.layout_open = false;
view.menu_open = false;
open
});
if local_dismissed {
self.redraw();
} else {
self.key(role, event.logical_key, consumed, modifiers);
}
self.key(role, event.logical_key, consumed, modifiers);
}
}
WindowEvent::Resized(_) | WindowEvent::ScaleFactorChanged { .. } => {
@ -1843,7 +1833,7 @@ impl ApplicationHandler for App {
for view in s.presenter_views.values_mut() {
view.layout = Default::default();
}
// Escape dismisses transient UI; fullscreen is an explicit control.
// Fullscreen remains an explicit control; Escape requests quit confirmation.
}
6 => {
if self.windows.iter().all(|w| w.frames > 0) && !self.windows.is_empty() {
@ -2181,43 +2171,29 @@ mod buffer_tests {
s.settings.presenter_fullscreen = true;
s.settings.presentation_fullscreen = true;
s.blanked = false;
s.jump = "12".into();
app.key(
Role::Presenter,
Key::Named(NamedKey::Escape),
false,
egui::Modifiers::NONE,
);
assert!(app.studio.as_ref().unwrap().jump.is_empty());
app.key(
Role::Presenter,
Key::Named(NamedKey::Escape),
false,
egui::Modifiers::NONE,
);
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());
for (key, modifiers) in [
(Key::Named(NamedKey::Escape), egui::Modifiers::NONE),
(Key::Character("q".into()), egui::Modifiers::CTRL),
] {
for role in [Role::Presenter, Role::Browser] {
app.key(role, key.clone(), true, modifiers);
let s = app.studio.as_ref().unwrap();
assert!(s.quit_confirmation && !s.close_requested && !s.blanked);
app.key(
role,
Key::Named(NamedKey::Space),
false,
egui::Modifiers::NONE,
);
assert!(app.studio.as_ref().unwrap().quit_confirmation);
app.key(
role,
Key::Named(NamedKey::Escape),
true,
egui::Modifiers::NONE,
);
assert!(!app.studio.as_ref().unwrap().quit_confirmation);
}
}
let (_tx, commands) = mpsc::sync_channel(4);
let (acks, rx) = mpsc::sync_channel(8);
@ -2250,10 +2226,8 @@ mod buffer_tests {
);
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"
);
let ack = rx.try_recv().unwrap();
assert!(ack.request_quit && !ack.request_blank);
app.key(
Role::Presentation,
Key::Character("b".into()),
@ -2326,6 +2300,7 @@ mod buffer_tests {
fn swap_allowed(s: &Studio) -> bool {
s.initialized
&& !s.quit_confirmation
&& s.notes_editor.is_none()
&& s.notes_import.is_none()
&& !s.dialog_busy

View File

@ -81,6 +81,8 @@ pub struct Ack {
#[serde(default)]
pub request_blank: bool,
#[serde(default)]
pub request_quit: bool,
#[serde(default)]
pub display_action: Option<DisplayAction>,
#[serde(default)]
pub route_trial: Option<u64>,

View File

@ -1414,9 +1414,9 @@ fn presenter_view(
},
s.jump,
if s.settings.language.french() {
"Entrée : diffuser · Échap : annuler"
"Entrée : diffuser · Retour arrière : effacer"
} else {
"Enter to show · Esc to cancel"
"Enter to show · Backspace to clear"
}
));
});
@ -1889,6 +1889,7 @@ fn presenter_view(
}
notes_import_ui(&ctx, s);
notes_editor_ui(&ctx, s);
quit_confirmation(&ctx, s);
}
fn notes_import_ui(ctx: &Context, s: &mut Studio) {
let Some(import) = &s.notes_import else {
@ -2263,9 +2264,9 @@ pub fn browser(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
},
s.jump,
if s.settings.language.french() {
"Entrée : diffuser, Échap : annuler"
"Entrée : diffuser, Retour arrière : effacer"
} else {
"Enter to show, Escape to cancel"
"Enter to show; Backspace to clear"
}
));
}
@ -2396,6 +2397,7 @@ pub fn browser(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
s.browser_preview = None;
}
}
quit_confirmation(ui.ctx(), s);
}
fn preferences_window(ctx: &egui::Context, s: &mut Studio, open: &mut bool) {
@ -2809,3 +2811,31 @@ pub fn output_display_recovery(
}
action
}
fn quit_confirmation(ctx: &egui::Context, s: &mut Studio) {
if !s.quit_confirmation {
return;
}
egui::Modal::new(egui::Id::new("confirm-quit")).show(ctx, |ui| {
ui.heading(tr(ctx, "Quit presentation?"));
ui.label(tr(ctx, "This closes Presenter and all Slides windows."));
let blocked = s.quit_block_reason();
if let Some(reason) = blocked {
ui.label(tr(ctx, reason));
}
ui.horizontal(|ui| {
if ui.button(tr(ctx, "Cancel")).clicked() {
s.actions.push(Action::CancelExit);
}
if ui
.add_enabled(
blocked.is_none(),
egui::Button::new(tr(ctx, "Quit presentation")),
)
.clicked()
{
s.actions.push(Action::ConfirmExit);
}
});
});
}

View File

@ -53,6 +53,8 @@ pub enum Action {
CloseBrowser,
Refresh,
Exit,
ConfirmExit,
CancelExit,
ToggleFullscreen,
ToggleTimer,
ResetTimer,
@ -181,6 +183,7 @@ pub struct Studio {
pub new_overlay: bool,
pub new_output: bool,
pub close_requested: bool,
pub quit_confirmation: bool,
failed: HashSet<(usize, u32)>,
pub smoke: bool,
pub startup: Instant,
@ -297,6 +300,7 @@ impl Studio {
new_overlay: false,
new_output: true,
close_requested: false,
quit_confirmation: false,
failed: HashSet::new(),
smoke,
startup: Instant::now(),
@ -802,18 +806,17 @@ impl Studio {
}
Action::Refresh => self.dirty_routes = true,
Action::Exit => {
if self.notes_import.as_ref().is_some_and(|i| i.busy) {
self.status = "Wait for notes import to finish before closing.".into();
return;
}
if self
.notes_editor
.as_ref()
.is_some_and(|editor| editor.busy || editor.text != editor.saved_text)
{
self.status = "Save or discard notes before closing the presentation.".into();
} else {
self.close_requested = true;
self.quit_confirmation = true;
}
Action::CancelExit => self.quit_confirmation = false,
Action::ConfirmExit => {
if self.quit_confirmation {
if let Some(reason) = self.quit_block_reason() {
self.status = reason.into();
} else {
self.quit_confirmation = false;
self.close_requested = true;
}
}
}
command @ (Action::EditNotes | Action::ReloadNotes) => {
@ -912,6 +915,19 @@ impl Studio {
_ => {}
}
}
pub fn quit_block_reason(&self) -> Option<&'static str> {
if self.notes_import.as_ref().is_some_and(|i| i.busy) {
Some("Wait for notes import to finish before closing.")
} else if self
.notes_editor
.as_ref()
.is_some_and(|e| e.busy || e.text != e.saved_text)
{
Some("Save or discard notes before closing the presentation.")
} else {
None
}
}
pub fn screen_fullscreen(&self, display: &str, global: bool) -> bool {
self.route_trial
.as_ref()

View File

@ -152,6 +152,8 @@ fn shared_actions_preserve_blanking_and_save_scope() {
s.execute(Action::Refresh);
assert!(s.dirty_routes);
s.execute(Action::Exit);
assert!(s.quit_confirmation && !s.close_requested);
s.execute(Action::ConfirmExit);
assert!(s.close_requested);
}
@ -1216,6 +1218,7 @@ fn double_click_notes_opens_editor_and_editor_keeps_unsaved_draft() {
s.execute(Action::Exit);
assert!(!s.close_requested);
assert_eq!(s.notes_editor.as_ref().unwrap().text, "Unsaved notes");
s.execute(Action::CancelExit);
let pos = text_pos(&output.shapes, "Save notes");
for pressed in [true, false] {
render(
@ -1974,3 +1977,102 @@ fn output_viewport_accepts_screen_override_instead_of_global_mode() {
s.output_viewport.as_mut().unwrap().fullscreen = true;
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
}
#[test]
fn quit_confirmation_requires_explicit_confirmation_and_protects_notes() {
let mut s = studio();
s.execute(Action::ConfirmExit);
assert!(!s.close_requested);
s.execute(Action::Exit);
assert!(s.quit_confirmation && !s.close_requested && !s.blanked);
s.execute(Action::CancelExit);
s.execute(Action::ConfirmExit);
assert!(!s.quit_confirmation && !s.close_requested);
s.notes_editor = Some(pdf_presenter::studio::NotesEditor {
page: 0,
text: "Unsaved".into(),
saved_text: "Saved".into(),
busy: false,
error: None,
snapshot: None,
});
s.execute(Action::Exit);
s.execute(Action::ConfirmExit);
assert!(s.quit_confirmation && !s.close_requested);
assert_eq!(s.notes_editor.as_ref().unwrap().text, "Unsaved");
s.notes_editor.as_mut().unwrap().text = "Saved".into();
s.notes_editor.as_mut().unwrap().busy = true;
s.execute(Action::ConfirmExit);
assert!(!s.close_requested);
s.notes_editor = None;
s.notes_import = Some(pdf_presenter::studio::NotesImport {
preview: None,
busy: true,
error: None,
});
s.execute(Action::ConfirmExit);
assert!(!s.close_requested);
s.notes_import = None;
s.execute(Action::ConfirmExit);
assert!(s.close_requested && !s.quit_confirmation);
}
#[test]
fn quit_modal_buttons_work_in_presenter_and_browser() {
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(shapes) => shapes.iter().find_map(|s| find(s, label)),
_ => None,
}
}
for browser in [false, true] {
for label in ["Cancel", "Quit presentation"] {
let ctx = Context::default();
let mut s = studio();
s.settings.language = pdf_presenter::localization::Language::En;
s.execute(Action::Exit);
let mut native = UiState::default();
let mut frame = |s: &mut Studio, events| {
let mut raw = input(Vec2::new(1920., 1080.));
raw.events = events;
ctx.run_ui(raw, |ui| {
if browser {
presenter_ui::browser(ui, s, &mut native);
} else {
presenter_ui::presenter(ui, s, &mut native);
}
})
};
let mut output = frame(&mut s, vec![]);
for _ in 0..3 {
output = frame(&mut s, vec![]);
}
let pos = output
.shapes
.iter()
.find_map(|shape| find(&shape.shape, label))
.unwrap();
for pressed in [true, false] {
frame(
&mut s,
vec![
egui::Event::PointerMoved(pos),
egui::Event::PointerButton {
pos,
button: egui::PointerButton::Primary,
pressed,
modifiers: Default::default(),
},
],
);
}
for action in std::mem::take(&mut s.actions) {
s.execute(action);
}
assert!(!s.quit_confirmation);
assert_eq!(s.close_requested, label == "Quit presentation");
assert!(!s.blanked);
}
}
}

View File

@ -2,6 +2,18 @@
## Unreleased
### 0.1.88
- Escape and Ctrl+Q request a shared quit-confirmation dialog, also used by Menu
Quit and Presenter window close. Cancel/Escape resumes the show; explicit Quit
closes it only when notes have no pending writes or unsaved edits. Audience
shortcuts request operator confirmation without showing dialogs or blanking
Slides. Escape still reverts active display trials first.
- Linux formatting, warnings-denied Clippy/rustdoc, workspace tests, build and
13 Python tests pass. GUI coverage remains blocked by `XOpenDisplayFailed` in
this environment; native physical testing and Windows/macOS validation were
not performed.
### 0.1.87
- Add per-screen Follow global / Always fullscreen / Always windowed choices in

View File

@ -225,3 +225,11 @@ no presenter layout, notes or paths. Placement and OutputViewport acknowledgment
use the same per-monitor value. Full state updates replace the map; lightweight
zoom/overlay updates preserve it. Values round-trip through JSON; both processes
must still run the same executable build.
## Quit confirmation — 0.1.88
ACK adds optional boolean `request_quit` (default false). Escape/Ctrl+Q on a
connected output requests the shared operator-only quit dialog; it does not blank
or stop the output. No confirmation text or notes are sent to the audience host.
Only a confirmed presenter-side quit triggers existing shutdown. Escape retains
priority for display-trial rollback; an orphan output can still close directly.

View File

@ -92,8 +92,14 @@ preserves blanking. Until an uncached requested slide is ready, output holds the
usable frame. The footer distinguishes requested and acknowledged displayed slides. A red
**NO OUTPUT DISPLAYED** warning marks blanking, no assigned output or no document;
it remains visible when the footer is hidden. Preparing output has a separate status.
Escape cancels a pending slide number/menu or closes the browser; it does not
leave Presenter fullscreen or blank Slides. Use **Enter fullscreen /
**Escape** or **Ctrl+Q** opens **Quit presentation?** in Presenter or All slides.
Choose **Quit presentation** to close the application, or **Cancel** (also Escape)
to continue. Menu → Quit and closing a Presenter use the same confirmation.
Unsaved notes or active notes writes/imports must be saved, discarded or finished
before quitting; Cancel returns to the editor. Slides keeps its current visibility
while confirmation is open. Shortcuts on a connected Slides window request the
confirmation on Presenter, never on the audience display. Escape still reverts
an active display trial before offering to quit. Use **Enter fullscreen /
Exit fullscreen** in the header to toggle both display roles. Like other
display changes, this previews the change with Keep/Revert confirmation. While a
Presenter is connected, closing a Slides window blanks it; close a Presenter or
@ -102,9 +108,9 @@ choose Menu → Quit to end the application.
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
number then Enter to jump; Backspace edits or clears it. Out-of-range numbers
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.
show; it requests quit confirmation, 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
@ -254,7 +260,7 @@ dependency/font notices without launching a window.
## Appearance and language
Menu opens a dropdown below its button; click outside or press Escape to dismiss it.
Menu opens a dropdown below its button; click outside to dismiss it.
Page zoom, fitted-area zoom and automatic Slides output stay in this dropdown for
quick access. **Preferences…** opens a separate resizable window for blank-output
artwork, RAM and cache controls, preparation/storage details and Windows integration.
@ -275,7 +281,7 @@ remain verbatim. Additional Canvas Pilot languages and external theme/language p
are not included in this version.
All slides opens a windowed browser above fullscreen windows and requests focus.
Opening it again restores/focuses the existing browser. Close or Escape dismisses it.
Opening it again restores/focuses the existing browser. Its Close button dismisses it; Escape requests application quit confirmation.
The destination remains configurable in the browser, defaulting to the presenter.
Window-manager focus restrictions may still require clicking the browser on some systems.
@ -344,7 +350,7 @@ See [Niri window rules](https://github.com/niri-wm/niri/wiki/Configuration%3A-Wi
The rule targets only All slides, not Presenter or Slides windows.
In All slides, double-click a thumbnail to open a larger, resizable preview inside
the browser. It does not change the presentation. Close it with its X or Escape.
the browser. It does not change the presentation. Close it with its X.
When Change on click is enabled, clicks switch the live slide and do not open previews.
The All slides grid fills the browser width and adapts as you resize it. Preview