sdl2-compat: Use the window's current display to select the mode

From f46abc51ba1f55ea50ad1f2da9480a21c4efb83c Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Sun, 31 Mar 2024 00:51:40 -0500
Subject: [PATCH] Use the window's current display to select the mode

We were always using the primary display before.
---
 src/sdl2_compat.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 6e42d5c..431abc2 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -5733,10 +5733,16 @@ ApplyFullscreenMode(SDL_Window *window)
     } else {
         int count = 0;
         const SDL_DisplayMode **list;
+        SDL_DisplayID displayID;
         int ret;
 
+        displayID = SDL3_GetDisplayForWindow(window);
+        if (!displayID) {
+            displayID = SDL3_GetPrimaryDisplay();
+        }
+
         /* FIXME: at least set a valid fullscreen mode */
-        list = SDL3_GetFullscreenDisplayModes(SDL3_GetPrimaryDisplay(), &count);
+        list = SDL3_GetFullscreenDisplayModes(displayID, &count);
         if (list && count) {
             ret = SDL3_SetWindowFullscreenMode(window, list[0]);
         } else {
@@ -5766,9 +5772,14 @@ SDL_GetWindowDisplayMode(SDL_Window *window, SDL2_DisplayMode *mode)
     if (dp) {
         DisplayMode_3to2(dp, mode);
     } else {
+        SDL_DisplayID displayID = SDL3_GetDisplayForWindow(window);
+        if (!displayID) {
+            displayID = SDL3_GetPrimaryDisplay();
+        }
+
         /* Desktop mode */
         /* FIXME: is this correct ? */
-        dp = SDL3_GetDesktopDisplayMode(SDL3_GetPrimaryDisplay());
+        dp = SDL3_GetDesktopDisplayMode(displayID);
         if (dp == NULL) {
             return -1;
         }