src/video/cocoa/SDL_cocoamodes.m
author Ryan C. Gordon <icculus@icculus.org>
Wed, 09 Nov 2011 00:27:44 -0500
changeset 6072 8b473f33c766
parent 6044 35448a5ea044
child 6101 4b88086910d3
permissions -rw-r--r--
Fixed compiler warnings for uninitialized variables.
slouken@1931
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@1931
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1931
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1931
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1931
    20
*/
slouken@1931
    21
#include "SDL_config.h"
slouken@1931
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_COCOA
slouken@6044
    24
slouken@1931
    25
#include "SDL_cocoavideo.h"
slouken@1931
    26
icculus@5643
    27
/* !!! FIXME: clean out the pre-10.6 code when it makes sense to do so. */
icculus@5643
    28
#define FORCE_OLD_API 0 || (MAC_OS_X_VERSION_MAX_ALLOWED < 1060)
icculus@5643
    29
icculus@5643
    30
#if FORCE_OLD_API
icculus@5643
    31
#undef MAC_OS_X_VERSION_MIN_REQUIRED
icculus@5646
    32
#define MAC_OS_X_VERSION_MIN_REQUIRED 1050
icculus@5643
    33
#endif
icculus@5643
    34
icculus@5646
    35
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
slouken@1973
    36
/* 
slouken@1973
    37
    Add methods to get at private members of NSScreen. 
slouken@1973
    38
    Since there is a bug in Apple's screen switching code
slouken@1973
    39
    that does not update this variable when switching
slouken@1973
    40
    to fullscreen, we'll set it manually (but only for the
slouken@1973
    41
    main screen).
slouken@1973
    42
*/
slouken@1973
    43
@interface NSScreen (NSScreenAccess)
slouken@1973
    44
- (void) setFrame:(NSRect)frame;
slouken@1973
    45
@end
slouken@1973
    46
slouken@1973
    47
@implementation NSScreen (NSScreenAccess)
slouken@1973
    48
- (void) setFrame:(NSRect)frame;
slouken@1973
    49
{
slouken@1973
    50
    _frame = frame;
slouken@1973
    51
}
slouken@1973
    52
@end
slouken@3246
    53
#endif
slouken@1973
    54
icculus@5643
    55
static inline BOOL
icculus@5643
    56
IS_SNOW_LEOPARD_OR_LATER(_THIS)
icculus@5643
    57
{
icculus@5643
    58
#if FORCE_OLD_API
icculus@5643
    59
    return NO;
icculus@5643
    60
#else
icculus@5643
    61
    return ((((SDL_VideoData *) _this->driverdata))->osversion >= 0x1060);
icculus@5643
    62
#endif
icculus@5643
    63
}
icculus@5643
    64
slouken@1934
    65
static void
slouken@1934
    66
CG_SetError(const char *prefix, CGDisplayErr result)
slouken@1934
    67
{
slouken@1934
    68
    const char *error;
slouken@1934
    69
slouken@1934
    70
    switch (result) {
slouken@1934
    71
    case kCGErrorFailure:
slouken@1934
    72
        error = "kCGErrorFailure";
slouken@1934
    73
        break;
slouken@1934
    74
    case kCGErrorIllegalArgument:
slouken@1934
    75
        error = "kCGErrorIllegalArgument";
slouken@1934
    76
        break;
slouken@1934
    77
    case kCGErrorInvalidConnection:
slouken@1934
    78
        error = "kCGErrorInvalidConnection";
slouken@1934
    79
        break;
slouken@1934
    80
    case kCGErrorInvalidContext:
slouken@1934
    81
        error = "kCGErrorInvalidContext";
slouken@1934
    82
        break;
slouken@1934
    83
    case kCGErrorCannotComplete:
slouken@1934
    84
        error = "kCGErrorCannotComplete";
slouken@1934
    85
        break;
slouken@1934
    86
    case kCGErrorNameTooLong:
slouken@1934
    87
        error = "kCGErrorNameTooLong";
slouken@1934
    88
        break;
slouken@1934
    89
    case kCGErrorNotImplemented:
slouken@1934
    90
        error = "kCGErrorNotImplemented";
slouken@1934
    91
        break;
slouken@1934
    92
    case kCGErrorRangeCheck:
slouken@1934
    93
        error = "kCGErrorRangeCheck";
slouken@1934
    94
        break;
slouken@1934
    95
    case kCGErrorTypeCheck:
slouken@1934
    96
        error = "kCGErrorTypeCheck";
slouken@1934
    97
        break;
slouken@1934
    98
    case kCGErrorNoCurrentPoint:
slouken@1934
    99
        error = "kCGErrorNoCurrentPoint";
slouken@1934
   100
        break;
slouken@1934
   101
    case kCGErrorInvalidOperation:
slouken@1934
   102
        error = "kCGErrorInvalidOperation";
slouken@1934
   103
        break;
slouken@1934
   104
    case kCGErrorNoneAvailable:
slouken@1934
   105
        error = "kCGErrorNoneAvailable";
slouken@1934
   106
        break;
slouken@1934
   107
    default:
slouken@1934
   108
        error = "Unknown Error";
slouken@1934
   109
        break;
slouken@1934
   110
    }
slouken@1934
   111
    SDL_SetError("%s: %s", prefix, error);
slouken@1934
   112
}
slouken@1934
   113
slouken@1934
   114
static SDL_bool
icculus@5643
   115
GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
slouken@1934
   116
{
slouken@1934
   117
    SDL_DisplayModeData *data;
icculus@6072
   118
    long width = 0;
icculus@6072
   119
    long height = 0;
icculus@6072
   120
    long bpp = 0;
icculus@6072
   121
    long refreshRate = 0;
slouken@1934
   122
slouken@1934
   123
    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
slouken@1934
   124
    if (!data) {
slouken@1934
   125
        return SDL_FALSE;
slouken@1934
   126
    }
slouken@1934
   127
    data->moderef = moderef;
slouken@1934
   128
icculus@5646
   129
    #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   130
    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   131
        CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
icculus@5643
   132
        CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
icculus@5643
   133
        width = (long) CGDisplayModeGetWidth(vidmode);
icculus@5643
   134
        height = (long) CGDisplayModeGetHeight(vidmode);
icculus@5643
   135
        refreshRate = (long) CGDisplayModeGetRefreshRate(vidmode);
icculus@5643
   136
icculus@5643
   137
        if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
icculus@5643
   138
                            kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
icculus@5643
   139
            bpp = 32;
icculus@5643
   140
        } else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels),
icculus@5643
   141
                            kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
icculus@5643
   142
            bpp = 16;
icculus@5643
   143
        } else {
icculus@5643
   144
            bpp = 0;  /* ignore 8-bit and such for now. */
icculus@5643
   145
        }
icculus@5643
   146
icculus@5643
   147
        CFRelease(fmt);
icculus@5643
   148
    }
icculus@5643
   149
    #endif
icculus@5643
   150
icculus@5646
   151
    #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
icculus@5643
   152
    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
slouken@6044
   153
        CFNumberRef number;
icculus@5643
   154
        CFDictionaryRef vidmode = (CFDictionaryRef) moderef;
icculus@5643
   155
        number = CFDictionaryGetValue(vidmode, kCGDisplayWidth);
icculus@5643
   156
        CFNumberGetValue(number, kCFNumberLongType, &width);
icculus@5643
   157
        number = CFDictionaryGetValue(vidmode, kCGDisplayHeight);
icculus@5643
   158
        CFNumberGetValue(number, kCFNumberLongType, &height);
icculus@5643
   159
        number = CFDictionaryGetValue(vidmode, kCGDisplayBitsPerPixel);
icculus@5643
   160
        CFNumberGetValue(number, kCFNumberLongType, &bpp);
icculus@5643
   161
        number = CFDictionaryGetValue(vidmode, kCGDisplayRefreshRate);
icculus@5643
   162
        CFNumberGetValue(number, kCFNumberLongType, &refreshRate);
icculus@5643
   163
    }
icculus@5643
   164
    #endif
slouken@1934
   165
slouken@1969
   166
    mode->format = SDL_PIXELFORMAT_UNKNOWN;
slouken@1934
   167
    switch (bpp) {
slouken@1934
   168
    case 16:
slouken@2237
   169
        mode->format = SDL_PIXELFORMAT_ARGB1555;
slouken@1934
   170
        break;
slouken@1934
   171
    case 32:
slouken@2237
   172
        mode->format = SDL_PIXELFORMAT_ARGB8888;
slouken@1934
   173
        break;
icculus@5643
   174
    case 8: /* We don't support palettized modes now */
icculus@5643
   175
    default: /* Totally unrecognizable bit depth. */
icculus@5643
   176
        return SDL_FALSE;
slouken@1934
   177
    }
slouken@1934
   178
    mode->w = width;
slouken@1934
   179
    mode->h = height;
slouken@1934
   180
    mode->refresh_rate = refreshRate;
slouken@1934
   181
    mode->driverdata = data;
slouken@1934
   182
    return SDL_TRUE;
slouken@1934
   183
}
slouken@1931
   184
icculus@5643
   185
static inline void
icculus@5643
   186
Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
icculus@5643
   187
{
icculus@5643
   188
    /* We don't own moderef unless we use the 10.6+ APIs. */
icculus@5646
   189
    #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   190
    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   191
        CGDisplayModeRelease((CGDisplayModeRef) moderef);  /* NULL is ok */
icculus@5643
   192
    }
icculus@5643
   193
    #endif
icculus@5643
   194
}
icculus@5643
   195
icculus@5643
   196
static inline void
icculus@5643
   197
Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
icculus@5643
   198
{
icculus@5643
   199
    /* We don't own modelis unless we use the 10.6+ APIs. */
icculus@5646
   200
    #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   201
    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   202
        CFRelease(modelist);  /* NULL is ok */
icculus@5643
   203
    }
icculus@5643
   204
    #endif
icculus@5643
   205
}
icculus@5643
   206
slouken@1931
   207
void
slouken@1931
   208
Cocoa_InitModes(_THIS)
slouken@1931
   209
{
slouken@1934
   210
    CGDisplayErr result;
slouken@1934
   211
    CGDirectDisplayID *displays;
slouken@1934
   212
    CGDisplayCount numDisplays;
slouken@3505
   213
    int pass, i;
slouken@1934
   214
slouken@1934
   215
    result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
slouken@1934
   216
    if (result != kCGErrorSuccess) {
slouken@1934
   217
        CG_SetError("CGGetOnlineDisplayList()", result);
slouken@1934
   218
        return;
slouken@1934
   219
    }
slouken@1934
   220
    displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
slouken@1934
   221
    result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
slouken@1934
   222
    if (result != kCGErrorSuccess) {
slouken@1934
   223
        CG_SetError("CGGetOnlineDisplayList()", result);
slouken@1934
   224
        SDL_stack_free(displays);
slouken@1934
   225
        return;
slouken@1934
   226
    }
slouken@1934
   227
slouken@3505
   228
    /* Pick up the primary display in the first pass, then get the rest */
slouken@3505
   229
    for (pass = 0; pass < 2; ++pass) {
slouken@3505
   230
        for (i = 0; i < numDisplays; ++i) {
slouken@3505
   231
            SDL_VideoDisplay display;
slouken@3505
   232
            SDL_DisplayData *displaydata;
slouken@3505
   233
            SDL_DisplayMode mode;
icculus@5643
   234
            const void *moderef = NULL;
slouken@1934
   235
slouken@3505
   236
            if (pass == 0) {
slouken@3505
   237
                if (!CGDisplayIsMain(displays[i])) {
slouken@3505
   238
                    continue;
slouken@3505
   239
                }
slouken@3505
   240
            } else {
slouken@3505
   241
                if (CGDisplayIsMain(displays[i])) {
slouken@3505
   242
                    continue;
slouken@3505
   243
                }
slouken@3505
   244
            }
slouken@1934
   245
slouken@3505
   246
            if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
slouken@3505
   247
                continue;
slouken@3505
   248
            }
icculus@5643
   249
icculus@5646
   250
            #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   251
            if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   252
                moderef = CGDisplayCopyDisplayMode(displays[i]);
icculus@5643
   253
            }
icculus@5643
   254
            #endif
icculus@5643
   255
icculus@5646
   256
            #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
icculus@5643
   257
            if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   258
                moderef = CGDisplayCurrentMode(displays[i]);
icculus@5643
   259
            }
icculus@5643
   260
            #endif
icculus@5643
   261
slouken@3505
   262
            if (!moderef) {
slouken@3505
   263
                continue;
slouken@3505
   264
            }
slouken@1934
   265
slouken@3505
   266
            displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
slouken@3505
   267
            if (!displaydata) {
icculus@5643
   268
                Cocoa_ReleaseDisplayMode(_this, moderef);
slouken@3505
   269
                continue;
slouken@3505
   270
            }
slouken@3505
   271
            displaydata->display = displays[i];
slouken@3505
   272
slouken@3505
   273
            SDL_zero(display);
icculus@5643
   274
            if (!GetDisplayMode (_this, moderef, &mode)) {
icculus@5643
   275
                Cocoa_ReleaseDisplayMode(_this, moderef);
slouken@3505
   276
                SDL_free(displaydata);
slouken@3505
   277
                continue;
slouken@3505
   278
            }
icculus@5643
   279
slouken@3505
   280
            display.desktop_mode = mode;
slouken@3505
   281
            display.current_mode = mode;
slouken@3505
   282
            display.driverdata = displaydata;
slouken@3505
   283
            SDL_AddVideoDisplay(&display);
slouken@1934
   284
        }
slouken@1934
   285
    }
slouken@1973
   286
    SDL_stack_free(displays);
slouken@1934
   287
}
slouken@1934
   288
slouken@3528
   289
int
slouken@3528
   290
Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
slouken@3525
   291
{
slouken@3528
   292
    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
slouken@3525
   293
    CGRect cgrect;
slouken@3525
   294
slouken@3528
   295
    cgrect = CGDisplayBounds(displaydata->display);
slouken@3528
   296
    rect->x = (int)cgrect.origin.x;
slouken@3528
   297
    rect->y = (int)cgrect.origin.y;
slouken@3528
   298
    rect->w = (int)cgrect.size.width;
slouken@3528
   299
    rect->h = (int)cgrect.size.height;
slouken@3528
   300
    return 0;
slouken@3525
   301
}
slouken@3525
   302
slouken@1931
   303
void
slouken@3500
   304
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
slouken@1931
   305
{
slouken@3500
   306
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
icculus@5643
   307
    CFArrayRef modes = NULL;
icculus@5643
   308
icculus@5646
   309
    #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   310
    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   311
        modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
icculus@5643
   312
    }
icculus@5643
   313
    #endif
icculus@5643
   314
icculus@5646
   315
    #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
icculus@5643
   316
    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   317
        modes = CGDisplayAvailableModes(data->display);
icculus@5643
   318
    }
icculus@5643
   319
    #endif
icculus@5643
   320
icculus@5643
   321
    if (modes) {
icculus@5643
   322
        const CFIndex count = CFArrayGetCount(modes);
icculus@5643
   323
        CFIndex i;
slouken@1934
   324
icculus@5643
   325
        for (i = 0; i < count; i++) {
icculus@5643
   326
            const void *moderef = CFArrayGetValueAtIndex(modes, i);
icculus@5643
   327
            SDL_DisplayMode mode;
icculus@5643
   328
            if (GetDisplayMode(_this, moderef, &mode)) {
icculus@5646
   329
                #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   330
                if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   331
                    CGDisplayModeRetain((CGDisplayModeRef) moderef);
icculus@5643
   332
                }
icculus@5643
   333
                #endif
icculus@5643
   334
                SDL_AddDisplayMode(display, &mode);
icculus@5643
   335
            }
icculus@5643
   336
        }
icculus@5643
   337
icculus@5643
   338
        Cocoa_ReleaseDisplayModeList(_this, modes);
slouken@1934
   339
    }
icculus@5643
   340
}
icculus@5643
   341
icculus@5643
   342
static CGError
icculus@5643
   343
Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
icculus@5643
   344
{
icculus@5646
   345
    #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
icculus@5643
   346
    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   347
        return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
icculus@5643
   348
    }
icculus@5643
   349
    #endif
icculus@5643
   350
icculus@5646
   351
    #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
icculus@5643
   352
    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
icculus@5643
   353
        return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode);
icculus@5643
   354
    }
icculus@5643
   355
    #endif
icculus@5643
   356
icculus@5643
   357
    return kCGErrorFailure;
slouken@1931
   358
}
slouken@1931
   359
slouken@1931
   360
int
slouken@3500
   361
Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
slouken@1931
   362
{
slouken@3500
   363
    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
slouken@1934
   364
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
slouken@1934
   365
    CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
slouken@1934
   366
    CGError result;
slouken@4939
   367
slouken@1934
   368
    /* Fade to black to hide resolution-switching flicker */
slouken@1934
   369
    if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
slouken@1934
   370
        CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
slouken@1934
   371
    }
slouken@1934
   372
slouken@3513
   373
    if (data == display->desktop_mode.driverdata) {
slouken@3513
   374
        /* Restoring desktop mode */
icculus@5643
   375
        Cocoa_SwitchMode(_this, displaydata->display, data->moderef);
slouken@4939
   376
slouken@5248
   377
        if (CGDisplayIsMain(displaydata->display)) {
slouken@5248
   378
            CGReleaseAllDisplays();
slouken@5248
   379
        } else {
slouken@5248
   380
            CGDisplayRelease(displaydata->display);
slouken@5248
   381
        }
slouken@1934
   382
slouken@3513
   383
        if (CGDisplayIsMain(displaydata->display)) {
slouken@3513
   384
            ShowMenuBar();
slouken@3513
   385
        }
slouken@3513
   386
    } else {
slouken@4939
   387
        /* Put up the blanking window (a window above all other windows) */
slouken@5248
   388
        if (CGDisplayIsMain(displaydata->display)) {
slouken@5248
   389
            /* If we don't capture all displays, Cocoa tries to rearrange windows... *sigh* */
slouken@5248
   390
            result = CGCaptureAllDisplays();
slouken@5248
   391
        } else {
slouken@5248
   392
            result = CGDisplayCapture(displaydata->display);
slouken@5248
   393
        }
slouken@4939
   394
        if (result != kCGErrorSuccess) {
slouken@4939
   395
            CG_SetError("CGDisplayCapture()", result);
slouken@4939
   396
            goto ERR_NO_CAPTURE;
slouken@4939
   397
        }
slouken@4939
   398
slouken@3513
   399
        /* Do the physical switch */
icculus@5643
   400
        result = Cocoa_SwitchMode(_this, displaydata->display, data->moderef);
slouken@3513
   401
        if (result != kCGErrorSuccess) {
slouken@3513
   402
            CG_SetError("CGDisplaySwitchToMode()", result);
slouken@3513
   403
            goto ERR_NO_SWITCH;
slouken@3513
   404
        }
slouken@3513
   405
slouken@3513
   406
        /* Hide the menu bar so it doesn't intercept events */
slouken@3513
   407
        if (CGDisplayIsMain(displaydata->display)) {
slouken@3513
   408
            HideMenuBar();
slouken@3513
   409
        }
slouken@3510
   410
    }
slouken@1973
   411
slouken@1934
   412
    /* Fade in again (asynchronously) */
slouken@1934
   413
    if (fade_token != kCGDisplayFadeReservationInvalidToken) {
slouken@1934
   414
        CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
slouken@1934
   415
        CGReleaseDisplayFadeReservation(fade_token);
slouken@1934
   416
    }
slouken@1973
   417
slouken@1934
   418
    return 0;
slouken@1934
   419
slouken@1934
   420
    /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
slouken@1934
   421
ERR_NO_SWITCH:
slouken@1934
   422
    CGDisplayRelease(displaydata->display);
slouken@1934
   423
ERR_NO_CAPTURE:
slouken@1934
   424
    if (fade_token != kCGDisplayFadeReservationInvalidToken) {
slouken@1934
   425
        CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
slouken@1934
   426
        CGReleaseDisplayFadeReservation(fade_token);
slouken@1934
   427
    }
slouken@1931
   428
    return -1;
slouken@1931
   429
}
slouken@1931
   430
slouken@1931
   431
void
slouken@1931
   432
Cocoa_QuitModes(_THIS)
slouken@1931
   433
{
icculus@5643
   434
    int i, j;
slouken@1934
   435
slouken@1934
   436
    for (i = 0; i < _this->num_displays; ++i) {
slouken@1934
   437
        SDL_VideoDisplay *display = &_this->displays[i];
icculus@5643
   438
        SDL_DisplayModeData *mode;
slouken@1934
   439
slouken@1934
   440
        if (display->current_mode.driverdata != display->desktop_mode.driverdata) {
slouken@3500
   441
            Cocoa_SetDisplayMode(_this, display, &display->desktop_mode);
slouken@1934
   442
        }
icculus@5643
   443
icculus@5643
   444
        mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
icculus@5643
   445
        Cocoa_ReleaseDisplayMode(_this, mode->moderef);
icculus@5643
   446
icculus@5643
   447
        for (j = 0; j < display->num_display_modes; j++) {
icculus@5643
   448
            mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata;
icculus@5643
   449
            Cocoa_ReleaseDisplayMode(_this, mode->moderef);
icculus@5643
   450
        }
icculus@5643
   451
slouken@1934
   452
    }
slouken@1973
   453
    ShowMenuBar();
slouken@1931
   454
}
slouken@1931
   455
slouken@6044
   456
#endif /* SDL_VIDEO_DRIVER_COCOA */
slouken@6044
   457
slouken@1931
   458
/* vi: set ts=4 sw=4 expandtab: */