Skip to content

Commit

Permalink
video: Apply cleared flag states when restoring hidden windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kontrabant committed Jun 8, 2023
1 parent 49b5cfa commit e15da19
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e15da19

Please sign in to comment.