SDL: kmsdrm: honor mode previously set by SDL_SetWindowDisplayMode when enabling fullscreen

From 0219928dd5416be9dfb21217c36f4d1b794e4b80 Mon Sep 17 00:00:00 2001
From: Anthony Pesch <[EMAIL REDACTED]>
Date: Sun, 23 May 2021 16:06:40 -0400
Subject: [PATCH] kmsdrm: honor mode previously set by SDL_SetWindowDisplayMode
 when enabling fullscreen and remove duplicate SDL_WINDOWEVENT_RESIZED event

commit 2067a7db8e4a36ba40ab34a55b3166ca28638a60 made SDL_SetWindowSize and
SDL_SetWindowFullscreen modify the display mode previously set by a call to
SDL_SetWindowDisplayMode

as far as I understand the SDL API, calling SDL_SetWindowDisplayMode followed
by calling SDL_SetWindowFullscreen(..., SDL_WINDOW_FULLSCREEN) is the correct
way to mode set / switch to fullscreen

this change restores that functionaliy when switching to SDL_WINDOW_FULLSCREEN,
but other cases are still modifying the display mode set by the user. rather
than modifying the display mode set by the user, it seems this logic inside of
KMSDRM_ReconfigureWindow should be pushed further down into KMSDRM_CreateSurfaces
(as it was originally) to only modify the final mode that's set (based on the
fullscreen flags), but not override the mode requested by the user
---
 src/video/kmsdrm/SDL_kmsdrmvideo.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 6f23e9280..9704d0e4f 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -1312,29 +1312,23 @@ KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window)
 {
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *dispdata = display->driverdata;
-    uint32_t refresh_rate = 0;
 
-    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) ==
-                         SDL_WINDOW_FULLSCREEN_DESKTOP)
+    if ((window->flags & SDL_WINDOW_FULLSCREEN) ==
+                         SDL_WINDOW_FULLSCREEN)
+    {
+        /* Nothing to do, honor the most recent mode requested by the user */
+    }
+    else if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) ==
+                              SDL_WINDOW_FULLSCREEN_DESKTOP)
     {
-
         /* Update the current mode to the desktop mode. */
         dispdata->mode = dispdata->original_mode;
-
     } else {
-
         drmModeModeInfo *mode;
 
-        /* Refresh rate is only important for fullscreen windows. */
-        if ((window->flags & SDL_WINDOW_FULLSCREEN) ==
-                             SDL_WINDOW_FULLSCREEN)
-        {
-            refresh_rate = (uint32_t)window->fullscreen_mode.refresh_rate;
-        }
-
         /* Try to find a valid video mode matching the size of the window. */
         mode = KMSDRM_GetClosestDisplayMode(display,
-          window->windowed.w, window->windowed.h, refresh_rate );
+          window->windowed.w, window->windowed.h, 0);
 
         if (mode) {
             /* If matching mode found, recreate the GBM surface with the size
@@ -1346,11 +1340,6 @@ KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window)
                and setup that mode on the CRTC. */
             dispdata->mode = dispdata->original_mode;
         }
-
-        /* Tell app about the size we have determined for the window,
-           so SDL pre-scales to that size for us. */
-        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
-                            dispdata->mode.hdisplay, dispdata->mode.vdisplay);
     }
 
     /* Recreate the GBM (and EGL) surfaces, and mark the CRTC mode/fb setting