feat: add per-screen fullscreen and windowed overrides

This commit is contained in:
Dandaedre 2026-11-21 07:13:15 +01:00
parent db39451ab3
commit fbdd1d2654
15 changed files with 345 additions and 7 deletions

2
Cargo.lock generated
View File

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

View File

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

View File

@ -192,6 +192,13 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
"Unused" => "Inutilisé",
"Presenter" => "Présentateur",
"Slides" => "Diapositives",
"Window mode" => "Mode de fenêtre",
"Follow global" => "Suivre le réglage global",
"Always fullscreen" => "Toujours en plein écran",
"Always windowed" => "Toujours en fenêtre",
"Always fullscreen/windowed overrides global fullscreen commands for this screen." => {
"Le mode toujours plein écran/fenêtre ignore les commandes globales pour cet écran."
}
"Swap groups" => "Inverser les groupes",
"Window positioning can be unreliable in windowed mode, especially on Linux. Switch back to fullscreen if you experience positioning issues." => {
"Le positionnement des fenêtres peut être peu fiable en mode fenêtré, surtout sous Linux. Revenez au plein écran si vous rencontrez des problèmes de positionnement."

View File

@ -847,7 +847,11 @@ 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.presenter_fullscreen()));
desired.push((
Role::Presenter,
id.clone(),
s.screen_fullscreen(id, s.presenter_fullscreen()),
));
}
if s.browser_open {
let id = s
@ -865,7 +869,7 @@ impl App {
if let Some(h) = &self.host {
for id in &h.state.monitors {
if self.handles.iter().any(|(m, _)| &m.id == id) {
desired.push((Role::Presentation, id.clone(), h.state.fullscreen));
desired.push((Role::Presentation, id.clone(), h.state.fullscreen_on(id)));
}
}
}
@ -1253,6 +1257,17 @@ impl App {
},
monitors: s.routes.presentation.clone(),
fullscreen: s.presentation_fullscreen(),
screen_fullscreen: s
.routes
.presentation
.iter()
.map(|id| {
(
id.clone(),
s.screen_fullscreen(id, s.presentation_fullscreen()),
)
})
.collect(),
blanked: s.blanked,
blank_picture: s.blank_picture.as_ref().map(|f| f.info.clone()),
..Default::default()
@ -1772,7 +1787,7 @@ impl ApplicationHandler for App {
crate::output::OutputViewport {
monitor: id.clone(),
size: [size.width, size.height],
fullscreen: host.state.fullscreen,
fullscreen: host.state.fullscreen_on(id),
}
})
});

View File

@ -47,11 +47,21 @@ pub struct HostState {
pub buffer_mib: u32,
pub monitors: Vec<String>,
pub fullscreen: bool,
#[serde(default)]
pub screen_fullscreen: std::collections::BTreeMap<String, bool>,
pub blanked: bool,
#[serde(default)]
pub blank_picture: Option<FrameInfo>,
pub quit: bool,
}
impl HostState {
pub fn fullscreen_on(&self, monitor: &str) -> bool {
self.screen_fullscreen
.get(monitor)
.copied()
.unwrap_or(self.fullscreen)
}
}
/// Actual size of the reference Slides window, never Presenter content.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OutputViewport {

View File

@ -1808,6 +1808,23 @@ fn presenter_view(
}
});
});
use crate::settings::ScreenMode;
let mut mode = s.draft_screen_modes.get(&m.id).copied().unwrap_or_default();
ui.horizontal(|ui| {
ui.label(tr(&locale, "Window mode"));
egui::ComboBox::from_id_salt(("screen-mode", &m.id))
.selected_text(tr(&locale, mode.label()))
.show_ui(ui, |ui| {
for option in [ScreenMode::FollowGlobal, ScreenMode::AlwaysFullscreen, ScreenMode::AlwaysWindowed] {
ui.selectable_value(&mut mode, option, tr(&locale, option.label()));
}
});
});
if mode == ScreenMode::FollowGlobal {
s.draft_screen_modes.remove(&m.id);
} else {
s.draft_screen_modes.insert(m.id.clone(), mode);
}
s.draft_routes.presenter.retain(|id| id != &m.id);
s.draft_routes.presentation.retain(|id| id != &m.id);
match role {
@ -1848,7 +1865,9 @@ fn presenter_view(
&locale,
"Output visibility is preserved while previewing display changes.",
));
if !s.draft_presenter_fullscreen || !s.draft_presentation_fullscreen {
ui.small(tr(&locale, "Always fullscreen/windowed overrides global fullscreen commands for this screen."));
if s.draft_routes.presenter.iter().any(|id| !s.draft_screen_modes.get(id).copied().unwrap_or_default().fullscreen(s.draft_presenter_fullscreen))
|| s.draft_routes.presentation.iter().any(|id| !s.draft_screen_modes.get(id).copied().unwrap_or_default().fullscreen(s.draft_presentation_fullscreen)) {
ui.colored_label(
ui.visuals().warn_fg_color,
tr(&locale, "Window positioning can be unreliable in windowed mode, especially on Linux. Switch back to fullscreen if you experience positioning issues."),

View File

@ -211,6 +211,39 @@ impl Default for SlideColors {
}
}
}
/// Per-monitor preference that takes priority over role-wide fullscreen commands.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ScreenMode {
#[default]
FollowGlobal,
AlwaysFullscreen,
AlwaysWindowed,
}
impl ScreenMode {
pub fn fullscreen(self, global: bool) -> bool {
match self {
Self::FollowGlobal => global,
Self::AlwaysFullscreen => true,
Self::AlwaysWindowed => false,
}
}
pub fn label(self) -> &'static str {
match self {
Self::FollowGlobal => "Follow global",
Self::AlwaysFullscreen => "Always fullscreen",
Self::AlwaysWindowed => "Always windowed",
}
}
}
pub fn validate_screen_modes(modes: &BTreeMap<String, ScreenMode>) -> Result<(), String> {
if modes.len() > 128 || modes.keys().any(|id| id.is_empty() || id.len() > 1024) {
return Err(
"Invalid screen modes: at most 128 nonempty monitor IDs of at most 1024 bytes".into(),
);
}
Ok(())
}
/// Saved visual layouts for one monitor; shared timer behavior uses legacy layouts.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(default)]
@ -226,6 +259,7 @@ pub struct Settings {
pub layout: Layout,
pub projects: BTreeMap<String, Layout>,
pub display_layouts: BTreeMap<String, DisplayLayouts>,
pub screen_modes: BTreeMap<String, ScreenMode>,
pub routes: Routes,
pub presenter_fullscreen: bool,
pub presentation_fullscreen: bool,
@ -272,6 +306,7 @@ impl Default for Settings {
layout: Layout::default(),
projects: BTreeMap::new(),
display_layouts: BTreeMap::new(),
screen_modes: BTreeMap::new(),
routes: Routes::default(),
presenter_fullscreen: true,
presentation_fullscreen: true,
@ -319,6 +354,7 @@ impl Settings {
layout.validate()?;
}
}
validate_screen_modes(&self.screen_modes)?;
self.routes.validate()?;
self.layout.validate()?;
for layout in self.projects.values() {

View File

@ -87,6 +87,7 @@ pub struct RouteTrial {
previous: Routes,
presenter_fullscreen: bool,
presentation_fullscreen: bool,
screen_modes: std::collections::BTreeMap<String, crate::settings::ScreenMode>,
}
#[derive(Default)]
pub struct PresenterView {
@ -104,6 +105,7 @@ pub struct Studio {
pub monitors: Vec<Monitor>,
pub routes: Routes,
pub draft_routes: Routes,
pub draft_screen_modes: std::collections::BTreeMap<String, crate::settings::ScreenMode>,
pub draft_presenter_fullscreen: bool,
pub draft_presentation_fullscreen: bool,
pub route_trial: Option<RouteTrial>,
@ -219,6 +221,7 @@ impl Studio {
monitors: vec![],
routes: Routes::default(),
draft_routes: Routes::default(),
draft_screen_modes: Default::default(),
draft_presenter_fullscreen: true,
draft_presentation_fullscreen: true,
route_trial: None,
@ -731,6 +734,10 @@ impl Studio {
}
if self.draft_routes.presenter.is_empty() {
self.status = "Choose at least one presenter screen.".into();
} else if let Err(e) =
crate::settings::validate_screen_modes(&self.draft_screen_modes)
{
self.status = e;
} else if let Err(e) = self.draft_routes.validate() {
self.status = e;
} else if self
@ -749,6 +756,7 @@ impl Studio {
previous: self.routes.clone(),
presenter_fullscreen: self.draft_presenter_fullscreen,
presentation_fullscreen: self.draft_presentation_fullscreen,
screen_modes: self.draft_screen_modes.clone(),
});
self.routes = self.draft_routes.clone();
self.dirty_routes = true;
@ -763,6 +771,7 @@ impl Studio {
self.execute(Action::RevertRoutes);
return;
}
self.settings.screen_modes = trial.screen_modes;
self.settings.routes = self.routes.clone();
self.settings.presenter_fullscreen = trial.presenter_fullscreen;
self.settings.presentation_fullscreen = trial.presentation_fullscreen;
@ -876,6 +885,7 @@ impl Studio {
}
let fullscreen = !(self.presenter_fullscreen() && self.presentation_fullscreen());
self.draft_routes = self.routes.clone();
self.draft_screen_modes = self.settings.screen_modes.clone();
self.draft_presenter_fullscreen = fullscreen;
self.draft_presentation_fullscreen = fullscreen;
self.execute(Action::ApplyRoutes);
@ -902,7 +912,17 @@ impl Studio {
_ => {}
}
}
pub fn screen_fullscreen(&self, display: &str, global: bool) -> bool {
self.route_trial
.as_ref()
.map_or(&self.settings.screen_modes, |trial| &trial.screen_modes)
.get(display)
.copied()
.unwrap_or_default()
.fullscreen(global)
}
pub fn begin_display_edit(&mut self) {
self.draft_screen_modes = self.settings.screen_modes.clone();
self.draft_routes = self.routes.clone();
self.draft_presenter_fullscreen = self.settings.presenter_fullscreen;
self.draft_presentation_fullscreen = self.settings.presentation_fullscreen;
@ -1467,7 +1487,8 @@ impl Studio {
.find_map(|id| self.monitors.iter().find(|m| &m.id == id))?;
if let Some(viewport) = &self.output_viewport
&& viewport.monitor == monitor.id
&& viewport.fullscreen == self.presentation_fullscreen()
&& viewport.fullscreen
== self.screen_fullscreen(&monitor.id, self.presentation_fullscreen())
&& viewport.size.iter().all(|v| *v > 0)
{
return Some(viewport.size);

View File

@ -1849,3 +1849,128 @@ fn explicit_swap_during_show_preserves_visibility_and_uses_reversible_trial() {
assert_eq!(s.blanked, blanked);
}
}
#[test]
fn screen_overrides_survive_global_commands_swap_and_hotplug_and_require_confirmation() {
use pdf_presenter::settings::ScreenMode::{AlwaysFullscreen, AlwaysWindowed};
for blanked in [false, true] {
let mut s = studio();
s.blanked = blanked;
s.begin_display_edit();
s.draft_screen_modes = [
("one".into(), AlwaysWindowed),
("two".into(), AlwaysFullscreen),
]
.into();
s.execute(Action::ApplyRoutes);
assert!(!s.screen_fullscreen("one", true));
assert!(s.screen_fullscreen("two", false));
assert!(s.settings.screen_modes.is_empty());
s.execute(Action::RevertRoutes);
assert!(s.screen_fullscreen("one", true));
s.begin_display_edit();
s.draft_screen_modes = [
("one".into(), AlwaysWindowed),
("two".into(), AlwaysFullscreen),
]
.into();
s.execute(Action::ApplyRoutes);
s.execute(Action::KeepRoutes);
let saved = s.settings.screen_modes.clone();
for global in [false, true] {
s.execute(Action::ToggleFullscreen);
assert_eq!(s.presenter_fullscreen(), global);
assert_eq!(s.presentation_fullscreen(), global);
assert!(!s.screen_fullscreen("one", global));
assert!(s.screen_fullscreen("two", global));
assert_eq!(s.screen_fullscreen("other", global), global);
assert_eq!(s.blanked, blanked);
s.execute(Action::KeepRoutes);
assert_eq!(s.settings.screen_modes, saved);
}
s.execute(Action::SwapRoutes);
assert!(!s.screen_fullscreen("one", s.presentation_fullscreen()));
assert!(s.screen_fullscreen("two", s.presenter_fullscreen()));
s.execute(Action::RevertRoutes);
s.begin_display_edit();
s.draft_screen_modes.clear();
s.execute(Action::ApplyRoutes);
s.set_monitors(vec![s.monitors[0].clone()], 0);
assert!(s.route_trial.is_none());
assert_eq!(s.settings.screen_modes, saved);
assert!(!s.screen_fullscreen("one", true));
assert_eq!(s.blanked, blanked);
}
}
#[test]
fn displays_dropdown_edits_only_selected_screen_until_applied() {
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,
}
}
let ctx = Context::default();
let mut s = studio();
s.settings.language = pdf_presenter::localization::Language::En;
s.begin_display_edit();
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| presenter_ui::presenter(ui, s, &mut native))
};
for label in ["Follow global", "Always windowed"] {
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_or_else(|| panic!("Missing {label}"));
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(),
},
],
);
}
}
assert_eq!(
s.draft_screen_modes.get("one"),
Some(&pdf_presenter::settings::ScreenMode::AlwaysWindowed)
);
assert!(!s.draft_screen_modes.contains_key("two"));
assert!(s.settings.screen_modes.is_empty());
assert!(s.screen_fullscreen("one", true));
s.execute(Action::ApplyRoutes);
assert!(!s.screen_fullscreen("one", true));
}
#[test]
fn output_viewport_accepts_screen_override_instead_of_global_mode() {
let mut s = studio();
s.settings.screen_modes.insert(
"two".into(),
pdf_presenter::settings::ScreenMode::AlwaysWindowed,
);
s.output_viewport = Some(pdf_presenter::output::OutputViewport {
monitor: "two".into(),
fullscreen: false,
size: [800, 600],
});
assert_eq!(s.presentation_viewport(), Some([800, 600]));
s.output_viewport.as_mut().unwrap().fullscreen = true;
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
}

View File

@ -303,3 +303,59 @@ fn display_layout_profiles_roundtrip_migrate_and_validate() {
.collect();
assert!(bad.validate().is_err());
}
#[test]
fn screen_modes_migrate_validate_and_roundtrip() {
use settings::ScreenMode::{AlwaysFullscreen, AlwaysWindowed, FollowGlobal};
let old: Settings = toml::from_str("version = 1").unwrap();
assert!(old.screen_modes.is_empty());
for global in [false, true] {
assert_eq!(FollowGlobal.fullscreen(global), global);
assert!(AlwaysFullscreen.fullscreen(global));
assert!(!AlwaysWindowed.fullscreen(global));
}
let mut s = old;
s.screen_modes = [
("one".into(), AlwaysFullscreen),
("two".into(), AlwaysWindowed),
("three".into(), FollowGlobal),
]
.into();
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("settings.toml");
settings::write(&path, &s).unwrap();
assert_eq!(settings::read(&path).unwrap().screen_modes, s.screen_modes);
assert!(toml::from_str::<Settings>("[screen_modes]\none = 'invalid'").is_err());
for id in [String::new(), "a".repeat(1025)] {
s.screen_modes.insert(id.clone(), AlwaysWindowed);
assert!(s.validate().is_err());
s.screen_modes.remove(&id);
}
s.screen_modes = (0..129)
.map(|i| (i.to_string(), AlwaysFullscreen))
.collect();
assert!(s.validate().is_err());
s.screen_modes.remove("128");
assert!(s.validate().is_ok());
}
#[test]
fn output_screen_modes_roundtrip_and_fall_back_to_global() {
use pdf_presenter::output::HostState;
let state = HostState {
fullscreen: true,
screen_fullscreen: [("one".into(), false), ("two".into(), true)].into(),
..Default::default()
};
let loaded: HostState = serde_json::from_slice(&serde_json::to_vec(&state).unwrap()).unwrap();
assert!(!loaded.fullscreen_on("one"));
assert!(loaded.fullscreen_on("two"));
assert!(loaded.fullscreen_on("unknown"));
let mut legacy = serde_json::to_value(state).unwrap();
legacy.as_object_mut().unwrap().remove("screen_fullscreen");
assert!(
serde_json::from_value::<HostState>(legacy)
.unwrap()
.fullscreen_on("one")
);
}

View File

@ -2,6 +2,18 @@
## Unreleased
### 0.1.87
- Add per-screen Follow global / Always fullscreen / Always windowed choices in
Displays. Overrides follow monitor identity through role swaps and hotplug,
bypass global fullscreen commands, and use the existing Keep/Revert trial.
Save bounded v1 settings and send resolved per-output modes to the independent
host, including matching viewport acknowledgments for mixed-mode mirrors.
- Linux formatting, warnings-denied Clippy/rustdoc, workspace tests, build and
13 Python tests pass. GUI coverage cannot complete without an accessible display
(`XOpenDisplayFailed`). Physical mixed-mode display testing remains pending;
Windows/macOS builds were not run.
### 0.1.86
- Hold S for one second in Presenter or All slides to swap display role groups,

View File

@ -49,3 +49,9 @@ size = 35.0
[display_layouts."Secondary#1".projects."0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"]
slide_progress = true
slide_progress_height = 40.0
# Per-screen mode overrides (0.1.87+), independent of display roles.
[screen_modes]
"Primary#1" = "always_windowed"
"Secondary#1" = "always_fullscreen"
"Third#1" = "follow_global"

View File

@ -214,3 +214,14 @@ slide, and a failed read leaves blank output black. Worker requests
`PickBlankPicture { owner }` and `BlankPicture { source, path }` select and
import/load the asset; source null loads the stored copy. See
[blank picture](blank-picture.md) for bounds.
## Per-screen window mode — 0.1.87
HostState adds `screen_fullscreen`, a monitor-ID-to-boolean map containing the
resolved mode for each assigned Slides monitor (at most 32 route entries).
Missing entries fall back to the existing `fullscreen` role-wide boolean.
The presenter resolves saved or trial overrides before sending; the map contains
no presenter layout, notes or paths. Placement and OutputViewport acknowledgments
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.

View File

@ -110,6 +110,19 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr
(`native-name#occurrence`), disjoint and unique, at most 32 entries combined.
Saved preferences are not overwritten by temporary missing-monitor fallback.
- `presenter_fullscreen`, `presentation_fullscreen`: booleans, default true.
- `screen_modes`: optional monitor-ID map added in 0.1.87. Values are
`follow_global`, `always_fullscreen`, or `always_windowed`; unknown values fail
deserialization. At most 128 entries, with nonempty UTF-8 keys of at most 1024
bytes. No units. Missing maps/entries follow the role's global fullscreen flag;
old v1 files need no migration. Forced choices override global fullscreen
commands and the `--windowed` global startup default. Choices stay attached to
the monitor ID across role swaps, mirrors, disconnects and reconnects, including
unused monitors. The All slides auxiliary window remains windowed.
Apply previews the map in the timed display trial; only Keep changes saves it.
Revert, timeout and hotplug restore confirmed preferences. The UI removes an
entry when Follow global is selected; explicit `follow_global` entries also
round-trip unchanged. Older binaries ignore this additive map and discard it
on resave. See the example and settings round-trip/boundary tests.
- `browser_monitor`: optional monitor ID; missing/unavailable means presenter screen.
- `thumbnail_size`: logical width in pixels, finite 100–400; default 220.
- `disk_cache.max_mib`: integer 64–1048576 MiB, default 10240 (10 GiB).

View File

@ -59,6 +59,13 @@ 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.
Each screen in **Displays** has a **Window mode** dropdown:
**Follow global**, **Always fullscreen**, or **Always windowed**. Forced modes
ignore Enter/Exit fullscreen commands and the global fullscreen checkboxes.
They stay with the screen when you swap roles or reconnect it. Apply and Keep
changes save the choices; Revert restores the previous modes. All slides remains
an ordinary window regardless of its screen's mode.
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.