From 4a468739f832615dcc21f52e695659e5e93da2cb Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 21 May 2016 00:20:52 -0300 Subject: [PATCH] Removed Mac OS 10.5 support (bug #3137). Also fixed a warning about deprecated Carbon code when using SDL_audio (bug #3127, thanks Dominik!) --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 4 +- .../SDLTest/SDLTest.xcodeproj/project.pbxproj | 4 +- build-scripts/g++-fat.sh | 6 +- build-scripts/gcc-fat.sh | 6 +- include/SDL_platform.h | 6 +- src/audio/coreaudio/SDL_coreaudio.c | 23 +-- src/joystick/darwin/SDL_sysjoystick.c | 18 +- src/video/cocoa/SDL_cocoaclipboard.m | 14 +- src/video/cocoa/SDL_cocoaevents.m | 38 ++--- src/video/cocoa/SDL_cocoakeyboard.m | 15 +- src/video/cocoa/SDL_cocoamodes.h | 2 +- src/video/cocoa/SDL_cocoamodes.m | 156 ++++-------------- src/video/cocoa/SDL_cocoashape.m | 4 +- src/video/cocoa/SDL_cocoawindow.m | 71 ++------ 14 files changed, 85 insertions(+), 282 deletions(-) diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 9fc2a50190db9..9d685daf62baf 100755 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -2774,7 +2774,7 @@ GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_OPTIMIZATION_LEVEL = 3; GCC_SYMBOLS_PRIVATE_EXTERN = YES; - MACOSX_DEPLOYMENT_TARGET = 10.5; + MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = macosx; STRIP_STYLE = "non-global"; }; @@ -2832,7 +2832,7 @@ GCC_ENABLE_SSE3_EXTENSIONS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_SYMBOLS_PRIVATE_EXTERN = YES; - MACOSX_DEPLOYMENT_TARGET = 10.5; + MACOSX_DEPLOYMENT_TARGET = 10.6; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; STRIP_INSTALLED_PRODUCT = NO; diff --git a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj index 59cdd631b8993..144d24ca5e8a6 100755 --- a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj +++ b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj @@ -3934,7 +3934,7 @@ ); GCC_OPTIMIZATION_LEVEL = 0; HEADER_SEARCH_PATHS = ../../include; - MACOSX_DEPLOYMENT_TARGET = 10.5; + MACOSX_DEPLOYMENT_TARGET = 10.6; }; name = Debug; }; @@ -4060,7 +4060,7 @@ ); GCC_GENERATE_DEBUGGING_SYMBOLS = NO; HEADER_SEARCH_PATHS = ../../include; - MACOSX_DEPLOYMENT_TARGET = 10.5; + MACOSX_DEPLOYMENT_TARGET = 10.6; }; name = Release; }; diff --git a/build-scripts/g++-fat.sh b/build-scripts/g++-fat.sh index 29b04302faeaf..0dbe990394b5b 100755 --- a/build-scripts/g++-fat.sh +++ b/build-scripts/g++-fat.sh @@ -6,11 +6,11 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" -# Intel 32-bit compiler flags (10.5 runtime compatibility) -GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.5 \ +# Intel 32-bit compiler flags (10.6 runtime compatibility) +GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.6 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.5" +GCC_LINK_X86="-mmacosx-version-min=10.6" # Intel 64-bit compiler flags (10.6 runtime compatibility) GCC_COMPILE_X64="g++ -arch x86_64 -mmacosx-version-min=10.6 \ diff --git a/build-scripts/gcc-fat.sh b/build-scripts/gcc-fat.sh index e556c1dd1378e..bfc72b87a6cc3 100755 --- a/build-scripts/gcc-fat.sh +++ b/build-scripts/gcc-fat.sh @@ -6,11 +6,11 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" -# Intel 32-bit compiler flags (10.5 runtime compatibility) -GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.5 \ +# Intel 32-bit compiler flags (10.6 runtime compatibility) +GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.5" +GCC_LINK_X86="-mmacosx-version-min=10.6" # Intel 64-bit compiler flags (10.6 runtime compatibility) GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \ diff --git a/include/SDL_platform.h b/include/SDL_platform.h index c6c21398b235c..974cafc0723b6 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -79,9 +79,9 @@ /* if not compiling for iPhone */ #undef __MACOSX__ #define __MACOSX__ 1 -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -# error SDL for Mac OS X only supports deploying on 10.5 and above. -#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */ +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 +# error SDL for Mac OS X only supports deploying on 10.6 and above. +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */ #endif /* TARGET_OS_IPHONE */ #endif /* defined(__APPLE__) */ diff --git a/src/audio/coreaudio/SDL_coreaudio.c b/src/audio/coreaudio/SDL_coreaudio.c index 46b617dc063bb..3641d530c7464 100644 --- a/src/audio/coreaudio/SDL_coreaudio.c +++ b/src/audio/coreaudio/SDL_coreaudio.c @@ -406,13 +406,7 @@ COREAUDIO_CloseDevice(_THIS) AudioUnitSetProperty(this->hidden->audioUnit, kAudioUnitProperty_SetRenderCallback, scope, bus, &callback, sizeof(callback)); - - #if MACOSX_COREAUDIO - CloseComponent(this->hidden->audioUnit); - #else AudioComponentInstanceDispose(this->hidden->audioUnit); - #endif - this->hidden->audioUnitOpened = 0; } SDL_free(this->hidden->buffer); @@ -482,13 +476,8 @@ prepare_audiounit(_THIS, void *handle, int iscapture, { OSStatus result = noErr; AURenderCallbackStruct callback; -#if MACOSX_COREAUDIO - ComponentDescription desc; - Component comp = NULL; -#else AudioComponentDescription desc; AudioComponent comp = NULL; -#endif const AudioUnitElement output_bus = 0; const AudioUnitElement input_bus = 1; const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); @@ -507,11 +496,10 @@ prepare_audiounit(_THIS, void *handle, int iscapture, #if MACOSX_COREAUDIO desc.componentSubType = kAudioUnitSubType_DefaultOutput; - comp = FindNextComponent(NULL, &desc); #else desc.componentSubType = kAudioUnitSubType_RemoteIO; - comp = AudioComponentFindNext(NULL, &desc); #endif + comp = AudioComponentFindNext(NULL, &desc); if (comp == NULL) { SDL_SetError("Couldn't find requested CoreAudio component"); @@ -519,17 +507,8 @@ prepare_audiounit(_THIS, void *handle, int iscapture, } /* Open & initialize the audio unit */ -#if MACOSX_COREAUDIO - result = OpenAComponent(comp, &this->hidden->audioUnit); - CHECK_RESULT("OpenAComponent"); -#else - /* - AudioComponentInstanceNew only available on iPhone OS 2.0 and Mac OS X 10.6 - We can't use OpenAComponent on iPhone because it is not present - */ result = AudioComponentInstanceNew(comp, &this->hidden->audioUnit); CHECK_RESULT("AudioComponentInstanceNew"); -#endif this->hidden->audioUnitOpened = 1; diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 6dd306aa8ee27..65cd2fca0bc32 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -422,6 +422,7 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic { recDevice *device; int device_index = 0; + io_service_t ioservice; if (res != kIOReturnSuccess) { return; @@ -451,20 +452,11 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic device->instance_id = ++s_joystick_instance_id; /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */ - -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (IOHIDDeviceGetService != NULL) { /* weak reference: available in 10.6 and later. */ -#endif - - const io_service_t ioservice = IOHIDDeviceGetService(ioHIDDeviceObject); + ioservice = IOHIDDeviceGetService(ioHIDDeviceObject); #if SDL_HAPTIC_IOKIT - if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) { - device->ffservice = ioservice; - MacHaptic_MaybeAddDevice(ioservice); - } -#endif - -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) { + device->ffservice = ioservice; + MacHaptic_MaybeAddDevice(ioservice); } #endif diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index 015d771065655..f97dd28275f70 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -25,23 +25,13 @@ #include "SDL_cocoavideo.h" #include "../../events/SDL_clipboardevents_c.h" -static NSString * -GetTextFormat(_THIS) -{ - if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { - return NSPasteboardTypeString; - } else { - return NSStringPboardType; - } -} - int Cocoa_SetClipboardText(_THIS, const char *text) { @autoreleasepool { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; NSPasteboard *pasteboard; - NSString *format = GetTextFormat(_this); + NSString *format = NSPasteboardTypeString; pasteboard = [NSPasteboard generalPasteboard]; data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; @@ -55,7 +45,7 @@ { @autoreleasepool { NSPasteboard *pasteboard; - NSString *format = GetTextFormat(_this); + NSString *format = NSPasteboardTypeString; NSString *available; char *text; diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index c0916fe851c85..a6c974597afd4 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -114,28 +114,23 @@ - (void)windowWillClose:(NSNotification *)notification; */ for (NSWindow *window in [NSApp orderedWindows]) { if (window != win && [window canBecomeKeyWindow]) { - if ([window respondsToSelector:@selector(isOnActiveSpace)]) { - if (![window isOnActiveSpace]) { - continue; - } + if (![window isOnActiveSpace]) { + continue; } [window makeKeyAndOrderFront:self]; return; } } - /* If a window wasn't found above, iterate through all visible windows - * (including the 'About' window, if it's shown) and make the first one key. - * Note that +[NSWindow windowNumbersWithOptions:] was added in 10.6. + /* If a window wasn't found above, iterate through all visible windows in + * the active Space in z-order (including the 'About' window, if it's shown) + * and make the first one key. */ - if ([NSWindow respondsToSelector:@selector(windowNumbersWithOptions:)]) { - /* Get all visible windows in the active Space, in z-order. */ - for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) { - NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]]; - if (window && window != win && [window canBecomeKeyWindow]) { - [window makeKeyAndOrderFront:self]; - return; - } + for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) { + NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]]; + if (window && window != win && [window canBecomeKeyWindow]) { + [window makeKeyAndOrderFront:self]; + return; } } } @@ -291,7 +286,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam /* Add the fullscreen view toggle menu option, if supported */ - if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) { + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) { /* Create the view menu */ viewMenu = [[NSMenu alloc] initWithTitle:@"View"]; @@ -321,16 +316,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam const char *hint = SDL_GetHint(SDL_HINT_MAC_BACKGROUND_APP); if (!hint || *hint == '0') { -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 - if ([NSApp respondsToSelector:@selector(setActivationPolicy:)]) { -#endif - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 - } else { - ProcessSerialNumber psn = {0, kCurrentProcess}; - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - } -#endif + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp activateIgnoringOtherApps:YES]; } diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 7f1d2308f34c0..8c6f177d304e7 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -69,14 +69,6 @@ - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange SDL_SendKeyboardText(str); } -- (void)insertText:(id)insertString -{ - /* This method is part of NSTextInput and not NSTextInputClient, but - * apparently it still might be called in OS X 10.5 and can cause beeps if - * the implementation is missing: http://crbug.com/47890 */ - [self insertText:insertString replacementRange:NSMakeRange(0, 0)]; -} - - (void)doCommandBySelector:(SEL)myselector { /* No need to do anything since we are not using Cocoa @@ -498,11 +490,8 @@ - (NSArray *)validAttributesForMarkedText SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option"); SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command"); - /* On pre-10.6, you might have the initial capslock key state wrong. */ - if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) { - data->modifierFlags = [NSEvent modifierFlags]; - SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0); - } + data->modifierFlags = [NSEvent modifierFlags]; + SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0); } void diff --git a/src/video/cocoa/SDL_cocoamodes.h b/src/video/cocoa/SDL_cocoamodes.h index 13a9620abe472..ce8601cbab842 100644 --- a/src/video/cocoa/SDL_cocoamodes.h +++ b/src/video/cocoa/SDL_cocoamodes.h @@ -30,7 +30,7 @@ typedef struct typedef struct { - const void *moderef; + CGDisplayModeRef moderef; } SDL_DisplayModeData; extern void Cocoa_InitModes(_THIS); diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 2fa619d12a10e..6d29c6be51051 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -56,25 +56,6 @@ #endif } - -/* !!! FIXME: clean out the pre-10.6 code when it makes sense to do so. */ -#define FORCE_OLD_API 0 - -#if FORCE_OLD_API -#undef MAC_OS_X_VERSION_MIN_REQUIRED -#define MAC_OS_X_VERSION_MIN_REQUIRED 1050 -#endif - -static BOOL -IS_SNOW_LEOPARD_OR_LATER() -{ -#if FORCE_OLD_API - return NO; -#else - return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5; -#endif -} - static int CG_SetError(const char *prefix, CGDisplayErr result) { @@ -119,59 +100,40 @@ } static SDL_bool -GetDisplayMode(_THIS, const void *moderef, CVDisplayLinkRef link, SDL_DisplayMode *mode) +GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CVDisplayLinkRef link, SDL_DisplayMode *mode) { SDL_DisplayModeData *data; long width = 0; long height = 0; long bpp = 0; long refreshRate = 0; + CFStringRef fmt; data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { return SDL_FALSE; } - data->moderef = moderef; - - if (IS_SNOW_LEOPARD_OR_LATER()) { - CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef; - CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode); - width = (long) CGDisplayModeGetWidth(vidmode); - height = (long) CGDisplayModeGetHeight(vidmode); - refreshRate = (long) (CGDisplayModeGetRefreshRate(vidmode) + 0.5); - - if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels), - kCFCompareCaseInsensitive) == kCFCompareEqualTo) { - bpp = 32; - } else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels), - kCFCompareCaseInsensitive) == kCFCompareEqualTo) { - bpp = 16; - } else if (CFStringCompare(fmt, CFSTR(kIO30BitDirectPixels), - kCFCompareCaseInsensitive) == kCFCompareEqualTo) { - bpp = 30; - } else { - bpp = 0; /* ignore 8-bit and such for now. */ - } - - CFRelease(fmt); + data->moderef = vidmode; + + fmt = CGDisplayModeCopyPixelEncoding(vidmode); + width = (long) CGDisplayModeGetWidth(vidmode); + height = (long) CGDisplayModeGetHeight(vidmode); + refreshRate = (long) (CGDisplayModeGetRefreshRate(vidmode) + 0.5); + + if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + bpp = 32; + } else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + bpp = 16; + } else if (CFStringCompare(fmt, CFSTR(kIO30BitDirectPixels), + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + bpp = 30; + } else { + bpp = 0; /* ignore 8-bit and such for now. */ } - #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER()) { - CFNumberRef number; - double refresh; - CFDictionaryRef vidmode = (CFDictionaryRef) moderef; - number = CFDictionaryGetValue(vidmode, kCGDisplayWidth); - CFNumberGetValue(number, kCFNumberLongType, &width); - number = CFDictionaryGetValue(vidmode, kCGDisplayHeight); - CFNumberGetValue(number, kCFNumberLongType, &height); - number = CFDictionaryGetValue(vidmode, kCGDisplayBitsPerPixel); - CFNumberGetValue(number, kCFNumberLongType, &bpp); - number = CFDictionaryGetValue(vidmode, kCGDisplayRefreshRate); - CFNumberGetValue(number, kCFNumberDoubleType, &refresh); - refreshRate = (long) (refresh + 0.5); - } - #endif + CFRelease(fmt); /* CGDisplayModeGetRefreshRate returns 0 for many non-CRT displays. */ if (refreshRate == 0 && link != NULL) { @@ -204,22 +166,6 @@ return SDL_TRUE; } -static void -Cocoa_ReleaseDisplayMode(_THIS, const void *moderef) -{ - if (IS_SNOW_LEOPARD_OR_LATER()) { - CGDisplayModeRelease((CGDisplayModeRef) moderef); /* NULL is ok */ - } -} - -static void -Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist) -{ - if (IS_SNOW_LEOPARD_OR_LATER()) { - CFRelease(modelist); /* NULL is ok */ - } -} - static const char * Cocoa_GetDisplayName(CGDirectDisplayID displayID) { @@ -262,7 +208,7 @@ SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; - const void *moderef = NULL; + CGDisplayModeRef moderef = NULL; CVDisplayLinkRef link = NULL; if (pass == 0) { @@ -279,15 +225,7 @@ continue; } - if (IS_SNOW_LEOPARD_OR_LATER()) { - moderef = CGDisplayCopyDisplayMode(displays[i]); - } - - #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER()) { - moderef = CGDisplayCurrentMode(displays[i]); - } - #endif + moderef = CGDisplayCopyDisplayMode(displays[i]); if (!moderef) { continue; @@ -295,7 +233,7 @@ displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); if (!displaydata) { - Cocoa_ReleaseDisplayMode(_this, moderef); + CGDisplayModeRelease(moderef); continue; } displaydata->display = displays[i]; @@ -307,7 +245,7 @@ display.name = (char *)Cocoa_GetDisplayName(displays[i]); if (!GetDisplayMode(_this, moderef, link, &mode)) { CVDisplayLinkRelease(link); - Cocoa_ReleaseDisplayMode(_this, moderef); + CGDisplayModeRelease(moderef); SDL_free(display.name); SDL_free(displaydata); continue; @@ -396,17 +334,7 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display) { SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; - CFArrayRef modes = NULL; - - if (IS_SNOW_LEOPARD_OR_LATER()) { - modes = CGDisplayCopyAllDisplayModes(data->display, NULL); - } - - #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER()) { - modes = CGDisplayAvailableModes(data->display); - } - #endif + CFArrayRef modes = CGDisplayCopyAllDisplayModes(data->display, NULL); if (modes) { CVDisplayLinkRef link = NULL; @@ -416,37 +344,19 @@ CVDisplayLinkCreateWithCGDisplay(data->display, &link); for (i = 0; i < count; i++) { - const void *moderef = CFArrayGetValueAtIndex(modes, i); + CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); SDL_DisplayMode mode; if (GetDisplayMode(_this, moderef, link, &mode)) { - if (IS_SNOW_LEOPARD_OR_LATER()) { - CGDisplayModeRetain((CGDisplayModeRef) moderef); - } + CGDisplayModeRetain(moderef); SDL_AddDisplayMode(display, &mode); } } CVDisplayLinkRelease(link); - Cocoa_ReleaseDisplayModeList(_this, modes); + CFRelease(modes); } } -static CGError -Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode) -{ - if (IS_SNOW_LEOPARD_OR_LATER()) { - return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL); - } - - #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER()) { - return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode); - } - #endif - - return kCGErrorFailure; -} - int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) { @@ -462,7 +372,7 @@ if (data == display->desktop_mode.driverdata) { /* Restoring desktop mode */ - Cocoa_SwitchMode(_this, displaydata->display, data->moderef); + CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL); if (CGDisplayIsMain(displaydata->display)) { CGReleaseAllDisplays(); @@ -487,7 +397,7 @@ } /* Do the physical switch */ - result = Cocoa_SwitchMode(_this, displaydata->display, data->moderef); + result = CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL); if (result != kCGErrorSuccess) { CG_SetError("CGDisplaySwitchToMode()", result); goto ERR_NO_SWITCH; @@ -532,11 +442,11 @@ } mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata; - Cocoa_ReleaseDisplayMode(_this, mode->moderef); + CGDisplayModeRelease(mode->moderef); for (j = 0; j < display->num_display_modes; j++) { mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata; - Cocoa_ReleaseDisplayMode(_this, mode->moderef); + CGDisplayModeRelease(mode->moderef); } } diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index cd5d97b70ea96..fc8a2775c016b 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -35,9 +35,7 @@ SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; [windata->nswindow setOpaque:NO]; - if ([windata->nswindow respondsToSelector:@selector(setStyleMask:)]) { - [windata->nswindow setStyleMask:NSBorderlessWindowMask]; - } + [windata->nswindow setStyleMask:NSBorderlessWindowMask]; SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper)); result->window = window; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 4435d8dd0193c..e98eebc74c65b 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -138,10 +138,7 @@ - (BOOL)performDragOperation:(id )sender NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease]; NSNumber *isAlias = nil; - /* Functionality for resolving URL aliases was added with OS X 10.6. */ - if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) { - [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil]; - } + [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil]; /* If the URL is an alias, resolve it. */ if ([isAlias boolValue]) { @@ -218,10 +215,10 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) return hint != NULL && *hint != '0'; } -static unsigned int +static NSUInteger GetWindowStyle(SDL_Window * window) { - unsigned int style; + NSUInteger style = 0; if (window->flags & SDL_WINDOW_FULLSCREEN) { style = NSBorderlessWindowMask; @@ -239,21 +236,17 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) } static SDL_bool -SetWindowStyle(SDL_Window * window, unsigned int style) +SetWindowStyle(SDL_Window * window, NSUInteger style) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = data->nswindow; - if (![nswindow respondsToSelector: @selector(setStyleMask:)]) { - return SDL_FALSE; - } - /* The view responder chain gets messed with during setStyleMask */ if ([[nswindow contentView] nextResponder] == data->listener) { [[nswindow contentView] setNextResponder:nil]; } - [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style]; + [nswindow setStyleMask:style]; /* The view responder chain gets messed with during setStyleMask */ if ([[nswindow contentView] nextResponder] != data->listener) { @@ -317,9 +310,7 @@ - (void)listen:(SDL_WindowData *)data [view setNextResponder:self]; - if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) { - [view setAcceptsTouchEvents:YES]; - } + [view setAcceptsTouchEvents:YES]; } - (void)observeValueForKeyPath:(NSString *)keyPath @@ -604,12 +595,9 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification [NSMenu setMenuBarVisible:NO]; } - /* On pre-10.6, you might have the capslock key state wrong now because we can't check here. */ - if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) { - const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask; - _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags; - SDL_ToggleModState(KMOD_CAPS, newflags != 0); - } + const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask; + _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags; + SDL_ToggleModState(KMOD_CAPS, newflags != 0); } - (void)windowDidResignKey:(NSNotification *)aNotification @@ -1483,27 +1471,6 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent } }} -static NSWindow * -Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style) -{ - if (!data->created) { - /* Don't mess with other people's windows... */ - return nswindow; - } - - [data->listener close]; - data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]]; - [data->nswindow setContentView:[nswindow contentView]]; - [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]]; - /* See comment in SetupWindowData. */ - [data->nswindow setOneShot:NO]; - [data->listener listen:data]; - - [nswindow close]; - - return data->nswindow; -} - void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) { @autoreleasepool @@ -1545,11 +1512,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent rect.origin.y += (screenRect.size.height - rect.size.height); } - if ([nswindow respondsToSelector: @selector(setStyleMask:)]) { - [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask]; - } else { - nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask); - } + [nswindow setStyleMask:NSBorderlessWindowMask]; } else { rect.origin.x = window->windowed.x; rect.origin.y = window->windowed.y; @@ -1557,16 +1520,12 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent rect.size.height = window->windowed.h; ConvertNSRect([nswindow screen], fullscreen, &rect); - if ([nswindow respondsToSelector: @selector(setStyleMask:)]) { - [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)]; + [nswindow setStyleMask:GetWindowStyle(window)]; - /* Hack to restore window decorations on Mac OS X 10.10 */ - NSRect frameRect = [nswindow frame]; - [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO]; - [nswindow setFrame:frameRect display:NO]; - } else { - nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window)); - } + /* Hack to restore window decorations on Mac OS X 10.10 */ + NSRect frameRect = [nswindow frame]; + [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO]; + [nswindow setFrame:frameRect display:NO]; } /* The view responder chain gets messed with during setStyleMask */