Skip to content

Commit

Permalink
Fixed bug 2631 - Mac: minor code cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Jul 7, 2014
1 parent febc479 commit fc4e798
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 241 deletions.
9 changes: 3 additions & 6 deletions src/file/cocoa/SDL_rwopsbundlesupport.m
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
83 changes: 41 additions & 42 deletions src/haptic/darwin/SDL_syshaptic.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -457,19 +451,19 @@ 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));
}

/* 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));
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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. */
}

Expand All @@ -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));
}
Expand All @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/video/cocoa/SDL_cocoaclipboard.m
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 9 additions & 21 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -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;
Expand All @@ -58,7 +48,7 @@ @interface NSApplication(NSAppleMenu)
- (void)setAppleMenu:(NSMenu *)menu;
@end

@interface SDLAppDelegate : NSObject {
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
@public
BOOL seenFirstActivate;
}
Expand All @@ -70,7 +60,6 @@ @implementation SDLAppDelegate : NSObject
- (id)init
{
self = [super init];

if (self) {
seenFirstActivate = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit fc4e798

Please sign in to comment.