Cleaned up Alt-Enter/Ctrl-Enter fullscreen toggle logic

Alt-Enter will go from the current state to fullscreen desktop, or if already there, will leave fullscreen mode.
Ctrl-Enter will go from the current state to exclusive fullscreen mode, or if already there, will leave fullscreen mode.
main
Sam Lantinga 2023-06-03 23:24:21 -07:00
parent 052a9d3284
commit d40695115f
1 changed files with 8 additions and 16 deletions

View File

@ -2186,10 +2186,12 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) { if (window) {
Uint32 flags = SDL_GetWindowFlags(window); Uint32 flags = SDL_GetWindowFlags(window);
if (flags & SDL_WINDOW_FULLSCREEN) { if (!(flags & SDL_WINDOW_FULLSCREEN) ||
SDL_SetWindowFullscreen(window, SDL_FALSE); !SDL_GetWindowFullscreenMode(window)) {
} else { SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
SDL_SetWindowFullscreen(window, SDL_TRUE); SDL_SetWindowFullscreen(window, SDL_TRUE);
} else {
SDL_SetWindowFullscreen(window, SDL_FALSE);
} }
} }
} else if (withAlt) { } else if (withAlt) {
@ -2197,23 +2199,13 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) { if (window) {
Uint32 flags = SDL_GetWindowFlags(window); Uint32 flags = SDL_GetWindowFlags(window);
if (flags & SDL_WINDOW_FULLSCREEN) { if (!(flags & SDL_WINDOW_FULLSCREEN) ||
SDL_SetWindowFullscreen(window, SDL_FALSE); SDL_GetWindowFullscreenMode(window)) {
} else {
SDL_SetWindowFullscreenMode(window, NULL); SDL_SetWindowFullscreenMode(window, NULL);
SDL_SetWindowFullscreen(window, SDL_TRUE); SDL_SetWindowFullscreen(window, SDL_TRUE);
}
}
} else if (withShift) {
/* Shift-Enter toggle fullscreen desktop / fullscreen */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
if (SDL_GetWindowFullscreenMode(window)) {
SDL_SetWindowFullscreenMode(window, NULL);
} else { } else {
SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode); SDL_SetWindowFullscreen(window, SDL_FALSE);
} }
SDL_SetWindowFullscreen(window, SDL_TRUE);
} }
} }