Skip to content

win32: avoid showing hidden windows when applying window state - #4575

Open
YelovSK wants to merge 1 commit into
rust-windowing:masterfrom
YelovSK:fix-hidden-window-maximize
Open

YelovSK wants to merge 1 commit into
rust-windowing:masterfrom
YelovSK:fix-hidden-window-maximize

Conversation

@YelovSK

@YelovSK YelovSK commented May 22, 2026

Copy link
Copy Markdown

On Windows, ShowWindow(SW_MAXIMIZE) and ShowWindow(SW_MINIMIZE) can make a hidden window visible.

This currently causes a problem when a window is configured while hidden. For example, eframe creates its window hidden, applies the persisted maximized state, renders the first frame, and only then shows the window. But when winit applies the maximized state, it calls ShowWindow(SW_MAXIMIZE) even though the target state is still hidden. The window can briefly appear before the first frame is rendered, causing a white flash.

This change avoids calling the show/maximize/minimize ShowWindow commands while the target window state is hidden. If the window is supposed to become visible and maximized/minimized, that state is applied when it is shown.

It also avoids doing a normal SW_SHOW first when the target state is maximized or minimized, so the window is shown directly in the intended state.

Tested with:

  • cargo +nightly fmt
  • cargo check -p winit-win32

Also tested downstream in an eframe app on Windows, where this fixes the startup flash when reopening a persisted maximized window. An example of the flicker/flash is shown in this egui issue - emilk/egui#7746.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

joe-loach added a commit to joe-loach/winit that referenced this pull request Jun 1, 2026
ggand0 added a commit to hml-pip/viewskater-egui that referenced this pull request Sep 8, 2026
eframe persistence snapshots the window at save time, so quitting
while maximized or fullscreen restored that state on the next launch.
On Windows that flashes white (rust-windowing/winit#4575) and the size
from before the maximize is lost (emilk/egui#3494).

Turn off persist_window and write the window entry from the app
instead: record the geometry every frame while the window is in its
normal state and store it under eframe's window key in App::save with
maximized and fullscreen set to false. eframe still does the restore
with its monitor and scale-factor handling, so a maximized or
fullscreen quit relaunches as a normal window at the last normal size
and position.

Building the entry needs a constructor on egui_winit::WindowSettings,
added to the egui-winit fork this project already patches in.
lucasmerlin added a commit to emilk/egui that referenced this pull request Oct 9, 2026
…indows

eframe creates its window hidden until the first frame is painted. winit
implements maximize with `ShowWindow(SW_MAXIMIZE)`, which shows the hidden
window, and then hides it again, so the window flashed on screen before
the real show.

On Windows, a window created hidden is no longer maximized via its window
attributes. `apply_viewport_builder_to_window` maximizes it instead, with
the window cloaked (`DWMWA_CLOAK`) so the brief show is never composited.
The window is already maximized when first shown, so the first frame is
rendered at the right size.

Can be removed once winit has rust-windowing/winit#4575 or #4587.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lucasmerlin added a commit to emilk/egui that referenced this pull request Oct 13, 2026
eframe now remembers the window's last *normal* (not maximized, not
fullscreen) size and position. After a relaunch, un-maximizing or
leaving fullscreen goes back to that size instead of a window that is
"maximized but not maximized".

Other fixes:
* A maximized or fullscreen window no longer paints its first frame
small.
* Leaving a restored fullscreen goes straight back to the normal size,
in one step.
* The window reopens on the correct monitor, also with monitors of
different scale factors on macOS. The position is saved in pixels
together with the scale factor, and converted on restore.
* On macOS and Windows, the window is placed exactly after creation,
then maximized or made fullscreen.
* On Windows, a window restored maximized no longer flashes on screen
(shown, hidden, then shown again) during startup. winit maximizes with
`ShowWindow(SW_MAXIMIZE)`, which shows the still-hidden window before
hiding it again. The new `egui_winit::set_maximized` cloaks a hidden
window (`DWMWA_CLOAK`) while maximizing it, so it stays invisible but is
already maximized for the first frame. This is a workaround until winit
has rust-windowing/winit#4575 or rust-windowing/winit#4587.
* On X11, a window saved maximized or fullscreen now restores as such.
winit sends these as `_NET_WM_STATE` client messages, which window
managers ignore while the window is still hidden (eframe keeps it hidden
until the first frame is painted). The new
`WindowSettings::after_first_show` re-applies them right after the
window is shown. `before_first_show` replaces the macOS-only
`enter_fullscreen_after_first_frame` / `enter_deferred_fullscreen`.

The save format changed, so old saved window settings are ignored once
(the window opens at its default size).

Known limitations:
* The normal geometry is sampled on save. If you resize, maximize before
the next autosave, and quit while maximized, un-maximizing after a
relaunch goes back to the size from before the resize.
* On X11, a restored maximized window may show un-maximized for a frame
before it maximizes.
* On X11 with GNOME (mutter), un-maximizing a window that was restored
maximized puts it in the top-left corner of its monitor, not at its
saved position. The size is right. mutter places windows that get
maximized right after mapping at the work area origin.
* On Wayland, the position (and so the monitor) can't be restored,
because Wayland doesn't let clients read or set window positions. Size
and maximized/fullscreen state are restored.
* On GNOME, a restored window that is close to the screen size gets
auto-maximized by mutter (`org.gnome.mutter auto-maximize`).

Tested on macOS, wayland, x11 (XWayland on GNOME, including two
monitors) and Windows (wgpu and glow).

* [x] I have followed the instructions in the PR template

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_019yMtdim1FPCsviY1FWfdTk

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SteGlaset added a commit to SteGlaset/neovide that referenced this pull request Oct 23, 2026
Vendor winit 0.30.13 with the three visibility guards from rust-windowing/winit#4575. Preserve the upstream license and document the backport; keep other dependency versions unchanged.
SteGlaset added a commit to SteGlaset/neovide that referenced this pull request Oct 23, 2026
Pin SteGlaset/winit at 1b0ee1d7c0518efe42eea15474341fb5b27efa92: winit 0.30.13 with the three Windows state guards backported from rust-windowing/winit#4575. Keep all other dependency versions unchanged.
richerfu pushed a commit to richerfu/winit that referenced this pull request Nov 2, 2026
Port of rust-windowing#4587 (focus-safe form of rust-windowing#4575).

Originally "M15.1: keep hidden maximized windows hidden" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant