SDL: Folded SDL_WINDOW_FULLSCREEN_EXCLUSIVE and SDL_WINDOW_FULLSCREEN_DESKTOP into a single SDL_WINDOW_FULLSCREEN flag

From ac75fe932449de9147708f1580e6d142eda855f4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 1 Feb 2023 11:30:28 -0800
Subject: [PATCH] Folded SDL_WINDOW_FULLSCREEN_EXCLUSIVE and
 SDL_WINDOW_FULLSCREEN_DESKTOP into a single SDL_WINDOW_FULLSCREEN flag

The fullscreen video mode used by the window can be used to determine whether it's in exclusive fullscreen or fullscreen desktop mode.
---
 docs/README-migration.md                    |   2 +-
 docs/README-winrt.md                        |   2 +-
 include/SDL3/SDL_oldnames.h                 |   2 -
 include/SDL3/SDL_shape.h                    |   2 +-
 include/SDL3/SDL_test_common.h              |   1 +
 include/SDL3/SDL_video.h                    |  10 +-
 src/SDL_assert.c                            |   2 +-
 src/core/winrt/SDL_winrtapp_direct3d.cpp    |   2 +-
 src/events/SDL_keyboard.c                   |   2 +-
 src/events/SDL_windowevents.c               |   4 +-
 src/render/direct3d/SDL_render_d3d.c        |   4 +-
 src/test/SDL_test_common.c                  |  37 +++--
 src/video/SDL_shape.c                       |   2 +-
 src/video/SDL_sysvideo.h                    |   5 +-
 src/video/SDL_video.c                       | 151 +++++++++-----------
 src/video/cocoa/SDL_cocoawindow.m           |  34 ++---
 src/video/emscripten/SDL_emscriptenevents.c |   4 +-
 src/video/emscripten/SDL_emscriptenvideo.c  |  12 +-
 src/video/haiku/SDL_bwindow.cc              |   2 +-
 src/video/kmsdrm/SDL_kmsdrmvideo.c          |   2 +-
 src/video/psp/SDL_pspgl.c                   |   2 +-
 src/video/riscos/SDL_riscoswindow.c         |   2 +-
 src/video/uikit/SDL_uikitmodes.m            |   2 +-
 src/video/uikit/SDL_uikitviewcontroller.m   |   4 +-
 src/video/uikit/SDL_uikitwindow.m           |   4 +-
 src/video/vita/SDL_vitagles.c               |   2 +-
 src/video/wayland/SDL_waylandwindow.c       |  71 +++------
 src/video/wayland/SDL_waylandwindow.h       |   1 -
 src/video/windows/SDL_windowsevents.c       |   2 +-
 src/video/windows/SDL_windowswindow.c       |   4 +-
 src/video/winrt/SDL_winrtvideo.cpp          |  21 ++-
 src/video/x11/SDL_x11events.c               |   4 +-
 src/video/x11/SDL_x11window.c               |  16 +--
 test/testautomation_video.c                 |  11 +-
 test/testsensor.c                           |   2 +-
 test/testwm.c                               |   2 +-
 36 files changed, 183 insertions(+), 249 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 32a7bb3f8afd..5daeb02f280d 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1009,7 +1009,7 @@ SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to d
 
 Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
 
-SDL_WINDOW_FULLSCREEN has been renamed SDL_WINDOW_FULLSCREEN_EXCLUSIVE, and SDL_WINDOW_FULLSCREEN_DESKTOP no longer includes the old SDL_WINDOW_FULLSCREEN flag. You can use `(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_MASK) != 0` if you want to check for either state.
+SDL_WINDOW_FULLSCREEN_DESKTOP has been removed, and you can call SDL_GetWindowFullscreenMode() to see whether an exclusive fullscreen mode will be used or the fullscreen desktop mode will be used when the window is fullscreen.
 
 SDL_SetWindowBrightness and SDL_SetWindowGammaRamp have been removed from the API, because they interact poorly with modern operating systems and aren't able to limit their effects to the SDL window.
 
diff --git a/docs/README-winrt.md b/docs/README-winrt.md
index f8c2e812fcbf..c65aa7d632cd 100644
--- a/docs/README-winrt.md
+++ b/docs/README-winrt.md
@@ -340,7 +340,7 @@ int main(int argc, char **argv)
   
     if (SDL_Init(SDL_INIT_VIDEO) != 0) {
         return 1;
-    } else if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &window, &renderer) != 0) {
+    } else if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN, &window, &renderer) != 0) {
         return 1;
     }
     
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index 80d73537a33a..0733964c9a8d 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -419,7 +419,6 @@
 #define SDL_GetWindowDisplayIndex SDL_GetDisplayForWindow
 #define SDL_GetWindowDisplayMode SDL_GetWindowFullscreenMode
 #define SDL_SetWindowDisplayMode SDL_SetWindowFullscreenMode
-#define SDL_WINDOW_FULLSCREEN SDL_WINDOW_FULLSCREEN_EXCLUSIVE
 #define SDL_WINDOW_INPUT_GRABBED SDL_WINDOW_MOUSE_GRABBED
 
 #elif !defined(SDL_DISABLE_OLD_NAMES)
@@ -805,7 +804,6 @@
 #define SDL_GetWindowDisplayIndex SDL_GetWindowDisplayIndex_renamed_SDL_GetDisplayForWindow
 #define SDL_GetWindowDisplayMode SDL_GetWindowDisplayMode_renamed_SDL_GetWindowFullscreenMode
 #define SDL_SetWindowDisplayMode SDL_SetWindowDisplayMode_renamed_SDL_SetWindowFullscreenMode
-#define SDL_WINDOW_FULLSCREEN SDL_WINDOW_FULLSCREEN_renamed_SDL_WINDOW_FULLSCREEN_EXCLUSIVE
 #define SDL_WINDOW_INPUT_GRABBED SDL_WINDOW_INPUT_GRABBED_renamed_SDL_WINDOW_MOUSE_GRABBED
 
 #endif /* SDL_ENABLE_OLD_NAMES */
diff --git a/include/SDL3/SDL_shape.h b/include/SDL3/SDL_shape.h
index 71bc15041c65..ea7b89f775e1 100644
--- a/include/SDL3/SDL_shape.h
+++ b/include/SDL3/SDL_shape.h
@@ -59,7 +59,7 @@ extern "C" {
  *              ::SDL_WINDOW_MOUSE_GRABBED, ::SDL_WINDOW_HIDDEN,
  *              ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED,
  *              ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_BORDERLESS is always set,
- *              and ::SDL_WINDOW_FULLSCREEN_MASK is always unset.
+ *              and ::SDL_WINDOW_FULLSCREEN is always unset.
  * \return the window created, or NULL if window creation failed.
  *
  * \since This function is available since SDL 3.0.0.
diff --git a/include/SDL3/SDL_test_common.h b/include/SDL3/SDL_test_common.h
index 50a612c34d51..9b3d7dab627e 100644
--- a/include/SDL3/SDL_test_common.h
+++ b/include/SDL3/SDL_test_common.h
@@ -80,6 +80,7 @@ typedef struct
     float scale;
     int depth;
     float refresh_rate;
+    SDL_bool fullscreen_exclusive;
     SDL_DisplayMode fullscreen_mode;
     int num_windows;
     SDL_Window **windows;
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 6a8002276dc4..ef5678799db7 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -107,7 +107,7 @@ typedef struct SDL_Window SDL_Window;
  */
 typedef enum
 {
-    SDL_WINDOW_FULLSCREEN_EXCLUSIVE = 0x00000001,   /**< window is in fullscreen exclusive mode */
+    SDL_WINDOW_FULLSCREEN           = 0x00000001,   /**< window is in fullscreen mode */
     SDL_WINDOW_OPENGL               = 0x00000002,   /**< window usable with OpenGL context */
     /* 0x00000004 was SDL_WINDOW_SHOWN in SDL2, please reserve this bit for sdl2-compat. */
     SDL_WINDOW_HIDDEN               = 0x00000008,   /**< window is not visible */
@@ -118,7 +118,7 @@ typedef enum
     SDL_WINDOW_MOUSE_GRABBED        = 0x00000100,   /**< window has grabbed mouse input */
     SDL_WINDOW_INPUT_FOCUS          = 0x00000200,   /**< window has input focus */
     SDL_WINDOW_MOUSE_FOCUS          = 0x00000400,   /**< window has mouse focus */
-    SDL_WINDOW_FULLSCREEN_DESKTOP   = 0x00001000,   /**< window is in fullscreen desktop mode */
+    /* 0x00001000 was SDL_WINDOW_FULLSCREEN_DESKTOP in SDL2, please reserve this bit for sdl2-compat. */
     SDL_WINDOW_FOREIGN              = 0x00000800,   /**< window not created by SDL */
     /* 0x00002000 was SDL_WINDOW_ALLOW_HIGHDPI in SDL2, please reserve this bit for sdl2-compat. */
     SDL_WINDOW_MOUSE_CAPTURE        = 0x00004000,   /**< window has mouse captured (unrelated to MOUSE_GRABBED) */
@@ -133,8 +133,6 @@ typedef enum
 
 } SDL_WindowFlags;
 
-#define SDL_WINDOW_FULLSCREEN_MASK  (SDL_WINDOW_FULLSCREEN_EXCLUSIVE | SDL_WINDOW_FULLSCREEN_DESKTOP)
-
 /**
  *  \brief Used to indicate that you don't care what the window position is.
  */
@@ -614,9 +612,7 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window);
  *
  * `flags` may be any of the following OR'd together:
  *
- * - `SDL_WINDOW_FULLSCREEN_EXCLUSIVE`: fullscreen window, switching display
- *   mode to the closest fullscreen resolution
- * - `SDL_WINDOW_FULLSCREEN_DESKTOP`: fullscreen window at desktop resolution
+ * - `SDL_WINDOW_FULLSCREEN`: fullscreen window at desktop resolution
  * - `SDL_WINDOW_OPENGL`: window usable with an OpenGL context
  * - `SDL_WINDOW_VULKAN`: window usable with a Vulkan instance
  * - `SDL_WINDOW_METAL`: window usable with a Metal instance
diff --git a/src/SDL_assert.c b/src/SDL_assert.c
index 63452a387257..705a1fa25b33 100644
--- a/src/SDL_assert.c
+++ b/src/SDL_assert.c
@@ -213,7 +213,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
     /* Leave fullscreen mode, if possible (scary!) */
     window = SDL_GetFocusWindow();
     if (window) {
-        if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
+        if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0) {
             SDL_MinimizeWindow(window);
         } else {
             /* !!! FIXME: ungrab the input if we're not fullscreen? */
diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp
index 1a20b313636a..3b3231da15ee 100644
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp
@@ -150,7 +150,7 @@ static void WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identify
                 SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESTORED, 0, 0);
             }
 
-            WINRT_UpdateWindowFlags(window, SDL_WINDOW_FULLSCREEN_MASK);
+            WINRT_UpdateWindowFlags(window, SDL_WINDOW_FULLSCREEN);
 
             /* The window can move during a resize event, such as when maximizing
                or resizing from a corner */
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index 68b59c114235..ca336a91dc97 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -931,7 +931,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, SDL_KeyboardFlags flags
         (keyboard->modstate & SDL_KMOD_ALT) &&
         keyboard->focus &&
         (keyboard->focus->flags & SDL_WINDOW_KEYBOARD_GRABBED) != 0 &&
-        (keyboard->focus->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0 &&
+        (keyboard->focus->flags & SDL_WINDOW_FULLSCREEN) != 0 &&
         SDL_GetHintBoolean(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, SDL_TRUE)) {
         /* We will temporarily forfeit our grab by minimizing our window,
            allowing the user to escape the application */
diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c
index 8753e495db00..5deba6fd9195 100644
--- a/src/events/SDL_windowevents.c
+++ b/src/events/SDL_windowevents.c
@@ -67,7 +67,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
             SDL_WINDOWPOS_ISUNDEFINED(data2)) {
             return 0;
         }
-        if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) {
+        if ((window->flags & SDL_WINDOW_FULLSCREEN) == 0) {
             window->windowed.x = data1;
             window->windowed.y = data2;
         }
@@ -78,7 +78,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
         window->y = data2;
         break;
     case SDL_EVENT_WINDOW_RESIZED:
-        if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) {
+        if ((window->flags & SDL_WINDOW_FULLSCREEN) == 0) {
             window->windowed.w = data1;
             window->windowed.h = data2;
         }
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 647898fe8340..64a59ebc61d5 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -294,7 +294,7 @@ static int D3D_ActivateRenderer(SDL_Renderer *renderer)
         SDL_GetWindowSizeInPixels(window, &w, &h);
         data->pparams.BackBufferWidth = w;
         data->pparams.BackBufferHeight = h;
-        if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
+        if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0) {
             fullscreen_mode = SDL_GetWindowFullscreenMode(window);
         }
         if (fullscreen_mode) {
@@ -1613,7 +1613,7 @@ D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
     renderer->driverdata = data;
 
     SDL_GetWindowSizeInPixels(window, &w, &h);
-    if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
+    if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0) {
         fullscreen_mode = SDL_GetWindowFullscreenMode(window);
     }
 
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 47176070bec4..726d823eae39 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -234,12 +234,14 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
         return 1;
     }
     if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
-        state->window_flags |= SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
+        state->window_flags |= SDL_WINDOW_FULLSCREEN;
+        state->fullscreen_exclusive = SDL_TRUE;
         state->num_windows = 1;
         return 1;
     }
     if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
-        state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+        state->window_flags |= SDL_WINDOW_FULLSCREEN;
+        state->fullscreen_exclusive = SDL_FALSE;
         state->num_windows = 1;
         return 1;
     }
@@ -248,7 +250,7 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
         if (!argv[index] || !SDL_isdigit((unsigned char)*argv[index])) {
             return -1;
         }
-        if ((state->window_flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) {
+        if ((state->window_flags & SDL_WINDOW_FULLSCREEN) == 0) {
             state->num_windows = SDL_atoi(argv[index]);
         }
         return 2;
@@ -668,8 +670,8 @@ static void SDLTest_PrintDisplayOrientation(char *text, size_t maxlen, SDL_Displ
 static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, Uint32 flag)
 {
     switch (flag) {
-    case SDL_WINDOW_FULLSCREEN_EXCLUSIVE:
-        SDL_snprintfcat(text, maxlen, "FULLSCREEN_EXCLUSIVE");
+    case SDL_WINDOW_FULLSCREEN:
+        SDL_snprintfcat(text, maxlen, "FULLSCREEN");
         break;
     case SDL_WINDOW_OPENGL:
         SDL_snprintfcat(text, maxlen, "OPENGL");
@@ -698,9 +700,6 @@ static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, Uint32 flag)
     case SDL_WINDOW_MOUSE_FOCUS:
         SDL_snprintfcat(text, maxlen, "MOUSE_FOCUS");
         break;
-    case SDL_WINDOW_FULLSCREEN_DESKTOP:
-        SDL_snprintfcat(text, maxlen, "FULLSCREEN_DESKTOP");
-        break;
     case SDL_WINDOW_FOREIGN:
         SDL_snprintfcat(text, maxlen, "FOREIGN");
         break;
@@ -740,7 +739,7 @@ static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, Uint32 flag)
 static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags)
 {
     const Uint32 window_flags[] = {
-        SDL_WINDOW_FULLSCREEN_EXCLUSIVE,
+        SDL_WINDOW_FULLSCREEN,
         SDL_WINDOW_OPENGL,
         SDL_WINDOW_HIDDEN,
         SDL_WINDOW_BORDERLESS,
@@ -750,7 +749,6 @@ static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags)
         SDL_WINDOW_MOUSE_GRABBED,
         SDL_WINDOW_INPUT_FOCUS,
         SDL_WINDOW_MOUSE_FOCUS,
-        SDL_WINDOW_FULLSCREEN_DESKTOP,
         SDL_WINDOW_FOREIGN,
         SDL_WINDOW_MOUSE_CAPTURE,
         SDL_WINDOW_ALWAYS_ON_TOP,
@@ -1265,11 +1263,9 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
                 state->window_w = w;
                 state->window_h = h;
             }
-            if ((state->window_flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
-                if ((state->window_flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
+            if ((state->window_flags & SDL_WINDOW_FULLSCREEN) != 0) {
+                if (state->fullscreen_exclusive) {
                     SDL_SetWindowFullscreenMode(state->windows[i], &state->fullscreen_mode);
-                } else {
-                    SDL_SetWindowFullscreenMode(state->windows[i], NULL);
                 }
                 SDL_SetWindowFullscreen(state->windows[i], SDL_TRUE);
             }
@@ -1737,7 +1733,7 @@ static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId)
             SDL_GetDisplayBounds(displays[index], &rect);
 
             flags = SDL_GetWindowFlags(window);
-            if ((flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
+            if ((flags & SDL_WINDOW_FULLSCREEN) != 0) {
                 SDL_SetWindowFullscreen(window, SDL_FALSE);
                 SDL_Delay(15);
             }
@@ -2051,7 +2047,7 @@ 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_MASK) != 0) {
+                    if ((flags & SDL_WINDOW_FULLSCREEN) != 0) {
                         SDL_SetWindowFullscreen(window, SDL_FALSE);
                     } else {
                         SDL_SetWindowFullscreen(window, SDL_TRUE);
@@ -2062,7 +2058,7 @@ 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_MASK) != 0) {
+                    if ((flags & SDL_WINDOW_FULLSCREEN) != 0) {
                         SDL_SetWindowFullscreen(window, SDL_FALSE);
                     } else {
                         SDL_SetWindowFullscreenMode(window, NULL);
@@ -2073,11 +2069,10 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
                 /* Shift-Enter toggle fullscreen desktop / fullscreen */
                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                 if (window) {
-                    Uint32 flags = SDL_GetWindowFlags(window);
-                    if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) {
-                        SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
-                    } else {
+                    if (SDL_GetWindowFullscreenMode(window)) {
                         SDL_SetWindowFullscreenMode(window, NULL);
+                    } else {
+                        SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
                     }
                     SDL_SetWindowFullscreen(window, SDL_TRUE);
                 }
diff --git a/src/video/SDL_shape.c b/src/video/SDL_shape.c
index c59e4411fac8..fb8bd71b8a47 100644
--- a/src/video/SDL_shape.c
+++ b/src/video/SDL_shape.c
@@ -27,7 +27,7 @@ SDL_Window *
 SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint32 flags)
 {
     SDL_Window *result = NULL;
-    result = SDL_CreateWindow(title, -1000, -1000, w, h, (flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN_MASK) & (~SDL_WINDOW_RESIZABLE));
+    result = SDL_CreateWindow(title, -1000, -1000, w, h, (flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE));
     if (result != NULL) {
         if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) {
             SDL_DestroyWindow(result);
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 0c78cdf56af7..55b544bf2d62 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -106,7 +106,8 @@ struct SDL_Window
     int max_w, max_h;
     int last_pixel_w, last_pixel_h;
     Uint32 flags;
-    Uint32 last_fullscreen_flags;
+    SDL_bool fullscreen_exclusive;  /* The window is currently fullscreen exclusive */
+    SDL_bool last_fullscreen_exclusive;  /* The last fullscreen_exclusive setting */
     SDL_DisplayID last_displayID;
 
     /* Stored position and size for windowed mode */
@@ -138,7 +139,7 @@ struct SDL_Window
     SDL_Window *next;
 };
 #define SDL_WINDOW_FULLSCREEN_VISIBLE(W)        \
-    ((((W)->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) &&   \
+    ((((W)->flags & SDL_WINDOW_FULLSCREEN) != 0) &&   \
      (((W)->flags & SDL_WINDOW_HIDDEN) == 0) && \
      (((W)->flags & SDL_WINDOW_MINIMIZED) == 0))
 
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 03c578333c4f..8cfc66fcd459 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1221,7 +1221,7 @@ SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window)
      * (for example if the window is off-screen), but other code may expect it
      * to succeed in that situation, so we fall back to a generic position-
      * based implementation in that case. */
-    if (!displayID && (window->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
+    if (!displayID && (window->flags & SDL_WINDOW_FULLSCREEN) != 0) {
         displayID = window->fullscreen_mode.displayID;
     }
     if (!displayID) {
@@ -1293,24 +1293,23 @@ static void SDL_RestoreMousePosition(SDL_Window *window)
 static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
 {
     SDL_VideoDisplay *display;
-    SDL_DisplayMode *mode;
+    SDL_DisplayMode *mode = NULL;
 
     CHECK_WINDOW_MAGIC(window, -1);
 
+    window->fullscreen_exclusive = SDL_FALSE;
+
     /* if we are in the process of hiding don't go back to fullscreen */
     if (window->is_hiding && fullscreen) {
-        return 0;
+        goto done;
     }
 
     display = SDL_GetVideoDisplayForWindow(window);
 
-    mode = NULL;
-    if (fullscreen && (window->flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
+    if (fullscreen) {
         mode = (SDL_DisplayMode *)SDL_GetWindowFullscreenMode(window);
-        if (!mode || mode->displayID != display->id) {
-            /* Couldn't find a matching mode, pop out of fullscreen mode */
-            window->flags &= ~SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
-            fullscreen = SDL_FALSE;
+        if (mode != NULL) {
+            window->fullscreen_exclusive = SDL_TRUE;
         }
     }
 
@@ -1319,20 +1318,17 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
        do nothing, or else we may trigger an ugly double-transition
      */
     if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
-        if (window->is_destroying && (window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) {
-            return 0;
+        if (window->is_destroying && !window->last_fullscreen_exclusive) {
+            window->fullscreen_exclusive = SDL_FALSE;
+            goto done;
         }
 
-        /* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */
-        if (fullscreen &&
-            (window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0 &&
-            (window->flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
+        /* If we're switching between a fullscreen Space and exclusive fullscreen, we need to get back to normal first. */
+        if (fullscreen && !window->last_fullscreen_exclusive && window->fullscreen_exclusive) {
             if (!Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE)) {
-                return -1;
+                goto error;
             }
-        } else if (fullscreen &&
-                   (window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0 &&
-                   (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) {
+        } else if (fullscreen && window->last_fullscreen_exclusive && !window->fullscreen_exclusive) {
             display = SDL_GetVideoDisplayForWindow(window);
             SDL_SetDisplayModeForDisplay(display, NULL);
             if (_this->SetWindowFullscreen) {
@@ -1342,10 +1338,9 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
 
         if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
             if (Cocoa_IsWindowInFullscreenSpace(window) != fullscreen) {
-                return -1;
+                goto error;
             }
-            window->last_fullscreen_flags = window->flags;
-            return 0;
+            goto done;
         }
     }
 #elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
@@ -1357,7 +1352,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
        to fullscreen (being active, or not), and figure out a return/error code
        from that.
     */
-    if (fullscreen == !(WINRT_DetectWindowFlags(window) & SDL_WINDOW_FULLSCREEN_MASK)) {
+    if (fullscreen == !(WINRT_DetectWindowFlags(window) & SDL_WINDOW_FULLSCREEN)) {
         /* Uh oh, either:
             1. fullscreen was requested, and we're already windowed
             2. windowed-mode was requested, and we're already fullscreen
@@ -1365,15 +1360,27 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
             WinRT 8.x can't resolve either programmatically, so we're
             giving up.
         */
-        return -1;
+        goto error;
     } else {
         /* Whatever was requested, fullscreen or windowed mode, is already
             in-place.
         */
-        return 0;
+        goto done;
     }
 #endif
 
+    /* Restore the video mode on other displays if needed */
+    if (window->last_fullscreen_exclusive) {
+        int i;
+
+        for (i = 0; i < _this->num_displays; ++i) {
+            SDL_VideoDisplay *other = &_this->displays[i];
+            if (display != other && other->fullscreen_window == window) {
+                SDL_SetDisplayModeForDisplay(other, NULL);
+            }
+        }
+    }
+
     if (fullscreen) {
         int mode_w = 0, mode_h = 0;
         SDL_bool resized = SDL_FALSE;
@@ -1385,7 +1392,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
         }
 
         if (SDL_SetDisplayModeForDisplay(display, mode) < 0) {
-            return -1;
+            goto error;
         }
         if (_this->SetWindowFullscreen) {
             _this->SetWindowFullscreen(_this, window, display, SDL_TRUE);
@@ -1395,7 +1402,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
 #if defined(__ANDROID__)
         /* Android may not resize the window to exactly what our fullscreen mode is,
          * especially on windowed Android environments like the Chromebook or Samsung DeX.
-         * Given this, we shouldn't use the mode size. As such, Android's SetWindowFullscreen
+         * Given this, we shouldn't use the mode size. Android's SetWindowFullscreen
          * will generate the window event for us with the proper final size.
          */
 #elif defined(__WIN32__)
@@ -1424,7 +1431,6 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
         SDL_RestoreMousePosition(window);
 
     } else {
-
         if (display->fullscreen_window == window) {
             /* Restore the desktop mode */
             SDL_SetDisplayModeForDisplay(display, NULL);
@@ -1443,9 +1449,17 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
         SDL_RestoreMousePosition(window);
     }
 
-    window->last_fullscreen_flags = window->flags;
-
+done:
+    window->last_fullscreen_exclusive = window->fullscreen_exclusive;
     return 0;
+
+error:
+    if (fullscreen) {
+        /* Something went wrong and the window is no longer fullscreen. */
+        window->flags &= ~SDL_WINDOW_FULLSCREEN;
+        SDL_UpdateFullscreenMode(window, SDL_FALSE);
+    }
+    return -1;
 }
 
 int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode)
@@ -1459,18 +1473,8 @@ int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode)
 
         /* Save the mode so we can look up the closest match later */
         SDL_memcpy(&window->fullscreen_mode, mode, sizeof(window->fullscreen_mode));
-
-        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) {
-            window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
-            window->flags |= SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
-        }
     } else {
         SDL_zero(window->fullscreen_mode);
-
-        if ((window->flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) {
-            window->flags &= ~SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
-            window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
-        }
     }
 
     if (SDL_WINDOW_FULLSCREEN_VISIBLE(window)) {
@@ -1554,7 +1558,7 @@ static void SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
     if (flags & SDL_WINDOW_MINIMIZED) {
         SDL_MinimizeWindow(window);
     }
-    if (flags & SDL_WINDOW_FULLSCREEN_MASK) {
+    if (flags & SDL_WINDOW_FULLSCREEN) {
         SDL_SetWindowFullscreen(window, flags);
     }
     if (flags & SDL_WINDOW_MOUSE_GRABBED) {
@@ -1698,14 +1702,10 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint
         }
     }
 
-    if (flags & SDL_WINDOW_FULLSCREEN_MASK) {
+    if (flags & SDL_WINDOW_FULLSCREEN) {
         SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
         SDL_Rect bounds;
 
-        /* Fullscreen at window creation time is always fullscreen desktop */
-        flags &= ~SDL_WINDOW_FULLSCREEN_MASK;
-        flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
-
         SDL_GetDisplayBounds(display->id, &bounds);
         window->x = bounds.x;
         window->y = bounds.y;
@@ -1714,7 +1714,6 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint
     }
 
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
-    window->last_fullscreen_flags = window->flags;
     window->opacity = 1.0f;
     window->next = _this->windows;
     window->is_destroying = SDL_FALSE;
@@ -1810,7 +1809,6 @@ SDL_Window *SDL_CreateWindowFrom(const void *data)
     window->magic = &_this->window_magic;
     window->id = _this->next_object_id++;
     window->flags = flags;
-    window->last_fullscreen_flags = window->flags;
     window->is_destroying = SDL_FALSE;
     window->opacity = 1.0f;
     window->next = _this->windows;
@@ -1932,7 +1930,6 @@ int SDL_RecreateWindow(SDL_Window *window, Uint32 flags)
     }
 
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
-    window->last_fullscreen_flags = window->flags;
     window->is_destroying = SDL_FALSE;
 
     if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_FOREIGN)) {
@@ -2139,7 +2136,7 @@ void SDL_SetWindowPosition(SDL_Window *window, int x, int y)
         }
     }
 
-    if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
+    if ((window->flags & SDL_WINDOW_FULLSCREEN) != 0) {
         if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
             window->windowed.x = x;
         }
@@ -2165,7 +2162,7 @@ void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)
     CHECK_WINDOW_MAGIC(window, );
 
     /* Fullscreen windows are always at their display's origin */
-    if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) {
+    if ((window->flags & SDL_WINDOW_FULLSCREEN) != 0) {
         SDL_DisplayID displayID;
 
         if (x) {
@@ -2204,7 +2201,7 @@ void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)

(Patch may be truncated, please check the link at the top of this post.)