Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Windows: keep full screen and maximized apart; never restore full screen (#4396)

Tommy Leonhardsene2a35b04fd69
diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs
index aee9eabca..00d334758 100644
--- a/apps/photocraft/src/main.rs
+++ b/apps/photocraft/src/main.rs
@@ -90,11 +90,21 @@ fn native_options(custom_titlebar: bool) -> eframe::NativeOptions {
// eframe saves native window geometry and egui panel/window sizes on exit.
// Keep that state beside preferences, including config overrides and portable mode.
persistence_path: services::config_dir().map(|dir| dir.join("ui.ron")),
- window_builder: Some(Box::new(at_least_min_size)),
+ window_builder: Some(Box::new(restored_window)),
..Default::default()
}
}
+/// The window eframe restores from `ui.ron`, corrected before it is created: at least the
+/// minimum size, and never full screen. PhotoCraft always starts in Standard Screen Mode, but
+/// eframe also saves and restores full screen, and a window closed in a full-screen mode is
+/// saved full screen and maximized at once: the overlap `view_cmds::screen_mode_commands` keeps
+/// apart at run time. [OBSERVED 2026-10-12, Windows 11] Restored that way, View › Screen Mode ›
+/// Full Screen did nothing until `F` had cycled through Standard.
+fn restored_window(builder: egui::ViewportBuilder) -> egui::ViewportBuilder {
+ at_least_min_size(builder).with_fullscreen(false)
+}
+
/// Grow a restored window that is smaller than the minimum size, keeping its centre. On
/// Windows, eframe saves a minimized window's size (160 pt wide, 64 pt tall once eframe has
/// clamped it), and the minimum size isn't applied to a restored one: PhotoCraft then reopened
@@ -624,6 +634,22 @@ mod tests {
assert_eq!(super::at_least_min_size(builder).inner_size, None);
}
+ #[test]
+ fn a_window_saved_in_full_screen_reopens_maximized_not_full_screen() {
+ let hook = super::native_options(super::CUSTOM_TITLEBAR).window_builder.expect("a window builder hook");
+ // What eframe restores from a ui.ron saved in a full-screen mode on Windows.
+ let saved = super::native_options(super::CUSTOM_TITLEBAR)
+ .viewport
+ .with_inner_size([2560.0, 1392.0])
+ .with_position([0.0, 0.0])
+ .with_fullscreen(true)
+ .with_maximized(true);
+ let opened = hook(saved);
+ assert_eq!(opened.fullscreen, Some(false), "Standard Screen Mode is where PhotoCraft starts");
+ assert_eq!(opened.maximized, Some(true), "the rest of the saved geometry is kept");
+ assert_eq!(opened.inner_size, Some(egui::vec2(2560.0, 1392.0)));
+ }
+
#[test]
fn the_system_title_bar_preference_keeps_the_window_decorations() {
// #1271, #1316: Preferences › Interface › System Title Bar gives the window back its
diff --git a/contributors/people.toml b/contributors/people.toml
index 53bd154ac..82a9e20a4 100644
--- a/contributors/people.toml
+++ b/contributors/people.toml
@@ -124,3 +124,6 @@ sync_github_name = true
[people.arthurdeka]
sync_github_name = true
+
+[people.aweussom]
+real_name = "Tommy Leonhardsen"
diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs
index 264550b88..33fc6affc 100644
--- a/crates/ui-egui/src/view_cmds.rs
+++ b/crates/ui-egui/src/view_cmds.rs
@@ -167,6 +167,41 @@ const LAYOUTS: [&str; 10] = [
"tile",
];
+/// Whether the window was maximized when a screen mode took it full screen (egui temp data).
+fn was_maximized_id() -> egui::Id {
+ egui::Id::new("pc-full-screen-was-maximized")
+}
+
+/// The window commands for switching to screen mode `next`, and whether the window should be
+/// maximized again when it leaves full screen. With `keep_apart` (Windows), full screen and
+/// maximized never overlap: a maximized window is un-maximized before it goes full screen and
+/// maximized again after it leaves. Why: winit on Windows keeps the maximized style on a window
+/// that goes full screen from maximized, and the shell then draws the taskbar black instead of
+/// hiding it; on the way out the window stays maximized at the monitor's full size, over the
+/// taskbar (#3550, #4018, #4230). [OBSERVED 2026-10-12, Windows 11, eframe 0.36.2, winit 0.30.13,
+/// a minimal eframe window; un-maximizing first gave a clean full screen and a work-area maximize.]
+///
+/// WORKAROUND(winit#4756): remove `keep_apart` once the winit in Cargo.lock (0.30.13 today) has
+/// the fix; check first with https://gist.github.com/aweussom/3f80ffb82df7f0102341858afbbffd9b
+/// (`--max`, no `--fix`: full screen must have no WS_MAXIMIZE and hide the taskbar).
+fn screen_mode_commands(keep_apart: bool, full_screen: bool, maximized: bool, was_maximized: bool, next: &str) -> (Vec<egui::ViewportCommand>, bool) {
+ let want = next != "standard";
+ let mut commands = Vec::new();
+ let mut remember = was_maximized;
+ if keep_apart && want && !full_screen && maximized {
+ commands.push(egui::ViewportCommand::Maximized(false));
+ remember = true;
+ }
+ commands.push(egui::ViewportCommand::Fullscreen(want));
+ if !want {
+ if keep_apart && full_screen && remember {
+ commands.push(egui::ViewportCommand::Maximized(true));
+ }
+ remember = false;
+ }
+ (commands, remember)
+}
+
/// Pixel aspect ratio (width / height of a pixel) of a preset id.
pub fn pixel_aspect_ratio(id: &str) -> f32 {
// View › Pixel Aspect Ratio › Custom: `custom:<ratio>:<name>` (see `workspace_ui`).
@@ -658,7 +693,13 @@ fn run(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, p: &Value) -> Res
};
o.screen_mode = next.to_string();
// Both full-screen modes take the whole display; the menu bar stays in the first.
- ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(next != "standard"));
+ let (full_screen, maximized) = ctx.input(|i| (i.viewport().fullscreen.unwrap_or(false), i.viewport().maximized.unwrap_or(false)));
+ let was_maximized = ctx.data(|d| d.get_temp::<bool>(was_maximized_id())).unwrap_or(false);
+ let (commands, was_maximized) = screen_mode_commands(cfg!(target_os = "windows"), full_screen, maximized, was_maximized, next);
+ ctx.data_mut(|d| d.insert_temp(was_maximized_id(), was_maximized));
+ for command in commands {
+ ctx.send_viewport_cmd(command);
+ }
return Ok(json!({"screenMode": next}));
}
if let Some(k) = id.strip_prefix("view.pixelAspectRatio.") {
diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rs
index 3de1a20b4..b930e6e26 100644
--- a/crates/ui-egui/src/view_cmds/tests.rs
+++ b/crates/ui-egui/src/view_cmds/tests.rs
@@ -59,6 +59,34 @@ fn show_snap_extras_and_screen_modes_are_state() {
assert_eq!(v["view"]["show"]["layer_edges"], true);
}
+#[test]
+fn full_screen_and_maximized_never_overlap_on_windows() {
+ use egui::ViewportCommand::{Fullscreen, Maximized};
+ // Maximized → full screen: un-maximize first, and remember it.
+ let (cmds, remember) = screen_mode_commands(true, false, true, false, "fullScreenWithMenuBar");
+ assert_eq!(cmds, vec![Maximized(false), Fullscreen(true)]);
+ assert!(remember);
+ // Full screen → the other full-screen mode: nothing about maximized changes.
+ let (cmds, remember) = screen_mode_commands(true, true, false, true, "fullScreen");
+ assert_eq!(cmds, vec![Fullscreen(true)]);
+ assert!(remember);
+ // Full screen → Standard: maximize again after leaving, then forget.
+ let (cmds, remember) = screen_mode_commands(true, true, false, true, "standard");
+ assert_eq!(cmds, vec![Fullscreen(false), Maximized(true)]);
+ assert!(!remember);
+ // A window that was not maximized goes in and out untouched.
+ let (cmds, remember) = screen_mode_commands(true, false, false, false, "fullScreen");
+ assert_eq!((cmds, remember), (vec![Fullscreen(true)], false));
+ let (cmds, remember) = screen_mode_commands(true, true, false, false, "standard");
+ assert_eq!((cmds, remember), (vec![Fullscreen(false)], false));
+ // Standard while already standard never maximizes.
+ let (cmds, _) = screen_mode_commands(true, false, false, true, "standard");
+ assert_eq!(cmds, vec![Fullscreen(false)]);
+ // Elsewhere the commands are as before.
+ let (cmds, remember) = screen_mode_commands(false, false, true, false, "fullScreen");
+ assert_eq!((cmds, remember), (vec![Fullscreen(true)], false));
+}
+
#[test]
fn zoom_presets_and_fit_layers() {
let (mut app, ctx) = app_with(1);