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