sdl2-compat: Check the fullscreen display property when entering fullscreen

https://github.com/libsdl-org/sdl2-compat/commit/46ddd90a9c7fe4129ff71e103917adb39243b9a0

From 46ddd90a9c7fe4129ff71e103917adb39243b9a0 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 30 Apr 2025 11:17:17 -0400
Subject: [PATCH] Check the fullscreen display property when entering
 fullscreen

Calling SDL3_GetDisplayForWindow supplies the display where the window currently is, but not necessarily the display on which the window should become fullscreen, particularly in cases where the backend can't actually reposition the window. SDL3 will store a better fullscreen display candidate in this property.
---
 src/sdl2_compat.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 061f2e7..dee9ea7 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -8468,15 +8468,22 @@ SDL_GetDesktopDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 #define PROP_WINDOW_FULLSCREEN_MODE "sdl2-compat.window.fullscreen-mode"
 #define PROP_WINDOW_FULLSCREEN_RESIZE_W "sdl2-compat.window.fullscreen_resize_w"
 #define PROP_WINDOW_FULLSCREEN_RESIZE_H "sdl2-compat.window.fullscreen_resize_h"
+#define PROP_WINDOW_FULLSCREEN_DISPLAY "sdl2-compat.window.preferred_fullscreen_display"
 
 static int ApplyFullscreenMode(SDL_Window *window)
 {
     /* Always try to enter fullscreen on the current display */
-    const SDL_DisplayID displayID = SDL3_GetDisplayForWindow(window);
+    SDL_DisplayID displayID = SDL3_GetDisplayForWindow(window);
     const SDL_PropertiesID window_props = SDL3_GetWindowProperties(window);
     SDL2_DisplayMode *property = (SDL2_DisplayMode *)SDL3_GetPointerProperty(window_props, PROP_WINDOW_FULLSCREEN_MODE, NULL);
     SDL_DisplayMode mode;
 
+    /* Calling SDL3_GetDisplayForWindow supplies the display where the window currently is, but not necessarily
+     * the display on which the window should become fullscreen, particularly in cases where the backend can't
+     * actually reposition the window. This must only be queried *after* calling SDL3_GetDisplayForWindow().
+     */
+    displayID = SDL3_GetNumberProperty(window_props, PROP_WINDOW_FULLSCREEN_DISPLAY, displayID);
+
     SDL3_zero(mode);
     if (property) {
         mode.w = property->w;