From a5c518bf7171f2f82239e6c3396337675f1d1b1c Mon Sep 17 00:00:00 2001
From: Joshua Root <[EMAIL REDACTED]>
Date: Fri, 3 Jan 2025 03:40:34 +1100
Subject: [PATCH] showAlert: legacy OS compatibility fix
(cherry picked from commit ed0eb7714a4d4abd0f6fcb67642f8c83b867eac1)
---
src/video/cocoa/SDL_cocoamessagebox.m | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m
index 90b0644a967e7..20eabe3eeece5 100644
--- a/src/video/cocoa/SDL_cocoamessagebox.m
+++ b/src/video/cocoa/SDL_cocoamessagebox.m
@@ -33,6 +33,9 @@ @interface SDLMessageBoxPresenter : NSObject {
NSWindow *nswindow;
}
- (id)initWithParentWindow:(SDL_Window *)window;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+#endif
@end
@implementation SDLMessageBoxPresenter
@@ -56,16 +59,32 @@ - (id) initWithParentWindow:(SDL_Window *)window
- (void)showAlert:(NSAlert*)alert
{
if (nswindow) {
- [alert beginSheetModalForWindow:nswindow
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
+ if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
+ [alert beginSheetModalForWindow:nswindow
completionHandler:^(NSModalResponse returnCode) {
[NSApp stopModalWithCode:returnCode];
}];
+ } else
+#endif
+ {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+ [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
+#endif
+ }
clicked = [NSApp runModalForWindow:nswindow];
nswindow = nil;
} else {
clicked = [alert runModal];
}
}
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ [NSApp stopModalWithCode:returnCode];
+}
+#endif
@end