[sdl+opengl+windows]handling focus loss from fullscreen

Started by
5 comments, last by rip-off 18 years, 4 months ago
i'm trying to write a simple sdl+opengl framework for use under both windows and linux. i've done some searching and i can't figure out how to properly handle losing focus while in fullscreen using sdl and opengl in windows. if the screensaver kicks in or if i alt+tab, i can't switch back into my app. i'd like to prevent the screensaver from activating and be able to properly minimize the app and toggle fullscreen if possible (without mangling my gl context). does anyone know how to handle these problems or know someplace i can find info on these and other platform-specific issues?
This space for rent.
Advertisement
Quote:Original post by gumpy macdrunken
i'm trying to write a simple sdl+opengl framework for use under both windows and linux. i've done some searching and i can't figure out how to properly handle losing focus while in fullscreen using sdl and opengl in windows. if the screensaver kicks in or if i alt+tab, i can't switch back into my app. i'd like to prevent the screensaver from activating and be able to properly minimize the app and toggle fullscreen if possible (without mangling my gl context). does anyone know how to handle these problems or know someplace i can find info on these and other platform-specific issues?


it has been suggested in the SDL development list to make the loss of an openGL context and textures a specific event that can be generated, but that won't happen for a while at best. you have 2 options, look at all the occansions in which you can lose an openGL context and re-init your GL settings and textures, or see if theres some hand-hack you can get to work to detect if it happened. either way its going to be ugly though...

good luck!
In Windows, when the screensaver starts up, a message (SC_SCREENSAVER) is sent out to WM_SYSCOMMAND. If you catch this message and prevent it from happening, you are stopping the screensaver from activating whilst your application is running. Here's an example of how to do it:
switch (msg) // msg is our window message{    case WM_SYSCOMMAND: // Interpret system commands    {        switch (wParam) // wParam is our additional message information        {            case SC_SCREENSAVER: // If the screensaver is trying to start...            return 0; // Stop it from starting        }        break; // Exit the switch-case    }}


Good luck!
i've searched and experimented for hours but i still can't find a way to get back into my fullscreen app after it loses focus. alt+tab, screensaver, or an instant messenger window popping up causes me to completely/permanently lose access to my app. is there a way for sdl to handle this issue?
This space for rent.
Quote:Original post by gumpy macdrunken
i've searched and experimented for hours but i still can't find a way to get back into my fullscreen app after it loses focus. alt+tab, screensaver, or an instant messenger window popping up causes me to completely/permanently lose access to my app. is there a way for sdl to handle this issue?


try calling SDL_SetVideoMode again. remember to resetup all the openGL parameters, textures etc.
i decided to watch all of the events, including windows events, and after i alt+tab out of the app it never recieves any more events even when clicking on the app on the taskbar. i'm completely lost here...

edit: no normal sdl event is generated when focus is lost in this way
This space for rent.
Quote:Original post by gumpy macdrunken
i decided to watch all of the events, including windows events, and after i alt+tab out of the app it never recieves any more events even when clicking on the app on the taskbar. i'm completely lost here...

edit: no normal sdl event is generated when focus is lost in this way


if you include a certain header then SDL will forward an unprocessed OS messages in an OS-specific way.

see the functions outlined in SDL_syswm.h ( it is not automatically included, you have to include it yourself )

This topic is closed to new replies.

Advertisement