Just to clarify, the hotkey combination only works if the application
is processing events, so if your application is hung, you would not be
able to use a hotkey to escape or restore the video mode.
Also, using SDL 1.1.0, you can choose to enable and disable hotkeys
via the hotkey API (which will probably go away if Alt-Enter is dropped)
The idea is that for applications that are not written to be aware of them,
the hotkeys will provide useful default functionality.
People have raised the concern that the application should be in charge
of handling key sequences explictly, and indeed, the code is very simple*
SDL_Surface screen; / The display screen */
int my_HotKeyFilter(const SDL_Event *event)
{
if ( event->type == SDL_KEYDOWN ) {
if ( (event->key.keysym.sym == SDLK_RETURN) &&
(event->key.keysym.mod & KMOD_ALT) )
Uint32 flags;
int w, h, bpp;
w = screen->w;
h = screen->h;
bpp = screen->format->BitsPerPixel;
if ( screen->flags & SDL_FULLSCREEN ) {
flags = screen->flags & ~SDL_FULLSCREEN;
} else {
flags = screen->flags | SDL_FULLSCREEN;
}
if ( VideoModeOK(w, h, bpp, flags) ) {
/* This changes the publicly visible surface */
screen = SDL_SetVideoMode(w, h, bpp, flags);
if ( screen == NULL ) {
/* Uh oh... */;
}
/* Redraw surface contents ... */
}
/* Drop the event */
return(0);
}
}
return(1);
}
…
SDL_SetEventFilter(my_HotKeyFilter);
[*] the code above has not been compiled and tested
See test/testwm.c for more hotkey examples.
The advantage of the current Alt-Enter toggle is that it takes advantage
of internal toggling functionality only available with the X11 driver,
and it does not change the contents of the screen and generally does
not fail.
It does change the screen flags, but otherwise is beyond the application
control. This would be difficult to implement in the other video drivers.
So, that said, who wants to keep the current hotkey functionality?
-Sam Lantinga (slouken at devolution.com)
Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec