Repository navigation
Restore the window size and position on launch - #20
Conversation
Skip the hardcoded with_inner_size and first-frame DPI resize when eframe has persisted window state from a previous session. Both paths now check for app.ron existence so the default 1280x720 only applies on first launch.
|
I tested it and window size was indeed not restoring. Two things were overriding eframe's restore:
The fix I pushed should now restore window size as well as positions, and I verified it working on macOS and Ubuntu. Can you verify it works on your Windows? |
|
Windows was already working as "intended" (It restore size and position correctly in window mode, but doesn't have the features we implemented for the iced version) before your commit, it seems Windows wasn't affect by your forced I think my requirements are edge cases. I'll see what I can do after completing the compressed file support and slider preview with possible additional PR if you want to merge this one. |
|
I was also trying the window persistence, but it has some annoying bugs, at least on Windows. The first one is that when restoring a maximized window, it briefly flashes white. I'm pretty sure that's an issue in winit, I made a PR here - rust-windowing/winit#4575. Basically, when the app is launched initially with the hidden and maximized state, winit first calls winapi's maximize API, which briefly shows the window, and then immediately hides it. The second one is that the normal window size is not persisted when maximized in egui. So when you unmaximize the window, it doesn't get restored to the previous size. Winit doesn't have an API that would return the normal window size, so I could only fix it by calling winapi in egui, and even that has some potentially sketchy cross-coordinate stuff, so I ignored it. Right now, the maximized window persistence on Windows is really annoying. |
|
Does the iced version work for you? |
The iced version is a bit less broken, but also acts weird when restoring the window. See video. Recording.2026-05-24.122318_1.mp4.mp4But I am using the egui version, since it feels a bit better to me. |
|
I'd say it's not perfect, but it gets the job done. The reason I'm asking is that, at worst, I can port the code made for the Iced version, but I'm not sure the added code complexity is worth it. Even then, the outcome might not satisfy your expectations. |
|
Oh, I don't have a strong opinion. Of course, ideally, the egui persistence would work perfectly, but that isn't the case. I already tried doing it directly in viewskater, and it was mostly passable, including getting rid of the white flash (iirc I created the window hidden, and maximized it a bit later, but that showed the maximizing animation), but it was a bit too.. I wasn't comfortable with that being the final implementation. I only got it working well with the winit and egui patches, but I have no idea if those will get merged. Well, except for the unmaximized size. I imagine it's possible without using the winapi by persisting the last window size when not maximized/minimized. |
|
Check my new implementation and see if that works for you, I think this PR might not be needed if there's no upstream changes. |
Seems to work fine, except for the white flash and the unmaximize not remembering the size. This PR emilk/egui#8191 was just merged in egui, so in theory, the egui persistence should work almost the same as your implementation, with the only difference being that, in your PR, unmaximize restores a smaller window, and in egui's persistence, it restores the maximized size. If the winit fix gets merged, I think it should fix the white flash in both your implementation and in the egui persistence. |
|
Thanks! I found another problem: when you set the scaling to anything other than 100% for a high-resolution monitor on Windows, maximized or full-screen window does not recover properly on the next startup in my implementation, I'll keep digging. |
|
Ok I reproduced these issues on Windows 10 dual monitor setup:
For 1, @YelovSK opened rust-windowing/winit#4575 but winit tends to be slow on PRs so probably not getting merged soon. For 3, @YelovSK's emilk/egui#8191 was merged, but we're pinned to egui 0.31 and it's not available yet. Given these, I think implementing custom persistence (PR #29's direction) is the right approach. |
|
I think updating to egui 0.35 is a chore and a lot of works to even get it to compile. This needs a separate PR to do if that's the direction we're heading. Incomplete summariesReplace improved-popups-tooltips-and-menus Some deprecations are easy, but others need additional testing. |
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.
The normal-window geometry is captured every frame while the viewport reports neither maximized, fullscreen nor minimized. On macOS egui-winit never queries the maximized state at runtime, and NSWindow.isZoomed only turns true once the zoom animation has landed, so the intermediate frames of a green-button zoom were captured as normal geometry and a relaunch came back nearly full screen. Ask the NSWindow directly. AppKit runs the zoom and un-zoom animations as a live resize, so isZoomed || inLiveResize is false exactly for the frames that are safe to record. Tested on macOS: green-button zoom, un-zoom, fullscreen and plain resize/move all relaunch at the last normal geometry.
|
I decided to go with size and position only and skip restoring maximized/fullscreen for now. Now the app saves the window state itself as RON instead of eframe doing it, and it only records the size and position while the window is in the normal state. A maximized or fullscreen window never gets saved. eframe still restores it on startup like before, and to write eframe's format from the app I added a custom constructor to If you quit while maximized or fullscreen, the next launch gives you a normal window with the size and position you had before. This should get rid of the white flash issue. For the wrong monitor problem we'd still need egui 0.35.
@hml-pip @YelovSK Can you check it on your machine to see if it works? We can look into restoring maximized state again in the future. |
Four sentences joined with semicolons are split in two, and the doc of `window_zoomed_or_resizing` says the zoom animation has finished.
`App::new` had eight arguments, one over clippy's `too_many_arguments` limit. `main` computed `needs_dpi_resize` from whether eframe's `app.ron` exists and passed it in. That check is now `window_state::has_persisted_state`, which `main` and `App::new` each call. eframe first writes `app.ron` when it saves, after `App::new` has returned, so both calls return the same value.
|
I merged main into the branch and tested it again on Windows, macOS and Ubuntu. |
This feature will create
data\app.ronfile in storage_dir.2: 1920x1080
It doesn't retain the previous window size when exiting in fullscreen mode, and when you exit application while in fullscreen on monitor 1, it restores to 2 at next startup on Windows, if there's other issues on other platform, I'll port the code from iced version.