Skip to content

Windows: a window closed maximized reopens without a white flash (winit#4587) - #674

Merged
echelon merged 2 commits into
storytold:mainfrom
cyfung1031:fix/winit-win-hidden-maximized
Oct 10, 2026
Merged

echelon merged 2 commits into
storytold:mainfrom
cyfung1031:fix/winit-win-hidden-maximized

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Windows, PdfCraft closed while maximized came back with a white, unpainted window before its first frame. eframe creates the window hidden, restores the saved maximized state (app.ron, persist_window) and shows the window after the first frame is drawn. But winit applies "maximized" with ShowWindow(SW_MAXIMIZE), which shows a hidden window. This keeps a hidden window hidden while its maximized state is set, and shows it maximized with a single SW_MAXIMIZE.

Port of rust-windowing/winit#4587 (reviewed head 9f8beaf502, approved upstream by kchibisov), which fixes winit#4586. It is the later, focus-safe form of winit#4575, whose author found the same startup flash in an eframe app with a saved maximized window (egui#7746).

PdfCraft impact

Every Windows launch after closing PdfCraft maximized.

Root cause

vendor/winit/src/platform_impl/windows/window_state.rs, WindowFlags::apply_diff. Over the start-up sequence, the window is created hidden, then:

  • set_maximized(true) while hidden calls ShowWindow(SW_MAXIMIZE), which shows the unpainted window, then ShowWindow(SW_HIDE);
  • after the first frame, set_visible(true) calls SW_SHOW, then SW_MAXIMIZE again.

Winit#4586 also shows the window's focus state going wrong on this path.

Change

  • While the target state is hidden, maximizing (and un-maximizing) doesn't call ShowWindow.
  • A hidden window that becomes visible while maximized is shown with one SW_MAXIMIZE.
  • Transitions between two visible states make exactly the same ShowWindow calls as before.

Not included

  • M14: pinned tabs open at every start (#2926) #4575's other change: it calls SW_MINIMIZE on every flag change while the window is minimized, which can move activation to another window. eframe never minimizes a hidden window.
  • Nothing else from winit master.

Verification

  • An exhaustive model of apply_diff's ShowWindow calls (old against new code, every combination of visible / maximized / minimized / activate before and after) confirms three things. Every visible-to-visible transition is unchanged (all 32 of them). A hidden target never gets SW_SHOW*, SW_MAXIMIZE or SW_RESTORE outside the minimize path, which is unchanged. And hidden-to-visible-and-maximized is exactly one SW_MAXIMIZE.
  • Upstream (winit#4587, M14: pinned tabs open at every start (#2926) #4575) checked it on Windows; M14: pinned tabs open at every start (#2926) #4575 in an eframe app with a saved maximized window.
  • Not run here: this machine has no Windows. To check by hand: maximize PdfCraft, quit, relaunch several times. There should be no white window or normal-size frame before the maximized one, and PdfCraft should have focus. Maximize, restore, minimize and restore must still work.
  • apps/pdfcraft/tests/winit_windows_hidden_maximized.rs fails if a re-vendored winit loses the patch.

Automated checks

  • The vendored winit built on its own for aarch64-apple-darwin, x86_64-pc-windows-msvc and x86_64-unknown-linux-musl (cargo clippy --lib, lints capped to warnings): the warnings are the same as on main for all three (the one existing clippy::iter_kv_map in linux/x11/event_processor.rs).
  • cargo check --locked -p winit inside the PdfCraft workspace, with PdfCraft's own Cargo.lock, on macOS and on the tree with all nine fixes merged: clean.
  • The new test was compiled and run against this branch (passes) and against main (fails); rustfmt --check and clippy -D warnings on it are clean.
  • Not run locally: the full cargo test --workspace and workspace clippy (the machine is short of disk space for a full build). CI runs them on Linux and Windows.

Risk

Known edge case, as on winit master: a window that was maximized while visible, then hidden, then un-maximized while hidden, is shown maximized (no SW_RESTORE while hidden). PdfCraft never hides its window after start-up.

Revert and removal

This change is independent of the other winit PRs and can be reverted on its own. Drop it, together with the test and README item (4), once PdfCraft uses a winit release that includes rust-windowing/winit#4587 or an equivalent fix.

Merging alongside the other winit PRs

This is one of nine fixes to vendor/winit sent together: #672 (Wayland IME after a capability change), #673 (Windows Korean IME caret), #674 (Windows maximized start-up), #675 (X11 input context focus), #676 (macOS IME commit state), #677 (macOS stale composition), and, building on #676, #678 (macOS emoji picker), #679 (macOS Korean double space), #680 (macOS first Korean key). Each adds one numbered item to the single winit row in vendor/README.md, so they conflict with each other on that one line, and nowhere else (each test is in its own file). The item numbers (2)–(10) are fixed in advance: to resolve, keep every item in numeric order. All nine were merged locally in one tree (only that line conflicted); the combined vendored winit builds for macOS, Windows and Linux with the same clippy output as main, and all nine tests pass on it.

🤖 Generated with Claude Code

…it#4587)

eframe creates PdfCraft's window hidden, restores the saved state
(app.ron, persist_window) and shows the window after the first frame is
drawn. For a window closed maximized, winit 0.30.13 applies the maximized
state with ShowWindow(SW_MAXIMIZE), which shows a hidden window: PdfCraft
appeared unpainted (white), was hidden again, then shown with SW_SHOW and
SW_MAXIMIZE once more. rust-windowing/winit#4586 also shows the window's
focus state going wrong on this path.

vendor/winit now skips the maximize while the window is hidden and shows a
hidden window that is maximized with one SW_MAXIMIZE, as
rust-windowing/winit#4587 (approved upstream) does on winit master. That is
the later, focus-safe form of storytold#4575; storytold#4575's other change (re-sending
SW_MINIMIZE on every flag change while minimized) is not taken. Transitions
between two visible states make the same ShowWindow calls as before. A test
fails if a re-vendored winit loses the patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon
echelon merged commit 9250e75 into storytold:main Oct 10, 2026
5 checks passed
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Merged, thank you! One SW_MAXIMIZE when a hidden window is first shown (winit#4587) removes the white flash on reopening maximized. Patch (4).

If you haven't already, come join us on Discord: https://discord.gg/artcraft

krichelj pushed a commit to krichelj/pdfcraft that referenced this pull request Oct 11, 2026
…it#4587) (storytold#674)

eframe creates PdfCraft's window hidden, restores the saved state
(app.ron, persist_window) and shows the window after the first frame is
drawn. For a window closed maximized, winit 0.30.13 applies the maximized
state with ShowWindow(SW_MAXIMIZE), which shows a hidden window: PdfCraft
appeared unpainted (white), was hidden again, then shown with SW_SHOW and
SW_MAXIMIZE once more. rust-windowing/winit#4586 also shows the window's
focus state going wrong on this path.

vendor/winit now skips the maximize while the window is hidden and shows a
hidden window that is maximized with one SW_MAXIMIZE, as
rust-windowing/winit#4587 (approved upstream) does on winit master. That is
the later, focus-safe form of storytold#4575; storytold#4575's other change (re-sending
SW_MINIMIZE on every flag change while minimized) is not taken. Transitions
between two visible states make the same ShowWindow calls as before. A test
fails if a re-vendored winit loses the patch.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Focus is broken when an invisible window is created with maximized

2 participants