From e15da1985a23bdc6e93701e728c327ba664dc1b8 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 7 Jun 2023 15:04:49 -0400
Subject: [PATCH] video: Apply cleared flag states when restoring hidden
windows
Hiding a window and then clearing the minimized, maximized, fullscreen, or grabbed flags wouldn't result in the new state being applied to the window when shown, as the pending flags would always be zero, resulting in the flag application function never being entered. Calling SDL_RestoreWindow() didn't result in the minimized or maximized state being cleared on the hidden window either.
Save the current window flags to the pending flags when hiding a window, and universally apply the pending flags when the window is shown again to ensure that all state that was set or cleared when the window was hidden is applied. Any pending flags that match the existing window flags will be automatically deduplicated by the corresponding functions.
---
src/video/SDL_video.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 83936dda9aaa..b9496d72eb38 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1747,9 +1747,12 @@ static void ApplyWindowFlags(SDL_Window *window, Uint32 flags)
if (flags & SDL_WINDOW_MINIMIZED) {
SDL_MinimizeWindow(window);
}
- if (flags & SDL_WINDOW_FULLSCREEN) {
- SDL_SetWindowFullscreen(window, SDL_TRUE);
+ if (!(flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
+ SDL_RestoreWindow(window);
}
+
+ SDL_SetWindowFullscreen(window, (flags & SDL_WINDOW_FULLSCREEN) != 0);
+
if (flags & SDL_WINDOW_MOUSE_GRABBED) {
/* We must specifically call SDL_SetWindowGrab() and not
SDL_SetWindowMouseGrab() here because older applications may use
@@ -2785,10 +2788,8 @@ int SDL_ShowWindow(SDL_Window *window)
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_SHOWN, 0, 0);
/* Set window state if we have pending window flags cached */
- if (window->pending_flags) {
- ApplyWindowFlags(window, window->pending_flags);
- window->pending_flags = 0;
- }
+ ApplyWindowFlags(window, window->pending_flags);
+ window->pending_flags = 0;
/* Restore child windows */
for (child = window->first_child; child != NULL; child = child->next_sibling) {
@@ -2820,6 +2821,9 @@ int SDL_HideWindow(SDL_Window *window)
child->restore_on_show = SDL_TRUE;
}
+ /* Store the flags for restoration later. */
+ window->pending_flags = window->flags;
+
window->is_hiding = SDL_TRUE;
if (_this->HideWindow) {
_this->HideWindow(_this, window);
@@ -2909,6 +2913,11 @@ int SDL_RestoreWindow(SDL_Window *window)
return 0;
}
+ if (window->flags & SDL_WINDOW_HIDDEN) {
+ window->pending_flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED);
+ return 0;
+ }
+
if (_this->RestoreWindow) {
_this->RestoreWindow(_this, window);
}