feat: swap display roles with a one-second S hold

This commit is contained in:
Dandaedre 2026-11-21 07:09:45 +01:00
parent 57c85b3af2
commit db39451ab3
8 changed files with 135 additions and 4 deletions

2
Cargo.lock generated
View File

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

View File

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

View File

@ -131,6 +131,7 @@ Useful controls:
- **Right / Space** — next slide
- **Left / Shift+Space** — previous slide
- **Number, then Enter** — jump to a slide
- **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

View File

@ -716,6 +716,7 @@ struct App {
override_presenter: Option<usize>,
override_output: Option<usize>,
navigation_hold: Option<(WindowId, Key, crate::navigation::Hold)>,
swap_hold: Option<(WindowId, Instant)>,
#[cfg(target_os = "windows")]
presenter_focus: Option<PresenterFocusRetry>,
}
@ -783,6 +784,7 @@ impl App {
}
if let Some(s) = &mut self.studio {
if changed {
self.swap_hold = None;
s.set_monitors(
self.handles.iter().map(|(m, _)| m.clone()).collect(),
primary,
@ -1062,6 +1064,18 @@ impl App {
s.execute(Action::FinishNavigation);
}
}
fn poll_swap(&mut self, now: Instant) {
let Some((owner, _)) = self.swap_hold else {
return;
};
let allowed = self.windows.iter().any(|w| {
w.window.id() == owner && w.window.has_focus() && !w.ctx.egui_wants_keyboard_input()
}) && self.studio.as_ref().is_some_and(swap_allowed);
if take_due_swap(&mut self.swap_hold, now, allowed) {
self.studio.as_mut().unwrap().execute(Action::SwapRoutes);
self.redraw();
}
}
fn repeat_navigation(&mut self, now: Instant) {
let Some((id, _, _)) = &self.navigation_hold else {
return;
@ -1580,16 +1594,24 @@ impl ApplicationHandler for App {
}
}
WindowEvent::Focused(false) => {
self.swap_hold = None;
self.stop_navigation();
self.windows[index].ui.navigation_hold = None;
}
WindowEvent::ModifiersChanged(_) => self.stop_navigation(),
WindowEvent::ModifiersChanged(_) => {
self.swap_hold = None;
self.stop_navigation();
}
WindowEvent::KeyboardInput {
event,
is_synthetic,
..
} => {
if event.state == ElementState::Released {
if matches!(&event.logical_key, Key::Character(c) if c.eq_ignore_ascii_case("s"))
{
self.swap_hold = None;
}
if self
.navigation_hold
.as_ref()
@ -1598,10 +1620,19 @@ impl ApplicationHandler for App {
self.stop_navigation();
}
} else if !event.repeat && !is_synthetic {
self.swap_hold = None;
self.stop_navigation();
let native = &self.windows[index];
let modifiers = native.input.egui_input().modifiers;
let consumed = native.ctx.egui_wants_keyboard_input();
if role != Role::Presentation
&& !consumed
&& modifiers.is_none()
&& matches!(&event.logical_key, Key::Character(c) if c.eq_ignore_ascii_case("s"))
&& self.studio.as_ref().is_some_and(swap_allowed)
{
self.swap_hold = Some((id, Instant::now()));
}
let direction = navigation_direction(&event.logical_key, modifiers);
let allowed = role != Role::Presentation
&& self.studio.as_ref().is_some_and(|s| {
@ -1713,6 +1744,7 @@ impl ApplicationHandler for App {
self.next_monitors = now + Duration::from_millis(750);
}
if now >= self.next_poll {
self.poll_swap(now);
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.
@ -1843,6 +1875,7 @@ pub fn run(options: crate::poc::Options, path: Option<std::path::PathBuf>) -> Re
override_presenter: options.presenter,
override_output: options.audience,
navigation_hold: None,
swap_hold: None,
#[cfg(target_os = "windows")]
presenter_focus: None,
};
@ -1913,6 +1946,7 @@ pub fn run_output() -> Result<(), Failure> {
override_presenter: None,
override_output: None,
navigation_hold: None,
swap_hold: None,
#[cfg(target_os = "windows")]
presenter_focus: None,
};
@ -2039,6 +2073,7 @@ mod buffer_tests {
override_presenter: None,
override_output: None,
navigation_hold: None,
swap_hold: None,
#[cfg(target_os = "windows")]
presenter_focus: None,
},
@ -2096,6 +2131,7 @@ mod buffer_tests {
override_presenter: None,
override_output: None,
navigation_hold: None,
swap_hold: None,
#[cfg(target_os = "windows")]
presenter_focus: None,
};
@ -2272,3 +2308,59 @@ mod buffer_tests {
));
}
}
fn swap_allowed(s: &Studio) -> bool {
s.initialized
&& s.notes_editor.is_none()
&& s.notes_import.is_none()
&& !s.dialog_busy
&& !s.loading
&& s.route_trial.is_none()
&& !s.routes.presenter.is_empty()
&& !s.routes.presentation.is_empty()
}
fn take_due_swap(hold: &mut Option<(WindowId, Instant)>, now: Instant, allowed: bool) -> bool {
if !allowed {
*hold = None;
return false;
}
if hold.is_some_and(|(_, start)| now.saturating_duration_since(start) >= Duration::from_secs(1))
{
*hold = None;
return true;
}
false
}
#[cfg(test)]
mod swap_tests {
use super::*;
#[test]
fn hold_requires_one_second_fires_once_and_cancels_when_disallowed() {
let now = Instant::now();
let mut hold = Some((WindowId::dummy(), now));
assert!(!take_due_swap(
&mut hold,
now + Duration::from_millis(999),
true
));
assert!(take_due_swap(&mut hold, now + Duration::from_secs(1), true));
assert!(!take_due_swap(
&mut hold,
now + Duration::from_secs(20),
true
));
hold = Some((WindowId::dummy(), now));
assert!(!take_due_swap(
&mut hold,
now + Duration::from_millis(500),
false
));
assert!(!take_due_swap(
&mut hold,
now + Duration::from_secs(2),
true
));
}
}

View File

@ -711,7 +711,7 @@ impl Studio {
}
Action::SwapRoutes => {
if self.route_trial.is_none()
&& !self.presentation_started
&& !self.routes.presenter.is_empty()
&& !self.routes.presentation.is_empty()
{
self.begin_display_edit();

View File

@ -1828,3 +1828,24 @@ fn any_presenter_can_edit_and_save_another_presenter_layout() {
|action| matches!(action, Action::SaveDisplayLayout { display, .. } if display == "two")
));
}
#[test]
fn explicit_swap_during_show_preserves_visibility_and_uses_reversible_trial() {
for blanked in [false, true] {
let mut s = studio();
s.execute(Action::Go(0));
s.blanked = blanked;
let original = s.routes.clone();
s.execute(Action::SwapRoutes);
assert!(s.route_trial.is_some());
assert_eq!(s.routes.presenter, original.presentation);
assert_eq!(s.routes.presentation, original.presenter);
assert_eq!(s.blanked, blanked);
let swapped = s.routes.clone();
s.execute(Action::SwapRoutes);
assert_eq!(s.routes, swapped);
s.execute(Action::RevertRoutes);
assert_eq!(s.routes, original);
assert_eq!(s.blanked, blanked);
}
}

View File

@ -2,6 +2,17 @@
## Unreleased
### 0.1.86
- Hold S for one second in Presenter or All slides to swap display role groups,
including during a live show, using the existing timed Keep/Revert trial.
Ignore repeats and text editing; cancel on release, focus/modifier changes,
other keys or display topology changes. Preserve shown/blanked output.
- Linux formatting, warnings-denied Clippy/rustdoc, workspace tests, build and
13 Python tests pass. GUI coverage is unavailable because the native smoke test
cannot open a display. Physical screen-swap testing remains pending;
Windows/macOS builds were not run.
### 0.1.85
- Document installation through cargo-binstall using repository release archives,

View File

@ -53,6 +53,12 @@ Confirmation controls appear on presenter and output windows so either screen ca
recover the change. Unconfirmed choices are never saved, and a disconnect cancels
the trial. Navigation is held until the trial is resolved; explicit blank/show controls remain available.
Hold **S** for one second in Presenter or All slides to swap the whole Presenter
and Slides groups, including during a show. The same Keep/Revert trial applies.
A short tap does nothing; release and press again for another swap. Focus loss,
a modifier or another key cancels the hold. The shortcut is inactive while typing
in controls, editing/importing notes, loading, or confirming a display trial.
Disabling either fullscreen option shows a positioning warning. Window placement
can be unreliable in windowed mode, especially on Linux; switch back to fullscreen
if you experience positioning issues.