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 540

Summary: Bug on SDL events...
Product: SDL Reporter: pouer <yoann.lecuyer>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: bombasticbryan, spartanj
Version: 1.2.13Keywords: target-1.2.14
Hardware: x86   
OS: Windows (XP)   
Attachments: Test case for the window resize event

Description pouer 2008-01-13 05:54:51 UTC
SDL don't send SDL_VIDEORESIZE event when we minimize the window.

An exemple :

//main.cpp

//init

int size = 0;

while (1)
{
        
        SDL_PollEvent(&event);
        
        switch(event.type)
        {
            case SDL_QUIT:
                exit(0);
            break;

            case SDL_VIDEORESIZE:
                size ^= 1;

                if (size) SDL_WM_SetCaption("Big...", NULL);
                else SDL_WM_SetCaption("Litle", NULL);

            break;
        }

}


You can show that the window's title change only when we maximize the window.
Comment 1 Sam Lantinga 2008-01-14 08:01:46 UTC
You don't get a video resize event when you iconify the window.  You get an app active event instead.

Go ahead and reopen this bug if you're talking about maximizing and restoring instead.
Comment 2 Sam Lantinga 2008-01-14 08:02:43 UTC
Nevermind, it appears you're talking about restoring after maximizing.  I'll look into this.
Comment 3 Ryan C. Gordon 2009-09-13 16:33:22 UTC
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.
Comment 4 Sam Lantinga 2009-09-26 23:56:05 UTC
Are you still getting this issue with the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-1.2.zip

I just tried the included testwm test and got the following (expected) output by minimizing, restoring, maximizing, restoring:

Title was set to: Testing  1.. 2.. 3...
Running in windowed mode
App gained mouse focus
App lost mouse focus
App lost active input focus
App has been iconified
App gained active input focus
App has been restored
App gained mouse focus
App lost mouse focus
App gained mouse focus
Got a resize event: 1920x1138
App lost mouse focus
Running in windowed mode
App gained mouse focus
App lost mouse focus
Got a resize event: 640x480
Running in windowed mode
App gained mouse focus
Key pressed:  27-escape  modifiers: (none)
Posting internal quit request
Handling internal quit request
Bye bye..
App lost input focus
Key released:  27-escape  modifiers: (none)
Comment 5 Martín Golini 2009-09-28 19:56:00 UTC
I'm having a problem restoring the previously maximized window and i think it's related with this bug report.
To avoid the lost of opengl context (in win32) i resize the window calling SetWindowPos (instead of calling SDL_SetVideoMode), thanks to the fix of this bug: http://bugzilla.libsdl.org/show_bug.cgi?id=713 now i can do this, but still have one problem.
That's what happen to me:
First create the window, then click on the maximize button, i receive the SDL_VIDEORESIZE event, so i resize the window and keep the context (no problem here), but, if i click on the maximize button again to restore the window, the SDL_VIDEORESIZE never happen. 
But... if before maximizing the window i resize the window calling SetWindowPos, and THEN click on the maximize button, and restore it, the SDL_VIDEORESIZE works perfectly well...
So for the moment i made a hack to avoid this problem, i create the window with an extra pixel, and then resize the window calling SetWindowPos without that extra pixel, and it works fine, but it's not an elegant solution.

Hope someone understand my poor explanation.

Thanks in advice, and sorry for my bad English.

PD: You can look my ugly solution at this diff file http://code.google.com/p/eepp/source/diff?spec=svn85&r=85&format=side&path=/trunk/cengine.cpp
Comment 6 Sam Lantinga 2009-10-03 03:09:58 UTC
Can you try with the latest snapshot and removing your hack?  I modified testgl.c to be resizable and it worked with no problems here.
Comment 7 Martín Golini 2009-10-03 17:32:32 UTC
Hi Sam!
I tried removing my patch and re-compiling the with latest version, but i'm still getting the same problem. Tell me if you need an example version to replicate the problem and i'll do it.
Thanks for you help!
Comment 8 Sam Lantinga 2009-10-17 11:03:50 UTC
Yes, a test case would be great.  Thanks!
Comment 9 Martín Golini 2009-10-18 20:07:57 UTC
Created attachment 425 [details]
Test case for the window resize event
Comment 10 Martín Golini 2009-10-18 20:11:40 UTC
Perfect!
To test what i'm talking about just maximize the window and then restore it (unmaximize), the unmaximize event is not handled.
Thanks!
Comment 11 Sam Lantinga 2009-10-18 21:18:13 UTC
Oh yeah, you're not allowed to manipulate the window yourself like you're doing.  You should be calling SDL_SetVideoMode() in response to the resize message.  This updates SDL's internal data structures and prevents it from generating or hiding messages during the resize.

Try replacing AdjustWindowRect() and SetWindowPos() with SDL_SetVideoMode() and you should be fine. :)
Comment 12 Sam Lantinga 2009-10-19 01:35:40 UTC
Actually, I'm waiting to hear back before closing this bug.
Comment 13 Sam Lantinga 2009-10-19 01:37:13 UTC
I tested this with a modified version of testgl.c which calls SDL_SetVideoMode() in response to SDL_VIDEORESIZE and resets the viewport, and everything worked fine.

Can you try this in your application and see if it works for you?
Comment 14 Martín Golini 2009-10-19 06:52:54 UTC
Hi Sam,
Yes, i tried using SDL_SetVideoMode, and it works as you expect.
I'm not calling SDL_SetVideoMode because i can't lose the OpenGL context, i'm using this code for an image viewer and the window is resized constantly, so i tried this method and it worked well until i saw this little problem, so i'll keep my little hack that works fine for me. I just thought that this could be fixed internally on SDL.
So, close this bug.
Thanks for you help Sam! :)
Comment 15 Sam Lantinga 2009-10-19 07:17:26 UTC
With the latest version of SDL (1.2.14) you no longer lose your context when you resize the window, so you should be good once that's released today.
Comment 16 Sam Lantinga 2009-10-19 07:18:01 UTC
FYI, you can try out the pre-release here:
http://www.libsdl.org/tmp/release/
Comment 17 Martín Golini 2009-10-19 08:02:00 UTC
Great!
I didn't know that it was fixed! :)
I tested and it's working perfectly.
Thanks for the link!
Comment 18 Sam Lantinga 2009-10-19 08:18:26 UTC
You're welcome!