egui icon indicating copy to clipboard operation
egui copied to clipboard

Incorrect maximize behaviour

Open JumpyLionnn opened this issue 1 year ago • 4 comments

Describe the bug There are a few problem with maximizing a native window in eframe.

  1. Every frame eframe provides a Frame struct and inside it there is an IntegrationInfo struct that you can retrieve with the info() method. In the integration info, there is some data about the native window including a boolean that indicates if the window is maximized or not. this boolean doesn't change to true even if the window is maximized.
  2. With the persist window option in NativeOptions Ive noticed when I start up the app with maximized set to true it does start that way, but instantly shrinks to the previous session's dimensions and if it was closed while maximized it does try to do the dimensions of a maximized window but not actually maximized and it becomes slightly offset.

To Reproduce Steps to reproduce the behavior: I dont know if it matters but here are my egui and eframe in my Cargo.toml

eframe = {version="0.23.0", features = ["persistence"]}
egui = {version="0.23.0", features = ["persistence", "serde"]}
  1. Set presist_window to true
  2. Run the app
  3. Maximize the window
  4. Close the window
  5. Rerun the the app and the window state wont be persisted correctly

Expected behavior When opening the window, if the presist_window is true and the window was maximized in the last session it should be maximized again in the same monitor. Also the WindowInfo struct in the Frame provided by eframe should have maximized set to true if the window is maximized.

Desktop:

  • OS: Windows

JumpyLionnn avatar Oct 22 '23 11:10 JumpyLionnn

probably related to #1517

Workaround: save the maximized state in you App struct and add a sentinel variable to indicate the first frame (not persisted, default false, set to true on the first frame). Then you can do:

if self.first_frame {
    self.first_frame = false;
    frame.set_maximized(self.persisted_maximized_state);
}

Turun avatar Nov 21 '23 16:11 Turun

Fix coming in https://github.com/emilk/egui/pull/3601

emilk avatar Nov 21 '23 17:11 emilk

Re-opened because of dead-lock: https://github.com/emilk/egui/pull/3612

emilk avatar Nov 23 '23 08:11 emilk

https://github.com/emilk/egui/pull/3831 will fix this for Windows, but Linux and Mac still has the issue

emilk avatar Jan 17 '24 11:01 emilk

Hmm, even without the deadlock and with the Windows fix, I think bug 2 in the issue is not addressed. persist_window does not seem to save the maximized state in the ron file at all.

After closing a maximized window, this is what is saved:

    "window": "(inner_position_pixels:Some((x:0.0,y:34.0)),outer_position_pixels:Some((x:-11.0,y:-11.0)),fullscreen:false,inner_size_points:Some((x:2560.0,y:1386.6666)))",

There is no info about maximization saved, which means the window will never be maximized on startup automatically. (In fact, for me, it causes a maximized-sized window to appear halfway off-screen on the wrong monitor).

The coordinates saved are also the ones of the maximized window. I think for consistent and nice behavior, the state should persist:

  1. the unmaximized position and size, i.e. what a window would restore its position and size to when pressing the restore button
  2. a flag whether the window was maximized

This way both the maximization state and even the size and position when un-maximizing the window are preserved, even across app restarts.

Maybe it makes sense to split bug 2 out into its own issue, since it's more a feature request than a bug?

seritools avatar Mar 09 '24 21:03 seritools