From fc4e798d7986a3e492c340e37fe2080471daaae3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 7 Jul 2014 12:48:25 -0700 Subject: [PATCH] Fixed bug 2631 - Mac: minor code cleanup Alex Szpakowski Some minor changes to the Mac-specific backend code: - Fixed up some code style issues (mostly brace style inconsistencies). - Fixed a compiler warning in SDL_cocoaevents.m. - Removed some useless code now that the 10.7 SDK is required to build SDL. - Removed Gestalt(gestaltSystemVersion, ...) call and switched to NSAppKitVersionNumber for version checking code. Using Gestalt with gestaltSystemVersion will give 0x1090 in Mac OS 10.10+, and the whole Gestalt function was deprecated in Mac OS 10.8. --- src/file/cocoa/SDL_rwopsbundlesupport.m | 9 +-- src/haptic/darwin/SDL_syshaptic.c | 83 ++++++++++++------------- src/joystick/darwin/SDL_sysjoystick.c | 10 +-- src/video/cocoa/SDL_cocoaclipboard.m | 6 +- src/video/cocoa/SDL_cocoaevents.m | 30 +++------ src/video/cocoa/SDL_cocoakeyboard.m | 64 ++++++------------- src/video/cocoa/SDL_cocoamessagebox.m | 14 +---- src/video/cocoa/SDL_cocoamodes.m | 31 ++++----- src/video/cocoa/SDL_cocoamouse.m | 12 ++-- src/video/cocoa/SDL_cocoamousetap.m | 3 +- src/video/cocoa/SDL_cocoaopengl.m | 16 +---- src/video/cocoa/SDL_cocoashape.m | 12 ++-- src/video/cocoa/SDL_cocoavideo.h | 1 - src/video/cocoa/SDL_cocoavideo.m | 12 +--- src/video/cocoa/SDL_cocoawindow.h | 8 +-- src/video/cocoa/SDL_cocoawindow.m | 64 ++++++------------- 16 files changed, 134 insertions(+), 241 deletions(-) diff --git a/src/file/cocoa/SDL_rwopsbundlesupport.m b/src/file/cocoa/SDL_rwopsbundlesupport.m index 682bd74a9be98..f6a65a99a41ed 100644 --- a/src/file/cocoa/SDL_rwopsbundlesupport.m +++ b/src/file/cocoa/SDL_rwopsbundlesupport.m @@ -37,8 +37,7 @@ FILE* fp = NULL; /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */ - if(strcmp("r", mode) && strcmp("rb", mode)) - { + if(strcmp("r", mode) && strcmp("rb", mode)) { return fopen(file, mode); } @@ -51,12 +50,10 @@ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; - if([file_manager fileExistsAtPath:full_path_with_file_to_try]) - { + if([file_manager fileExistsAtPath:full_path_with_file_to_try]) { fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); } - else - { + else { fp = fopen(file, mode); } diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 81282d6fe1a8b..408b81a88b936 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -257,21 +257,18 @@ MacHaptic_MaybeAddDevice( io_object_t device ) kCFAllocatorDefault, kNilOptions); if ((result == KERN_SUCCESS) && hidProperties) { - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsagePageKey)); + refCF = CFDictionaryGetValue(hidProperties, + CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { - if (!CFNumberGetValue(refCF, kCFNumberLongType, - &item->usagePage)) - SDL_SetError - ("Haptic: Recieving device's usage page."); - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsageKey)); + if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usagePage)) { + SDL_SetError("Haptic: Recieving device's usage page."); + } + refCF = CFDictionaryGetValue(hidProperties, + CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) { - if (!CFNumberGetValue(refCF, kCFNumberLongType, - &item->usage)) + if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usage)) { SDL_SetError("Haptic: Recieving device's usage."); + } } } CFRelease(hidProperties); @@ -377,24 +374,21 @@ HIDGetDeviceProduct(io_service_t dev, char *name) /* Get product name */ - refCF = - CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); - if (!refCF) - refCF = - CFDictionaryGetValue(usbProperties, - CFSTR("USB Product Name")); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); + if (!refCF) { + refCF = CFDictionaryGetValue(usbProperties, + CFSTR("USB Product Name")); + } if (refCF) { if (!CFStringGetCString(refCF, name, 256, CFStringGetSystemEncoding())) { - return SDL_SetError - ("Haptic: CFStringGetCString error retrieving pDevice->product."); + return SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product."); } } CFRelease(usbProperties); } else { - return SDL_SetError - ("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties."); + return SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties."); } /* Release stuff. */ @@ -457,9 +451,9 @@ GetSupportedFeatures(SDL_Haptic * haptic) /* Check if supports gain. */ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN, &val, sizeof(val)); - if (ret == FF_OK) + if (ret == FF_OK) { supported |= SDL_HAPTIC_GAIN; - else if (ret != FFERR_UNSUPPORTED) { + } else if (ret != FFERR_UNSUPPORTED) { return SDL_SetError("Haptic: Unable to get if device supports gain: %s.", FFStrError(ret)); } @@ -467,9 +461,9 @@ GetSupportedFeatures(SDL_Haptic * haptic) /* Checks if supports autocenter. */ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, &val, sizeof(val)); - if (ret == FF_OK) + if (ret == FF_OK) { supported |= SDL_HAPTIC_AUTOCENTER; - else if (ret != FFERR_UNSUPPORTED) { + } else if (ret != FFERR_UNSUPPORTED) { return SDL_SetError ("Haptic: Unable to get if device supports autocenter: %s.", FFStrError(ret)); @@ -604,8 +598,9 @@ SDL_SYS_HapticMouse(void) int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) { - if (joystick->hwdata->ffservice != 0) + if (joystick->hwdata->ffservice != 0) { return SDL_TRUE; + } return SDL_FALSE; } @@ -617,8 +612,9 @@ int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device), - joystick->hwdata->ffservice)) + joystick->hwdata->ffservice)) { return 1; + } return 0; } @@ -739,18 +735,22 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) case SDL_HAPTIC_CARTESIAN: effect->dwFlags |= FFEFF_CARTESIAN; rglDir[0] = dir->dir[0]; - if (naxes > 1) + if (naxes > 1) { rglDir[1] = dir->dir[1]; - if (naxes > 2) + } + if (naxes > 2) { rglDir[2] = dir->dir[2]; + } return 0; case SDL_HAPTIC_SPHERICAL: effect->dwFlags |= FFEFF_SPHERICAL; rglDir[0] = dir->dir[0]; - if (naxes > 1) + if (naxes > 1) { rglDir[1] = dir->dir[1]; - if (naxes > 2) + } + if (naxes > 2) { rglDir[2] = dir->dir[2]; + } return 0; default: @@ -767,8 +767,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) * Creates the FFEFFECT from a SDL_HapticEffect. */ static int -SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, - SDL_HapticEffect * src) +SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src) { int i; FFCONSTANTFORCE *constant; @@ -1269,8 +1268,7 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { HRESULT ret; - ret = - FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref); + ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref); if (ret != FF_OK) { SDL_SetError("Haptic: Error removing the effect from the device: %s.", FFStrError(ret)); @@ -1299,8 +1297,9 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, return -1; } - if (status == 0) + if (status == 0) { return SDL_FALSE; + } return SDL_TRUE; /* Assume it's playing or emulated. */ } @@ -1315,9 +1314,8 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) Uint32 val; val = gain * 100; /* Mac OS X uses 0 to 10,000 */ - ret = - FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, - FFPROP_FFGAIN, &val); + ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, + FFPROP_FFGAIN, &val); if (ret != FF_OK) { return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); } @@ -1336,10 +1334,11 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) Uint32 val; /* Mac OS X only has 0 (off) and 1 (on) */ - if (autocenter == 0) + if (autocenter == 0) { val = 0; - else + } else { val = 1; + } ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_AUTOCENTER, &val); diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 12c104820383e..f0bd5b8d14bb0 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -406,17 +406,13 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic s_bDeviceAdded = SDL_TRUE; /* Add device to the end of the list */ - if ( !gpDeviceList ) - { + if ( !gpDeviceList ) { gpDeviceList = device; - } - else - { + } else { recDevice *curdevice; curdevice = gpDeviceList; - while ( curdevice->pNext ) - { + while ( curdevice->pNext ) { curdevice = curdevice->pNext; } curdevice->pNext = device; diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index 495c934c05c7b..c2f3be73ccb87 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -28,9 +28,7 @@ static NSString * GetTextFormat(_THIS) { - SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; - - if (data->osversion >= 0x1060) { + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { return NSPasteboardTypeString; } else { return NSStringPboardType; @@ -96,7 +94,7 @@ char *text = Cocoa_GetClipboardText(_this); if (text) { result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE; - SDL_free(text); + SDL_free(text); } return result; } diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 11b5ee106e036..3474d159ad926 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -27,16 +27,6 @@ #include "../../events/SDL_events_c.h" #include "SDL_assert.h" -#if !defined(UsrActivity) && defined(__LP64__) && !defined(__POWER__) -/* - * Workaround for a bug in the 10.5 SDK: By accident, OSService.h does - * not include Power.h at all when compiling in 64bit mode. This has - * been fixed in 10.6, but for 10.5, we manually define UsrActivity - * to ensure compilation works. - */ -#define UsrActivity 1 -#endif - @interface SDLApplication : NSApplication - (void)terminate:(id)sender; @@ -58,7 +48,7 @@ @interface NSApplication(NSAppleMenu) - (void)setAppleMenu:(NSMenu *)menu; @end -@interface SDLAppDelegate : NSObject { +@interface SDLAppDelegate : NSObject { @public BOOL seenFirstActivate; } @@ -70,7 +60,6 @@ @implementation SDLAppDelegate : NSObject - (id)init { self = [super init]; - if (self) { seenFirstActivate = NO; [[NSNotificationCenter defaultCenter] addObserver:self @@ -101,15 +90,12 @@ - (void)focusSomeWindow:(NSNotification *)aNotification } SDL_VideoDevice *device = SDL_GetVideoDevice(); - if (device && device->windows) - { + if (device && device->windows) { SDL_Window *window = device->windows; int i; - for (i = 0; i < device->num_displays; ++i) - { + for (i = 0; i < device->num_displays; ++i) { SDL_Window *fullscreen_window = device->displays[i].fullscreen_window; - if (fullscreen_window) - { + if (fullscreen_window) { if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) { SDL_RestoreWindow(fullscreen_window); } @@ -140,11 +126,13 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam /* Determine the application name */ appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; - if (!appName) + if (!appName) { appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]; + } - if (![appName length]) + if (![appName length]) { appName = [[NSProcessInfo processInfo] processName]; + } return appName; } @@ -294,7 +282,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam * termination into SDL_Quit, and we can't handle application:openFile: */ if (![NSApp delegate]) { - [NSApp setDelegate:appDelegate]; + [(NSApplication *)NSApp setDelegate:appDelegate]; } else { appDelegate->seenFirstActivate = YES; } diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index c68ee8b8ae365..53f58866ccfb8 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -32,33 +32,7 @@ /*#define DEBUG_IME NSLog */ #define DEBUG_IME(...) -#ifndef NX_DEVICERCTLKEYMASK - #define NX_DEVICELCTLKEYMASK 0x00000001 -#endif -#ifndef NX_DEVICELSHIFTKEYMASK - #define NX_DEVICELSHIFTKEYMASK 0x00000002 -#endif -#ifndef NX_DEVICERSHIFTKEYMASK - #define NX_DEVICERSHIFTKEYMASK 0x00000004 -#endif -#ifndef NX_DEVICELCMDKEYMASK - #define NX_DEVICELCMDKEYMASK 0x00000008 -#endif -#ifndef NX_DEVICERCMDKEYMASK - #define NX_DEVICERCMDKEYMASK 0x00000010 -#endif -#ifndef NX_DEVICELALTKEYMASK - #define NX_DEVICELALTKEYMASK 0x00000020 -#endif -#ifndef NX_DEVICERALTKEYMASK - #define NX_DEVICERALTKEYMASK 0x00000040 -#endif -#ifndef NX_DEVICERCTLKEYMASK - #define NX_DEVICERCTLKEYMASK 0x00002000 -#endif - -@interface SDLTranslatorResponder : NSView -{ +@interface SDLTranslatorResponder : NSView { NSString *_markedText; NSRange _markedRange; NSRange _selectedRange; @@ -83,10 +57,11 @@ - (void) insertText:(id) aString /* Could be NSString or NSAttributedString, so we have * to test and convert it before return as SDL event */ - if ([aString isKindOfClass: [NSAttributedString class]]) + if ([aString isKindOfClass: [NSAttributedString class]]) { str = [[aString string] UTF8String]; - else + } else { str = [aString UTF8String]; + } SDL_SendKeyboardText(str); } @@ -117,17 +92,16 @@ - (NSRange) selectedRange - (void) setMarkedText:(id) aString selectedRange:(NSRange) selRange { - if ([aString isKindOfClass: [NSAttributedString class]]) + if ([aString isKindOfClass: [NSAttributedString class]]) { aString = [aString string]; + } - if ([aString length] == 0) - { + if ([aString length] == 0) { [self unmarkText]; return; } - if (_markedText != aString) - { + if (_markedText != aString) { [_markedText release]; _markedText = [aString retain]; } @@ -443,10 +417,11 @@ - (NSArray *) validAttributesForMarkedText /* Try Unicode data first */ CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData); - if (uchrDataRef) + if (uchrDataRef) { chr_data = CFDataGetBytePtr(uchrDataRef); - else + } else { goto cleanup; + } if (chr_data) { UInt32 keyboard_type = LMGetKbdType(); @@ -470,8 +445,9 @@ - (NSArray *) validAttributesForMarkedText 0, keyboard_type, kUCKeyTranslateNoDeadKeysMask, &dead_key_state, 8, &len, s); - if (err != noErr) + if (err != noErr) { continue; + } if (len > 0 && s[0] != 0x10) { keymap[scancode] = s[0]; @@ -508,8 +484,9 @@ - (NSArray *) validAttributesForMarkedText NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_Window *window = SDL_GetKeyboardFocus(); NSWindow *nswindow = nil; - if (window) + if (window) { nswindow = ((SDL_WindowData*)window->driverdata)->nswindow; + } NSView *parentView = [nswindow contentView]; @@ -523,8 +500,7 @@ - (NSArray *) validAttributesForMarkedText [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; } - if (![[data->fieldEdit superview] isEqual: parentView]) - { + if (![[data->fieldEdit superview] isEqual: parentView]) { /* DEBUG_IME(@"add fieldEdit to window contentView"); */ [data->fieldEdit removeFromSuperview]; [parentView addSubview: data->fieldEdit]; @@ -554,8 +530,8 @@ - (NSArray *) validAttributesForMarkedText SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (!rect) { - SDL_InvalidParamError("rect"); - return; + SDL_InvalidParamError("rect"); + return; } [data->fieldEdit setInputRect: rect]; @@ -579,10 +555,10 @@ - (NSArray *) validAttributesForMarkedText /* see comments in SDL_cocoakeys.h */ scancode = 60 - scancode; } + if (scancode < SDL_arraysize(darwin_scancode_table)) { code = darwin_scancode_table[scancode]; - } - else { + } else { /* Hmm, does this ever happen? If so, need to extend the keymap... */ code = SDL_SCANCODE_UNKNOWN; } diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m index f022fcf3b8908..2ed7d90578cf1 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.m +++ b/src/video/cocoa/SDL_cocoamessagebox.m @@ -22,13 +22,6 @@ #if SDL_VIDEO_DRIVER_COCOA -#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__) -#include -#undef bool -#undef vector -#undef pixel -#endif - #include "SDL_events.h" #include "SDL_timer.h" #include "SDL_messagebox.h" @@ -125,13 +118,10 @@ - (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextIn int returnValue = 0; NSInteger clicked = presenter->clicked; - if (clicked >= NSAlertFirstButtonReturn) - { + if (clicked >= NSAlertFirstButtonReturn) { clicked -= NSAlertFirstButtonReturn; *buttonid = buttons[clicked].buttonid; - } - else - { + } else { returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked); } diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 68a1cff0193e0..a98d376ffa51f 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -43,10 +43,11 @@ * we can just simply do without it on newer OSes... */ #if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__) - if (show) + if (show) { ShowMenuBar(); - else + } else { HideMenuBar(); + } #endif } @@ -60,12 +61,12 @@ #endif static BOOL -IS_SNOW_LEOPARD_OR_LATER(_THIS) +IS_SNOW_LEOPARD_OR_LATER() { #if FORCE_OLD_API return NO; #else - return ((((SDL_VideoData *) _this->driverdata))->osversion >= 0x1060); + return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5; #endif } @@ -127,7 +128,7 @@ } data->moderef = moderef; - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (IS_SNOW_LEOPARD_OR_LATER()) { CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef; CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode); width = (long) CGDisplayModeGetWidth(vidmode); @@ -148,7 +149,7 @@ } #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (!IS_SNOW_LEOPARD_OR_LATER()) { CFNumberRef number; CFDictionaryRef vidmode = (CFDictionaryRef) moderef; number = CFDictionaryGetValue(vidmode, kCGDisplayWidth); @@ -184,7 +185,7 @@ static void Cocoa_ReleaseDisplayMode(_THIS, const void *moderef) { - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (IS_SNOW_LEOPARD_OR_LATER()) { CGDisplayModeRelease((CGDisplayModeRef) moderef); /* NULL is ok */ } } @@ -192,7 +193,7 @@ static void Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist) { - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (IS_SNOW_LEOPARD_OR_LATER()) { CFRelease(modelist); /* NULL is ok */ } } @@ -257,12 +258,12 @@ continue; } - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (IS_SNOW_LEOPARD_OR_LATER()) { moderef = CGDisplayCopyDisplayMode(displays[i]); } #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (!IS_SNOW_LEOPARD_OR_LATER()) { moderef = CGDisplayCurrentMode(displays[i]); } #endif @@ -319,12 +320,12 @@ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; CFArrayRef modes = NULL; - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + 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(_this)) { + if (!IS_SNOW_LEOPARD_OR_LATER()) { modes = CGDisplayAvailableModes(data->display); } #endif @@ -337,7 +338,7 @@ const void *moderef = CFArrayGetValueAtIndex(modes, i); SDL_DisplayMode mode; if (GetDisplayMode(_this, moderef, &mode)) { - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + if (IS_SNOW_LEOPARD_OR_LATER()) { CGDisplayModeRetain((CGDisplayModeRef) moderef); } SDL_AddDisplayMode(display, &mode); @@ -351,12 +352,12 @@ static CGError Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode) { - if (IS_SNOW_LEOPARD_OR_LATER(_this)) { + 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(_this)) { + if (!IS_SNOW_LEOPARD_OR_LATER()) { return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode); } #endif diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 287dcd719e969..4ea420d229d8b 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -120,8 +120,7 @@ + (NSCursor *)invisibleCursor NSCursor *nscursor = NULL; SDL_Cursor *cursor = NULL; - switch(id) - { + switch(id) { case SDL_SYSTEM_CURSOR_ARROW: nscursor = [NSCursor arrowCursor]; break; @@ -212,8 +211,7 @@ + (NSCursor *)invisibleCursor Cocoa_WarpMouse(SDL_Window * window, int x, int y) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if ([data->listener isMoving]) - { + if ([data->listener isMoving]) { DLog("Postponing warp, window being moved."); [data->listener setPendingMoveX:x Y:y]; @@ -370,8 +368,7 @@ + (NSCursor *)invisibleCursor void Cocoa_HandleMouseEvent(_THIS, NSEvent *event) { - switch ([event type]) - { + switch ([event type]) { case NSMouseMoved: case NSLeftMouseDragged: case NSRightMouseDragged: @@ -415,8 +412,7 @@ + (NSCursor *)invisibleCursor float deltaX = [event deltaX]; float deltaY = [event deltaY]; - if (seenWarp) - { + if (seenWarp) { deltaX += (lastMoveX - driverdata->lastWarpX); deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY); diff --git a/src/video/cocoa/SDL_cocoamousetap.m b/src/video/cocoa/SDL_cocoamousetap.m index 9cf531cb5ea15..c274289552456 100644 --- a/src/video/cocoa/SDL_cocoamousetap.m +++ b/src/video/cocoa/SDL_cocoamousetap.m @@ -67,8 +67,7 @@ NSRect windowRect; CGPoint eventLocation; - switch (type) - { + switch (type) { case kCGEventTapDisabledByTimeout: case kCGEventTapDisabledByUserInput: { diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index d9fb244092a0e..0bbbbcb72de34 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -35,16 +35,6 @@ #define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" -#ifndef NSOpenGLPFAOpenGLProfile -#define NSOpenGLPFAOpenGLProfile 99 -#endif -#ifndef NSOpenGLProfileVersionLegacy -#define NSOpenGLProfileVersionLegacy 0x1000 -#endif -#ifndef NSOpenGLProfileVersion3_2Core -#define NSOpenGLProfileVersion3_2Core 0x3200 -#endif - @implementation SDLOpenGLContext : NSOpenGLContext - (id)initWithFormat:(NSOpenGLPixelFormat *)format @@ -161,10 +151,10 @@ - (void)setWindow:(SDL_Window *)newWindow SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window) { - SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; NSAutoreleasePool *pool; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormat *fmt; SDLOpenGLContext *context; @@ -178,7 +168,7 @@ - (void)setWindow:(SDL_Window *)newWindow SDL_SetError ("OpenGL ES is not supported on this platform"); return NULL; } - if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && (data->osversion < 0x1070)) { + if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) { SDL_SetError ("OpenGL Core Profile is not supported on this platform version"); return NULL; } @@ -186,7 +176,7 @@ - (void)setWindow:(SDL_Window *)newWindow pool = [[NSAutoreleasePool alloc] init]; /* specify a profile if we're on Lion (10.7) or later. */ - if (data->osversion >= 0x1070) { + if (lion_or_later) { NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy; if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) { profile = NSOpenGLProfileVersion3_2Core; diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index 0fe7fb659cea3..61d800b6a7fe9 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -30,7 +30,8 @@ #include "SDL_assert.h" SDL_WindowShaper* -Cocoa_CreateShaper(SDL_Window* window) { +Cocoa_CreateShaper(SDL_Window* window) +{ SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; [windata->nswindow setOpaque:NO]; @@ -63,7 +64,8 @@ } SDL_CocoaClosure; void -ConvertRects(SDL_ShapeTree* tree,void* closure) { +ConvertRects(SDL_ShapeTree* tree, void* closure) +{ SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure; if(tree->kind == OpaqueShape) { NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h); @@ -72,7 +74,8 @@ } int -Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) { +Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode) +{ SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata; SDL_CocoaClosure closure; @@ -102,7 +105,8 @@ } int -Cocoa_ResizeWindowShape(SDL_Window *window) { +Cocoa_ResizeWindowShape(SDL_Window *window) +{ SDL_ShapeData* data = window->shaper->driverdata; SDL_assert(data != NULL); return 0; diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h index f194e1f722690..288c41fca9582 100644 --- a/src/video/cocoa/SDL_cocoavideo.h +++ b/src/video/cocoa/SDL_cocoavideo.h @@ -45,7 +45,6 @@ typedef struct SDL_VideoData { - SInt32 osversion; int allow_spaces; unsigned int modifierFlags; void *key_layout; diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 41670378f37ed..ad4f14c21ddbe 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -22,13 +22,6 @@ #if SDL_VIDEO_DRIVER_COCOA -#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__) -#include -#undef bool -#undef vector -#undef pixel -#endif - #include "SDL.h" #include "SDL_endian.h" #include "SDL_cocoavideo.h" @@ -76,9 +69,6 @@ } device->driverdata = data; - /* Find out what version of Mac OS X we're running */ - Gestalt(gestaltSystemVersion, &data->osversion); - /* Set the function pointers */ device->VideoInit = Cocoa_VideoInit; device->VideoQuit = Cocoa_VideoQuit; @@ -156,7 +146,7 @@ Cocoa_InitMouse(_this); const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES); - data->allow_spaces = ( (data->osversion >= 0x1070) && (!hint || (*hint != '0')) ); + data->allow_spaces = ( (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && (!hint || (*hint != '0')) ); return 0; } diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index de75092ca6eed..65a2c2fcf601e 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -97,13 +97,7 @@ typedef enum -(void) touchesCancelledWithEvent:(NSEvent *) theEvent; /* Touch event handling */ -typedef enum { - COCOA_TOUCH_DOWN, - COCOA_TOUCH_UP, - COCOA_TOUCH_MOVE, - COCOA_TOUCH_CANCELLED -} cocoaTouchType; --(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event; +-(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent; @end /* *INDENT-ON* */ diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index efcf26f314894..5141a5b8b226e 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -362,8 +362,7 @@ - (void)close !!! FIXME: http://bugzilla.libsdl.org/show_bug.cgi?id=1825 */ windows = [NSApp orderedWindows]; - for (NSWindow *win in windows) - { + for (NSWindow *win in windows) { if (win == window) { continue; } @@ -386,8 +385,7 @@ -(void) setPendingMoveX:(int)x Y:(int)y - (void)windowDidFinishMoving { - if ([self isMoving]) - { + if ([self isMoving]) { isMoving = NO; SDL_Mouse *mouse = SDL_GetMouse(); @@ -859,48 +857,29 @@ - (void)scrollWheel:(NSEvent *)theEvent - (void)touchesBeganWithEvent:(NSEvent *) theEvent { - [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent]; + [self handleTouches:NSTouchPhaseBegan withEvent:theEvent]; } - (void)touchesMovedWithEvent:(NSEvent *) theEvent { - [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent]; + [self handleTouches:NSTouchPhaseMoved withEvent:theEvent]; } - (void)touchesEndedWithEvent:(NSEvent *) theEvent { - [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent]; + [self handleTouches:NSTouchPhaseEnded withEvent:theEvent]; } - (void)touchesCancelledWithEvent:(NSEvent *) theEvent { - [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent]; + [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent]; } -- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event +- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent { - NSSet *touches = 0; - NSEnumerator *enumerator; - NSTouch *touch; - - switch (type) { - case COCOA_TOUCH_DOWN: - touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil]; - break; - case COCOA_TOUCH_UP: - touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil]; - break; - case COCOA_TOUCH_CANCELLED: - touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil]; - break; - case COCOA_TOUCH_MOVE: - touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil]; - break; - } + NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil]; - enumerator = [touches objectEnumerator]; - touch = (NSTouch*)[enumerator nextObject]; - while (touch) { + for (NSTouch *touch in touches) { const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device]; if (!SDL_GetTouch(touchId)) { if (SDL_AddTouch(touchId, "") < 0) { @@ -914,20 +893,20 @@ - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event /* Make the origin the upper left instead of the lower left */ y = 1.0f - y; - switch (type) { - case COCOA_TOUCH_DOWN: + switch (phase) { + case NSTouchPhaseBegan: SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f); break; - case COCOA_TOUCH_UP: - case COCOA_TOUCH_CANCELLED: + case NSTouchPhaseEnded: + case NSTouchPhaseCancelled: SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f); break; - case COCOA_TOUCH_MOVE: + case NSTouchPhaseMoved: SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f); break; + default: + break; } - - touch = (NSTouch*)[enumerator nextObject]; } } @@ -1065,23 +1044,20 @@ - (void)resetCursorRects NSRect rect; SDL_Rect bounds; unsigned int style; + NSArray *screens = [NSScreen screens]; Cocoa_GetDisplayBounds(_this, display, &bounds); rect.origin.x = window->x; rect.origin.y = window->y; rect.size.width = window->w; rect.size.height = window->h; - ConvertNSRect([[NSScreen screens] objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect); + ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect); style = GetWindowStyle(window); /* Figure out which screen to place this window */ - NSArray *screens = [NSScreen screens]; NSScreen *screen = nil; - NSScreen *candidate; - int i, count = [screens count]; - for (i = 0; i < count; ++i) { - candidate = [screens objectAtIndex:i]; + for (NSScreen *candidate in screens) { NSRect screenRect = [candidate frame]; if (rect.origin.x >= screenRect.origin.x && rect.origin.x < screenRect.origin.x + screenRect.size.width && @@ -1104,7 +1080,7 @@ - (void)resetCursorRects [nswindow setBackgroundColor:[NSColor blackColor]]; if (videodata->allow_spaces) { - SDL_assert(videodata->osversion >= 0x1070); + SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6); SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]); /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */ if (window->flags & SDL_WINDOW_RESIZABLE) {