Cleaned out all the deprecated stuff in Mac OS X 10.6 SDK.
--HG-- branch : SDL-1.2
This commit is contained in:
parent
44d762fc92
commit
1322d06516
4 changed files with 304 additions and 115 deletions
|
@ -79,9 +79,10 @@
|
||||||
|
|
||||||
void QZ_InitOSKeymap (_THIS) {
|
void QZ_InitOSKeymap (_THIS) {
|
||||||
const void *KCHRPtr;
|
const void *KCHRPtr;
|
||||||
|
BOOL saw_layout = NO;
|
||||||
UInt32 state;
|
UInt32 state;
|
||||||
UInt32 value;
|
UInt32 value;
|
||||||
int i;
|
Uint16 i;
|
||||||
int world = SDLK_WORLD_0;
|
int world = SDLK_WORLD_0;
|
||||||
|
|
||||||
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
|
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
|
||||||
|
@ -212,6 +213,66 @@ void QZ_InitOSKeymap (_THIS) {
|
||||||
why we keep the static table, too.
|
why we keep the static table, too.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
|
||||||
|
if (TISCopyCurrentKeyboardLayoutInputSource != NULL) {
|
||||||
|
TISInputSourceRef src = TISCopyCurrentKeyboardLayoutInputSource();
|
||||||
|
if (src != NULL) {
|
||||||
|
CFDataRef data = (CFDataRef)
|
||||||
|
TISGetInputSourceProperty(src,
|
||||||
|
kTISPropertyUnicodeKeyLayoutData);
|
||||||
|
if (data != NULL) {
|
||||||
|
const UCKeyboardLayout *layout = (const UCKeyboardLayout *)
|
||||||
|
CFDataGetBytePtr(data);
|
||||||
|
if (layout != NULL) {
|
||||||
|
const UInt32 kbdtype = LMGetKbdType();
|
||||||
|
saw_layout = YES;
|
||||||
|
|
||||||
|
/* Loop over all 127 possible scan codes */
|
||||||
|
for (i = 0; i < 0x7F; i++) {
|
||||||
|
UniChar buf[16];
|
||||||
|
UniCharCount count = 0;
|
||||||
|
|
||||||
|
/* We pretend a clean start to begin with (i.e. no dead keys active */
|
||||||
|
state = 0;
|
||||||
|
|
||||||
|
if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
|
||||||
|
0, &state, 16, &count, buf) != noErr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the state become 0, it was a dead key. We need to
|
||||||
|
translate again, passing in the new state, to get
|
||||||
|
the actual key value */
|
||||||
|
if (state != 0) {
|
||||||
|
if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
|
||||||
|
0, &state, 16, &count, buf) != noErr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count != 1) {
|
||||||
|
continue; /* no multi-char. Use SDL 1.3 instead. :) */
|
||||||
|
}
|
||||||
|
|
||||||
|
value = (UInt32) buf[0];
|
||||||
|
if (value >= 128) {
|
||||||
|
/* Some non-ASCII char, map it to SDLK_WORLD_* */
|
||||||
|
if (world < 0xFF) {
|
||||||
|
keymap[i] = world++;
|
||||||
|
}
|
||||||
|
} else if (value >= 32) { /* non-control ASCII char */
|
||||||
|
keymap[i] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CFRelease(src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1050)
|
||||||
|
if (!saw_layout) {
|
||||||
/* Get a pointer to the systems cached KCHR */
|
/* Get a pointer to the systems cached KCHR */
|
||||||
KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
|
KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
|
||||||
if (KCHRPtr)
|
if (KCHRPtr)
|
||||||
|
@ -231,12 +292,17 @@ void QZ_InitOSKeymap (_THIS) {
|
||||||
value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
|
value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
|
||||||
|
|
||||||
/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
|
/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
|
||||||
if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
|
if (value >= 128) { /* Some non-ASCII char, map it to SDLK_WORLD_* */
|
||||||
|
if (world < 0xFF) {
|
||||||
keymap[i] = world++;
|
keymap[i] = world++;
|
||||||
else if (value >= 32) /* non-control ASCII char */
|
}
|
||||||
|
} else if (value >= 32) { /* non-control ASCII char */
|
||||||
keymap[i] = value;
|
keymap[i] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The keypad codes are re-setup here, because the loop above cannot
|
The keypad codes are re-setup here, because the loop above cannot
|
||||||
|
@ -730,7 +796,7 @@ static int QZ_OtherMouseButtonToSDL(int button)
|
||||||
|
|
||||||
void QZ_PumpEvents (_THIS)
|
void QZ_PumpEvents (_THIS)
|
||||||
{
|
{
|
||||||
CGMouseDelta dx, dy;
|
int32_t dx, dy;
|
||||||
|
|
||||||
NSDate *distantPast;
|
NSDate *distantPast;
|
||||||
NSEvent *event;
|
NSEvent *event;
|
||||||
|
@ -853,7 +919,7 @@ void QZ_PumpEvents (_THIS)
|
||||||
so we have to call the lowlevel window server
|
so we have to call the lowlevel window server
|
||||||
function. This is less accurate but works OK.
|
function. This is less accurate but works OK.
|
||||||
*/
|
*/
|
||||||
CGMouseDelta dx1, dy1;
|
int32_t dx1, dy1;
|
||||||
CGGetLastMouseDelta (&dx1, &dy1);
|
CGGetLastMouseDelta (&dx1, &dy1);
|
||||||
dx += dx1;
|
dx += dx1;
|
||||||
dy += dy1;
|
dy += dy1;
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
- Check accuracy of QZ_SetGamma()
|
- Check accuracy of QZ_SetGamma()
|
||||||
Problems:
|
Problems:
|
||||||
- OGL not working in full screen with software renderer
|
- OGL not working in full screen with software renderer
|
||||||
- SetColors sets palette correctly but clears framebuffer
|
|
||||||
- Crash in CG after several mode switches (I think this has been fixed)
|
- Crash in CG after several mode switches (I think this has been fixed)
|
||||||
- Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
|
- Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
|
||||||
- Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
|
- Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
|
||||||
|
@ -86,13 +85,11 @@ CGLContextObj QZ_GetCGLContextObj(NSOpenGLContext *nsctx);
|
||||||
|
|
||||||
/* Main driver structure to store required state information */
|
/* Main driver structure to store required state information */
|
||||||
typedef struct SDL_PrivateVideoData {
|
typedef struct SDL_PrivateVideoData {
|
||||||
|
BOOL snow_leopard_or_later;
|
||||||
BOOL allow_screensaver; /* 0 == disable screensaver */
|
BOOL allow_screensaver; /* 0 == disable screensaver */
|
||||||
CGDirectDisplayID display; /* 0 == main display (only support single display) */
|
CGDirectDisplayID display; /* 0 == main display (only support single display) */
|
||||||
CFDictionaryRef mode; /* current mode of the display */
|
const void *mode; /* current mode of the display */
|
||||||
CFDictionaryRef save_mode; /* original mode of the display */
|
const void *save_mode; /* original mode of the display */
|
||||||
CFArrayRef mode_list; /* list of available fullscreen modes */
|
|
||||||
CGDirectPaletteRef palette; /* palette of an 8-bit display */
|
|
||||||
NSOpenGLContext *gl_context; /* OpenGL rendering context */
|
NSOpenGLContext *gl_context; /* OpenGL rendering context */
|
||||||
Uint32 width, height, bpp; /* frequently used data about the display */
|
Uint32 width, height, bpp; /* frequently used data about the display */
|
||||||
Uint32 flags; /* flags for current mode, for teardown purposes */
|
Uint32 flags; /* flags for current mode, for teardown purposes */
|
||||||
|
@ -129,9 +126,8 @@ typedef struct SDL_PrivateVideoData {
|
||||||
#define display_id (this->hidden->display)
|
#define display_id (this->hidden->display)
|
||||||
#define mode (this->hidden->mode)
|
#define mode (this->hidden->mode)
|
||||||
#define save_mode (this->hidden->save_mode)
|
#define save_mode (this->hidden->save_mode)
|
||||||
|
#define snow_leopard_or_later (this->hidden->snow_leopard_or_later)
|
||||||
#define allow_screensaver (this->hidden->allow_screensaver)
|
#define allow_screensaver (this->hidden->allow_screensaver)
|
||||||
#define mode_list (this->hidden->mode_list)
|
|
||||||
#define palette (this->hidden->palette)
|
|
||||||
#define gl_context (this->hidden->gl_context)
|
#define gl_context (this->hidden->gl_context)
|
||||||
#define device_width (this->hidden->width)
|
#define device_width (this->hidden->width)
|
||||||
#define device_height (this->hidden->height)
|
#define device_height (this->hidden->height)
|
||||||
|
|
|
@ -178,15 +178,75 @@ static SDL_VideoDevice* QZ_CreateDevice (int device_index)
|
||||||
|
|
||||||
static void QZ_DeleteDevice (SDL_VideoDevice *device)
|
static void QZ_DeleteDevice (SDL_VideoDevice *device)
|
||||||
{
|
{
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
_THIS = device;
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
CGDisplayModeRelease((CGDisplayModeRef) save_mode); /* NULL is ok */
|
||||||
|
CGDisplayModeRelease((CGDisplayModeRef) mode); /* NULL is ok */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SDL_free (device->hidden);
|
SDL_free (device->hidden);
|
||||||
SDL_free (device);
|
SDL_free (device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void QZ_GetModeInfo(_THIS, const void *_mode, Uint32 *w, Uint32 *h, Uint32 *bpp)
|
||||||
|
{
|
||||||
|
*w = *h = *bpp = 0;
|
||||||
|
if (_mode == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
CGDisplayModeRef vidmode = (CGDisplayModeRef) _mode;
|
||||||
|
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||||
|
|
||||||
|
*w = (Uint32) CGDisplayModeGetWidth(vidmode);
|
||||||
|
*h = (Uint32) CGDisplayModeGetHeight(vidmode);
|
||||||
|
|
||||||
|
/* we only care about the 32-bit modes... */
|
||||||
|
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
|
||||||
|
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
*bpp = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
CFRelease(fmt);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
|
CFDictionaryRef vidmode = (CFDictionaryRef) _mode;
|
||||||
|
CFNumberGetValue (
|
||||||
|
CFDictionaryGetValue (vidmode, kCGDisplayBitsPerPixel),
|
||||||
|
kCFNumberSInt32Type, bpp);
|
||||||
|
|
||||||
|
CFNumberGetValue (
|
||||||
|
CFDictionaryGetValue (vidmode, kCGDisplayWidth),
|
||||||
|
kCFNumberSInt32Type, w);
|
||||||
|
|
||||||
|
CFNumberGetValue (
|
||||||
|
CFDictionaryGetValue (vidmode, kCGDisplayHeight),
|
||||||
|
kCFNumberSInt32Type, h);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we only care about the 32-bit modes... */
|
||||||
|
if (*bpp != 32) {
|
||||||
|
*bpp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
||||||
{
|
{
|
||||||
NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
||||||
const char *env = NULL;
|
const char *env = NULL;
|
||||||
|
|
||||||
|
/* we don't set this from system_version; you might not have the SDK. */
|
||||||
|
snow_leopard_or_later = NO;
|
||||||
|
|
||||||
|
if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
|
||||||
|
system_version = 0;
|
||||||
|
|
||||||
/* Initialize the video settings; this data persists between mode switches */
|
/* Initialize the video settings; this data persists between mode switches */
|
||||||
display_id = kCGDirectMainDisplay;
|
display_id = kCGDirectMainDisplay;
|
||||||
|
|
||||||
|
@ -203,9 +263,23 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
if (CGDisplayCopyDisplayMode != NULL) {
|
||||||
|
snow_leopard_or_later = YES;
|
||||||
|
save_mode = CGDisplayCopyDisplayMode(display_id);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
|
if (!snow_leopard_or_later) {
|
||||||
save_mode = CGDisplayCurrentMode(display_id);
|
save_mode = CGDisplayCurrentMode(display_id);
|
||||||
mode_list = CGDisplayAvailableModes (display_id);
|
}
|
||||||
palette = CGPaletteCreateDefaultColorPalette ();
|
#endif
|
||||||
|
|
||||||
|
if (save_mode == NULL) {
|
||||||
|
SDL_SetError("Couldn't figure out current display mode.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Allow environment override of screensaver disable. */
|
/* Allow environment override of screensaver disable. */
|
||||||
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
|
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
|
||||||
|
@ -220,14 +294,18 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gather some information that is useful to know about the display */
|
/* Gather some information that is useful to know about the display */
|
||||||
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel),
|
QZ_GetModeInfo(this, save_mode, &device_width, &device_height, &device_bpp);
|
||||||
kCFNumberSInt32Type, &device_bpp);
|
if (device_bpp == 0) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
CGDisplayModeRelease((CGDisplayModeRef) save_mode);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayWidth),
|
save_mode = NULL;
|
||||||
kCFNumberSInt32Type, &device_width);
|
SDL_SetError("Unsupported display mode");
|
||||||
|
return -1;
|
||||||
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayHeight),
|
}
|
||||||
kCFNumberSInt32Type, &device_height);
|
|
||||||
|
|
||||||
/* Determine the current screen size */
|
/* Determine the current screen size */
|
||||||
this->info.current_w = device_width;
|
this->info.current_w = device_width;
|
||||||
|
@ -243,9 +321,6 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
||||||
current_mods = 0;
|
current_mods = 0;
|
||||||
field_edit = [[SDLTranslatorResponder alloc] initWithFrame:r];
|
field_edit = [[SDLTranslatorResponder alloc] initWithFrame:r];
|
||||||
|
|
||||||
if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
|
|
||||||
system_version = 0;
|
|
||||||
|
|
||||||
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
|
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
|
||||||
QZ_RegisterForSleepNotifications (this);
|
QZ_RegisterForSleepNotifications (this);
|
||||||
|
|
||||||
|
@ -257,6 +332,7 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format)
|
||||||
|
|
||||||
static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
{
|
{
|
||||||
|
CFArrayRef mode_list = NULL; /* list of available fullscreen modes */
|
||||||
CFIndex num_modes;
|
CFIndex num_modes;
|
||||||
CFIndex i;
|
CFIndex i;
|
||||||
|
|
||||||
|
@ -268,7 +344,6 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
|
|
||||||
/* Free memory from previous call, if any */
|
/* Free memory from previous call, if any */
|
||||||
if ( client_mode_list != NULL ) {
|
if ( client_mode_list != NULL ) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; client_mode_list[i] != NULL; i++)
|
for (i = 0; client_mode_list[i] != NULL; i++)
|
||||||
|
@ -278,37 +353,30 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
client_mode_list = NULL;
|
client_mode_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
|
mode_list = CGDisplayAvailableModes(display_id);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
num_modes = CFArrayGetCount (mode_list);
|
num_modes = CFArrayGetCount (mode_list);
|
||||||
|
|
||||||
/* Build list of modes with the requested bpp */
|
/* Build list of modes with the requested bpp */
|
||||||
for (i = 0; i < num_modes; i++) {
|
for (i = 0; i < num_modes; i++) {
|
||||||
|
Uint32 width, height, bpp;
|
||||||
|
const void *onemode = CFArrayGetValueAtIndex(mode_list, i);
|
||||||
|
|
||||||
CFDictionaryRef onemode;
|
QZ_GetModeInfo(this, onemode, &width, &height, &bpp);
|
||||||
CFNumberRef number;
|
|
||||||
int bpp;
|
|
||||||
|
|
||||||
onemode = CFArrayGetValueAtIndex (mode_list, i);
|
if (bpp && (bpp == format->BitsPerPixel)) {
|
||||||
number = CFDictionaryGetValue (onemode, kCGDisplayBitsPerPixel);
|
int hasMode = SDL_FALSE;
|
||||||
CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
|
int i;
|
||||||
|
|
||||||
if (bpp == format->BitsPerPixel) {
|
|
||||||
|
|
||||||
int intvalue;
|
|
||||||
int hasMode;
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
number = CFDictionaryGetValue (onemode, kCGDisplayWidth);
|
|
||||||
CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
|
|
||||||
width = (Uint16) intvalue;
|
|
||||||
|
|
||||||
number = CFDictionaryGetValue (onemode, kCGDisplayHeight);
|
|
||||||
CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
|
|
||||||
height = (Uint16) intvalue;
|
|
||||||
|
|
||||||
/* Check if mode is already in the list */
|
/* Check if mode is already in the list */
|
||||||
{
|
|
||||||
int i;
|
|
||||||
hasMode = SDL_FALSE;
|
|
||||||
for (i = 0; i < list_size; i++) {
|
for (i = 0; i < list_size; i++) {
|
||||||
if (client_mode_list[i]->w == width &&
|
if (client_mode_list[i]->w == width &&
|
||||||
client_mode_list[i]->h == height) {
|
client_mode_list[i]->h == height) {
|
||||||
|
@ -316,11 +384,9 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Grow the list and add mode to the list */
|
/* Grow the list and add mode to the list */
|
||||||
if ( ! hasMode ) {
|
if ( ! hasMode ) {
|
||||||
|
|
||||||
SDL_Rect *rect;
|
SDL_Rect *rect;
|
||||||
|
|
||||||
list_size++;
|
list_size++;
|
||||||
|
@ -328,13 +394,21 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
if (client_mode_list == NULL)
|
if (client_mode_list == NULL)
|
||||||
client_mode_list = (SDL_Rect**)
|
client_mode_list = (SDL_Rect**)
|
||||||
SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
|
SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
|
||||||
else
|
else {
|
||||||
|
/* !!! FIXME: this leaks memory if SDL_realloc() fails! */
|
||||||
client_mode_list = (SDL_Rect**)
|
client_mode_list = (SDL_Rect**)
|
||||||
SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
|
SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
|
||||||
|
}
|
||||||
|
|
||||||
rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
|
rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
|
||||||
|
|
||||||
if (client_mode_list == NULL || rect == NULL) {
|
if (client_mode_list == NULL || rect == NULL) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
/* we own this memory in 10.6+ */
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
CFRelease(mode_list);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
SDL_OutOfMemory ();
|
SDL_OutOfMemory ();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -349,6 +423,12 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
CFRelease(mode_list); /* we own this memory in 10.6+ */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sort list largest to smallest (by area) */
|
/* Sort list largest to smallest (by area) */
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
@ -367,6 +447,7 @@ static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client_mode_list;
|
return client_mode_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +462,26 @@ static SDL_bool QZ_WindowPosition(_THIS, int *x, int *y)
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CGError QZ_SetDisplayMode(_THIS, const void *vidmode)
|
||||||
|
{
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
return CGDisplaySetDisplayMode(display_id, (CGDisplayModeRef) vidmode, NULL);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
|
return CGDisplaySwitchToMode(display_id, (CFDictionaryRef) vidmode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return kCGErrorFailure;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline CGError QZ_RestoreDisplayMode(_THIS)
|
||||||
|
{
|
||||||
|
return QZ_SetDisplayMode(this, save_mode);
|
||||||
|
}
|
||||||
|
|
||||||
static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
|
static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
|
||||||
{
|
{
|
||||||
/* Reset values that may change between switches */
|
/* Reset values that may change between switches */
|
||||||
|
@ -418,7 +519,7 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
|
||||||
if (to_desktop) {
|
if (to_desktop) {
|
||||||
ShowMenuBar ();
|
ShowMenuBar ();
|
||||||
/* Restore original screen resolution/bpp */
|
/* Restore original screen resolution/bpp */
|
||||||
CGDisplaySwitchToMode (display_id, save_mode);
|
QZ_RestoreDisplayMode (this);
|
||||||
CGReleaseAllDisplays ();
|
CGReleaseAllDisplays ();
|
||||||
/*
|
/*
|
||||||
Reset the main screen's rectangle
|
Reset the main screen's rectangle
|
||||||
|
@ -445,10 +546,51 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
|
||||||
video_set = SDL_FALSE;
|
video_set = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const void *QZ_BestMode(_THIS, const int bpp, const int w, const int h)
|
||||||
|
{
|
||||||
|
const void *best = NULL;
|
||||||
|
|
||||||
|
if (bpp == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
/* apparently, we have to roll our own now. :/ */
|
||||||
|
CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
|
||||||
|
if (mode_list != NULL) {
|
||||||
|
const CFIndex num_modes = CFArrayGetCount(mode_list);
|
||||||
|
CFIndex i;
|
||||||
|
for (i = 0; i < num_modes; i++) {
|
||||||
|
const void *vidmode = CFArrayGetValueAtIndex(mode_list, i);
|
||||||
|
Uint32 thisw, thish, thisbpp;
|
||||||
|
QZ_GetModeInfo(this, vidmode, &thisw, &thish, &thisbpp);
|
||||||
|
|
||||||
|
/* We only care about exact matches, apparently. */
|
||||||
|
if ((thisbpp == bpp) && (thisw == w) && (thish == h)) {
|
||||||
|
best = vidmode;
|
||||||
|
break; /* got it! */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CGDisplayModeRetain((CGDisplayModeRef) best); /* NULL is ok */
|
||||||
|
CFRelease(mode_list);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
|
||||||
|
boolean_t exact = 0;
|
||||||
|
best = CGDisplayBestModeForParameters(display_id, bpp, w, h, &exact);
|
||||||
|
if (!exact) {
|
||||||
|
best = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
|
static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
|
||||||
int height, int bpp, Uint32 flags)
|
int height, int bpp, Uint32 flags)
|
||||||
{
|
{
|
||||||
boolean_t exact_match = 0;
|
|
||||||
NSRect screen_rect;
|
NSRect screen_rect;
|
||||||
CGError error;
|
CGError error;
|
||||||
NSRect contentRect;
|
NSRect contentRect;
|
||||||
|
@ -476,12 +618,17 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
|
||||||
goto ERR_NO_MATCH;
|
goto ERR_NO_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||||
|
if (snow_leopard_or_later) {
|
||||||
|
CGDisplayModeRelease((CGDisplayModeRef) mode); /* NULL is ok */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* See if requested mode exists */
|
/* See if requested mode exists */
|
||||||
mode = CGDisplayBestModeForParameters (display_id, bpp, width,
|
mode = QZ_BestMode(this, bpp, width, height);
|
||||||
height, &exact_match);
|
|
||||||
|
|
||||||
/* Require an exact match to the requested mode */
|
/* Require an exact match to the requested mode */
|
||||||
if ( ! exact_match ) {
|
if ( mode == NULL ) {
|
||||||
SDL_SetError ("Failed to find display resolution: %dx%dx%d", width, height, bpp);
|
SDL_SetError ("Failed to find display resolution: %dx%dx%d", width, height, bpp);
|
||||||
goto ERR_NO_MATCH;
|
goto ERR_NO_MATCH;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +645,7 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do the physical switch */
|
/* Do the physical switch */
|
||||||
if ( CGDisplayNoErr != CGDisplaySwitchToMode (display_id, mode) ) {
|
if ( CGDisplayNoErr != QZ_SetDisplayMode(this, mode) ) {
|
||||||
SDL_SetError ("Failed switching display resolution");
|
SDL_SetError ("Failed switching display resolution");
|
||||||
goto ERR_NO_SWITCH;
|
goto ERR_NO_SWITCH;
|
||||||
}
|
}
|
||||||
|
@ -627,8 +774,7 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
|
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
|
||||||
ERR_NO_GL:
|
ERR_NO_GL: QZ_RestoreDisplayMode(this);
|
||||||
ERR_DOUBLEBUF: CGDisplaySwitchToMode (display_id, save_mode);
|
|
||||||
ERR_NO_SWITCH: CGReleaseAllDisplays ();
|
ERR_NO_SWITCH: CGReleaseAllDisplays ();
|
||||||
ERR_NO_CAPTURE:
|
ERR_NO_CAPTURE:
|
||||||
ERR_NO_MATCH: if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
|
ERR_NO_MATCH: if ( fade_token != kCGDisplayFadeReservationInvalidToken ) {
|
||||||
|
@ -876,25 +1022,7 @@ static int QZ_ToggleFullScreen (_THIS, int on)
|
||||||
static int QZ_SetColors (_THIS, int first_color, int num_colors,
|
static int QZ_SetColors (_THIS, int first_color, int num_colors,
|
||||||
SDL_Color *colors)
|
SDL_Color *colors)
|
||||||
{
|
{
|
||||||
CGTableCount index;
|
return 0; /* always fail: we shouldn't have an 8-bit mode on Mac OS X! */
|
||||||
CGDeviceColor color;
|
|
||||||
|
|
||||||
for (index = first_color; index < first_color+num_colors; index++) {
|
|
||||||
|
|
||||||
/* Clamp colors between 0.0 and 1.0 */
|
|
||||||
color.red = colors->r / 255.0;
|
|
||||||
color.blue = colors->b / 255.0;
|
|
||||||
color.green = colors->g / 255.0;
|
|
||||||
|
|
||||||
colors++;
|
|
||||||
|
|
||||||
CGPaletteSetColorAtIndex (palette, color, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( CGDisplayNoErr != CGDisplaySetPalette (display_id, palette) )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1019,8 +1147,6 @@ static void QZ_VideoQuit (_THIS)
|
||||||
else
|
else
|
||||||
QZ_UnsetVideoMode (this, TRUE);
|
QZ_UnsetVideoMode (this, TRUE);
|
||||||
|
|
||||||
CGPaletteRelease (palette);
|
|
||||||
|
|
||||||
if (opengl_library) {
|
if (opengl_library) {
|
||||||
SDL_UnloadObject(opengl_library);
|
SDL_UnloadObject(opengl_library);
|
||||||
opengl_library = NULL;
|
opengl_library = NULL;
|
||||||
|
@ -1096,7 +1222,7 @@ int QZ_GetGamma (_THIS, float *red, float *green, float *blue)
|
||||||
|
|
||||||
int QZ_SetGammaRamp (_THIS, Uint16 *ramp)
|
int QZ_SetGammaRamp (_THIS, Uint16 *ramp)
|
||||||
{
|
{
|
||||||
const CGTableCount tableSize = 255;
|
const uint32_t tableSize = 255;
|
||||||
CGGammaValue redTable[tableSize];
|
CGGammaValue redTable[tableSize];
|
||||||
CGGammaValue greenTable[tableSize];
|
CGGammaValue greenTable[tableSize];
|
||||||
CGGammaValue blueTable[tableSize];
|
CGGammaValue blueTable[tableSize];
|
||||||
|
@ -1122,11 +1248,11 @@ int QZ_SetGammaRamp (_THIS, Uint16 *ramp)
|
||||||
|
|
||||||
int QZ_GetGammaRamp (_THIS, Uint16 *ramp)
|
int QZ_GetGammaRamp (_THIS, Uint16 *ramp)
|
||||||
{
|
{
|
||||||
const CGTableCount tableSize = 255;
|
const uint32_t tableSize = 255;
|
||||||
CGGammaValue redTable[tableSize];
|
CGGammaValue redTable[tableSize];
|
||||||
CGGammaValue greenTable[tableSize];
|
CGGammaValue greenTable[tableSize];
|
||||||
CGGammaValue blueTable[tableSize];
|
CGGammaValue blueTable[tableSize];
|
||||||
CGTableCount actual;
|
uint32_t actual;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ( CGDisplayNoErr != CGGetDisplayTransferByTable
|
if ( CGDisplayNoErr != CGGetDisplayTransferByTable
|
||||||
|
|
|
@ -49,13 +49,13 @@ WMcursor* QZ_CreateWMCursor (_THIS, Uint8 *data, Uint8 *mask,
|
||||||
if (cursor == NULL) goto outOfMemory;
|
if (cursor == NULL) goto outOfMemory;
|
||||||
|
|
||||||
/* create the image representation and get the pointers to its storage */
|
/* create the image representation and get the pointers to its storage */
|
||||||
imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w+7)/8 bitsPerPixel: 0 ] autorelease ];
|
imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceWhiteColorSpace bytesPerRow: (w+7)/8 bitsPerPixel: 0 ] autorelease ];
|
||||||
if (imgrep == nil) goto outOfMemory;
|
if (imgrep == nil) goto outOfMemory;
|
||||||
[ imgrep getBitmapDataPlanes: planes ];
|
[ imgrep getBitmapDataPlanes: planes ];
|
||||||
|
|
||||||
/* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
|
/* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
|
||||||
for (i = 0; i < (w+7)/8*h; i++) {
|
for (i = 0; i < (w+7)/8*h; i++) {
|
||||||
planes[0][i] = data[i];
|
planes[0][i] = data[i] ^ 0xFF;
|
||||||
planes[1][i] = mask[i] | data[i];
|
planes[1][i] = mask[i] | data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
|
||||||
#endif /* Dead code */
|
#endif /* Dead code */
|
||||||
|
|
||||||
void QZ_PrivateWarpCursor (_THIS, int x, int y) {
|
void QZ_PrivateWarpCursor (_THIS, int x, int y) {
|
||||||
|
CGEventSourceRef evsrc = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
|
||||||
NSPoint p;
|
NSPoint p;
|
||||||
CGPoint cgp;
|
CGPoint cgp;
|
||||||
|
|
||||||
|
@ -240,8 +240,9 @@ void QZ_PrivateWarpCursor (_THIS, int x, int y) {
|
||||||
cgp = QZ_PrivateSDLToCG (this, &p);
|
cgp = QZ_PrivateSDLToCG (this, &p);
|
||||||
|
|
||||||
/* this is the magic call that fixes cursor "freezing" after warp */
|
/* this is the magic call that fixes cursor "freezing" after warp */
|
||||||
CGSetLocalEventsSuppressionInterval (0.0);
|
CGEventSourceSetLocalEventsSuppressionInterval(evsrc, 0.0);
|
||||||
CGWarpMouseCursorPosition (cgp);
|
CGWarpMouseCursorPosition (cgp);
|
||||||
|
CFRelease(evsrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
|
void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue