Browse Source

video: Store the preferred fullscreen display in a property for sdl2-compat

sdl2-compat will call SDL_GetDisplayForWindow() when querying the display to use for fullscreen, which won't always be correct if the backend can't actually reposition the window. When calling this function, get the ideal fullscreen display and store it in a property for retrieval by sdl2-compat.

(cherry picked from commit c5d5967c3a435748733536e1061de76864eed214)
Frank Praznik 3 months ago
parent
commit
a96e72da02
1 changed files with 13 additions and 0 deletions
  1. 13 0
      src/video/SDL_video.c

+ 13 - 0
src/video/SDL_video.c

@@ -1731,12 +1731,25 @@ SDL_VideoDisplay *SDL_GetVideoDisplayForFullscreenWindow(SDL_Window *window)
     return SDL_GetVideoDisplay(displayID);
     return SDL_GetVideoDisplay(displayID);
 }
 }
 
 
+#define SDL_PROP_SDL2_COMPAT_WINDOW_PREFERRED_FULLSCREEN_DISPLAY "sdl2-compat.window.preferred_fullscreen_display"
+
 SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window)
 SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window)
 {
 {
     SDL_DisplayID displayID = 0;
     SDL_DisplayID displayID = 0;
 
 
     CHECK_WINDOW_MAGIC(window, 0);
     CHECK_WINDOW_MAGIC(window, 0);
 
 
+    /* sdl2-compat calls this function to get a display on which to make the window fullscreen,
+     * so pass it the preferred fullscreen display ID in a property.
+     */
+    SDL_PropertiesID window_props = SDL_GetWindowProperties(window);
+    SDL_VideoDisplay *fs_display = SDL_GetVideoDisplayForFullscreenWindow(window);
+    if (fs_display) {
+        SDL_SetNumberProperty(window_props, SDL_PROP_SDL2_COMPAT_WINDOW_PREFERRED_FULLSCREEN_DISPLAY, fs_display->id);
+    } else {
+        SDL_ClearProperty(window_props, SDL_PROP_SDL2_COMPAT_WINDOW_PREFERRED_FULLSCREEN_DISPLAY);
+    }
+
     // An explicit fullscreen display overrides all
     // An explicit fullscreen display overrides all
     if (window->flags & SDL_WINDOW_FULLSCREEN) {
     if (window->flags & SDL_WINDOW_FULLSCREEN) {
         displayID = window->current_fullscreen_mode.displayID;
         displayID = window->current_fullscreen_mode.displayID;