The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_RestoreWindow() does not restore the window (and why)
nc-pv


Joined: 06 Jan 2017
Posts: 3
Сalling

SDL_MinimizeWindow(window);
SDL_RestoreWindow(window);

does not result in window being restored.

I tracked it down to the fact that the window does not get SDL_WINDOWEVENT_MINIMIZED flag assigned. Therefore, SDL_RestoreWindow() returns without restoring the window:

Code:
void
SDL_RestoreWindow(SDL_Window * window)
{
    CHECK_WINDOW_MAGIC(window,);

    if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
        return;
    }

    if (_this->RestoreWindow) {
        _this->RestoreWindow(_this, window);
    }
}


These flags are managed in the SDL_SendWindowEvent() function. So, adding calls to SDL_SendWindowEvent() in SDL_MinimizeWindow() and SDL_RestoreWindow() fixes the problem.

Patch:

Code:
--- src/video/SDL_video~.c  2017-01-18 17:31:08.180521882 -0500
+++ src/video/SDL_video.c   2017-01-18 17:12:37.025949492 -0500
@@ -2105,6 +2105,7 @@
     if (_this->MinimizeWindow) {
         _this->MinimizeWindow(_this, window);
     }
+    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
 }

 void
@@ -2119,6 +2120,7 @@
     if (_this->RestoreWindow) {
         _this->RestoreWindow(_this, window);
     }
+    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
 }

 int


I assume SDL_MaximizeWindow() is affected as well and needs the same fix, but I did not try it.
nc-pv


Joined: 06 Jan 2017
Posts: 3
Sorry, I misspelled the flag name. It is SDL_WINDOW_MINIMIZED flag.

Quote:
I tracked it down to the fact that the window does not get SDL_WINDOWEVENT_MINIMIZED flag assigned. Therefore, SDL_RestoreWindow() returns without restoring the window: