From d40695115f8fa5d7c81ac5bc5e8b0188d040b3b5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Jun 2023 23:24:21 -0700
Subject: [PATCH] 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.
---
src/test/SDL_test_common.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 7533d0446fb4..d77b65212dd7 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -2186,10 +2186,12 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
Uint32 flags = SDL_GetWindowFlags(window);
- if (flags & SDL_WINDOW_FULLSCREEN) {
- SDL_SetWindowFullscreen(window, SDL_FALSE);
- } else {
+ if (!(flags & SDL_WINDOW_FULLSCREEN) ||
+ !SDL_GetWindowFullscreenMode(window)) {
+ SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
SDL_SetWindowFullscreen(window, SDL_TRUE);
+ } else {
+ SDL_SetWindowFullscreen(window, SDL_FALSE);
}
}
} 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);
if (window) {
Uint32 flags = SDL_GetWindowFlags(window);
- if (flags & SDL_WINDOW_FULLSCREEN) {
- SDL_SetWindowFullscreen(window, SDL_FALSE);
- } else {
+ if (!(flags & SDL_WINDOW_FULLSCREEN) ||
+ SDL_GetWindowFullscreenMode(window)) {
SDL_SetWindowFullscreenMode(window, NULL);
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 {
- SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
+ SDL_SetWindowFullscreen(window, SDL_FALSE);
}
- SDL_SetWindowFullscreen(window, SDL_TRUE);
}
}