Fix window placement being overwritten when closing while fullscreen.
Related Issue
Fixes #253
Description
When starting a game and pressing F11 to enter fullscreen, closing Ryujinx while still in fullscreen can cause the window bounds to be persisted incorrectly.
On the next launch, the main window appears offset from its previous position. Manually dragging the window to the top of the screen corrects the placement, but this in turn interferes with fullscreen behavior again.
The root cause is that fullscreen (or other non-normal states) can overwrite the stored normal window placement during shutdown. As a result, the saved startup position becomes invalid or inconsistent.
This MR:
- Tracks and caches the last known Normal window bounds separately.
- Ensures fullscreen or maximized states do not overwrite the stored normal bounds.
- Clamps restored window position to the working area to prevent negative/off-screen placement.
Reproduction Steps (Before Fix)
- Start Ryujinx.
- Launch a game.
- Press F11 to enter fullscreen.
- Close Ryujinx while still in fullscreen.
- Reopen Ryujinx.
- Observe that the window appears offset from its previous position.
Dragging the window to the top temporarily fixes the placement, but it can interfere with subsequent fullscreen transitions.
Expected Behavior
Ryujinx should always restore the last valid normal window position and size, regardless of being closed from fullscreen or maximized states.
The window should never reopen offset or outside of the visible working area.
Testing Performed
- Clean build succeeds
-
dotnet formatrun - Verified window position persists correctly after closing from fullscreen
- Verified no regression in normal window restore behavior
- Tested fullscreen toggle after restore
-
Notes for Reviewers
Changes are localized to MainWindow window-bound tracking and persistence logic.
Special care was taken to ensure that only WindowState == Normal updates the cached bounds.