src/video/SDL_video.c
changeset 3502 98a819296cdc
parent 3501 467e67d301f3
child 3503 7931094e4c48
     1.1 --- a/src/video/SDL_video.c	Tue Dec 01 06:15:10 2009 +0000
     1.2 +++ b/src/video/SDL_video.c	Tue Dec 01 08:56:12 2009 +0000
     1.3 @@ -599,30 +599,31 @@
     1.4      SDL_DisplayMode current_mode;
     1.5      int i, ncolors;
     1.6  
     1.7 -    if (!mode) {
     1.8 -        mode = &display->desktop_mode;
     1.9 -    }
    1.10 -    display_mode = *mode;
    1.11 -
    1.12 -    /* Default to the current mode */
    1.13 -    if (!display_mode.format) {
    1.14 -        display_mode.format = display->current_mode.format;
    1.15 -    }
    1.16 -    if (!display_mode.w) {
    1.17 -        display_mode.w = display->current_mode.w;
    1.18 -    }
    1.19 -    if (!display_mode.h) {
    1.20 -        display_mode.h = display->current_mode.h;
    1.21 -    }
    1.22 -    if (!display_mode.refresh_rate) {
    1.23 -        display_mode.refresh_rate = display->current_mode.refresh_rate;
    1.24 -    }
    1.25 -
    1.26 -    /* Get a good video mode, the closest one possible */
    1.27 -    if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
    1.28 -        SDL_SetError("No video mode large enough for %dx%d",
    1.29 -                     display_mode.w, display_mode.h);
    1.30 -        return -1;
    1.31 +    if (mode) {
    1.32 +        display_mode = *mode;
    1.33 +
    1.34 +        /* Default to the current mode */
    1.35 +        if (!display_mode.format) {
    1.36 +            display_mode.format = display->current_mode.format;
    1.37 +        }
    1.38 +        if (!display_mode.w) {
    1.39 +            display_mode.w = display->current_mode.w;
    1.40 +        }
    1.41 +        if (!display_mode.h) {
    1.42 +            display_mode.h = display->current_mode.h;
    1.43 +        }
    1.44 +        if (!display_mode.refresh_rate) {
    1.45 +            display_mode.refresh_rate = display->current_mode.refresh_rate;
    1.46 +        }
    1.47 +
    1.48 +        /* Get a good video mode, the closest one possible */
    1.49 +        if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
    1.50 +            SDL_SetError("No video mode large enough for %dx%d",
    1.51 +                         display_mode.w, display_mode.h);
    1.52 +            return -1;
    1.53 +        }
    1.54 +    } else {
    1.55 +        display_mode = display->desktop_mode;
    1.56      }
    1.57  
    1.58      /* See if there's anything left to do */
    1.59 @@ -719,6 +720,63 @@
    1.60      return 0;
    1.61  }
    1.62  
    1.63 +static void
    1.64 +SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
    1.65 +{
    1.66 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.67 +    int i;
    1.68 +
    1.69 +    /* See if we're already processing a window */
    1.70 +    if (display->updating_fullscreen) {
    1.71 +        return;
    1.72 +    }
    1.73 +
    1.74 +    display->updating_fullscreen = SDL_TRUE;
    1.75 +
    1.76 +    /* See if we even want to do anything here */
    1.77 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
    1.78 +        (window->flags & SDL_WINDOW_SHOWN)) {
    1.79 +        if (attempt) {
    1.80 +            /* We just gained some state, try to gain all states */
    1.81 +            if (window->flags & SDL_WINDOW_MINIMIZED) {
    1.82 +                SDL_RestoreWindow(window->id);
    1.83 +            } else {
    1.84 +                SDL_RaiseWindow(window->id);
    1.85 +            }
    1.86 +        } else {
    1.87 +            /* We just lost some state, try to release all states */
    1.88 +            SDL_MinimizeWindow(window->id);
    1.89 +        }
    1.90 +    }
    1.91 +
    1.92 +    if (FULLSCREEN_VISIBLE(window)) {
    1.93 +        /* Hide any other fullscreen windows */
    1.94 +        for (i = 0; i < display->num_windows; ++i) {
    1.95 +            SDL_Window *other = &display->windows[i];
    1.96 +            if (other != window && FULLSCREEN_VISIBLE(other)) {
    1.97 +                SDL_MinimizeWindow(other->id);
    1.98 +            }
    1.99 +        }
   1.100 +    }
   1.101 +
   1.102 +    display->updating_fullscreen = SDL_FALSE;
   1.103 +
   1.104 +    /* See if there are any fullscreen windows */
   1.105 +    for (i = 0; i < display->num_windows; ++i) {
   1.106 +        window = &display->windows[i];
   1.107 +        if (FULLSCREEN_VISIBLE(window)) {
   1.108 +            SDL_DisplayMode fullscreen_mode;
   1.109 +            if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) {
   1.110 +                SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
   1.111 +                return;
   1.112 +            }
   1.113 +        }
   1.114 +    }
   1.115 +
   1.116 +    /* Nope, restore the desktop mode */
   1.117 +    SDL_SetDisplayModeForDisplay(display, NULL);
   1.118 +}
   1.119 +
   1.120  int
   1.121  SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors)
   1.122  {
   1.123 @@ -1223,6 +1281,9 @@
   1.124      }
   1.125      if (_this->RaiseWindow) {
   1.126          _this->RaiseWindow(_this, window);
   1.127 +    } else {
   1.128 +        /* FIXME: What we really want is a way to request focus */
   1.129 +        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.130      }
   1.131  }
   1.132  
   1.133 @@ -1289,29 +1350,11 @@
   1.134      if (fullscreen) {
   1.135          window->flags |= SDL_WINDOW_FULLSCREEN;
   1.136  
   1.137 -        if (FULLSCREEN_VISIBLE(window)) {
   1.138 -            SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.139 -            SDL_DisplayMode fullscreen_mode;
   1.140 -
   1.141 -            /* Hide any other fullscreen windows */
   1.142 -            int i;
   1.143 -            for (i = 0; i < display->num_windows; ++i) {
   1.144 -                SDL_Window *other = &display->windows[i];
   1.145 -                if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
   1.146 -                    SDL_MinimizeWindow(other->id);
   1.147 -                }
   1.148 -            }
   1.149 -
   1.150 -            if (SDL_GetWindowDisplayMode(windowID, &fullscreen_mode) == 0) {
   1.151 -                SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
   1.152 -            }
   1.153 -        }
   1.154 +        SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.155      } else {
   1.156          window->flags &= ~SDL_WINDOW_FULLSCREEN;
   1.157  
   1.158 -        if (FULLSCREEN_VISIBLE(window)) {
   1.159 -            SDL_SetDisplayMode(NULL);
   1.160 -        }
   1.161 +        SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.162      }
   1.163      return 0;
   1.164  }
   1.165 @@ -1354,17 +1397,14 @@
   1.166  void
   1.167  SDL_OnWindowShown(SDL_Window * window)
   1.168  {
   1.169 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   1.170 -        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.171 -    }
   1.172 +    SDL_RaiseWindow(window->id);
   1.173 +    SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.174  }
   1.175  
   1.176  void
   1.177  SDL_OnWindowHidden(SDL_Window * window)
   1.178  {
   1.179 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   1.180 -        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   1.181 -    }
   1.182 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.183  }
   1.184  
   1.185  void
   1.186 @@ -1378,13 +1418,24 @@
   1.187  }
   1.188  
   1.189  void
   1.190 +SDL_OnWindowMinimized(SDL_Window * window)
   1.191 +{
   1.192 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.193 +}
   1.194 +
   1.195 +void
   1.196 +SDL_OnWindowRestored(SDL_Window * window)
   1.197 +{
   1.198 +    SDL_RaiseWindow(window->id);
   1.199 +    SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.200 +}
   1.201 +
   1.202 +void
   1.203  SDL_OnWindowFocusGained(SDL_Window * window)
   1.204  {
   1.205      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.206  
   1.207 -    if (FULLSCREEN_VISIBLE(window)) {
   1.208 -        SDL_SetDisplayMode(&window->fullscreen_mode);
   1.209 -    }
   1.210 +    SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.211      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.212          _this->SetDisplayGammaRamp(_this, display, display->gamma);
   1.213      }
   1.214 @@ -1399,10 +1450,7 @@
   1.215  {
   1.216      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.217  
   1.218 -    if (FULLSCREEN_VISIBLE(window)) {
   1.219 -        SDL_MinimizeWindow(window->id);
   1.220 -        SDL_SetDisplayMode(NULL);
   1.221 -    }
   1.222 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.223      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.224          _this->SetDisplayGammaRamp(_this, display, display->saved_gamma);
   1.225      }