comparison src/video/SDL_video.c @ 3502:98a819296cdc

Whenever a window becomes fullscreen, shown, unminimized, and has input focus it will change the display to the corresponding fullscreen video mode. If it loses any of those properties the desktop mode will be restored.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Dec 2009 08:56:12 +0000
parents 467e67d301f3
children 7931094e4c48
comparison
equal deleted inserted replaced
3501:467e67d301f3 3502:98a819296cdc
597 { 597 {
598 SDL_DisplayMode display_mode; 598 SDL_DisplayMode display_mode;
599 SDL_DisplayMode current_mode; 599 SDL_DisplayMode current_mode;
600 int i, ncolors; 600 int i, ncolors;
601 601
602 if (!mode) { 602 if (mode) {
603 mode = &display->desktop_mode; 603 display_mode = *mode;
604 } 604
605 display_mode = *mode; 605 /* Default to the current mode */
606 606 if (!display_mode.format) {
607 /* Default to the current mode */ 607 display_mode.format = display->current_mode.format;
608 if (!display_mode.format) { 608 }
609 display_mode.format = display->current_mode.format; 609 if (!display_mode.w) {
610 } 610 display_mode.w = display->current_mode.w;
611 if (!display_mode.w) { 611 }
612 display_mode.w = display->current_mode.w; 612 if (!display_mode.h) {
613 } 613 display_mode.h = display->current_mode.h;
614 if (!display_mode.h) { 614 }
615 display_mode.h = display->current_mode.h; 615 if (!display_mode.refresh_rate) {
616 } 616 display_mode.refresh_rate = display->current_mode.refresh_rate;
617 if (!display_mode.refresh_rate) { 617 }
618 display_mode.refresh_rate = display->current_mode.refresh_rate; 618
619 } 619 /* Get a good video mode, the closest one possible */
620 620 if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
621 /* Get a good video mode, the closest one possible */ 621 SDL_SetError("No video mode large enough for %dx%d",
622 if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) { 622 display_mode.w, display_mode.h);
623 SDL_SetError("No video mode large enough for %dx%d", 623 return -1;
624 display_mode.w, display_mode.h); 624 }
625 return -1; 625 } else {
626 display_mode = display->desktop_mode;
626 } 627 }
627 628
628 /* See if there's anything left to do */ 629 /* See if there's anything left to do */
629 SDL_GetCurrentDisplayModeForDisplay(display, &current_mode); 630 SDL_GetCurrentDisplayModeForDisplay(display, &current_mode);
630 if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) { 631 if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
715 716
716 if (mode) { 717 if (mode) {
717 *mode = fullscreen_mode; 718 *mode = fullscreen_mode;
718 } 719 }
719 return 0; 720 return 0;
721 }
722
723 static void
724 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
725 {
726 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
727 int i;
728
729 /* See if we're already processing a window */
730 if (display->updating_fullscreen) {
731 return;
732 }
733
734 display->updating_fullscreen = SDL_TRUE;
735
736 /* See if we even want to do anything here */
737 if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
738 (window->flags & SDL_WINDOW_SHOWN)) {
739 if (attempt) {
740 /* We just gained some state, try to gain all states */
741 if (window->flags & SDL_WINDOW_MINIMIZED) {
742 SDL_RestoreWindow(window->id);
743 } else {
744 SDL_RaiseWindow(window->id);
745 }
746 } else {
747 /* We just lost some state, try to release all states */
748 SDL_MinimizeWindow(window->id);
749 }
750 }
751
752 if (FULLSCREEN_VISIBLE(window)) {
753 /* Hide any other fullscreen windows */
754 for (i = 0; i < display->num_windows; ++i) {
755 SDL_Window *other = &display->windows[i];
756 if (other != window && FULLSCREEN_VISIBLE(other)) {
757 SDL_MinimizeWindow(other->id);
758 }
759 }
760 }
761
762 display->updating_fullscreen = SDL_FALSE;
763
764 /* See if there are any fullscreen windows */
765 for (i = 0; i < display->num_windows; ++i) {
766 window = &display->windows[i];
767 if (FULLSCREEN_VISIBLE(window)) {
768 SDL_DisplayMode fullscreen_mode;
769 if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) {
770 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
771 return;
772 }
773 }
774 }
775
776 /* Nope, restore the desktop mode */
777 SDL_SetDisplayModeForDisplay(display, NULL);
720 } 778 }
721 779
722 int 780 int
723 SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors) 781 SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors)
724 { 782 {
1221 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { 1279 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
1222 return; 1280 return;
1223 } 1281 }
1224 if (_this->RaiseWindow) { 1282 if (_this->RaiseWindow) {
1225 _this->RaiseWindow(_this, window); 1283 _this->RaiseWindow(_this, window);
1284 } else {
1285 /* FIXME: What we really want is a way to request focus */
1286 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
1226 } 1287 }
1227 } 1288 }
1228 1289
1229 void 1290 void
1230 SDL_MaximizeWindow(SDL_WindowID windowID) 1291 SDL_MaximizeWindow(SDL_WindowID windowID)
1287 return 0; 1348 return 0;
1288 } 1349 }
1289 if (fullscreen) { 1350 if (fullscreen) {
1290 window->flags |= SDL_WINDOW_FULLSCREEN; 1351 window->flags |= SDL_WINDOW_FULLSCREEN;
1291 1352
1292 if (FULLSCREEN_VISIBLE(window)) { 1353 SDL_UpdateFullscreenMode(window, SDL_TRUE);
1293 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1294 SDL_DisplayMode fullscreen_mode;
1295
1296 /* Hide any other fullscreen windows */
1297 int i;
1298 for (i = 0; i < display->num_windows; ++i) {
1299 SDL_Window *other = &display->windows[i];
1300 if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
1301 SDL_MinimizeWindow(other->id);
1302 }
1303 }
1304
1305 if (SDL_GetWindowDisplayMode(windowID, &fullscreen_mode) == 0) {
1306 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
1307 }
1308 }
1309 } else { 1354 } else {
1310 window->flags &= ~SDL_WINDOW_FULLSCREEN; 1355 window->flags &= ~SDL_WINDOW_FULLSCREEN;
1311 1356
1312 if (FULLSCREEN_VISIBLE(window)) { 1357 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1313 SDL_SetDisplayMode(NULL);
1314 }
1315 } 1358 }
1316 return 0; 1359 return 0;
1317 } 1360 }
1318 1361
1319 void 1362 void
1352 } 1395 }
1353 1396
1354 void 1397 void
1355 SDL_OnWindowShown(SDL_Window * window) 1398 SDL_OnWindowShown(SDL_Window * window)
1356 { 1399 {
1357 if (window->flags & SDL_WINDOW_FULLSCREEN) { 1400 SDL_RaiseWindow(window->id);
1358 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); 1401 SDL_UpdateFullscreenMode(window, SDL_TRUE);
1359 }
1360 } 1402 }
1361 1403
1362 void 1404 void
1363 SDL_OnWindowHidden(SDL_Window * window) 1405 SDL_OnWindowHidden(SDL_Window * window)
1364 { 1406 {
1365 if (window->flags & SDL_WINDOW_FULLSCREEN) { 1407 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1366 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
1367 }
1368 } 1408 }
1369 1409
1370 void 1410 void
1371 SDL_OnWindowResized(SDL_Window * window) 1411 SDL_OnWindowResized(SDL_Window * window)
1372 { 1412 {
1376 renderer->DisplayModeChanged(renderer); 1416 renderer->DisplayModeChanged(renderer);
1377 } 1417 }
1378 } 1418 }
1379 1419
1380 void 1420 void
1421 SDL_OnWindowMinimized(SDL_Window * window)
1422 {
1423 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1424 }
1425
1426 void
1427 SDL_OnWindowRestored(SDL_Window * window)
1428 {
1429 SDL_RaiseWindow(window->id);
1430 SDL_UpdateFullscreenMode(window, SDL_TRUE);
1431 }
1432
1433 void
1381 SDL_OnWindowFocusGained(SDL_Window * window) 1434 SDL_OnWindowFocusGained(SDL_Window * window)
1382 { 1435 {
1383 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 1436 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1384 1437
1385 if (FULLSCREEN_VISIBLE(window)) { 1438 SDL_UpdateFullscreenMode(window, SDL_TRUE);
1386 SDL_SetDisplayMode(&window->fullscreen_mode);
1387 }
1388 if (display->gamma && _this->SetDisplayGammaRamp) { 1439 if (display->gamma && _this->SetDisplayGammaRamp) {
1389 _this->SetDisplayGammaRamp(_this, display, display->gamma); 1440 _this->SetDisplayGammaRamp(_this, display, display->gamma);
1390 } 1441 }
1391 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) 1442 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1392 && _this->SetWindowGrab) { 1443 && _this->SetWindowGrab) {
1397 void 1448 void
1398 SDL_OnWindowFocusLost(SDL_Window * window) 1449 SDL_OnWindowFocusLost(SDL_Window * window)
1399 { 1450 {
1400 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 1451 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1401 1452
1402 if (FULLSCREEN_VISIBLE(window)) { 1453 SDL_UpdateFullscreenMode(window, SDL_FALSE);
1403 SDL_MinimizeWindow(window->id);
1404 SDL_SetDisplayMode(NULL);
1405 }
1406 if (display->gamma && _this->SetDisplayGammaRamp) { 1454 if (display->gamma && _this->SetDisplayGammaRamp) {
1407 _this->SetDisplayGammaRamp(_this, display, display->saved_gamma); 1455 _this->SetDisplayGammaRamp(_this, display, display->saved_gamma);
1408 } 1456 }
1409 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) 1457 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1410 && _this->SetWindowGrab) { 1458 && _this->SetWindowGrab) {