SDL: macOS: get the correct display name on macOS 10.15+

From ba95c54f9983f143623ae8b3d022556b3723cc59 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 18 Jan 2025 09:38:15 -0800
Subject: [PATCH] macOS: get the correct display name on macOS 10.15+

---
 src/video/cocoa/SDL_cocoamodes.m | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index 4fd245a21f683..7de75729c1746 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -283,6 +283,16 @@ static bool GetDisplayMode(CGDisplayModeRef vidmode, bool vidmodeCurrent, CFArra
 
 static char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
 {
+    if (@available(macOS 10.15, *)) {
+        NSScreen *screen = GetNSScreenForDisplayID(displayID);
+        if (screen) {
+            const char *name = [screen.localizedName UTF8String];
+            if (name) {
+                return SDL_strdup(name);
+            }
+        }
+    }
+
     // This API is deprecated in 10.9 with no good replacement (as of 10.15).
     io_service_t servicePort = CGDisplayIOServicePort(displayID);
     CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);