Toggling fullscreen and windowed

I found a message thread dating to about a year ago on toggling fullscreen.
It had to do with using/hardcoding Alt+Enter to that functionality, but Sam
eventually decided to can it and to add example code in the “Whatsnew” file:

"1.0.5:
Exposed SDL_AudioInit(), SDL_VideoInit()
Added SDL_AudioDriverName() and SDL_VideoDriverName()

Added new window manager function:
SDL_WM_ToggleFullScreen()
This is currently implemented only on Linux

The ALT-ENTER code has been removed - it’s not appropriate for a
lib to bind keys when they aren’t even emergency escape sequences.

ALT-ENTER functionality can be implemented with the following code:

int Handle_AltEnter(const SDL_Event *event)
{
if ( event->type == SDL_KEYDOWN ) {
if ( (event->key.keysym.sym == SDLK_RETURN) &&
(event->key.keysym.mod & KMOD_ALT) ) {
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
return(0);
}
}
return(1);
}
SDL_SetEventFilter(Handle_AltEnter);"

This isn’t very portable (“only on Linux”), so I was wondering if I could
use the code posted by Sam in message
http://www.lokigames.com/ml/sdl/2498.html in my code, since it will probably
work on all platforms? Sam said it wasn’t compiled or tested, in the year
since this was posted, has anybody tried it? The only other relevant thread
I could find has someone discovering a bug where surfaces aren’t getting
freed when toggling from one to the other (but not the other way around):
http://www.lokigames.com/ml/sdl/8086.html (has this been fixed)

Thanks for any help!–

Olivier A. Dagenais - Software Architect and Developer

I found a message thread dating to about a year ago on toggling fullscreen.
It had to do with using/hardcoding Alt+Enter to that functionality, but Sam
eventually decided to can it and to add example code in the “Whatsnew” file:

[code snipped]

Yes, this code works very well, but only on X11.

This isn’t very portable (“only on Linux”), so I was wondering if I could
use the code posted by Sam in message
http://www.lokigames.com/ml/sdl/2498.html in my code, since it will probably
work on all platforms?

My only concern with that code is that the callback may run from
a thread, and you may not be able to change the video mode from a
thread. It’s better to handle ALT-Enter in the main message processing
loop of your application.

The only other relevant thread
I could find has someone discovering a bug where surfaces aren’t getting
freed when toggling from one to the other (but not the other way around):
http://www.lokigames.com/ml/sdl/8086.html (has this been fixed)

Yes, it has.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software