Skip to content

SDL2: compatibility fixes for macOS < 10.15 #11827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/audio/coreaudio/SDL_coreaudio.m
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,25 @@ static int prepare_audioqueue(_THIS)
// L R C LFE Ls Rs
layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_12;
break;
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || \
(defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101500)
case 7:
// L R C LFE Cs Ls Rs
layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_6_1;
if (@available(macOS 10.15, iOS 13, *)) {
layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_6_1;
} else {
return SDL_SetError("Unsupported audio channels");
}
break;
case 8:
// L R C LFE Rls Rrs Ls Rs
layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_7_1;
if (@available(macOS 10.15, iOS 13, *)) {
layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_7_1;
} else {
return SDL_SetError("Unsupported audio channels");
}
break;
#endif
default:
return SDL_SetError("Unsupported audio channels");
}
Expand Down
21 changes: 20 additions & 1 deletion src/video/cocoa/SDL_cocoamessagebox.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoawindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef enum
/* Window delegate functionality */
-(BOOL) windowShouldClose:(id) sender;
-(void) windowDidExpose:(NSNotification *) aNotification;
-(void) onLiveResizeTimerFire:(id) sender;
-(void) windowWillStartLiveResize:(NSNotification *)aNotification;
-(void) windowDidEndLiveResize:(NSNotification *)aNotification;
-(void) windowDidMove:(NSNotification *) aNotification;
Expand Down
20 changes: 15 additions & 5 deletions src/video/cocoa/SDL_cocoawindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,26 @@ - (void)windowDidExpose:(NSNotification *)aNotification
SDL_SendWindowEvent(_data.window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}

- (void)onLiveResizeTimerFire:(id)sender
{
SDL_OnWindowLiveResizeUpdate(_data.window);
}

- (void)windowWillStartLiveResize:(NSNotification *)aNotification
{
// We'll try to maintain 60 FPS during live resizing
const NSTimeInterval interval = 1.0 / 60.0;

NSMethodSignature *invocationSig = [Cocoa_WindowListener
instanceMethodSignatureForSelector:@selector(onLiveResizeTimerFire:)];
NSInvocation *invocation = [NSInvocation
invocationWithMethodSignature:invocationSig];
[invocation setTarget:self];
[invocation setSelector:@selector(onLiveResizeTimerFire:)];

liveResizeTimer = [NSTimer scheduledTimerWithTimeInterval:interval
repeats:TRUE
block:^(NSTimer *unusedTimer)
{
SDL_OnWindowLiveResizeUpdate(_data.window);
}];
invocation:invocation
repeats:TRUE];

[[NSRunLoop currentRunLoop] addTimer:liveResizeTimer forMode:NSRunLoopCommonModes];
}
Expand Down
Loading