comparison src/video/SDL_video.c @ 5254:7a963be087ef

Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off. There are still some problems with the ConvertNSRect() calculations when switching video modes, which causes wierd window positioning issues, and the fullscreen window is still minimized on exit.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Feb 2011 00:25:44 -0800
parents 58265e606e4e
children f908e06b3c96
comparison
equal deleted inserted replaced
5253:ff2564c24045 5254:7a963be087ef
598 598
599 if (rect) { 599 if (rect) {
600 SDL_VideoDisplay *display = &_this->displays[displayIndex]; 600 SDL_VideoDisplay *display = &_this->displays[displayIndex];
601 601
602 if (_this->GetDisplayBounds) { 602 if (_this->GetDisplayBounds) {
603 if (_this->GetDisplayBounds(_this, display, rect) < 0) { 603 if (_this->GetDisplayBounds(_this, display, rect) == 0) {
604 return -1; 604 return 0;
605 } 605 }
606 }
607
608 /* Assume that the displays are left to right */
609 if (displayIndex == 0) {
610 rect->x = 0;
611 rect->y = 0;
606 } else { 612 } else {
607 /* Assume that the displays are left to right */ 613 SDL_GetDisplayBounds(displayIndex-1, rect);
608 if (displayIndex == 0) { 614 rect->x += rect->w;
609 rect->x = 0; 615 }
610 rect->y = 0; 616 rect->w = display->desktop_mode.w;
611 } else { 617 rect->h = display->desktop_mode.h;
612 SDL_GetDisplayBounds(displayIndex-1, rect);
613 rect->x += rect->w;
614 }
615 rect->w = display->desktop_mode.w;
616 rect->h = display->desktop_mode.h;
617 }
618 } 618 }
619 return 0; 619 return 0;
620 } 620 }
621 621
622 SDL_bool 622 SDL_bool
1014 1014
1015 static void 1015 static void
1016 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) 1016 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
1017 { 1017 {
1018 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); 1018 SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
1019 1019 SDL_Window *other;
1020 /* See if we're already processing a window */ 1020
1021 if (display->updating_fullscreen) { 1021 /* See if anything changed */
1022 if ((display->fullscreen_window == window) == attempt) {
1022 return; 1023 return;
1023 } 1024 }
1024
1025 display->updating_fullscreen = SDL_TRUE;
1026 1025
1027 /* See if we even want to do anything here */ 1026 /* See if we even want to do anything here */
1028 if ((window->flags & SDL_WINDOW_FULLSCREEN) && 1027 if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
1029 (window->flags & SDL_WINDOW_SHOWN)) { 1028 (window->flags & SDL_WINDOW_SHOWN)) {
1030 if (attempt) { 1029 if (attempt) {
1040 } 1039 }
1041 } 1040 }
1042 1041
1043 if (FULLSCREEN_VISIBLE(window)) { 1042 if (FULLSCREEN_VISIBLE(window)) {
1044 /* Hide any other fullscreen windows */ 1043 /* Hide any other fullscreen windows */
1045 if (display->fullscreen_window != window) { 1044 if (display->fullscreen_window &&
1045 display->fullscreen_window != window) {
1046 SDL_MinimizeWindow(display->fullscreen_window); 1046 SDL_MinimizeWindow(display->fullscreen_window);
1047 } 1047 }
1048 } 1048 }
1049 1049
1050 display->updating_fullscreen = SDL_FALSE;
1051
1052 /* See if there are any fullscreen windows */ 1050 /* See if there are any fullscreen windows */
1053 for (window = _this->windows; window; window = window->next) { 1051 for (other = _this->windows; other; other = other->next) {
1054 if (FULLSCREEN_VISIBLE(window) && 1052 if (FULLSCREEN_VISIBLE(other) &&
1055 SDL_GetDisplayForWindow(window) == display) { 1053 SDL_GetDisplayForWindow(other) == display) {
1056 SDL_DisplayMode fullscreen_mode; 1054 SDL_DisplayMode fullscreen_mode;
1057 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { 1055 if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
1056 if (_this->PrepWindowFullscreen) {
1057 _this->PrepWindowFullscreen(_this, other);
1058 }
1059
1058 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); 1060 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
1059 display->fullscreen_window = window; 1061
1062 if (_this->SetWindowFullscreen) {
1063 _this->SetWindowFullscreen(_this, other);
1064 }
1065 display->fullscreen_window = other;
1066
1067 /* Generate a mode change events here */
1068 SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
1069 fullscreen_mode.w, fullscreen_mode.h);
1060 return; 1070 return;
1061 } 1071 }
1062 } 1072 }
1063 } 1073 }
1064 1074
1065 /* Nope, restore the desktop mode */ 1075 /* Nope, restore the desktop mode */
1076 if (_this->PrepWindowFullscreen) {
1077 _this->PrepWindowFullscreen(_this, window);
1078 }
1079
1066 SDL_SetDisplayModeForDisplay(display, NULL); 1080 SDL_SetDisplayModeForDisplay(display, NULL);
1081
1082 if (_this->SetWindowFullscreen) {
1083 _this->SetWindowFullscreen(_this, window);
1084 }
1067 display->fullscreen_window = NULL; 1085 display->fullscreen_window = NULL;
1086
1087 /* Generate a mode change events here */
1088 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
1089 window->windowed.w, window->windowed.h);
1068 } 1090 }
1069 1091
1070 SDL_Window * 1092 SDL_Window *
1071 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) 1093 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
1072 { 1094 {
1082 /* Initialize the video system if needed */ 1104 /* Initialize the video system if needed */
1083 if (SDL_VideoInit(NULL) < 0) { 1105 if (SDL_VideoInit(NULL) < 0) {
1084 return NULL; 1106 return NULL;
1085 } 1107 }
1086 } 1108 }
1109
1110 /* Some platforms have OpenGL enabled by default */
1111 #if (SDL_VIDEO_OPENGL && __MACOSX__) || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
1112 flags |= SDL_WINDOW_OPENGL;
1113 #endif
1087 if (flags & SDL_WINDOW_OPENGL) { 1114 if (flags & SDL_WINDOW_OPENGL) {
1088 if (!_this->GL_CreateContext) { 1115 if (!_this->GL_CreateContext) {
1089 SDL_SetError("No OpenGL support in video driver"); 1116 SDL_SetError("No OpenGL support in video driver");
1090 return NULL; 1117 return NULL;
1091 } 1118 }
1167 1194
1168 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { 1195 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
1169 SDL_SetError("No OpenGL support in video driver"); 1196 SDL_SetError("No OpenGL support in video driver");
1170 return -1; 1197 return -1;
1171 } 1198 }
1199
1200 if (window->flags & SDL_WINDOW_FOREIGN) {
1201 /* Can't destroy and re-create foreign windows, hrm */
1202 flags |= SDL_WINDOW_FOREIGN;
1203 } else {
1204 flags &= ~SDL_WINDOW_FOREIGN;
1205 }
1206
1207 /* Restore video mode, etc. */
1208 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1209
1210 /* Tear down the old native window */
1211 if (window->surface) {
1212 window->surface->refcount = 0;
1213 SDL_FreeSurface(window->surface);
1214 }
1215 if (_this->DestroyWindowFramebuffer) {
1216 _this->DestroyWindowFramebuffer(_this, window);
1217 }
1218 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
1219 _this->DestroyWindow(_this, window);
1220 }
1221
1172 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) { 1222 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
1173 if (flags & SDL_WINDOW_OPENGL) { 1223 if (flags & SDL_WINDOW_OPENGL) {
1174 SDL_GL_LoadLibrary(NULL); 1224 SDL_GL_LoadLibrary(NULL);
1175 } else { 1225 } else {
1176 SDL_GL_UnloadLibrary(); 1226 SDL_GL_UnloadLibrary();
1177 } 1227 }
1178 }
1179
1180 if (window->flags & SDL_WINDOW_FOREIGN) {
1181 /* Can't destroy and re-create foreign windows, hrm */
1182 flags |= SDL_WINDOW_FOREIGN;
1183 } else {
1184 flags &= ~SDL_WINDOW_FOREIGN;
1185 }
1186
1187 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
1188 _this->DestroyWindow(_this, window);
1189 } 1228 }
1190 1229
1191 window->title = NULL; 1230 window->title = NULL;
1192 window->flags = (flags & allowed_flags); 1231 window->flags = (flags & allowed_flags);
1193 1232
1394 void 1433 void
1395 SDL_SetWindowSize(SDL_Window * window, int w, int h) 1434 SDL_SetWindowSize(SDL_Window * window, int w, int h)
1396 { 1435 {
1397 CHECK_WINDOW_MAGIC(window, ); 1436 CHECK_WINDOW_MAGIC(window, );
1398 1437
1399 window->w = w; 1438 /* FIXME: Should this change fullscreen modes? */
1400 window->h = h; 1439 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
1401 1440 if (_this->SetWindowSize) {
1402 if (_this->SetWindowSize) { 1441 _this->SetWindowSize(_this, window);
1403 _this->SetWindowSize(_this, window); 1442 }
1404 } 1443 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
1405 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h); 1444 }
1406 } 1445 }
1407 1446
1408 void 1447 void
1409 SDL_GetWindowSize(SDL_Window * window, int *w, int *h) 1448 SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
1410 { 1449 {