We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3563

Summary: SDL_RestoreWindow() does not restore the window after SDL_MinimizeWindow()
Product: SDL Reporter: nikolay.p
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   
Attachments: patch for SDL_RestoreWindow()

Description nikolay.p 2017-01-19 00:15:03 UTC
Created attachment 2683 [details]
patch for SDL_RestoreWindow()

С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_WINDOW_MINIMIZED flag assigned. Therefore, SDL_RestoreWindow() returns without restoring the window:

https://hg.libsdl.org/SDL/file/007dfe83abf8/src/video/SDL_video.c#l2093

The solution seems to be to make sure that the SDL_WINDOW_MINIMIZED flag is properly assigned by SDL_MinimizeWindow() and removed by SDL_RestoreWindow().

Please, review the patch attached.
Comment 1 Sam Lantinga 2017-01-28 05:40:46 UTC
Under Linux, what's supposed to happen is that SDL_MinimizeWindow() calls XIconifyWindow(), and then we get an UnmapNotify event, which sends an SDL_WINDOWEVENT_MINIMIZED event. What's happening in your case?
Comment 2 nikolay.p 2017-01-28 20:40:12 UTC
Could you please point out a place in code where:

1) XIconifyWindow() is being called by SDL_MinimizeWindow()
2) SDL receives UnmapNotify and generates SDL_WINDOWEVENT_MINIMIZED event

Then I will be able to add some debug code and run few tests in order to see what is (not) occurring.
Comment 3 Sam Lantinga 2017-01-28 22:31:18 UTC
SDL_MinimizeWindow() calls X11_MinimizeWindow() in SDL_x11window.c
UnmapNotify is handled in SDL_x11events.c

You may want to define DEBUG_XEVENTS at the top of SDL_x11events.c to show what's happening.
Comment 4 nikolay.p 2017-01-29 01:44:53 UTC
This is what I get after creating a window, rendering picture on it and calling:

SDL_MinimizeWindow(window); (Window disappears)
SDL_RestoreWindow(window); (Window does not appear)
SDL_MinimizeWindow(window);
SDL_RestoreWindow(window);

window 0x1444eb0: PropertyNotify: XdndAware changed time=1039088932
{ BITMAP }
window 0x1444eb0: PropertyNotify: WM_NAME changed time=1039088932
{ "SDL_Window" }
window 0x1444eb0: PropertyNotify: _NET_WM_NAME changed time=1039088932
{ "SDL_Window" }
window 0x1444eb0: PropertyNotify: _KDE_NET_WM_USER_CREATION_TIME changed time=1039088933
{ 1039088932 }
window 0x1444eb0: PropertyNotify: WM_NORMAL_HINTS changed time=1039101789
Unknown type: 41 (WM_SIZE_HINTS)
window 0x1444eb0: ConfigureNotify! (position: 0,0, size: 160x90)
window 0x1444eb0: ConfigureNotify! (position: 1760,990, size: 160x90)
window 0x1444eb0: Unhandled event 21
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101791
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101791
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101791
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: PropertyNotify: _NET_WM_DESKTOP changed time=1039101792
{ 0 }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101792
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: Expose (count = 0)
window 0x1444eb0: PropertyNotify: WM_STATE changed time=1039101795
Unknown type: 296 (WM_STATE)
window 0x1444eb0: PropertyNotify: _NET_WM_DESKTOP changed time=1039101795
{ 0 }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101795
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: PropertyNotify: _NET_WM_ALLOWED_ACTIONS changed time=1039101795
{ _NET_WM_ACTION_MOVE _NET_WM_ACTION_MINIMIZE _NET_WM_ACTION_CHANGE_DESKTOP _NET_WM_ACTION_CLOSE }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101797
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101797
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: ConfigureNotify! (position: 1760,950, size: 160x90)
window 0x1444eb0: PropertyNotify: _KDE_NET_WM_ACTIVITIES changed time=1039101801
{ "00000000-0000-0000-0000-000000000000" }
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039101801
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: Expose (count = 0)
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039102793
{ _NET_WM_STATE_HIDDEN _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: UnmapNotify!
window 0x1444eb0: PropertyNotify: WM_STATE changed time=1039102796
Unknown type: 296 (WM_STATE)
window 0x1444eb0: ConfigureNotify! (position: 1760,950, size: 160x90)
window 0x1444eb0: ConfigureNotify! (position: 1760,950, size: 160x90)
window 0x1444eb0: ConfigureNotify! (position: 1760,950, size: 160x90)
window 0x1444eb0: PropertyNotify: _NET_WM_STATE changed time=1039103795
{ _NET_WM_STATE_DEMANDS_ATTENTION _NET_WM_STATE_ABOVE _NET_WM_STATE_STAYS_ON_TOP _NET_WM_STATE_SKIP_TASKBAR _NET_WM_STATE_SKIP_PAGER }
window 0x1444eb0: Expose (count = 0)
window 0x1444eb0: PropertyNotify: WM_STATE changed time=1039103799
Unknown type: 296 (WM_STATE)
window 0x1444eb0: EnterNotify! (155,44,2)
Mode: NotifyUngrab
window 0x1444eb0: Expose (count = 0)
window 0x1444eb0: LeaveNotify! (-12,51,0)
Comment 5 Sam Lantinga 2017-01-29 05:54:45 UTC
Oh, out of curiosity, does it work if you add a call to SDL_PumpEvents() between the call to minimize and then restore?
Comment 6 nikolay.p 2017-01-30 00:19:28 UTC
It works now. The errors were in my code.

There are two things I got wrong:

Was not calling any functions that handle events until you mentioned events.

After I fixed that it still did not work because I did not properly render the window, therefore it was not visible to me.

Now it is resolved. Thank you for help!
Comment 7 Sam Lantinga 2017-01-30 18:34:38 UTC
You're welcome! :)