mirror of https://github.com/encounter/SDL.git
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.
This commit is contained in:
parent
febc47976b
commit
fc4e798d79
|
@ -37,8 +37,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
|
|
||||||
/* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */
|
/* 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);
|
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* 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];
|
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);
|
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
fp = fopen(file, mode);
|
fp = fopen(file, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,21 +257,18 @@ MacHaptic_MaybeAddDevice( io_object_t device )
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
kNilOptions);
|
kNilOptions);
|
||||||
if ((result == KERN_SUCCESS) && hidProperties) {
|
if ((result == KERN_SUCCESS) && hidProperties) {
|
||||||
refCF =
|
refCF = CFDictionaryGetValue(hidProperties,
|
||||||
CFDictionaryGetValue(hidProperties,
|
CFSTR(kIOHIDPrimaryUsagePageKey));
|
||||||
CFSTR(kIOHIDPrimaryUsagePageKey));
|
|
||||||
if (refCF) {
|
if (refCF) {
|
||||||
if (!CFNumberGetValue(refCF, kCFNumberLongType,
|
if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usagePage)) {
|
||||||
&item->usagePage))
|
SDL_SetError("Haptic: Recieving device's usage page.");
|
||||||
SDL_SetError
|
}
|
||||||
("Haptic: Recieving device's usage page.");
|
refCF = CFDictionaryGetValue(hidProperties,
|
||||||
refCF =
|
CFSTR(kIOHIDPrimaryUsageKey));
|
||||||
CFDictionaryGetValue(hidProperties,
|
|
||||||
CFSTR(kIOHIDPrimaryUsageKey));
|
|
||||||
if (refCF) {
|
if (refCF) {
|
||||||
if (!CFNumberGetValue(refCF, kCFNumberLongType,
|
if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usage)) {
|
||||||
&item->usage))
|
|
||||||
SDL_SetError("Haptic: Recieving device's usage.");
|
SDL_SetError("Haptic: Recieving device's usage.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CFRelease(hidProperties);
|
CFRelease(hidProperties);
|
||||||
|
@ -377,24 +374,21 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
||||||
|
|
||||||
|
|
||||||
/* Get product name */
|
/* Get product name */
|
||||||
refCF =
|
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
|
||||||
CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
|
if (!refCF) {
|
||||||
if (!refCF)
|
refCF = CFDictionaryGetValue(usbProperties,
|
||||||
refCF =
|
CFSTR("USB Product Name"));
|
||||||
CFDictionaryGetValue(usbProperties,
|
}
|
||||||
CFSTR("USB Product Name"));
|
|
||||||
if (refCF) {
|
if (refCF) {
|
||||||
if (!CFStringGetCString(refCF, name, 256,
|
if (!CFStringGetCString(refCF, name, 256,
|
||||||
CFStringGetSystemEncoding())) {
|
CFStringGetSystemEncoding())) {
|
||||||
return SDL_SetError
|
return SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product.");
|
||||||
("Haptic: CFStringGetCString error retrieving pDevice->product.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(usbProperties);
|
CFRelease(usbProperties);
|
||||||
} else {
|
} else {
|
||||||
return SDL_SetError
|
return SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
|
||||||
("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release stuff. */
|
/* Release stuff. */
|
||||||
|
@ -457,9 +451,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
||||||
/* Check if supports gain. */
|
/* Check if supports gain. */
|
||||||
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
|
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
|
||||||
&val, sizeof(val));
|
&val, sizeof(val));
|
||||||
if (ret == FF_OK)
|
if (ret == FF_OK) {
|
||||||
supported |= SDL_HAPTIC_GAIN;
|
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.",
|
return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
|
||||||
FFStrError(ret));
|
FFStrError(ret));
|
||||||
}
|
}
|
||||||
|
@ -467,9 +461,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
||||||
/* Checks if supports autocenter. */
|
/* Checks if supports autocenter. */
|
||||||
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
|
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
|
||||||
&val, sizeof(val));
|
&val, sizeof(val));
|
||||||
if (ret == FF_OK)
|
if (ret == FF_OK) {
|
||||||
supported |= SDL_HAPTIC_AUTOCENTER;
|
supported |= SDL_HAPTIC_AUTOCENTER;
|
||||||
else if (ret != FFERR_UNSUPPORTED) {
|
} else if (ret != FFERR_UNSUPPORTED) {
|
||||||
return SDL_SetError
|
return SDL_SetError
|
||||||
("Haptic: Unable to get if device supports autocenter: %s.",
|
("Haptic: Unable to get if device supports autocenter: %s.",
|
||||||
FFStrError(ret));
|
FFStrError(ret));
|
||||||
|
@ -604,8 +598,9 @@ SDL_SYS_HapticMouse(void)
|
||||||
int
|
int
|
||||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||||
{
|
{
|
||||||
if (joystick->hwdata->ffservice != 0)
|
if (joystick->hwdata->ffservice != 0) {
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,8 +612,9 @@ int
|
||||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||||
{
|
{
|
||||||
if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
|
if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
|
||||||
joystick->hwdata->ffservice))
|
joystick->hwdata->ffservice)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,18 +735,22 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||||
case SDL_HAPTIC_CARTESIAN:
|
case SDL_HAPTIC_CARTESIAN:
|
||||||
effect->dwFlags |= FFEFF_CARTESIAN;
|
effect->dwFlags |= FFEFF_CARTESIAN;
|
||||||
rglDir[0] = dir->dir[0];
|
rglDir[0] = dir->dir[0];
|
||||||
if (naxes > 1)
|
if (naxes > 1) {
|
||||||
rglDir[1] = dir->dir[1];
|
rglDir[1] = dir->dir[1];
|
||||||
if (naxes > 2)
|
}
|
||||||
|
if (naxes > 2) {
|
||||||
rglDir[2] = dir->dir[2];
|
rglDir[2] = dir->dir[2];
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case SDL_HAPTIC_SPHERICAL:
|
case SDL_HAPTIC_SPHERICAL:
|
||||||
effect->dwFlags |= FFEFF_SPHERICAL;
|
effect->dwFlags |= FFEFF_SPHERICAL;
|
||||||
rglDir[0] = dir->dir[0];
|
rglDir[0] = dir->dir[0];
|
||||||
if (naxes > 1)
|
if (naxes > 1) {
|
||||||
rglDir[1] = dir->dir[1];
|
rglDir[1] = dir->dir[1];
|
||||||
if (naxes > 2)
|
}
|
||||||
|
if (naxes > 2) {
|
||||||
rglDir[2] = dir->dir[2];
|
rglDir[2] = dir->dir[2];
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -767,8 +767,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||||
* Creates the FFEFFECT from a SDL_HapticEffect.
|
* Creates the FFEFFECT from a SDL_HapticEffect.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
||||||
SDL_HapticEffect * src)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
FFCONSTANTFORCE *constant;
|
FFCONSTANTFORCE *constant;
|
||||||
|
@ -1269,8 +1268,7 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||||
{
|
{
|
||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
|
|
||||||
ret =
|
ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
|
||||||
FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
|
|
||||||
if (ret != FF_OK) {
|
if (ret != FF_OK) {
|
||||||
SDL_SetError("Haptic: Error removing the effect from the device: %s.",
|
SDL_SetError("Haptic: Error removing the effect from the device: %s.",
|
||||||
FFStrError(ret));
|
FFStrError(ret));
|
||||||
|
@ -1299,8 +1297,9 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == 0)
|
if (status == 0) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
return SDL_TRUE; /* Assume it's playing or emulated. */
|
return SDL_TRUE; /* Assume it's playing or emulated. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1315,9 +1314,8 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||||
Uint32 val;
|
Uint32 val;
|
||||||
|
|
||||||
val = gain * 100; /* Mac OS X uses 0 to 10,000 */
|
val = gain * 100; /* Mac OS X uses 0 to 10,000 */
|
||||||
ret =
|
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||||
FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
FFPROP_FFGAIN, &val);
|
||||||
FFPROP_FFGAIN, &val);
|
|
||||||
if (ret != FF_OK) {
|
if (ret != FF_OK) {
|
||||||
return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
|
return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
|
||||||
}
|
}
|
||||||
|
@ -1336,10 +1334,11 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||||
Uint32 val;
|
Uint32 val;
|
||||||
|
|
||||||
/* Mac OS X only has 0 (off) and 1 (on) */
|
/* Mac OS X only has 0 (off) and 1 (on) */
|
||||||
if (autocenter == 0)
|
if (autocenter == 0) {
|
||||||
val = 0;
|
val = 0;
|
||||||
else
|
} else {
|
||||||
val = 1;
|
val = 1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||||
FFPROP_AUTOCENTER, &val);
|
FFPROP_AUTOCENTER, &val);
|
||||||
|
|
|
@ -406,17 +406,13 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
|
||||||
s_bDeviceAdded = SDL_TRUE;
|
s_bDeviceAdded = SDL_TRUE;
|
||||||
|
|
||||||
/* Add device to the end of the list */
|
/* Add device to the end of the list */
|
||||||
if ( !gpDeviceList )
|
if ( !gpDeviceList ) {
|
||||||
{
|
|
||||||
gpDeviceList = device;
|
gpDeviceList = device;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
recDevice *curdevice;
|
recDevice *curdevice;
|
||||||
|
|
||||||
curdevice = gpDeviceList;
|
curdevice = gpDeviceList;
|
||||||
while ( curdevice->pNext )
|
while ( curdevice->pNext ) {
|
||||||
{
|
|
||||||
curdevice = curdevice->pNext;
|
curdevice = curdevice->pNext;
|
||||||
}
|
}
|
||||||
curdevice->pNext = device;
|
curdevice->pNext = device;
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
static NSString *
|
static NSString *
|
||||||
GetTextFormat(_THIS)
|
GetTextFormat(_THIS)
|
||||||
{
|
{
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
|
||||||
|
|
||||||
if (data->osversion >= 0x1060) {
|
|
||||||
return NSPasteboardTypeString;
|
return NSPasteboardTypeString;
|
||||||
} else {
|
} else {
|
||||||
return NSStringPboardType;
|
return NSStringPboardType;
|
||||||
|
@ -96,7 +94,7 @@ Cocoa_HasClipboardText(_THIS)
|
||||||
char *text = Cocoa_GetClipboardText(_this);
|
char *text = Cocoa_GetClipboardText(_this);
|
||||||
if (text) {
|
if (text) {
|
||||||
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
|
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
|
||||||
SDL_free(text);
|
SDL_free(text);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,16 +27,6 @@
|
||||||
#include "../../events/SDL_events_c.h"
|
#include "../../events/SDL_events_c.h"
|
||||||
#include "SDL_assert.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
|
@interface SDLApplication : NSApplication
|
||||||
|
|
||||||
- (void)terminate:(id)sender;
|
- (void)terminate:(id)sender;
|
||||||
|
@ -58,7 +48,7 @@
|
||||||
- (void)setAppleMenu:(NSMenu *)menu;
|
- (void)setAppleMenu:(NSMenu *)menu;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface SDLAppDelegate : NSObject {
|
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
|
||||||
@public
|
@public
|
||||||
BOOL seenFirstActivate;
|
BOOL seenFirstActivate;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +60,6 @@
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
seenFirstActivate = NO;
|
seenFirstActivate = NO;
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
@ -101,15 +90,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
||||||
if (device && device->windows)
|
if (device && device->windows) {
|
||||||
{
|
|
||||||
SDL_Window *window = device->windows;
|
SDL_Window *window = device->windows;
|
||||||
int i;
|
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;
|
SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
|
||||||
if (fullscreen_window)
|
if (fullscreen_window) {
|
||||||
{
|
|
||||||
if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
|
if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
|
||||||
SDL_RestoreWindow(fullscreen_window);
|
SDL_RestoreWindow(fullscreen_window);
|
||||||
}
|
}
|
||||||
|
@ -140,11 +126,13 @@ GetApplicationName(void)
|
||||||
|
|
||||||
/* Determine the application name */
|
/* Determine the application name */
|
||||||
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||||
if (!appName)
|
if (!appName) {
|
||||||
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
|
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
|
||||||
|
}
|
||||||
|
|
||||||
if (![appName length])
|
if (![appName length]) {
|
||||||
appName = [[NSProcessInfo processInfo] processName];
|
appName = [[NSProcessInfo processInfo] processName];
|
||||||
|
}
|
||||||
|
|
||||||
return appName;
|
return appName;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +282,7 @@ Cocoa_RegisterApp(void)
|
||||||
* termination into SDL_Quit, and we can't handle application:openFile:
|
* termination into SDL_Quit, and we can't handle application:openFile:
|
||||||
*/
|
*/
|
||||||
if (![NSApp delegate]) {
|
if (![NSApp delegate]) {
|
||||||
[NSApp setDelegate:appDelegate];
|
[(NSApplication *)NSApp setDelegate:appDelegate];
|
||||||
} else {
|
} else {
|
||||||
appDelegate->seenFirstActivate = YES;
|
appDelegate->seenFirstActivate = YES;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,33 +32,7 @@
|
||||||
/*#define DEBUG_IME NSLog */
|
/*#define DEBUG_IME NSLog */
|
||||||
#define DEBUG_IME(...)
|
#define DEBUG_IME(...)
|
||||||
|
|
||||||
#ifndef NX_DEVICERCTLKEYMASK
|
@interface SDLTranslatorResponder : NSView <NSTextInput> {
|
||||||
#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>
|
|
||||||
{
|
|
||||||
NSString *_markedText;
|
NSString *_markedText;
|
||||||
NSRange _markedRange;
|
NSRange _markedRange;
|
||||||
NSRange _selectedRange;
|
NSRange _selectedRange;
|
||||||
|
@ -83,10 +57,11 @@
|
||||||
|
|
||||||
/* Could be NSString or NSAttributedString, so we have
|
/* Could be NSString or NSAttributedString, so we have
|
||||||
* to test and convert it before return as SDL event */
|
* to test and convert it before return as SDL event */
|
||||||
if ([aString isKindOfClass: [NSAttributedString class]])
|
if ([aString isKindOfClass: [NSAttributedString class]]) {
|
||||||
str = [[aString string] UTF8String];
|
str = [[aString string] UTF8String];
|
||||||
else
|
} else {
|
||||||
str = [aString UTF8String];
|
str = [aString UTF8String];
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SendKeyboardText(str);
|
SDL_SendKeyboardText(str);
|
||||||
}
|
}
|
||||||
|
@ -117,17 +92,16 @@
|
||||||
- (void) setMarkedText:(id) aString
|
- (void) setMarkedText:(id) aString
|
||||||
selectedRange:(NSRange) selRange
|
selectedRange:(NSRange) selRange
|
||||||
{
|
{
|
||||||
if ([aString isKindOfClass: [NSAttributedString class]])
|
if ([aString isKindOfClass: [NSAttributedString class]]) {
|
||||||
aString = [aString string];
|
aString = [aString string];
|
||||||
|
}
|
||||||
|
|
||||||
if ([aString length] == 0)
|
if ([aString length] == 0) {
|
||||||
{
|
|
||||||
[self unmarkText];
|
[self unmarkText];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_markedText != aString)
|
if (_markedText != aString) {
|
||||||
{
|
|
||||||
[_markedText release];
|
[_markedText release];
|
||||||
_markedText = [aString retain];
|
_markedText = [aString retain];
|
||||||
}
|
}
|
||||||
|
@ -443,10 +417,11 @@ UpdateKeymap(SDL_VideoData *data)
|
||||||
|
|
||||||
/* Try Unicode data first */
|
/* Try Unicode data first */
|
||||||
CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
|
CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
|
||||||
if (uchrDataRef)
|
if (uchrDataRef) {
|
||||||
chr_data = CFDataGetBytePtr(uchrDataRef);
|
chr_data = CFDataGetBytePtr(uchrDataRef);
|
||||||
else
|
} else {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (chr_data) {
|
if (chr_data) {
|
||||||
UInt32 keyboard_type = LMGetKbdType();
|
UInt32 keyboard_type = LMGetKbdType();
|
||||||
|
@ -470,8 +445,9 @@ UpdateKeymap(SDL_VideoData *data)
|
||||||
0, keyboard_type,
|
0, keyboard_type,
|
||||||
kUCKeyTranslateNoDeadKeysMask,
|
kUCKeyTranslateNoDeadKeysMask,
|
||||||
&dead_key_state, 8, &len, s);
|
&dead_key_state, 8, &len, s);
|
||||||
if (err != noErr)
|
if (err != noErr) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (len > 0 && s[0] != 0x10) {
|
if (len > 0 && s[0] != 0x10) {
|
||||||
keymap[scancode] = s[0];
|
keymap[scancode] = s[0];
|
||||||
|
@ -508,8 +484,9 @@ Cocoa_StartTextInput(_THIS)
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||||
NSWindow *nswindow = nil;
|
NSWindow *nswindow = nil;
|
||||||
if (window)
|
if (window) {
|
||||||
nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
|
nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
|
||||||
|
}
|
||||||
|
|
||||||
NSView *parentView = [nswindow contentView];
|
NSView *parentView = [nswindow contentView];
|
||||||
|
|
||||||
|
@ -523,8 +500,7 @@ Cocoa_StartTextInput(_THIS)
|
||||||
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
|
[[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"); */
|
/* DEBUG_IME(@"add fieldEdit to window contentView"); */
|
||||||
[data->fieldEdit removeFromSuperview];
|
[data->fieldEdit removeFromSuperview];
|
||||||
[parentView addSubview: data->fieldEdit];
|
[parentView addSubview: data->fieldEdit];
|
||||||
|
@ -554,8 +530,8 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
SDL_InvalidParamError("rect");
|
SDL_InvalidParamError("rect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data->fieldEdit setInputRect: rect];
|
[data->fieldEdit setInputRect: rect];
|
||||||
|
@ -579,10 +555,10 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
|
||||||
/* see comments in SDL_cocoakeys.h */
|
/* see comments in SDL_cocoakeys.h */
|
||||||
scancode = 60 - scancode;
|
scancode = 60 - scancode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scancode < SDL_arraysize(darwin_scancode_table)) {
|
if (scancode < SDL_arraysize(darwin_scancode_table)) {
|
||||||
code = darwin_scancode_table[scancode];
|
code = darwin_scancode_table[scancode];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* Hmm, does this ever happen? If so, need to extend the keymap... */
|
/* Hmm, does this ever happen? If so, need to extend the keymap... */
|
||||||
code = SDL_SCANCODE_UNKNOWN;
|
code = SDL_SCANCODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,6 @@
|
||||||
|
|
||||||
#if SDL_VIDEO_DRIVER_COCOA
|
#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_events.h"
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
#include "SDL_messagebox.h"
|
#include "SDL_messagebox.h"
|
||||||
|
@ -125,13 +118,10 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
|
|
||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
NSInteger clicked = presenter->clicked;
|
NSInteger clicked = presenter->clicked;
|
||||||
if (clicked >= NSAlertFirstButtonReturn)
|
if (clicked >= NSAlertFirstButtonReturn) {
|
||||||
{
|
|
||||||
clicked -= NSAlertFirstButtonReturn;
|
clicked -= NSAlertFirstButtonReturn;
|
||||||
*buttonid = buttons[clicked].buttonid;
|
*buttonid = buttons[clicked].buttonid;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
|
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,11 @@ Cocoa_ToggleMenuBar(const BOOL show)
|
||||||
* we can just simply do without it on newer OSes...
|
* we can just simply do without it on newer OSes...
|
||||||
*/
|
*/
|
||||||
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
|
||||||
if (show)
|
if (show) {
|
||||||
ShowMenuBar();
|
ShowMenuBar();
|
||||||
else
|
} else {
|
||||||
HideMenuBar();
|
HideMenuBar();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +61,12 @@ Cocoa_ToggleMenuBar(const BOOL show)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
IS_SNOW_LEOPARD_OR_LATER(_THIS)
|
IS_SNOW_LEOPARD_OR_LATER()
|
||||||
{
|
{
|
||||||
#if FORCE_OLD_API
|
#if FORCE_OLD_API
|
||||||
return NO;
|
return NO;
|
||||||
#else
|
#else
|
||||||
return ((((SDL_VideoData *) _this->driverdata))->osversion >= 0x1060);
|
return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
|
||||||
}
|
}
|
||||||
data->moderef = moderef;
|
data->moderef = moderef;
|
||||||
|
|
||||||
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
|
CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
|
||||||
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||||
width = (long) CGDisplayModeGetWidth(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 MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
||||||
if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (!IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
CFNumberRef number;
|
CFNumberRef number;
|
||||||
CFDictionaryRef vidmode = (CFDictionaryRef) moderef;
|
CFDictionaryRef vidmode = (CFDictionaryRef) moderef;
|
||||||
number = CFDictionaryGetValue(vidmode, kCGDisplayWidth);
|
number = CFDictionaryGetValue(vidmode, kCGDisplayWidth);
|
||||||
|
@ -184,7 +185,7 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
|
||||||
static void
|
static void
|
||||||
Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
|
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 */
|
CGDisplayModeRelease((CGDisplayModeRef) moderef); /* NULL is ok */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +193,7 @@ Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
|
||||||
static void
|
static void
|
||||||
Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
|
Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
|
||||||
{
|
{
|
||||||
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
CFRelease(modelist); /* NULL is ok */
|
CFRelease(modelist); /* NULL is ok */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,12 +258,12 @@ Cocoa_InitModes(_THIS)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
moderef = CGDisplayCopyDisplayMode(displays[i]);
|
moderef = CGDisplayCopyDisplayMode(displays[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
#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]);
|
moderef = CGDisplayCurrentMode(displays[i]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -319,12 +320,12 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||||
CFArrayRef modes = NULL;
|
CFArrayRef modes = NULL;
|
||||||
|
|
||||||
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
|
modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
#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);
|
modes = CGDisplayAvailableModes(data->display);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -337,7 +338,7 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
const void *moderef = CFArrayGetValueAtIndex(modes, i);
|
const void *moderef = CFArrayGetValueAtIndex(modes, i);
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
if (GetDisplayMode(_this, moderef, &mode)) {
|
if (GetDisplayMode(_this, moderef, &mode)) {
|
||||||
if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
|
if (IS_SNOW_LEOPARD_OR_LATER()) {
|
||||||
CGDisplayModeRetain((CGDisplayModeRef) moderef);
|
CGDisplayModeRetain((CGDisplayModeRef) moderef);
|
||||||
}
|
}
|
||||||
SDL_AddDisplayMode(display, &mode);
|
SDL_AddDisplayMode(display, &mode);
|
||||||
|
@ -351,12 +352,12 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
static CGError
|
static CGError
|
||||||
Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
|
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);
|
return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
#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);
|
return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -120,8 +120,7 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
NSCursor *nscursor = NULL;
|
NSCursor *nscursor = NULL;
|
||||||
SDL_Cursor *cursor = NULL;
|
SDL_Cursor *cursor = NULL;
|
||||||
|
|
||||||
switch(id)
|
switch(id) {
|
||||||
{
|
|
||||||
case SDL_SYSTEM_CURSOR_ARROW:
|
case SDL_SYSTEM_CURSOR_ARROW:
|
||||||
nscursor = [NSCursor arrowCursor];
|
nscursor = [NSCursor arrowCursor];
|
||||||
break;
|
break;
|
||||||
|
@ -212,8 +211,7 @@ static void
|
||||||
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
|
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
|
||||||
{
|
{
|
||||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||||
if ([data->listener isMoving])
|
if ([data->listener isMoving]) {
|
||||||
{
|
|
||||||
DLog("Postponing warp, window being moved.");
|
DLog("Postponing warp, window being moved.");
|
||||||
[data->listener setPendingMoveX:x
|
[data->listener setPendingMoveX:x
|
||||||
Y:y];
|
Y:y];
|
||||||
|
@ -370,8 +368,7 @@ Cocoa_InitMouse(_THIS)
|
||||||
void
|
void
|
||||||
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
{
|
{
|
||||||
switch ([event type])
|
switch ([event type]) {
|
||||||
{
|
|
||||||
case NSMouseMoved:
|
case NSMouseMoved:
|
||||||
case NSLeftMouseDragged:
|
case NSLeftMouseDragged:
|
||||||
case NSRightMouseDragged:
|
case NSRightMouseDragged:
|
||||||
|
@ -415,8 +412,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
float deltaX = [event deltaX];
|
float deltaX = [event deltaX];
|
||||||
float deltaY = [event deltaY];
|
float deltaY = [event deltaY];
|
||||||
|
|
||||||
if (seenWarp)
|
if (seenWarp) {
|
||||||
{
|
|
||||||
deltaX += (lastMoveX - driverdata->lastWarpX);
|
deltaX += (lastMoveX - driverdata->lastWarpX);
|
||||||
deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
|
deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
|
||||||
NSRect windowRect;
|
NSRect windowRect;
|
||||||
CGPoint eventLocation;
|
CGPoint eventLocation;
|
||||||
|
|
||||||
switch (type)
|
switch (type) {
|
||||||
{
|
|
||||||
case kCGEventTapDisabledByTimeout:
|
case kCGEventTapDisabledByTimeout:
|
||||||
case kCGEventTapDisabledByUserInput:
|
case kCGEventTapDisabledByUserInput:
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,16 +35,6 @@
|
||||||
|
|
||||||
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
|
#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
|
@implementation SDLOpenGLContext : NSOpenGLContext
|
||||||
|
|
||||||
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
|
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
|
||||||
|
@ -161,10 +151,10 @@ Cocoa_GL_UnloadLibrary(_THIS)
|
||||||
SDL_GLContext
|
SDL_GLContext
|
||||||
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
{
|
{
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
|
||||||
NSAutoreleasePool *pool;
|
NSAutoreleasePool *pool;
|
||||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||||
|
SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
|
||||||
NSOpenGLPixelFormatAttribute attr[32];
|
NSOpenGLPixelFormatAttribute attr[32];
|
||||||
NSOpenGLPixelFormat *fmt;
|
NSOpenGLPixelFormat *fmt;
|
||||||
SDLOpenGLContext *context;
|
SDLOpenGLContext *context;
|
||||||
|
@ -178,7 +168,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
SDL_SetError ("OpenGL ES is not supported on this platform");
|
SDL_SetError ("OpenGL ES is not supported on this platform");
|
||||||
return NULL;
|
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");
|
SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +176,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
pool = [[NSAutoreleasePool alloc] init];
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
/* specify a profile if we're on Lion (10.7) or later. */
|
/* specify a profile if we're on Lion (10.7) or later. */
|
||||||
if (data->osversion >= 0x1070) {
|
if (lion_or_later) {
|
||||||
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
|
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
|
||||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
||||||
profile = NSOpenGLProfileVersion3_2Core;
|
profile = NSOpenGLProfileVersion3_2Core;
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
#include "SDL_assert.h"
|
#include "SDL_assert.h"
|
||||||
|
|
||||||
SDL_WindowShaper*
|
SDL_WindowShaper*
|
||||||
Cocoa_CreateShaper(SDL_Window* window) {
|
Cocoa_CreateShaper(SDL_Window* window)
|
||||||
|
{
|
||||||
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
|
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
|
||||||
[windata->nswindow setOpaque:NO];
|
[windata->nswindow setOpaque:NO];
|
||||||
|
|
||||||
|
@ -63,7 +64,8 @@ typedef struct {
|
||||||
} SDL_CocoaClosure;
|
} SDL_CocoaClosure;
|
||||||
|
|
||||||
void
|
void
|
||||||
ConvertRects(SDL_ShapeTree* tree,void* closure) {
|
ConvertRects(SDL_ShapeTree* tree, void* closure)
|
||||||
|
{
|
||||||
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
|
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
|
||||||
if(tree->kind == OpaqueShape) {
|
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);
|
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
|
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_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
|
||||||
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
|
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
|
||||||
SDL_CocoaClosure closure;
|
SDL_CocoaClosure closure;
|
||||||
|
@ -102,7 +105,8 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Cocoa_ResizeWindowShape(SDL_Window *window) {
|
Cocoa_ResizeWindowShape(SDL_Window *window)
|
||||||
|
{
|
||||||
SDL_ShapeData* data = window->shaper->driverdata;
|
SDL_ShapeData* data = window->shaper->driverdata;
|
||||||
SDL_assert(data != NULL);
|
SDL_assert(data != NULL);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
|
|
||||||
typedef struct SDL_VideoData
|
typedef struct SDL_VideoData
|
||||||
{
|
{
|
||||||
SInt32 osversion;
|
|
||||||
int allow_spaces;
|
int allow_spaces;
|
||||||
unsigned int modifierFlags;
|
unsigned int modifierFlags;
|
||||||
void *key_layout;
|
void *key_layout;
|
||||||
|
|
|
@ -22,13 +22,6 @@
|
||||||
|
|
||||||
#if SDL_VIDEO_DRIVER_COCOA
|
#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.h"
|
||||||
#include "SDL_endian.h"
|
#include "SDL_endian.h"
|
||||||
#include "SDL_cocoavideo.h"
|
#include "SDL_cocoavideo.h"
|
||||||
|
@ -76,9 +69,6 @@ Cocoa_CreateDevice(int devindex)
|
||||||
}
|
}
|
||||||
device->driverdata = data;
|
device->driverdata = data;
|
||||||
|
|
||||||
/* Find out what version of Mac OS X we're running */
|
|
||||||
Gestalt(gestaltSystemVersion, &data->osversion);
|
|
||||||
|
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
device->VideoInit = Cocoa_VideoInit;
|
device->VideoInit = Cocoa_VideoInit;
|
||||||
device->VideoQuit = Cocoa_VideoQuit;
|
device->VideoQuit = Cocoa_VideoQuit;
|
||||||
|
@ -156,7 +146,7 @@ Cocoa_VideoInit(_THIS)
|
||||||
Cocoa_InitMouse(_this);
|
Cocoa_InitMouse(_this);
|
||||||
|
|
||||||
const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,13 +97,7 @@ typedef enum
|
||||||
-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
|
-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
|
||||||
|
|
||||||
/* Touch event handling */
|
/* Touch event handling */
|
||||||
typedef enum {
|
-(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
|
||||||
COCOA_TOUCH_DOWN,
|
|
||||||
COCOA_TOUCH_UP,
|
|
||||||
COCOA_TOUCH_MOVE,
|
|
||||||
COCOA_TOUCH_CANCELLED
|
|
||||||
} cocoaTouchType;
|
|
||||||
-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
|
@ -362,8 +362,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||||
!!! FIXME: http://bugzilla.libsdl.org/show_bug.cgi?id=1825
|
!!! FIXME: http://bugzilla.libsdl.org/show_bug.cgi?id=1825
|
||||||
*/
|
*/
|
||||||
windows = [NSApp orderedWindows];
|
windows = [NSApp orderedWindows];
|
||||||
for (NSWindow *win in windows)
|
for (NSWindow *win in windows) {
|
||||||
{
|
|
||||||
if (win == window) {
|
if (win == window) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -386,8 +385,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||||
|
|
||||||
- (void)windowDidFinishMoving
|
- (void)windowDidFinishMoving
|
||||||
{
|
{
|
||||||
if ([self isMoving])
|
if ([self isMoving]) {
|
||||||
{
|
|
||||||
isMoving = NO;
|
isMoving = NO;
|
||||||
|
|
||||||
SDL_Mouse *mouse = SDL_GetMouse();
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
@ -859,48 +857,29 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||||
|
|
||||||
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
|
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
|
||||||
{
|
{
|
||||||
[self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
|
[self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
|
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
|
||||||
{
|
{
|
||||||
[self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
|
[self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
|
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
|
||||||
{
|
{
|
||||||
[self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
|
[self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesCancelledWithEvent:(NSEvent *) 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;
|
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
||||||
NSEnumerator *enumerator;
|
|
||||||
NSTouch *touch;
|
|
||||||
|
|
||||||
switch (type) {
|
for (NSTouch *touch in touches) {
|
||||||
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) {
|
|
||||||
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
||||||
if (!SDL_GetTouch(touchId)) {
|
if (!SDL_GetTouch(touchId)) {
|
||||||
if (SDL_AddTouch(touchId, "") < 0) {
|
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 */
|
/* Make the origin the upper left instead of the lower left */
|
||||||
y = 1.0f - y;
|
y = 1.0f - y;
|
||||||
|
|
||||||
switch (type) {
|
switch (phase) {
|
||||||
case COCOA_TOUCH_DOWN:
|
case NSTouchPhaseBegan:
|
||||||
SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
|
SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
|
||||||
break;
|
break;
|
||||||
case COCOA_TOUCH_UP:
|
case NSTouchPhaseEnded:
|
||||||
case COCOA_TOUCH_CANCELLED:
|
case NSTouchPhaseCancelled:
|
||||||
SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
|
SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
|
||||||
break;
|
break;
|
||||||
case COCOA_TOUCH_MOVE:
|
case NSTouchPhaseMoved:
|
||||||
SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
|
SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
touch = (NSTouch*)[enumerator nextObject];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1065,23 +1044,20 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||||
NSRect rect;
|
NSRect rect;
|
||||||
SDL_Rect bounds;
|
SDL_Rect bounds;
|
||||||
unsigned int style;
|
unsigned int style;
|
||||||
|
NSArray *screens = [NSScreen screens];
|
||||||
|
|
||||||
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
||||||
rect.origin.x = window->x;
|
rect.origin.x = window->x;
|
||||||
rect.origin.y = window->y;
|
rect.origin.y = window->y;
|
||||||
rect.size.width = window->w;
|
rect.size.width = window->w;
|
||||||
rect.size.height = window->h;
|
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);
|
style = GetWindowStyle(window);
|
||||||
|
|
||||||
/* Figure out which screen to place this window */
|
/* Figure out which screen to place this window */
|
||||||
NSArray *screens = [NSScreen screens];
|
|
||||||
NSScreen *screen = nil;
|
NSScreen *screen = nil;
|
||||||
NSScreen *candidate;
|
for (NSScreen *candidate in screens) {
|
||||||
int i, count = [screens count];
|
|
||||||
for (i = 0; i < count; ++i) {
|
|
||||||
candidate = [screens objectAtIndex:i];
|
|
||||||
NSRect screenRect = [candidate frame];
|
NSRect screenRect = [candidate frame];
|
||||||
if (rect.origin.x >= screenRect.origin.x &&
|
if (rect.origin.x >= screenRect.origin.x &&
|
||||||
rect.origin.x < screenRect.origin.x + screenRect.size.width &&
|
rect.origin.x < screenRect.origin.x + screenRect.size.width &&
|
||||||
|
@ -1104,7 +1080,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||||
[nswindow setBackgroundColor:[NSColor blackColor]];
|
[nswindow setBackgroundColor:[NSColor blackColor]];
|
||||||
|
|
||||||
if (videodata->allow_spaces) {
|
if (videodata->allow_spaces) {
|
||||||
SDL_assert(videodata->osversion >= 0x1070);
|
SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
|
||||||
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
|
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
|
||||||
/* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
|
/* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
|
||||||
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
||||||
|
|
Loading…
Reference in New Issue