annotate src/video/cocoa/SDL_cocoamodes.m @ 3540:3ad09fdbfcb0

Fixed constness in RenderRects() parameter
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 09:13:51 +0000
parents 59ff7a2beb57
children 3d91e31fcf71
rev   line source
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2237
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_cocoavideo.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
3248
cde30895105d Added 64-bit architectures to the fat build script
Sam Lantinga <slouken@libsdl.org>
parents: 3246
diff changeset
26 #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
27 /*
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
28 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
29 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
30 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
31 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
32 main screen).
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
33 */
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
34 @interface NSScreen (NSScreenAccess)
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
35 - (void) setFrame:(NSRect)frame;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
36 @end
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
37
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
38 @implementation NSScreen (NSScreenAccess)
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
39 - (void) setFrame:(NSRect)frame;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
40 {
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
41 _frame = frame;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
42 }
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
43 @end
3246
c843261f74a4 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
44 #endif
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
45
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
46 static void
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
47 CG_SetError(const char *prefix, CGDisplayErr result)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
48 {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
49 const char *error;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
50
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
51 switch (result) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
52 case kCGErrorFailure:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
53 error = "kCGErrorFailure";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
54 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
55 case kCGErrorIllegalArgument:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
56 error = "kCGErrorIllegalArgument";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
57 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
58 case kCGErrorInvalidConnection:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
59 error = "kCGErrorInvalidConnection";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
60 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
61 case kCGErrorInvalidContext:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
62 error = "kCGErrorInvalidContext";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
63 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
64 case kCGErrorCannotComplete:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
65 error = "kCGErrorCannotComplete";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
66 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
67 case kCGErrorNameTooLong:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
68 error = "kCGErrorNameTooLong";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
69 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
70 case kCGErrorNotImplemented:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
71 error = "kCGErrorNotImplemented";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
72 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
73 case kCGErrorRangeCheck:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
74 error = "kCGErrorRangeCheck";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
75 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
76 case kCGErrorTypeCheck:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
77 error = "kCGErrorTypeCheck";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
78 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
79 case kCGErrorNoCurrentPoint:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
80 error = "kCGErrorNoCurrentPoint";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
81 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
82 case kCGErrorInvalidOperation:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
83 error = "kCGErrorInvalidOperation";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
84 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
85 case kCGErrorNoneAvailable:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
86 error = "kCGErrorNoneAvailable";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
87 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
88 default:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
89 error = "Unknown Error";
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
90 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
91 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
92 SDL_SetError("%s: %s", prefix, error);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
93 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
94
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
95 static SDL_bool
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
96 GetDisplayMode(CFDictionaryRef moderef, SDL_DisplayMode *mode)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
97 {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
98 SDL_DisplayModeData *data;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
99 CFNumberRef number;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
100 long width, height, bpp, refreshRate;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
101
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
102 data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
103 if (!data) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
104 return SDL_FALSE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
105 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
106 data->moderef = moderef;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
107
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
108 number = CFDictionaryGetValue(moderef, kCGDisplayWidth);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
109 CFNumberGetValue(number, kCFNumberLongType, &width);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
110 number = CFDictionaryGetValue(moderef, kCGDisplayHeight);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
111 CFNumberGetValue(number, kCFNumberLongType, &height);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
112 number = CFDictionaryGetValue(moderef, kCGDisplayBitsPerPixel);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
113 CFNumberGetValue(number, kCFNumberLongType, &bpp);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
114 number = CFDictionaryGetValue(moderef, kCGDisplayRefreshRate);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
115 CFNumberGetValue(number, kCFNumberLongType, &refreshRate);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
116
1969
5d3724f64f2b Clarified the difference between render drivers and render contexts
Sam Lantinga <slouken@libsdl.org>
parents: 1934
diff changeset
117 mode->format = SDL_PIXELFORMAT_UNKNOWN;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
118 switch (bpp) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
119 case 8:
1969
5d3724f64f2b Clarified the difference between render drivers and render contexts
Sam Lantinga <slouken@libsdl.org>
parents: 1934
diff changeset
120 mode->format = SDL_PIXELFORMAT_INDEX8;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
121 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
122 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
123 mode->format = SDL_PIXELFORMAT_ARGB1555;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
124 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
125 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
126 mode->format = SDL_PIXELFORMAT_ARGB8888;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
127 break;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
128 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
129 mode->w = width;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
130 mode->h = height;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
131 mode->refresh_rate = refreshRate;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
132 mode->driverdata = data;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
133 return SDL_TRUE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
134 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 Cocoa_InitModes(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 {
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
139 CGDisplayErr result;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
140 CGDirectDisplayID *displays;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
141 CGDisplayCount numDisplays;
3505
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
142 int pass, i;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
143
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
144 result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
145 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
146 CG_SetError("CGGetOnlineDisplayList()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
147 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
148 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
149 displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
150 result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
151 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
152 CG_SetError("CGGetOnlineDisplayList()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
153 SDL_stack_free(displays);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
154 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
155 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
156
3505
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
157 /* 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
158 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
159 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
160 SDL_VideoDisplay display;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
161 SDL_DisplayData *displaydata;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
162 SDL_DisplayMode mode;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
163 CFDictionaryRef moderef;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
164
3505
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
165 if (pass == 0) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
166 if (!CGDisplayIsMain(displays[i])) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
167 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
168 }
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
169 } else {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
170 if (CGDisplayIsMain(displays[i])) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
171 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
172 }
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
173 }
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
174
3505
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
175 if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
176 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
177 }
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
178 moderef = CGDisplayCurrentMode(displays[i]);
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
179 if (!moderef) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
180 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
181 }
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
182
3505
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
183 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
184 if (!displaydata) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
185 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
186 }
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
187 displaydata->display = displays[i];
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
188
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
189 SDL_zero(display);
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
190 if (!GetDisplayMode (moderef, &mode)) {
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
191 SDL_free(displaydata);
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
192 continue;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
193 }
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
194 display.desktop_mode = mode;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
195 display.current_mode = mode;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
196 display.driverdata = displaydata;
a1bf34bc2a58 Ensure that the main display is picked up first
Sam Lantinga <slouken@libsdl.org>
parents: 3504
diff changeset
197 SDL_AddVideoDisplay(&display);
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
198 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
199 }
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
200 SDL_stack_free(displays);
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
201 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
202
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3525
diff changeset
203 int
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3525
diff changeset
204 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
205 {
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3525
diff changeset
206 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
207 CGRect cgrect;
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3513
diff changeset
208
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3525
diff changeset
209 cgrect = CGDisplayBounds(displaydata->display);
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3525
diff changeset
210 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
211 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
212 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
213 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
214 return 0;
3525
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3513
diff changeset
215 }
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3513
diff changeset
216
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
217 static void
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
218 AddDisplayMode(const void *moderef, void *context)
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
220 SDL_VideoDisplay *display = (SDL_VideoDisplay *) context;
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 SDL_DisplayMode mode;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 if (GetDisplayMode(moderef, &mode)) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
224 SDL_AddDisplayMode(display, &mode);
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
225 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
229 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
230 {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
231 SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
232 CFArrayRef modes;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
233 CFRange range;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
235 modes = CGDisplayAvailableModes(data->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 if (!modes) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
237 return;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
238 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
239 range.location = 0;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
240 range.length = CFArrayGetCount(modes);
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
241 CFArrayApplyFunction(modes, range, AddDisplayMode, display);
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
245 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
246 {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
247 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
248 SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
249 CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
250 CGError result;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
251
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
252 /* 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
253 if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
254 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
255 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
256
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
257 /* Put up the blanking window (a window above all other windows) */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
258 result = CGDisplayCapture(displaydata->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
259 if (result != kCGErrorSuccess) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
260 CG_SetError("CGDisplayCapture()", result);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
261 goto ERR_NO_CAPTURE;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
262 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
263
3513
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
264 if (data == display->desktop_mode.driverdata) {
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
265 /* Restoring desktop mode */
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
266 CGDisplayRelease(displaydata->display);
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
267
3513
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
268 if (CGDisplayIsMain(displaydata->display)) {
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
269 ShowMenuBar();
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
270 }
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
271 } else {
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
272 /* Do the physical switch */
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
273 result = CGDisplaySwitchToMode(displaydata->display, data->moderef);
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
274 if (result != kCGErrorSuccess) {
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
275 CG_SetError("CGDisplaySwitchToMode()", result);
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
276 goto ERR_NO_SWITCH;
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
277 }
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
278
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
279 /* 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
280 if (CGDisplayIsMain(displaydata->display)) {
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
281 HideMenuBar();
b66c9e8090d4 Restore the desktop mode when requested
Sam Lantinga <slouken@libsdl.org>
parents: 3510
diff changeset
282 }
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
283 }
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
284
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
285 /* Fade in again (asynchronously) */
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
286 if (fade_token != kCGDisplayFadeReservationInvalidToken) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
287 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
288 CGReleaseDisplayFadeReservation(fade_token);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
289 }
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
290
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3248
diff changeset
291 [[NSApp mainWindow] makeKeyAndOrderFront: nil];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3248
diff changeset
292
3248
cde30895105d Added 64-bit architectures to the fat build script
Sam Lantinga <slouken@libsdl.org>
parents: 3246
diff changeset
293 #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
294 /*
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
295 There is a bug in Cocoa where NSScreen doesn't synchronize
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
296 with CGDirectDisplay, so the main screen's frame is wrong.
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
297 As a result, coordinate translation produces incorrect results.
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
298 We can hack around this bug by setting the screen rect
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
299 ourselves. This hack should be removed if/when the bug is fixed.
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
300 */
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
301 [[NSScreen mainScreen] setFrame:NSMakeRect(0,0,mode->w,mode->h)];
3246
c843261f74a4 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
302 #endif
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
303
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
304 return 0;
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
305
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
306 /* 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
307 ERR_NO_SWITCH:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
308 CGDisplayRelease(displaydata->display);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
309 ERR_NO_CAPTURE:
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
310 if (fade_token != kCGDisplayFadeReservationInvalidToken) {
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
311 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
312 CGReleaseDisplayFadeReservation(fade_token);
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
313 }
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 return -1;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 Cocoa_QuitModes(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3280
diff changeset
320 int i;
1934
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
321
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
322 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
323 SDL_VideoDisplay *display = &_this->displays[i];
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
324
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
325 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
326 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
327 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
328 }
70139af5ac27 Implemented Mac OS X video mode selection.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
329 CGReleaseAllDisplays();
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1969
diff changeset
330 ShowMenuBar();
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 /* vi: set ts=4 sw=4 expandtab: */