SDL: Fix For issue #6948 (#6991) (dfc56)

From dfc56cfc0eae8e09d9da401483655d4e171b6080 Mon Sep 17 00:00:00 2001
From: Matt Durgavich <[EMAIL REDACTED]>
Date: Thu, 5 Jan 2023 11:54:27 -0500
Subject: [PATCH] Fix For issue #6948 (#6991)

MessageBoxes attached to a window in macOS should use modal APIs and not
use a poll/sleep pattern on the main thread. Sleeping the main thread
makes the NSWindow message loop sluggish and interferes with external
applications that need to send messages to that window, such as
VoiceOver.
---
 src/video/cocoa/SDL_cocoamessagebox.m | 32 +++++----------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m
index 2de717adb435..a8d8943a6421 100644
--- a/src/video/cocoa/SDL_cocoamessagebox.m
+++ b/src/video/cocoa/SDL_cocoamessagebox.m
@@ -32,8 +32,7 @@ @interface SDLMessageBoxPresenter : NSObject {
     NSInteger clicked;
     NSWindow *nswindow;
 }
-- (id) initWithParentWindow:(SDL_Window *)window;
-- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+- (id)initWithParentWindow:(SDL_Window *)window;
 @end
 
 @implementation SDLMessageBoxPresenter
@@ -57,35 +56,16 @@ - (id) initWithParentWindow:(SDL_Window *)window
 - (void)showAlert:(NSAlert*)alert
 {
     if (nswindow) {
-#ifdef MAC_OS_X_VERSION_10_9
-        if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
-            [alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
-                self->clicked = returnCode;
-            }];
-        } else
-#endif
-        {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
-            [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
-#endif
-        }
-
-        while (clicked < 0) {
-            SDL_PumpEvents();
-            SDL_Delay(100);
-        }
-
+        [alert beginSheetModalForWindow:nswindow
+                      completionHandler:^(NSModalResponse returnCode) {
+                        [NSApp stopModalWithCode:returnCode];
+                      }];
+        clicked = [NSApp runModalForWindow:nswindow];
         nswindow = nil;
     } else {
         clicked = [alert runModal];
     }
 }
-
-- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
-{
-    clicked = returnCode;
-}
-
 @end