Windows 10, SDL3
I’m having some trouble understanding the base window size and handling window minimization and full screen mode.
A window, when displayed in its basic mode (let’s call it windowed), i.e. smaller than the screen area, has its own position and size. When a window is maximized, its base size is remembered, so restoring the window causes its position and size to be what the window had before it was maximized. Everything works intuitively here.
If I do the same with the window, but instead of maximizing it, I enable fullscreen mode (e.g. desktop fullscreen), the base size and position will also be remembered, so exiting fullscreen mode will restore its position and size to the one the window had before enabling fullscreen. Everything is correct.
The problem occurs when I enable fullscreen while the window is maximized. In this case, the base size and position of the window are lost — overwritten by those of the maximized window. If I disable fullscreen, the window is messed up — it has the size of the maximized window, the position is almost the same as the maximized one (a few pixels shifted to the side). Restoring the window only disables maximization, but the window is not restored to the size before maximization and fullscreen — these dimensions and position are lost.
I noticed this already in SDL2, but didn’t report it because I thought that was the way the OS managed windows and didn’t store the size and position of the base, maximized, and full-screen windows separately — that it only stored data for the previous mode, so changing the mode from windowed to maximized and then to full-screen caused the windowed mode data to be overwritten by the maximized mode.
This problem also got worse when I implemented a borderless window with my own decoration — minimizing a maximized window causes problems with restoring maximization. I’ll investigate this further, because it may be my fault.
That’s why in my projects I simply store the base window size and position data myself, so that I could work around issues with changing window display modes.
The question is: should the lack of storing the base position and size of the window be treated as a bug and reported so that it can be added to the SDL, or is that just how Windows works and does it need to be programmed by yourself, in the application itself?
Maybe I’m doing something wrong in my project, so here’s a list of steps to reproduce this problem:
- Create a resizable window and set its initial size to e.g.
640x480
. - Maximize window.
- Enable fullscreen mode (can be fullscreen desktop),
- Disable fullscreen.
The result should be that the window may not be restored to its maximized form, and even if it is, trying to restore the window to its windowed form (e.g. using the restore button on the window title bar), i.e. to 640x480
size, will not be possible — the window will not resize.
However, in the case of a borderless window, the problem can be encountered with the following steps:
- Create a borderless window and set its initial size to e.g.
640x480
. - Maximize the window by calling
SDL_MaximizeWindow
, - Minimize the window by clicking the application button on the taskbar.
- Restore the window by clicking the application button on the taskbar.
The window may not be properly restored to its maximized state.