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.
main
Sam Lantinga 2014-07-07 12:48:25 -07:00
parent febc47976b
commit fc4e798d79
16 changed files with 134 additions and 241 deletions

View File

@ -37,8 +37,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
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 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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 @@ Cocoa_HasClipboardText(_THIS)
char *text = Cocoa_GetClipboardText(_this);
if (text) {
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
SDL_free(text);
}
return result;
}

View File

@ -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 @@
- (void)setAppleMenu:(NSMenu *)menu;
@end
@interface SDLAppDelegate : NSObject {
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
@public
BOOL seenFirstActivate;
}
@ -70,7 +60,6 @@
- (id)init
{
self = [super init];
if (self) {
seenFirstActivate = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
@ -101,15 +90,12 @@
}
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 @@ GetApplicationName(void)
/* 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 @@ Cocoa_RegisterApp(void)
* 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;
}

View File

@ -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 <NSTextInput>
{
@interface SDLTranslatorResponder : NSView <NSTextInput> {
NSString *_markedText;
NSRange _markedRange;
NSRange _selectedRange;
@ -83,10 +57,11 @@
/* 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 @@
- (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 @@ UpdateKeymap(SDL_VideoData *data)
/* 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 @@ UpdateKeymap(SDL_VideoData *data)
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 @@ Cocoa_StartTextInput(_THIS)
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 @@ Cocoa_StartTextInput(_THIS)
[[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 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
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 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
/* 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;
}

View File

@ -22,13 +22,6 @@
#if SDL_VIDEO_DRIVER_COCOA
#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
#include <altivec.h>
#undef bool
#undef vector
#undef pixel
#endif
#include "SDL_events.h"
#include "SDL_timer.h"
#include "SDL_messagebox.h"
@ -125,13 +118,10 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
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);
}

View File

@ -43,10 +43,11 @@ Cocoa_ToggleMenuBar(const BOOL show)
* 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 @@ Cocoa_ToggleMenuBar(const BOOL show)
#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 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
}
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 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
}
#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 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
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 @@ Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
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 @@ Cocoa_InitModes(_THIS)
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 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
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 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
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 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
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

View File

@ -120,8 +120,7 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
NSCursor *nscursor = NULL;
SDL_Cursor *cursor = NULL;
switch(id)
{
switch(id) {
case SDL_SYSTEM_CURSOR_ARROW:
nscursor = [NSCursor arrowCursor];
break;
@ -212,8 +211,7 @@ static void
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 @@ Cocoa_InitMouse(_THIS)
void
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{
switch ([event type])
{
switch ([event type]) {
case NSMouseMoved:
case NSLeftMouseDragged:
case NSRightMouseDragged:
@ -415,8 +412,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
float deltaX = [event deltaX];
float deltaY = [event deltaY];
if (seenWarp)
{
if (seenWarp) {
deltaX += (lastMoveX - driverdata->lastWarpX);
deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);

View File

@ -67,8 +67,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
NSRect windowRect;
CGPoint eventLocation;
switch (type)
{
switch (type) {
case kCGEventTapDisabledByTimeout:
case kCGEventTapDisabledByUserInput:
{

View File

@ -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 @@ Cocoa_GL_UnloadLibrary(_THIS)
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 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
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 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
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;

View File

@ -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 @@ typedef struct {
} 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 @@ ConvertRects(SDL_ShapeTree* tree,void* closure) {
}
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 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
}
int
Cocoa_ResizeWindowShape(SDL_Window *window) {
Cocoa_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData* data = window->shaper->driverdata;
SDL_assert(data != NULL);
return 0;

View File

@ -45,7 +45,6 @@
typedef struct SDL_VideoData
{
SInt32 osversion;
int allow_spaces;
unsigned int modifierFlags;
void *key_layout;

View File

@ -22,13 +22,6 @@
#if SDL_VIDEO_DRIVER_COCOA
#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
#include <altivec.h>
#undef bool
#undef vector
#undef pixel
#endif
#include "SDL.h"
#include "SDL_endian.h"
#include "SDL_cocoavideo.h"
@ -76,9 +69,6 @@ Cocoa_CreateDevice(int devindex)
}
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_VideoInit(_THIS)
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;
}

View File

@ -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* */

View File

@ -362,8 +362,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
!!! 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 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (void)windowDidFinishMoving
{
if ([self isMoving])
{
if ([self isMoving]) {
isMoving = NO;
SDL_Mouse *mouse = SDL_GetMouse();
@ -859,48 +857,29 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (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;
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
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;
}
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 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
/* 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 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
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 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
[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) {