SDL: video: Select the closest mode for the target refresh rate accounting for small variations

From 4187c6c08c2f0a6c84ea274c95c10ac7fdc5147a Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 12 Feb 2023 15:48:59 -0500
Subject: [PATCH] video: Select the closest mode for the target refresh rate
 accounting for small variations

Use the delta of the target refresh rate and the refresh rate of the mode to select the closest matching display mode, as the actual closest mode may have a slightly lower rate than the target by a small fraction of a hz (e.g 59.98 vs 60.0).
---
 src/video/SDL_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index a1a60a939f5a..0353118d3ea3 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1055,8 +1055,8 @@ const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID display
                     continue;
                 }
 
-                if (mode->refresh_rate < refresh_rate) {
-                    /* We already found a mode and the new mode doesn't meet our
+                if (SDL_fabsf(closest->refresh_rate - refresh_rate) < SDL_fabsf(mode->refresh_rate - refresh_rate)) {
+                    /* We already found a mode and the new mode is further from our
                      * refresh rate target */
                     continue;
                 }