瀏覽代碼

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.
Frank Praznik 2 年之前
父節點
當前提交
e15da1985a
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      src/video/SDL_video.c

+ 15 - 6
src/video/SDL_video.c

@@ -1747,9 +1747,12 @@ static void ApplyWindowFlags(SDL_Window *window, Uint32 flags)
     if (flags & SDL_WINDOW_MINIMIZED) {
     if (flags & SDL_WINDOW_MINIMIZED) {
         SDL_MinimizeWindow(window);
         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) {
     if (flags & SDL_WINDOW_MOUSE_GRABBED) {
         /* We must specifically call SDL_SetWindowGrab() and not
         /* We must specifically call SDL_SetWindowGrab() and not
            SDL_SetWindowMouseGrab() here because older applications may use
            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);
     SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_SHOWN, 0, 0);
 
 
     /* Set window state if we have pending window flags cached */
     /* 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 */
     /* Restore child windows */
     for (child = window->first_child; child != NULL; child = child->next_sibling) {
     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;
         child->restore_on_show = SDL_TRUE;
     }
     }
 
 
+    /* Store the flags for restoration later. */
+    window->pending_flags = window->flags;
+
     window->is_hiding = SDL_TRUE;
     window->is_hiding = SDL_TRUE;
     if (_this->HideWindow) {
     if (_this->HideWindow) {
         _this->HideWindow(_this, window);
         _this->HideWindow(_this, window);
@@ -2909,6 +2913,11 @@ int SDL_RestoreWindow(SDL_Window *window)
         return 0;
         return 0;
     }
     }
 
 
+    if (window->flags & SDL_WINDOW_HIDDEN) {
+        window->pending_flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED);
+        return 0;
+    }
+
     if (_this->RestoreWindow) {
     if (_this->RestoreWindow) {
         _this->RestoreWindow(_this, window);
         _this->RestoreWindow(_this, window);
     }
     }