--- include/SDL_config.h +++ include/SDL_config.h @@ -1,3 +1,4 @@ +/* include/SDL_config.h. Generated from SDL_config.h.in by configure. */ /* Simple DirectMedia Layer Copyright (C) 1997-2018 Sam Lantinga @@ -22,32 +23,388 @@ #ifndef SDL_config_h_ #define SDL_config_h_ -#include "SDL_platform.h" - /** - * \file SDL_config.h + * \file SDL_config.h.in + * + * This is a set of defines to configure the SDL features */ -/* Add any platform that doesn't build using the configure system. */ -#if defined(__WIN32__) -#include "SDL_config_windows.h" -#elif defined(__WINRT__) -#include "SDL_config_winrt.h" -#elif defined(__MACOSX__) -#include "SDL_config_macosx.h" -#elif defined(__IPHONEOS__) -#include "SDL_config_iphoneos.h" -#elif defined(__ANDROID__) -#include "SDL_config_android.h" -#elif defined(__PSP__) -#include "SDL_config_psp.h" +/* General platform specific identifiers */ +#include "SDL_platform.h" + +/* Make sure that this isn't included by Visual C++ */ +#ifdef _MSC_VER +#error You should run hg revert SDL_config.h +#endif + +/* C language features */ +/* #undef const */ +/* #undef inline */ +/* #undef volatile */ + +/* C datatypes */ +#ifdef __LP64__ +#define SIZEOF_VOIDP 8 #else -/* This is a minimal configuration just to get SDL running on new platforms */ -#include "SDL_config_minimal.h" -#endif /* platform config */ +#define SIZEOF_VOIDP 4 +#endif +/* #undef HAVE_GCC_ATOMICS */ +/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */ -#ifdef USING_GENERATED_CONFIG_H -#error Wrong SDL_config.h, check your include path? +/* Comment this if you want to build without any C library requirements */ +#define HAVE_LIBC 1 +#if HAVE_LIBC + +/* Useful headers */ +#define STDC_HEADERS 1 +#define HAVE_ALLOCA_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_FLOAT_H 1 +#define HAVE_ICONV_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_LIMITS_H 1 +/* #undef HAVE_MALLOC_H */ +#define HAVE_MATH_H 1 +#define HAVE_MEMORY_H 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDIO_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_WCHAR_H 1 +/* #undef HAVE_PTHREAD_NP_H */ +/* #undef HAVE_LIBUNWIND_H */ + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */ +#define HAVE_GETENV 1 +#define HAVE_SETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_UNSETENV 1 #endif +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_WCSLEN 1 +/* #undef HAVE_WCSLCPY */ +/* #undef HAVE_WCSLCAT */ +#define HAVE_WCSCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +/* #undef HAVE__STRREV */ +/* #undef HAVE__STRUPR */ +/* #undef HAVE__STRLWR */ +/* #undef HAVE_INDEX */ +/* #undef HAVE_RINDEX */ +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +/* #undef HAVE_ITOA */ +/* #undef HAVE__LTOA */ +/* #undef HAVE__UITOA */ +/* #undef HAVE__ULTOA */ +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +/* #undef HAVE__I64TOA */ +/* #undef HAVE__UI64TOA */ +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +/* #undef HAVE__STRICMP */ +#define HAVE_STRCASECMP 1 +/* #undef HAVE__STRNICMP */ +#define HAVE_STRNCASECMP 1 +/* #undef HAVE_SSCANF */ +#define HAVE_VSSCANF 1 +/* #undef HAVE_SNPRINTF */ +#define HAVE_VSNPRINTF 1 +#define HAVE_M_PI /**/ +#define HAVE_ACOS 1 +#define HAVE_ACOSF 1 +#define HAVE_ASIN 1 +#define HAVE_ASINF 1 +#define HAVE_ATAN 1 +#define HAVE_ATANF 1 +#define HAVE_ATAN2 1 +#define HAVE_ATAN2F 1 +#define HAVE_CEIL 1 +#define HAVE_CEILF 1 +#define HAVE_COPYSIGN 1 +#define HAVE_COPYSIGNF 1 +#define HAVE_COS 1 +#define HAVE_COSF 1 +#define HAVE_FABS 1 +#define HAVE_FABSF 1 +#define HAVE_FLOOR 1 +#define HAVE_FLOORF 1 +#define HAVE_FMOD 1 +#define HAVE_FMODF 1 +#define HAVE_LOG 1 +#define HAVE_LOGF 1 +#define HAVE_LOG10 1 +#define HAVE_LOG10F 1 +#define HAVE_POW 1 +#define HAVE_POWF 1 +#define HAVE_SCALBN 1 +#define HAVE_SCALBNF 1 +#define HAVE_SIN 1 +#define HAVE_SINF 1 +#define HAVE_SQRT 1 +#define HAVE_SQRTF 1 +#define HAVE_TAN 1 +#define HAVE_TANF 1 +/* #undef HAVE_FOPEN64 */ +#define HAVE_FSEEKO 1 +/* #undef HAVE_FSEEKO64 */ +#define HAVE_SIGACTION 1 +#define HAVE_SA_SIGACTION 1 +#define HAVE_SETJMP 1 +#define HAVE_NANOSLEEP 1 +#define HAVE_SYSCONF 1 +#define HAVE_SYSCTLBYNAME 1 +/* #undef HAVE_CLOCK_GETTIME */ +/* #undef HAVE_GETPAGESIZE */ +#define HAVE_MPROTECT 1 +#define HAVE_ICONV 1 +/* #undef HAVE_PTHREAD_SETNAME_NP */ +/* #undef HAVE_PTHREAD_SET_NAME_NP */ +/* #undef HAVE_SEM_TIMEDWAIT */ +/* #undef HAVE_GETAUXVAL */ +#define HAVE_POLL 1 + +#else +#define HAVE_STDARG_H 1 +#define HAVE_STDDEF_H 1 +#define HAVE_STDINT_H 1 +#endif /* HAVE_LIBC */ + +#define HAVE_ALTIVEC_H 1 +/* #undef HAVE_DBUS_DBUS_H */ +/* #undef HAVE_FCITX_FRONTEND_H */ +/* #undef HAVE_IBUS_IBUS_H */ +/* #undef HAVE_IMMINTRIN_H */ +/* #undef HAVE_LIBSAMPLERATE_H */ +/* #undef HAVE_LIBUDEV_H */ + +/* #undef HAVE_DDRAW_H */ +/* #undef HAVE_DINPUT_H */ +/* #undef HAVE_DSOUND_H */ +/* #undef HAVE_DXGI_H */ +/* #undef HAVE_XINPUT_H */ +/* #undef HAVE_XINPUT_GAMEPAD_EX */ +/* #undef HAVE_XINPUT_STATE_EX */ + +/* SDL internal assertion support */ +/* #undef SDL_DEFAULT_ASSERT_LEVEL */ + +/* Allow disabling of core subsystems */ +/* #undef SDL_ATOMIC_DISABLED */ +/* #undef SDL_AUDIO_DISABLED */ +/* #undef SDL_CPUINFO_DISABLED */ +/* #undef SDL_EVENTS_DISABLED */ +/* #undef SDL_FILE_DISABLED */ +/* #undef SDL_JOYSTICK_DISABLED */ +/* #undef SDL_HAPTIC_DISABLED */ +/* #undef SDL_LOADSO_DISABLED */ +/* #undef SDL_RENDER_DISABLED */ +/* #undef SDL_THREADS_DISABLED */ +/* #undef SDL_TIMERS_DISABLED */ +/* #undef SDL_VIDEO_DISABLED */ +/* #undef SDL_POWER_DISABLED */ +/* #undef SDL_FILESYSTEM_DISABLED */ + +/* Enable various audio drivers */ +/* #undef SDL_AUDIO_DRIVER_ALSA */ +/* #undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_ANDROID */ +/* #undef SDL_AUDIO_DRIVER_ARTS */ +/* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */ +#define SDL_AUDIO_DRIVER_COREAUDIO 1 +#define SDL_AUDIO_DRIVER_DISK 1 +/* #undef SDL_AUDIO_DRIVER_DSOUND */ +#define SDL_AUDIO_DRIVER_DUMMY 1 +/* #undef SDL_AUDIO_DRIVER_EMSCRIPTEN */ +/* #undef SDL_AUDIO_DRIVER_ESD */ +/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND */ +/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_HAIKU */ +/* #undef SDL_AUDIO_DRIVER_JACK */ +/* #undef SDL_AUDIO_DRIVER_JACK_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_NACL */ +/* #undef SDL_AUDIO_DRIVER_NAS */ +/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_NETBSD */ +/* #undef SDL_AUDIO_DRIVER_OSS */ +/* #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H */ +/* #undef SDL_AUDIO_DRIVER_PAUDIO */ +/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO */ +/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_QSA */ +/* #undef SDL_AUDIO_DRIVER_SNDIO */ +/* #undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_SUNAUDIO */ +/* #undef SDL_AUDIO_DRIVER_WASAPI */ +/* #undef SDL_AUDIO_DRIVER_WINMM */ + +/* Enable various input drivers */ +/* #undef SDL_INPUT_LINUXEV */ +/* #undef SDL_INPUT_LINUXKD */ +/* #undef SDL_INPUT_TSLIB */ +/* #undef SDL_JOYSTICK_HAIKU */ +/* #undef SDL_JOYSTICK_DINPUT */ +/* #undef SDL_JOYSTICK_XINPUT */ +/* #undef SDL_JOYSTICK_DUMMY */ +#define SDL_JOYSTICK_IOKIT 1 +/* #undef SDL_JOYSTICK_LINUX */ +/* #undef SDL_JOYSTICK_ANDROID */ +/* #undef SDL_JOYSTICK_WINMM */ +/* #undef SDL_JOYSTICK_USBHID */ +/* #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */ +/* #undef SDL_JOYSTICK_EMSCRIPTEN */ +/* #undef SDL_HAPTIC_DUMMY */ +/* #undef SDL_HAPTIC_ANDROID */ +/* #undef SDL_HAPTIC_LINUX */ +#define SDL_HAPTIC_IOKIT 1 +/* #undef SDL_HAPTIC_DINPUT */ +/* #undef SDL_HAPTIC_XINPUT */ + +/* Enable various shared object loading systems */ +#define SDL_LOADSO_DLOPEN 1 +/* #undef SDL_LOADSO_DUMMY */ +/* #undef SDL_LOADSO_LDG */ +/* #undef SDL_LOADSO_WINDOWS */ + +/* Enable various threading systems */ +#define SDL_THREAD_PTHREAD 1 +#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1 +/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */ +/* #undef SDL_THREAD_WINDOWS */ + +/* Enable various timer systems */ +/* #undef SDL_TIMER_HAIKU */ +/* #undef SDL_TIMER_DUMMY */ +#define SDL_TIMER_UNIX 1 +/* #undef SDL_TIMER_WINDOWS */ + +/* Enable various video drivers */ +/* #undef SDL_VIDEO_DRIVER_HAIKU */ +#define SDL_VIDEO_DRIVER_COCOA 1 +/* #undef SDL_VIDEO_DRIVER_DIRECTFB */ +/* #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC */ +#define SDL_VIDEO_DRIVER_DUMMY 1 +/* #undef SDL_VIDEO_DRIVER_WINDOWS */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR */ +/* #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON */ +/* #undef SDL_VIDEO_DRIVER_MIR */ +/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC */ +/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON */ +#define SDL_VIDEO_DRIVER_X11 1 +/* #undef SDL_VIDEO_DRIVER_RPI */ +/* #undef SDL_VIDEO_DRIVER_KMSDRM */ +/* #undef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */ +/* #undef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM */ +/* #undef SDL_VIDEO_DRIVER_ANDROID */ +/* #undef SDL_VIDEO_DRIVER_EMSCRIPTEN */ +#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib" +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib" +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "/usr/X11R6/lib/libXcursor.1.dylib" +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "/usr/X11R6/lib/libXinerama.1.dylib" +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 */ +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR */ +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib" +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib" +#define SDL_VIDEO_DRIVER_X11_XCURSOR 1 +#define SDL_VIDEO_DRIVER_X11_XDBE 1 +#define SDL_VIDEO_DRIVER_X11_XINERAMA 1 +/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2 */ +/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */ +/* #undef SDL_VIDEO_DRIVER_X11_XRANDR */ +#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1 +#define SDL_VIDEO_DRIVER_X11_XSHAPE 1 +#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1 +/* #undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */ +/* #undef SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY */ +#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1 +/* #undef SDL_VIDEO_DRIVER_NACL */ +/* #undef SDL_VIDEO_DRIVER_VIVANTE */ +/* #undef SDL_VIDEO_DRIVER_VIVANTE_VDK */ +/* #undef SDL_VIDEO_DRIVER_QNX */ + +/* #undef SDL_VIDEO_RENDER_D3D */ +/* #undef SDL_VIDEO_RENDER_D3D11 */ +#define SDL_VIDEO_RENDER_OGL 1 +/* #undef SDL_VIDEO_RENDER_OGL_ES */ +/* #undef SDL_VIDEO_RENDER_OGL_ES2 */ +/* #undef SDL_VIDEO_RENDER_DIRECTFB */ +/* #undef SDL_VIDEO_RENDER_METAL */ + +/* Enable OpenGL support */ +#define SDL_VIDEO_OPENGL 1 +/* #undef SDL_VIDEO_OPENGL_ES */ +/* #undef SDL_VIDEO_OPENGL_ES2 */ +/* #undef SDL_VIDEO_OPENGL_BGL */ +#define SDL_VIDEO_OPENGL_CGL 1 +/* #undef SDL_VIDEO_OPENGL_EGL */ +#define SDL_VIDEO_OPENGL_GLX 1 +/* #undef SDL_VIDEO_OPENGL_WGL */ +/* #undef SDL_VIDEO_OPENGL_OSMESA */ +/* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */ + +/* Enable Vulkan support */ +/* #undef SDL_VIDEO_VULKAN */ + +/* Enable system power support */ +/* #undef SDL_POWER_LINUX */ +/* #undef SDL_POWER_WINDOWS */ +#define SDL_POWER_MACOSX 1 +/* #undef SDL_POWER_HAIKU */ +/* #undef SDL_POWER_ANDROID */ +/* #undef SDL_POWER_EMSCRIPTEN */ +/* #undef SDL_POWER_HARDWIRED */ + +/* Enable system filesystem support */ +/* #undef SDL_FILESYSTEM_HAIKU */ +#define SDL_FILESYSTEM_COCOA 1 +/* #undef SDL_FILESYSTEM_DUMMY */ +/* #undef SDL_FILESYSTEM_UNIX */ +/* #undef SDL_FILESYSTEM_WINDOWS */ +/* #undef SDL_FILESYSTEM_NACL */ +/* #undef SDL_FILESYSTEM_ANDROID */ +/* #undef SDL_FILESYSTEM_EMSCRIPTEN */ + +/* Enable assembly routines */ +#define SDL_ASSEMBLY_ROUTINES 1 +#define SDL_ALTIVEC_BLITTERS 1 + +/* Enable ime support */ +/* #undef SDL_USE_IME */ + +/* Enable dynamic udev support */ +/* #undef SDL_UDEV_DYNAMIC */ + +/* Enable dynamic libsamplerate support */ +/* #undef SDL_LIBSAMPLERATE_DYNAMIC */ #endif /* SDL_config_h_ */ --- include/SDL_platform.h +++ include/SDL_platform.h @@ -84,7 +84,9 @@ #undef __MACOSX__ #define __MACOSX__ 1 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 +#if 0 # error SDL for Mac OS X only supports deploying on 10.6 and above. +#endif #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */ #endif /* TARGET_OS_IPHONE */ #endif /* defined(__APPLE__) */ --- include/SDL_syswm.h +++ include/SDL_syswm.h @@ -229,21 +229,29 @@ #if defined(SDL_VIDEO_DRIVER_COCOA) struct { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 #if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc) NSWindow __unsafe_unretained *window; /**< The Cocoa window */ #else NSWindow *window; /**< The Cocoa window */ #endif +#else + NSWindow *window; /**< The Cocoa window */ +#endif } cocoa; #endif #if defined(SDL_VIDEO_DRIVER_UIKIT) struct { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 #if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc) UIWindow __unsafe_unretained *window; /**< The UIKit window */ #else UIWindow *window; /**< The UIKit window */ #endif +#else + UIWindow *window; /**< The UIKit window */ +#endif GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */ GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */ GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */ --- src/atomic/SDL_spinlock.c +++ src/atomic/SDL_spinlock.c @@ -28,6 +28,10 @@ #include "SDL_mutex.h" #include "SDL_timer.h" +#if defined(__MACOSX__) || defined(__IPHONEOS__) +#include +#endif + #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__) #include #endif --- src/file/cocoa/SDL_rwopsbundlesupport.m +++ src/file/cocoa/SDL_rwopsbundlesupport.m @@ -33,7 +33,9 @@ Also, note the bundle layouts are different for iPhone and Mac. */ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool +#endif { FILE* fp = NULL; @@ -42,6 +44,9 @@ return fopen(file, mode); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; +#endif NSFileManager* file_manager = [NSFileManager defaultManager]; NSString* resource_path = [[NSBundle mainBundle] resourcePath]; @@ -54,8 +59,15 @@ fp = fopen(file, mode); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [autorelease_pool drain]; +#endif return fp; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +} +#else }} +#endif #endif /* __APPLE__ */ --- src/filesystem/cocoa/SDL_sysfilesystem.m +++ src/filesystem/cocoa/SDL_sysfilesystem.m @@ -35,8 +35,13 @@ char * SDL_GetBasePath(void) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSBundle *bundle = [NSBundle mainBundle]; const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String]; const char *base = NULL; @@ -64,13 +69,24 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 return retval; }} +#else + [pool release]; + return retval; +} +#endif char * SDL_GetPrefPath(const char *org, const char *app) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif if (!app) { SDL_InvalidParamError("app"); return NULL; @@ -109,8 +125,14 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 return retval; }} +#else + [pool release]; + return retval; +} +#endif #endif /* SDL_FILESYSTEM_COCOA */ --- src/joystick/darwin/SDL_sysjoystick.c +++ src/joystick/darwin/SDL_sysjoystick.c @@ -469,7 +469,11 @@ device->instance_id = ++s_joystick_instance_id; /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */ + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 ioservice = IOHIDDeviceGetService(ioHIDDeviceObject); + #else + ioservice = 0; + #endif #if SDL_HAPTIC_IOKIT if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) { device->ffservice = ioservice; --- src/video/cocoa/SDL_cocoaclipboard.m +++ src/video/cocoa/SDL_cocoaclipboard.m @@ -25,27 +25,64 @@ #include "SDL_cocoavideo.h" #include "../../events/SDL_clipboardevents_c.h" +static NSString * +GetTextFormat(_THIS) +{ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { + return NSPasteboardTypeString; + } else { +#endif + return NSStringPboardType; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 + } +#endif +} + int Cocoa_SetClipboardText(_THIS, const char *text) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; NSPasteboard *pasteboard; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 NSString *format = NSPasteboardTypeString; +#else + NSString *format = GetTextFormat(_this); +#endif pasteboard = [NSPasteboard generalPasteboard]; data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text] forType:format]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif char * Cocoa_GetClipboardText(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif NSPasteboard *pasteboard; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 NSString *format = NSPasteboardTypeString; +#else + NSString *format = GetTextFormat(_this); +#endif NSString *available; char *text; @@ -66,8 +103,15 @@ text = SDL_strdup(""); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return text; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif SDL_bool Cocoa_HasClipboardText(_THIS) @@ -83,8 +127,12 @@ void Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif NSPasteboard *pasteboard; NSInteger count; @@ -96,7 +144,12 @@ } data->clipboard_count = count; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif #endif /* SDL_VIDEO_DRIVER_COCOA */ --- src/video/cocoa/SDL_cocoaevents.m +++ src/video/cocoa/SDL_cocoaevents.m @@ -57,6 +57,19 @@ SDL_VideoDevice *_this = SDL_GetVideoDevice(); switch ([theEvent type]) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + case NSLeftMouseDown: + case NSOtherMouseDown: + case NSRightMouseDown: + case NSLeftMouseUp: + case NSOtherMouseUp: + case NSRightMouseUp: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: /* usually middle mouse dragged */ + case NSMouseMoved: + case NSScrollWheel: +#else case NSEventTypeLeftMouseDown: case NSEventTypeOtherMouseDown: case NSEventTypeRightMouseDown: @@ -68,11 +81,18 @@ case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */ case NSEventTypeMouseMoved: case NSEventTypeScrollWheel: +#endif Cocoa_HandleMouseEvent(_this, theEvent); break; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + case NSKeyDown: + case NSKeyUp: + case NSFlagsChanged: +#else case NSEventTypeKeyDown: case NSEventTypeKeyUp: case NSEventTypeFlagsChanged: +#endif Cocoa_HandleKeyEvent(_this, theEvent); break; default: @@ -110,7 +130,11 @@ - (void)setAppleMenu:(NSMenu *)menu; @end +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 @interface SDLAppDelegate : NSObject { +#else +@interface SDLAppDelegate : NSObject { +#endif @public BOOL seenFirstActivate; } @@ -170,8 +194,10 @@ */ for (NSWindow *window in [NSApp orderedWindows]) { if (window != win && [window canBecomeKeyWindow]) { - if (![window isOnActiveSpace]) { - continue; + if ([window respondsToSelector:@selector(isOnActiveSpace)]) { + if (![window isOnActiveSpace]) { + continue; + } } [window makeKeyAndOrderFront:self]; return; @@ -357,6 +383,7 @@ [windowMenu release]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 /* Add the fullscreen view toggle menu option, if supported */ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) { /* Create the view menu */ @@ -374,12 +401,18 @@ [viewMenu release]; } +#endif } void Cocoa_RegisterApp(void) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif /* This can get called more than once! Be careful what you initialize! */ if (NSApp == nil) { @@ -389,7 +422,9 @@ s_bShouldHandleEventsInSDLApplication = SDL_TRUE; if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) { +#if defined(MAC_OS_X_VERSION_10_6) [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; +#endif } if ([NSApp mainMenu] == nil) { @@ -415,12 +450,22 @@ appDelegate->seenFirstActivate = YES; } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_PumpEvents(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool; +#endif #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 /* Update activity every 30 seconds to prevent screensaver */ SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; @@ -434,8 +479,15 @@ } #endif +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + pool = [[NSAutoreleasePool alloc] init]; +#endif for ( ; ; ) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; +#else NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; +#endif if ( event == nil ) { break; } @@ -447,10 +499,16 @@ // Pass events down to SDLApplication to be handled in sendEvent: [NSApp sendEvent:event]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SuspendScreenSaver(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; @@ -477,6 +535,10 @@ &data->screensaver_assertion); } }} +#else +{ +} +#endif #endif /* SDL_VIDEO_DRIVER_COCOA */ --- src/video/cocoa/SDL_cocoakeyboard.m +++ src/video/cocoa/SDL_cocoakeyboard.m @@ -144,12 +144,18 @@ NSStringFromRect(rect)); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +#if defined(MAC_OS_X_VERSION_10_7) if (![window respondsToSelector:@selector(convertRectToScreen:)]) { +#endif rect.origin = [window convertBaseToScreen:rect.origin]; +#if defined(MAC_OS_X_VERSION_10_7) } else #endif +#endif { +#if defined(MAC_OS_X_VERSION_10_7) rect = [window convertRectToScreen:rect]; +#endif } return rect; @@ -591,8 +597,13 @@ void Cocoa_StartTextInput(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_Window *window = SDL_GetKeyboardFocus(); NSWindow *nswindow = nil; @@ -618,20 +629,37 @@ [parentView addSubview: data->fieldEdit]; [nswindow makeFirstResponder: data->fieldEdit]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_StopTextInput(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool +#endif { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (data && data->fieldEdit) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif [data->fieldEdit removeFromSuperview]; [data->fieldEdit release]; data->fieldEdit = nil; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif void Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect) @@ -673,7 +701,11 @@ } switch ([event type]) { +#if !defined(MAC_OS_X_VERSION_10_12) + case NSKeyDown: +#else case NSEventTypeKeyDown: +#endif if (![event isARepeat]) { /* See if we need to rebuild the keyboard layout */ UpdateKeymap(data, SDL_TRUE); @@ -697,10 +729,18 @@ #endif } break; +#if !defined(MAC_OS_X_VERSION_10_12) + case NSKeyUp: +#else case NSEventTypeKeyUp: +#endif SDL_SendKeyboardKey(SDL_RELEASED, code); break; +#if !defined(MAC_OS_X_VERSION_10_12) + case NSFlagsChanged: +#else case NSEventTypeFlagsChanged: +#endif /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ HandleModifiers(_this, scancode, [event modifierFlags]); break; --- src/video/cocoa/SDL_cocoamessagebox.m +++ src/video/cocoa/SDL_cocoamessagebox.m @@ -92,10 +92,15 @@ /* Display a Cocoa message box */ int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool +#endif { Cocoa_RegisterApp(); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSAlert* alert = [[[NSAlert alloc] init] autorelease]; if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) { @@ -137,8 +142,15 @@ returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return returnValue; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif #endif /* SDL_VIDEO_DRIVER_COCOA */ --- src/video/cocoa/SDL_cocoamodes.h +++ src/video/cocoa/SDL_cocoamodes.h @@ -30,7 +30,11 @@ typedef struct { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRef moderef; +#else + const void *moderef; +#endif } SDL_DisplayModeData; extern void Cocoa_InitModes(_THIS); --- src/video/cocoa/SDL_cocoamodes.m +++ src/video/cocoa/SDL_cocoamodes.m @@ -100,21 +100,37 @@ } static SDL_bool +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CVDisplayLinkRef link, SDL_DisplayMode *mode) +#else +GetDisplayMode(_THIS, const void *moderef, CVDisplayLinkRef link, SDL_DisplayMode *mode) +#endif { SDL_DisplayModeData *data; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 int width = 0; int height = 0; int bpp = 0; int refreshRate = 0; CFStringRef fmt; +#else + long width = 0; + long height = 0; + long bpp = 0; + long refreshRate = 0; +#endif data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { return SDL_FALSE; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 data->moderef = vidmode; +#else + data->moderef = moderef; +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 fmt = CGDisplayModeCopyPixelEncoding(vidmode); width = (int) CGDisplayModeGetWidth(vidmode); height = (int) CGDisplayModeGetHeight(vidmode); @@ -134,6 +150,22 @@ } CFRelease(fmt); +#else + { + CFNumberRef number; + double refresh; + CFDictionaryRef vidmode = (CFDictionaryRef) moderef; + number = CFDictionaryGetValue(vidmode, kCGDisplayWidth); + CFNumberGetValue(number, kCFNumberLongType, &width); + number = CFDictionaryGetValue(vidmode, kCGDisplayHeight); + CFNumberGetValue(number, kCFNumberLongType, &height); + number = CFDictionaryGetValue(vidmode, kCGDisplayBitsPerPixel); + CFNumberGetValue(number, kCFNumberLongType, &bpp); + number = CFDictionaryGetValue(vidmode, kCGDisplayRefreshRate); + CFNumberGetValue(number, kCFNumberDoubleType, &refresh); + refreshRate = (long) (refresh + 0.5); + } +#endif /* CGDisplayModeGetRefreshRate returns 0 for many non-CRT displays. */ if (refreshRate == 0 && link != NULL) { @@ -182,8 +214,13 @@ void Cocoa_InitModes(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif CGDisplayErr result; CGDirectDisplayID *displays; CGDisplayCount numDisplays; @@ -192,6 +229,9 @@ result = CGGetOnlineDisplayList(0, NULL, &numDisplays); if (result != kCGErrorSuccess) { CG_SetError("CGGetOnlineDisplayList()", result); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return; } displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays); @@ -199,6 +239,9 @@ if (result != kCGErrorSuccess) { CG_SetError("CGGetOnlineDisplayList()", result); SDL_stack_free(displays); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return; } @@ -208,7 +251,11 @@ SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRef moderef = NULL; +#else + const void *moderef = NULL; +#endif CVDisplayLinkRef link = NULL; if (pass == 0) { @@ -225,7 +272,11 @@ continue; } + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 moderef = CGDisplayCopyDisplayMode(displays[i]); + #else + moderef = CGDisplayCurrentMode(displays[i]); + #endif if (!moderef) { continue; @@ -233,7 +284,9 @@ displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); if (!displaydata) { + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRelease(moderef); + #endif continue; } displaydata->display = displays[i]; @@ -245,7 +298,9 @@ display.name = (char *)Cocoa_GetDisplayName(displays[i]); if (!GetDisplayMode(_this, moderef, link, &mode)) { CVDisplayLinkRelease(link); + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRelease(moderef); + #endif SDL_free(display.name); SDL_free(displaydata); continue; @@ -261,7 +316,12 @@ } } SDL_stack_free(displays); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +} +#else }} +#endif int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect) @@ -341,12 +401,15 @@ { SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; CVDisplayLinkRef link = NULL; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRef desktopmoderef; SDL_DisplayMode desktopmode; +#endif CFArrayRef modes; CVDisplayLinkCreateWithCGDisplay(data->display, &link); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 desktopmoderef = CGDisplayCopyDisplayMode(data->display); /* CopyAllDisplayModes won't always contain the desktop display mode (if @@ -363,20 +426,31 @@ } else { CGDisplayModeRelease(desktopmoderef); } +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 modes = CGDisplayCopyAllDisplayModes(data->display, NULL); +#else + modes = CGDisplayAvailableModes(data->display); +#endif if (modes) { CFIndex i; const CFIndex count = CFArrayGetCount(modes); for (i = 0; i < count; i++) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); +#else + const void *moderef = CFArrayGetValueAtIndex(modes, i); +#endif SDL_DisplayMode mode; if (GetDisplayMode(_this, moderef, link, &mode)) { if (SDL_AddDisplayMode(display, &mode)) { + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRetain(moderef); + #endif } else { SDL_free(mode.driverdata); } @@ -404,7 +478,11 @@ if (data == display->desktop_mode.driverdata) { /* Restoring desktop mode */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL); +#else + CGDisplaySwitchToMode(displaydata->display, data->moderef); +#endif if (CGDisplayIsMain(displaydata->display)) { CGReleaseAllDisplays(); @@ -429,7 +507,11 @@ } /* Do the physical switch */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 result = CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL); +#else + result = CGDisplaySwitchToMode(displaydata->display, data->moderef); +#endif if (result != kCGErrorSuccess) { CG_SetError("CGDisplaySwitchToMode()", result); goto ERR_NO_SWITCH; @@ -474,11 +556,15 @@ } mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata; + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRelease(mode->moderef); + #endif for (j = 0; j < display->num_display_modes; j++) { mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata; + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 CGDisplayModeRelease(mode->moderef); + #endif } } --- src/video/cocoa/SDL_cocoamouse.m +++ src/video/cocoa/SDL_cocoamouse.m @@ -67,8 +67,13 @@ static SDL_Cursor * Cocoa_CreateDefaultCursor() +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSCursor *nscursor; SDL_Cursor *cursor = NULL; @@ -82,13 +87,25 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return cursor; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif static SDL_Cursor * Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSImage *nsimage; NSCursor *nscursor = NULL; SDL_Cursor *cursor = NULL; @@ -107,13 +124,25 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return cursor; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif static SDL_Cursor * Cocoa_CreateSystemCursor(SDL_SystemCursor id) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSCursor *nscursor = NULL; SDL_Cursor *cursor = NULL; @@ -166,23 +195,45 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return cursor; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif static void Cocoa_FreeCursor(SDL_Cursor * cursor) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSCursor *nscursor = (NSCursor *)cursor->driverdata; [nscursor release]; SDL_free(cursor); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif static int Cocoa_ShowCursor(SDL_Cursor * cursor) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_Window *window = (device ? device->windows : NULL); for (; window != NULL; window = window->next) { @@ -193,8 +244,15 @@ waitUntilDone:NO]; } } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif static SDL_Window * SDL_FindWindowAtPoint(const int x, const int y) @@ -364,10 +422,17 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) { switch ([event type]) { +#if !defined(MAC_OS_X_VERSION_10_12) + case NSMouseMoved: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: +#else case NSEventTypeMouseMoved: case NSEventTypeLeftMouseDragged: case NSEventTypeRightMouseDragged: case NSEventTypeOtherMouseDragged: +#endif break; default: --- src/video/cocoa/SDL_cocoaopengl.m +++ src/video/cocoa/SDL_cocoaopengl.m @@ -151,11 +151,20 @@ SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool; +#endif SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1670 SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; +#else + SDL_bool lion_or_later = SDL_FALSE; +#endif NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormat *fmt; SDLOpenGLContext *context; @@ -195,7 +204,11 @@ attr[i++] = NSOpenGLPFAAllowOfflineRenderers; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + pool = [[NSAutoreleasePool alloc] init]; +#endif /* specify a profile if we're on Lion (10.7) or later. */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 if (lion_or_later) { NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy; if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) { @@ -204,6 +217,7 @@ attr[i++] = NSOpenGLPFAOpenGLProfile; attr[i++] = profile; } +#endif attr[i++] = NSOpenGLPFAColorSize; attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8; @@ -259,6 +273,9 @@ fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; if (fmt == nil) { SDL_SetError("Failed creating OpenGL pixel format"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } @@ -272,12 +289,18 @@ if (context == nil) { SDL_SetError("Failed creating OpenGL context"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError("Failed making OpenGL context current"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } @@ -292,6 +315,9 @@ if (!glGetStringFunc) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError ("Failed getting OpenGL glGetString entry point"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } @@ -299,12 +325,18 @@ if (glversion == NULL) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError ("Failed getting OpenGL context version"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError ("Failed parsing OpenGL context version"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } @@ -312,6 +344,9 @@ ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError ("Failed creating OpenGL context at version requested"); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NULL; } @@ -321,13 +356,25 @@ /*_this->gl_config.major_version = glversion_major;*/ /*_this->gl_config.minor_version = glversion_minor;*/ } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return context; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +} +#else }} +#endif int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif if (context) { SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; [nscontext setWindow:window]; @@ -337,8 +384,15 @@ [NSOpenGLContext clearCurrentContext]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif void Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) @@ -349,9 +403,11 @@ /* This gives us the correct viewport for a Retina-enabled view, only * supported on 10.7+. */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) { viewport = [contentView convertRectToBacking:viewport]; } +#endif if (w) { *w = viewport.size.width; @@ -364,7 +420,9 @@ int Cocoa_GL_SetSwapInterval(_THIS, int interval) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool +#endif { NSOpenGLContext *nscontext; GLint value; @@ -373,6 +431,9 @@ if (interval < 0) { /* no extension for this on Mac OS X at the moment. */ return SDL_SetError("Late swap tearing currently unsupported"); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); if (nscontext != nil) { @@ -383,13 +444,25 @@ status = SDL_SetError("No current OpenGL context"); } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return status; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif int Cocoa_GL_GetSwapInterval(_THIS) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSOpenGLContext *nscontext; GLint value; int status = 0; @@ -400,28 +473,57 @@ status = (int)value; } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return status; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext(); [nscontext flushBuffer]; [nscontext updateIfNeeded]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; [nscontext setWindow:NULL]; [nscontext release]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif #endif /* SDL_VIDEO_OPENGL_CGL */ --- src/video/cocoa/SDL_cocoashape.m +++ src/video/cocoa/SDL_cocoashape.m @@ -73,8 +73,13 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata; SDL_CocoaClosure closure; @@ -97,8 +102,15 @@ SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure); [closure.path addClip]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif int Cocoa_ResizeWindowShape(SDL_Window *window) --- src/video/cocoa/SDL_cocoavideo.h +++ src/video/cocoa/SDL_cocoavideo.h @@ -58,7 +58,9 @@ DECLARE_EVENT(FlagsChanged); #undef DECLARE_EVENT +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 static const NSEventMask NSEventMaskAny = NSAnyEventMask; +#endif #define DECLARE_MODIFIER_FLAG(name) static const NSUInteger NSEventModifierFlag##name = NS##name##KeyMask DECLARE_MODIFIER_FLAG(Shift); @@ -79,7 +81,9 @@ DECLARE_WINDOW_MASK(Resizable); DECLARE_WINDOW_MASK(TexturedBackground); DECLARE_WINDOW_MASK(UnifiedTitleAndToolbar); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 DECLARE_WINDOW_MASK(FullScreen); +#endif /*DECLARE_WINDOW_MASK(FullSizeContentView);*/ /* Not used, fails compile on older SDKs */ static const unsigned int NSWindowStyleMaskUtilityWindow = NSUtilityWindowMask; static const unsigned int NSWindowStyleMaskDocModalWindow = NSDocModalWindowMask; --- src/video/cocoa/SDL_cocoavideo.m +++ src/video/cocoa/SDL_cocoavideo.m @@ -22,6 +22,13 @@ #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" @@ -169,10 +176,15 @@ Cocoa_InitKeyboard(_this); Cocoa_InitMouse(_this); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE)); /* The IOPM assertion API can disable the screensaver as of 10.7. */ data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; +#else + data->allow_spaces = 0; + data->screensaver_use_iopm = 0; +#endif return 0; } --- src/video/cocoa/SDL_cocoawindow.h +++ src/video/cocoa/SDL_cocoawindow.h @@ -39,7 +39,11 @@ PENDING_OPERATION_MINIMIZE } PendingWindowOperation; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 @interface Cocoa_WindowListener : NSResponder { +#else +@interface Cocoa_WindowListener : NSResponder { +#endif SDL_WindowData *_data; BOOL observingVisible; BOOL wasCtrlLeft; @@ -79,7 +83,9 @@ -(void) windowDidEnterFullScreen:(NSNotification *) aNotification; -(void) windowWillExitFullScreen:(NSNotification *) aNotification; -(void) windowDidExitFullScreen:(NSNotification *) aNotification; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions; +#endif /* See if event is in a drag area, toggle on window dragging. */ -(BOOL) processHitTest:(NSEvent *)theEvent; @@ -102,7 +108,17 @@ -(void) touchesCancelledWithEvent:(NSEvent *) theEvent; /* Touch event handling */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 -(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent; +#else +typedef enum { + COCOA_TOUCH_DOWN, + COCOA_TOUCH_UP, + COCOA_TOUCH_MOVE, + COCOA_TOUCH_CANCELLED +} cocoaTouchType; +-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event; +#endif @end /* *INDENT-ON* */ --- src/video/cocoa/SDL_cocoawindow.m +++ src/video/cocoa/SDL_cocoawindow.m @@ -23,7 +23,9 @@ #if SDL_VIDEO_DRIVER_COCOA #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +#if 0 # error SDL for Mac OS X must be built with a 10.7 SDK or above. +#endif #endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */ #include "SDL_syswm.h" @@ -55,7 +57,11 @@ #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN) +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +@interface SDLWindow : NSWindow +#else @interface SDLWindow : NSWindow +#endif /* These are needed for borderless/fullscreen windows */ - (BOOL)canBecomeKeyWindow; - (BOOL)canBecomeMainWindow; @@ -137,8 +143,13 @@ } - (BOOL)performDragOperation:(id )sender +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool; +#endif NSPasteboard *pasteboard = [sender draggingPasteboard]; NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType]; NSString *desiredType = [pasteboard availableTypeFromArray:types]; @@ -153,11 +164,16 @@ return NO; } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + pool = [[NSAutoreleasePool alloc] init]; +#endif + SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]); NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"]; for (NSString *path in array) { NSURL *fileURL = [NSURL fileURLWithPath:path]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 NSNumber *isAlias = nil; [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil]; @@ -178,15 +194,26 @@ } } } +#endif if (!SDL_SendDropFile(sdlwindow, [[fileURL path] UTF8String])) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return NO; } } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif SDL_SendDropComplete(sdlwindow); return YES; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +} +#else }} +#endif - (BOOL)wantsPeriodicDraggingUpdates { @@ -314,11 +341,13 @@ [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window]; [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window]; [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window]; [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window]; [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window]; [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window]; [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window]; +#endif [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window]; [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window]; } else { @@ -409,7 +438,9 @@ inFullscreenTransition = YES; /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; +#endif [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO]; return YES; } @@ -445,11 +476,13 @@ [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window]; [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window]; [center removeObserver:self name:NSWindowDidResignKeyNotification object:window]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window]; [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window]; [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window]; [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window]; [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window]; +#endif [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window]; [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window]; } else { @@ -629,9 +662,11 @@ [NSMenu setMenuBarVisible:NO]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock; _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags; SDL_ToggleModState(KMOD_CAPS, newflags != 0); +#endif } - (void)windowDidResignKey:(NSNotification *)aNotification @@ -658,6 +693,7 @@ - (void)windowDidChangeBackingProperties:(NSNotification *)aNotification { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]; if (inFullscreenTransition) { @@ -670,6 +706,7 @@ _data->window->h = 0; [self windowDidResize:aNotification]; } +#endif } - (void)windowWillEnterFullScreen:(NSNotification *)aNotification @@ -778,12 +815,14 @@ [nswindow miniaturize:nil]; } else { /* Adjust the fullscreen toggle button and readd menu now that we're here. */ +#if MAC_OS_X_VERSION_MIN_REQUIRED > 1070 if (window->flags & SDL_WINDOW_RESIZABLE) { /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; } else { [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged]; } +#endif [NSMenu setMenuBarVisible:YES]; pendingWindowOperation = PENDING_OPERATION_NONE; @@ -826,6 +865,7 @@ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions { if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) { @@ -834,6 +874,7 @@ return proposedOptions; } } +#endif /* We'll respond to key events by doing nothing so we don't beep. @@ -1060,6 +1101,7 @@ - (void)touchesBeganWithEvent:(NSEvent *) theEvent { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil]; int existingTouchCount = 0; @@ -1080,25 +1122,89 @@ DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount); [self handleTouches:NSTouchPhaseBegan withEvent:theEvent]; +#endif } - (void)touchesMovedWithEvent:(NSEvent *) theEvent { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [self handleTouches:NSTouchPhaseMoved withEvent:theEvent]; +#endif } - (void)touchesEndedWithEvent:(NSEvent *) theEvent { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [self handleTouches:NSTouchPhaseEnded withEvent:theEvent]; +#endif } - (void)touchesCancelledWithEvent:(NSEvent *) theEvent { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent]; +#endif } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 - (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent +#else +- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event +#endif { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + 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; + } + + enumerator = [touches objectEnumerator]; + touch = (NSTouch*)[enumerator nextObject]; + while (touch) { + const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device]; + if (!SDL_GetTouch(touchId)) { + if (SDL_AddTouch(touchId, "") < 0) { + return; + } + } + + const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity]; + float x = [touch normalizedPosition].x; + float y = [touch normalizedPosition].y; + /* Make the origin the upper left instead of the lower left */ + y = 1.0f - y; + + switch (type) { + case COCOA_TOUCH_DOWN: + SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f); + break; + case COCOA_TOUCH_UP: + case COCOA_TOUCH_CANCELLED: + SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f); + break; + case COCOA_TOUCH_MOVE: + SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f); + break; + } + + touch = (NSTouch*)[enumerator nextObject]; + } +#else NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil]; for (NSTouch *touch in touches) { @@ -1128,7 +1234,9 @@ break; } } +#endif } +#endif @end @@ -1200,8 +1308,13 @@ static int SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool; +#endif SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; SDL_WindowData *data; @@ -1216,6 +1329,9 @@ data->videodata = videodata; data->nscontexts = [[NSMutableArray alloc] init]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + pool = [[NSAutoreleasePool alloc] init]; +#endif /* Create an event listener for the window */ data->listener = [[Cocoa_WindowListener alloc] init]; @@ -1276,15 +1392,27 @@ */ [nswindow setOneShot:NO]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif /* All done! */ window->driverdata = data; return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +} +#else }} +#endif int Cocoa_CreateWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; NSWindow *nswindow; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); @@ -1324,6 +1452,7 @@ } if (videodata->allow_spaces) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 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 */ @@ -1331,6 +1460,7 @@ /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; } +#endif } /* Create a default view for this window */ @@ -1359,10 +1489,16 @@ if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { [nswindow release]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return -1; } if (!(window->flags & SDL_WINDOW_OPENGL)) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; } @@ -1372,21 +1508,42 @@ #if SDL_VIDEO_OPENGL_EGL if (Cocoa_GLES_SetupWindow(_this, window) < 0) { Cocoa_DestroyWindow(_this, window); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return -1; } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; #else +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return SDL_SetError("Could not create GLES window surface (EGL support not configured)"); #endif /* SDL_VIDEO_OPENGL_EGL */ } #endif /* SDL_VIDEO_OPENGL_ES2 */ +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return 0; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSWindow *nswindow = (NSWindow *) data; NSString *title; @@ -1397,34 +1554,64 @@ } return SetupWindowData(_this, window, nswindow, SDL_FALSE); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowTitle(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif const char *title = window->title ? window->title : ""; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; NSString *string = [[NSString alloc] initWithUTF8String:title]; [nswindow setTitle:string]; [string release]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSImage *nsimage = Cocoa_CreateImage(icon); if (nsimage) { [NSApp setApplicationIconImage:nsimage]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowPosition(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; NSRect rect; @@ -1442,12 +1629,22 @@ s_moveHack = moveHack; ScheduleContextUpdates(windata); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowSize(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; NSRect rect; @@ -1469,12 +1666,22 @@ s_moveHack = moveHack; ScheduleContextUpdates(windata); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSSize minSize; @@ -1482,12 +1689,22 @@ minSize.height = window->min_h; [windata->nswindow setContentMinSize:minSize]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSSize maxSize; @@ -1495,12 +1712,22 @@ maxSize.height = window->max_h; [windata->nswindow setContentMaxSize:maxSize]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_ShowWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata); NSWindow *nswindow = windowData->nswindow; @@ -1509,21 +1736,41 @@ [nswindow makeKeyAndOrderFront:nil]; [windowData->listener resumeVisibleObservation]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_HideWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; [nswindow orderOut:nil]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_RaiseWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata); NSWindow *nswindow = windowData->nswindow; @@ -1536,24 +1783,44 @@ [nswindow makeKeyAndOrderFront:nil]; } [windowData->listener resumeVisibleObservation]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_MaximizeWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; [nswindow zoom:nil]; ScheduleContextUpdates(windata); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_MinimizeWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *data = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = data->nswindow; @@ -1562,12 +1829,22 @@ } else { [nswindow miniaturize:nil]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_RestoreWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; if ([nswindow isMiniaturized]) { @@ -1575,23 +1852,44 @@ } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) { [nswindow zoom:nil]; } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif if (SetWindowStyle(window, GetWindowStyle(window))) { if (bordered) { Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */ } } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif + void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif /* Don't set this if we're in a space! * The window will get permanently stuck if resizable is false. * -flibit @@ -1601,12 +1899,23 @@ if (![listener isInFullscreenSpace]) { SetWindowStyle(window, GetWindowStyle(window)); } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif + void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *data = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = data->nswindow; NSRect rect; @@ -1677,7 +1986,12 @@ } ScheduleContextUpdates(data); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) @@ -1767,8 +2081,13 @@ void Cocoa_DestroyWindow(_THIS, SDL_Window * window) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if (data) { @@ -1791,7 +2110,12 @@ SDL_free(data); } window->driverdata = NULL; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else + [pool release]; +} +#endif SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) @@ -1823,8 +2147,13 @@ SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state) +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 { @autoreleasepool { +#else +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif SDL_bool succeeded = SDL_FALSE; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; @@ -1855,8 +2184,15 @@ succeeded = SDL_TRUE; } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + [pool release]; +#endif return succeeded; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 }} +#else +} +#endif int Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)