Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
authorSam Lantinga <slouken@libsdl.org>
Tue, 15 Feb 2011 23:07:14 -0800
changeset 530575f5ff92ad08
parent 5304 59e6e16351e6
child 5306 cf3cd833dcd3
Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
src/video/windows/SDL_windowsmodes.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
     1.1 --- a/src/video/SDL_sysvideo.h	Tue Feb 15 22:51:29 2011 -0800
     1.2 +++ b/src/video/SDL_sysvideo.h	Tue Feb 15 23:07:14 2011 -0800
     1.3 @@ -181,7 +181,7 @@
     1.4      void (*MinimizeWindow) (_THIS, SDL_Window * window);
     1.5      void (*RestoreWindow) (_THIS, SDL_Window * window);
     1.6      void (*PrepWindowFullscreen) (_THIS, SDL_Window * window);
     1.7 -    void (*SetWindowFullscreen) (_THIS, SDL_Window * window);
     1.8 +    void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     1.9      void (*SetWindowGrab) (_THIS, SDL_Window * window);
    1.10      void (*DestroyWindow) (_THIS, SDL_Window * window);
    1.11      int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
     2.1 --- a/src/video/SDL_video.c	Tue Feb 15 22:51:29 2011 -0800
     2.2 +++ b/src/video/SDL_video.c	Tue Feb 15 23:07:14 2011 -0800
     2.3 @@ -1001,32 +1001,11 @@
     2.4  }
     2.5  
     2.6  static void
     2.7 -SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
     2.8 +SDL_UpdateFullscreenMode(SDL_Window * window)
     2.9  {
    2.10      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    2.11      SDL_Window *other;
    2.12  
    2.13 -    /* See if anything changed */
    2.14 -    if ((display->fullscreen_window == window) == attempt) {
    2.15 -        return;
    2.16 -    }
    2.17 -
    2.18 -    /* See if we even want to do anything here */
    2.19 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
    2.20 -        (window->flags & SDL_WINDOW_SHOWN)) {
    2.21 -        if (attempt) {
    2.22 -            /* We just gained some state, try to gain all states */
    2.23 -            if (window->flags & SDL_WINDOW_MINIMIZED) {
    2.24 -                SDL_RestoreWindow(window);
    2.25 -            } else {
    2.26 -                SDL_RaiseWindow(window);
    2.27 -            }
    2.28 -        } else {
    2.29 -            /* We just lost some state, try to release all states */
    2.30 -            SDL_MinimizeWindow(window);
    2.31 -        }
    2.32 -    }
    2.33 -
    2.34      if (FULLSCREEN_VISIBLE(window)) {
    2.35          /* Hide any other fullscreen windows */
    2.36          if (display->fullscreen_window &&
    2.37 @@ -1035,6 +1014,11 @@
    2.38          }
    2.39      }
    2.40  
    2.41 +    /* See if anything needs to be done now */
    2.42 +    if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
    2.43 +        return;
    2.44 +    }
    2.45 +
    2.46      /* See if there are any fullscreen windows */
    2.47      for (other = _this->windows; other; other = other->next) {
    2.48          if (FULLSCREEN_VISIBLE(other) &&
    2.49 @@ -1048,7 +1032,7 @@
    2.50                  SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
    2.51  
    2.52                  if (_this->SetWindowFullscreen) {
    2.53 -                    _this->SetWindowFullscreen(_this, other);
    2.54 +                    _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
    2.55                  }
    2.56                  display->fullscreen_window = other;
    2.57  
    2.58 @@ -1068,7 +1052,7 @@
    2.59      SDL_SetDisplayModeForDisplay(display, NULL);
    2.60  
    2.61      if (_this->SetWindowFullscreen) {
    2.62 -        _this->SetWindowFullscreen(_this, window);
    2.63 +        _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
    2.64      }
    2.65      display->fullscreen_window = NULL;
    2.66  }
    2.67 @@ -1188,7 +1172,7 @@
    2.68      }
    2.69  
    2.70      /* Restore video mode, etc. */
    2.71 -    SDL_UpdateFullscreenMode(window, SDL_FALSE);
    2.72 +    SDL_HideWindow(window);
    2.73  
    2.74      /* Tear down the old native window */
    2.75      if (window->surface) {
    2.76 @@ -1373,10 +1357,10 @@
    2.77  {
    2.78      CHECK_WINDOW_MAGIC(window, );
    2.79  
    2.80 -    if (x != SDL_WINDOWPOS_UNDEFINED) {
    2.81 +    if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
    2.82          window->x = x;
    2.83      }
    2.84 -    if (y != SDL_WINDOWPOS_UNDEFINED) {
    2.85 +    if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
    2.86          window->y = y;
    2.87      }
    2.88      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    2.89 @@ -1569,13 +1553,11 @@
    2.90      }
    2.91      if (fullscreen) {
    2.92          window->flags |= SDL_WINDOW_FULLSCREEN;
    2.93 -
    2.94 -        SDL_UpdateFullscreenMode(window, SDL_TRUE);
    2.95      } else {
    2.96          window->flags &= ~SDL_WINDOW_FULLSCREEN;
    2.97 +    }
    2.98 +    SDL_UpdateFullscreenMode(window);
    2.99  
   2.100 -        SDL_UpdateFullscreenMode(window, SDL_FALSE);
   2.101 -    }
   2.102      return 0;
   2.103  }
   2.104  
   2.105 @@ -1686,13 +1668,13 @@
   2.106  SDL_OnWindowShown(SDL_Window * window)
   2.107  {
   2.108      SDL_RaiseWindow(window);
   2.109 -    SDL_UpdateFullscreenMode(window, SDL_TRUE);
   2.110 +    SDL_UpdateFullscreenMode(window);
   2.111  }
   2.112  
   2.113  void
   2.114  SDL_OnWindowHidden(SDL_Window * window)
   2.115  {
   2.116 -    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   2.117 +    SDL_UpdateFullscreenMode(window);
   2.118  }
   2.119  
   2.120  void
   2.121 @@ -1705,14 +1687,14 @@
   2.122  void
   2.123  SDL_OnWindowMinimized(SDL_Window * window)
   2.124  {
   2.125 -    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   2.126 +    SDL_UpdateFullscreenMode(window);
   2.127  }
   2.128  
   2.129  void
   2.130  SDL_OnWindowRestored(SDL_Window * window)
   2.131  {
   2.132      SDL_RaiseWindow(window);
   2.133 -    SDL_UpdateFullscreenMode(window, SDL_TRUE);
   2.134 +    SDL_UpdateFullscreenMode(window);
   2.135  }
   2.136  
   2.137  void
   2.138 @@ -1763,7 +1745,7 @@
   2.139      CHECK_WINDOW_MAGIC(window, );
   2.140  
   2.141      /* Restore video mode, etc. */
   2.142 -    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   2.143 +    SDL_HideWindow(window);
   2.144  
   2.145      if (window->surface) {
   2.146          window->surface->flags &= ~SDL_DONTFREE;
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Tue Feb 15 22:51:29 2011 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Tue Feb 15 23:07:14 2011 -0800
     3.3 @@ -102,7 +102,7 @@
     3.4  extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
     3.5  extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
     3.6  extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
     3.7 -extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window);
     3.8 +extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     3.9  extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window);
    3.10  extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
    3.11  extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
     4.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 15 22:51:29 2011 -0800
     4.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 15 23:07:14 2011 -0800
     4.3 @@ -399,18 +399,22 @@
     4.4  @end
     4.5  
     4.6  static unsigned int
     4.7 -GetStyleMask(SDL_Window * window)
     4.8 +GetWindowStyle(SDL_Window * window)
     4.9  {
    4.10      unsigned int style;
    4.11  
    4.12 -    if (window->flags & SDL_WINDOW_BORDERLESS) {
    4.13 +	if (window->flags & SDL_WINDOW_FULLSCREEN) {
    4.14          style = NSBorderlessWindowMask;
    4.15 -    } else {
    4.16 -        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    4.17 -    }
    4.18 -    if (window->flags & SDL_WINDOW_RESIZABLE) {
    4.19 -        style |= NSResizableWindowMask;
    4.20 -    }
    4.21 +	} else {
    4.22 +		if (window->flags & SDL_WINDOW_BORDERLESS) {
    4.23 +			style = NSBorderlessWindowMask;
    4.24 +		} else {
    4.25 +			style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    4.26 +		}
    4.27 +		if (window->flags & SDL_WINDOW_RESIZABLE) {
    4.28 +			style |= NSResizableWindowMask;
    4.29 +		}
    4.30 +	}
    4.31      return style;
    4.32  }
    4.33  
    4.34 @@ -528,7 +532,7 @@
    4.35      rect.size.height = window->h;
    4.36      ConvertNSRect(&rect);
    4.37  
    4.38 -    style = GetStyleMask(window);
    4.39 +    style = GetWindowStyle(window);
    4.40  
    4.41      /* Figure out which screen to place this window */
    4.42      NSArray *screens = [NSScreen screens];
    4.43 @@ -704,15 +708,14 @@
    4.44  }
    4.45  
    4.46  void
    4.47 -Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window)
    4.48 +Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
    4.49  {
    4.50      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.51      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    4.52      NSWindow *nswindow = data->nswindow;
    4.53      NSRect rect;
    4.54  
    4.55 -    if (FULLSCREEN_VISIBLE(window)) {
    4.56 -        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    4.57 +    if (fullscreen) {
    4.58          SDL_Rect bounds;
    4.59  
    4.60          Cocoa_GetDisplayBounds(_this, display, &bounds);
    4.61 @@ -726,14 +729,14 @@
    4.62          [nswindow setContentSize:rect.size];
    4.63          [nswindow setFrameOrigin:rect.origin];
    4.64      } else {
    4.65 -        [nswindow setStyleMask:GetStyleMask(window)];
    4.66 +        [nswindow setStyleMask:GetWindowStyle(window)];
    4.67  
    4.68          // This doesn't seem to do anything...
    4.69          //[nswindow setFrameOrigin:origin];
    4.70      }
    4.71  
    4.72  #ifdef FULLSCREEN_TOGGLEABLE
    4.73 -    if (FULLSCREEN_VISIBLE(window)) {
    4.74 +    if (fullscreen) {
    4.75          /* OpenGL is rendering to the window, so make it visible! */
    4.76          [nswindow setLevel:CGShieldingWindowLevel()];
    4.77      } else {
     5.1 --- a/src/video/windows/SDL_windowsmodes.c	Tue Feb 15 22:51:29 2011 -0800
     5.2 +++ b/src/video/windows/SDL_windowsmodes.c	Tue Feb 15 23:07:14 2011 -0800
     5.3 @@ -131,10 +131,6 @@
     5.4              }
     5.5          }
     5.6      }
     5.7 -    if (SDL_ISPIXELFORMAT_INDEXED(mode->format)) {
     5.8 -        /* We don't support palettized modes now */
     5.9 -        return SDL_FALSE;
    5.10 -    }
    5.11      return SDL_TRUE;
    5.12  }
    5.13  
    5.14 @@ -170,35 +166,58 @@
    5.15  int
    5.16  WIN_InitModes(_THIS)
    5.17  {
    5.18 +    int pass;
    5.19      DWORD i, j, count;
    5.20      DISPLAY_DEVICE device;
    5.21  
    5.22      device.cb = sizeof(device);
    5.23 -    for (i = 0;; ++i) {
    5.24 -        TCHAR DeviceName[32];
    5.25  
    5.26 -        if (!EnumDisplayDevices(NULL, i, &device, 0)) {
    5.27 -            break;
    5.28 -        }
    5.29 -        if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    5.30 -            continue;
    5.31 -        }
    5.32 -        SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
    5.33 -#ifdef DEBUG_MODES
    5.34 -        printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
    5.35 -#endif
    5.36 -        count = 0;
    5.37 -        for (j = 0;; ++j) {
    5.38 -            if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
    5.39 +    /* Get the primary display in the first pass */
    5.40 +    for (pass = 0; pass < 2; ++pass) {
    5.41 +        for (i = 0; ; ++i) {
    5.42 +            TCHAR DeviceName[32];
    5.43 +
    5.44 +            if (!EnumDisplayDevices(NULL, i, &device, 0)) {
    5.45                  break;
    5.46              }
    5.47              if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    5.48                  continue;
    5.49              }
    5.50 -            count += WIN_AddDisplay(device.DeviceName);
    5.51 -        }
    5.52 -        if (count == 0) {
    5.53 -            WIN_AddDisplay(DeviceName);
    5.54 +            if (pass == 0) {
    5.55 +                if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
    5.56 +                    continue;
    5.57 +                }
    5.58 +            } else {
    5.59 +                if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
    5.60 +                    continue;
    5.61 +                }
    5.62 +            }
    5.63 +            SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
    5.64 +#ifdef DEBUG_MODES
    5.65 +            printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
    5.66 +#endif
    5.67 +            count = 0;
    5.68 +            for (j = 0; ; ++j) {
    5.69 +                if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
    5.70 +                    break;
    5.71 +                }
    5.72 +                if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    5.73 +                    continue;
    5.74 +                }
    5.75 +                if (pass == 0) {
    5.76 +                    if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
    5.77 +                        continue;
    5.78 +                    }
    5.79 +                } else {
    5.80 +                    if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
    5.81 +                        continue;
    5.82 +                    }
    5.83 +                }
    5.84 +                count += WIN_AddDisplay(device.DeviceName);
    5.85 +            }
    5.86 +            if (count == 0) {
    5.87 +                WIN_AddDisplay(DeviceName);
    5.88 +            }
    5.89          }
    5.90      }
    5.91      if (_this->num_displays == 0) {
    5.92 @@ -211,7 +230,7 @@
    5.93  int
    5.94  WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
    5.95  {
    5.96 -    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
    5.97 +    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
    5.98  
    5.99  #ifdef _WIN32_WCE
   5.100      // WINCE: DEVMODE.dmPosition not found, or may be mingw32ce bug
   5.101 @@ -239,6 +258,10 @@
   5.102          if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) {
   5.103              break;
   5.104          }
   5.105 +        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
   5.106 +            /* We don't support palettized modes now */
   5.107 +            continue;
   5.108 +        }
   5.109          if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
   5.110              if (!SDL_AddDisplayMode(display, &mode)) {
   5.111                  SDL_free(mode.driverdata);
   5.112 @@ -265,9 +288,7 @@
   5.113      status =
   5.114          ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode,
   5.115                                  NULL, CDS_FULLSCREEN, NULL);
   5.116 -    if (status == DISP_CHANGE_SUCCESSFUL) {
   5.117 -        return 0;
   5.118 -    } else {
   5.119 +    if (status != DISP_CHANGE_SUCCESSFUL) {
   5.120          const char *reason = "Unknown reason";
   5.121          switch (status) {
   5.122          case DISP_CHANGE_BADFLAGS:
   5.123 @@ -286,12 +307,14 @@
   5.124          SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
   5.125          return -1;
   5.126      }
   5.127 +    EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
   5.128 +    return 0;
   5.129  }
   5.130  
   5.131  void
   5.132  WIN_QuitModes(_THIS)
   5.133  {
   5.134 -    ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
   5.135 +    /* All fullscreen windows should have restored modes by now */
   5.136  }
   5.137  
   5.138  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/windows/SDL_windowsvideo.c	Tue Feb 15 22:51:29 2011 -0800
     6.2 +++ b/src/video/windows/SDL_windowsvideo.c	Tue Feb 15 23:07:14 2011 -0800
     6.3 @@ -124,6 +124,7 @@
     6.4      device->MaximizeWindow = WIN_MaximizeWindow;
     6.5      device->MinimizeWindow = WIN_MinimizeWindow;
     6.6      device->RestoreWindow = WIN_RestoreWindow;
     6.7 +    device->SetWindowFullscreen = WIN_SetWindowFullscreen;
     6.8      device->SetWindowGrab = WIN_SetWindowGrab;
     6.9      device->DestroyWindow = WIN_DestroyWindow;
    6.10      device->GetWindowWMInfo = WIN_GetWindowWMInfo;
     7.1 --- a/src/video/windows/SDL_windowswindow.c	Tue Feb 15 22:51:29 2011 -0800
     7.2 +++ b/src/video/windows/SDL_windowswindow.c	Tue Feb 15 23:07:14 2011 -0800
     7.3 @@ -42,6 +42,33 @@
     7.4  static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
     7.5  static ATOM SDL_HelperWindowClass = 0;
     7.6  
     7.7 +#define STYLE_BASIC         (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
     7.8 +#define STYLE_FULLSCREEN    (WS_POPUP)
     7.9 +#define STYLE_BORDERLESS    (WS_POPUP)
    7.10 +#define STYLE_NORMAL        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
    7.11 +#define STYLE_RESIZABLE     (WS_THICKFRAME | WS_MAXIMIZEBOX)
    7.12 +#define STYLE_MASK          (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
    7.13 +
    7.14 +static DWORD
    7.15 +GetWindowStyle(SDL_Window * window)
    7.16 +{
    7.17 +    DWORD style = 0;
    7.18 +
    7.19 +	if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.20 +        style |= STYLE_FULLSCREEN;
    7.21 +	} else {
    7.22 +		if (window->flags & SDL_WINDOW_BORDERLESS) {
    7.23 +            style |= STYLE_BORDERLESS;
    7.24 +		} else {
    7.25 +            style |= STYLE_NORMAL;
    7.26 +		}
    7.27 +		if (window->flags & SDL_WINDOW_RESIZABLE) {
    7.28 +            style |= STYLE_RESIZABLE;
    7.29 +		}
    7.30 +	}
    7.31 +    return style;
    7.32 +}
    7.33 +
    7.34  static int
    7.35  SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
    7.36  {
    7.37 @@ -168,19 +195,11 @@
    7.38      HWND hwnd;
    7.39      RECT rect;
    7.40      SDL_Rect bounds;
    7.41 -    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
    7.42 +    DWORD style = STYLE_BASIC;
    7.43      int x, y;
    7.44      int w, h;
    7.45 -
    7.46 -    if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
    7.47 -        style |= WS_POPUP;
    7.48 -    } else {
    7.49 -        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
    7.50 -    }
    7.51 -    if ((window->flags & SDL_WINDOW_RESIZABLE)
    7.52 -        && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
    7.53 -        style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
    7.54 -    }
    7.55 +    
    7.56 +    style |= GetWindowStyle(window);
    7.57  
    7.58      /* Figure out what the window area will be */
    7.59      rect.left = 0;
    7.60 @@ -192,16 +211,7 @@
    7.61      h = (rect.bottom - rect.top);
    7.62  
    7.63      WIN_GetDisplayBounds(_this, display, &bounds);
    7.64 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.65 -        /* The bounds when this window is visible is the fullscreen mode */
    7.66 -        SDL_DisplayMode fullscreen_mode;
    7.67 -        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
    7.68 -            bounds.w = fullscreen_mode.w;
    7.69 -            bounds.h = fullscreen_mode.h;
    7.70 -        }
    7.71 -    }
    7.72 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
    7.73 -        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
    7.74 +    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
    7.75          x = bounds.x + (bounds.w - w) / 2;
    7.76      } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
    7.77          if (bounds.x == 0) {
    7.78 @@ -212,8 +222,7 @@
    7.79      } else {
    7.80          x = window->x + rect.left;
    7.81      }
    7.82 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
    7.83 -        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
    7.84 +    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
    7.85          y = bounds.y + (bounds.h - h) / 2;
    7.86      } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
    7.87          if (bounds.x == 0) {
    7.88 @@ -232,7 +241,6 @@
    7.89          WIN_SetError("Couldn't create window");
    7.90          return -1;
    7.91      }
    7.92 -	//RegisterTouchWindow(hwnd, 0);
    7.93  
    7.94      WIN_PumpEvents(_this);
    7.95  
    7.96 @@ -394,22 +402,12 @@
    7.97      h = (rect.bottom - rect.top);
    7.98  
    7.99      WIN_GetDisplayBounds(_this, display, &bounds);
   7.100 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.101 -        /* The bounds when this window is visible is the fullscreen mode */
   7.102 -        SDL_DisplayMode fullscreen_mode;
   7.103 -        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
   7.104 -            bounds.w = fullscreen_mode.w;
   7.105 -            bounds.h = fullscreen_mode.h;
   7.106 -        }
   7.107 -    }
   7.108 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   7.109 -        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
   7.110 +    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
   7.111          x = bounds.x + (bounds.w - w) / 2;
   7.112      } else {
   7.113          x = window->x + rect.left;
   7.114      }
   7.115 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   7.116 -        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
   7.117 +    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
   7.118          y = bounds.y + (bounds.h - h) / 2;
   7.119      } else {
   7.120          y = window->y + rect.top;
   7.121 @@ -541,7 +539,7 @@
   7.122  
   7.123  #ifdef _WIN32_WCE
   7.124      if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
   7.125 -	videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
   7.126 +        videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
   7.127  #endif
   7.128  }
   7.129  
   7.130 @@ -554,6 +552,59 @@
   7.131  }
   7.132  
   7.133  void
   7.134 +WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   7.135 +{
   7.136 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   7.137 +    HWND hwnd = data->hwnd;
   7.138 +    RECT rect;
   7.139 +    SDL_Rect bounds;
   7.140 +    DWORD style;
   7.141 +    HWND top;
   7.142 +    BOOL menu;
   7.143 +    int x, y;
   7.144 +    int w, h;
   7.145 +
   7.146 +    if (fullscreen) {
   7.147 +        top = HWND_TOPMOST;
   7.148 +    } else {
   7.149 +        top = HWND_NOTOPMOST;
   7.150 +    }
   7.151 +    style = GetWindowLong(hwnd, GWL_STYLE);
   7.152 +    style &= ~STYLE_MASK;
   7.153 +    style |= GetWindowStyle(window);
   7.154 +
   7.155 +    WIN_GetDisplayBounds(_this, display, &bounds);
   7.156 +
   7.157 +    if (fullscreen) {
   7.158 +        /* Save the windowed position */
   7.159 +        data->windowed_x = window->x;
   7.160 +        data->windowed_y = window->y;
   7.161 +
   7.162 +        x = bounds.x;
   7.163 +        y = bounds.y;
   7.164 +        w = bounds.w;
   7.165 +        h = bounds.h;
   7.166 +    } else {
   7.167 +        rect.left = 0;
   7.168 +        rect.top = 0;
   7.169 +        rect.right = window->w;
   7.170 +        rect.bottom = window->h;
   7.171 +#ifdef _WIN32_WCE
   7.172 +        menu = FALSE;
   7.173 +#else
   7.174 +        menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
   7.175 +#endif
   7.176 +        AdjustWindowRectEx(&rect, style, menu, 0);
   7.177 +        w = (rect.right - rect.left);
   7.178 +        h = (rect.bottom - rect.top);
   7.179 +        x = data->windowed_x + rect.left;
   7.180 +        y = data->windowed_y + rect.top;
   7.181 +    }
   7.182 +    SetWindowLong(hwnd, GWL_STYLE, style);
   7.183 +    SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
   7.184 +}
   7.185 +
   7.186 +void
   7.187  WIN_SetWindowGrab(_THIS, SDL_Window * window)
   7.188  {
   7.189      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     8.1 --- a/src/video/windows/SDL_windowswindow.h	Tue Feb 15 22:51:29 2011 -0800
     8.2 +++ b/src/video/windows/SDL_windowswindow.h	Tue Feb 15 23:07:14 2011 -0800
     8.3 @@ -43,6 +43,8 @@
     8.4      WNDPROC wndproc;
     8.5      SDL_bool created;
     8.6      int mouse_pressed;
     8.7 +    int windowed_x;
     8.8 +    int windowed_y;
     8.9      struct SDL_VideoData *videodata;
    8.10  } SDL_WindowData;
    8.11  
    8.12 @@ -58,6 +60,7 @@
    8.13  extern void WIN_MaximizeWindow(_THIS, SDL_Window * window);
    8.14  extern void WIN_MinimizeWindow(_THIS, SDL_Window * window);
    8.15  extern void WIN_RestoreWindow(_THIS, SDL_Window * window);
    8.16 +extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
    8.17  extern void WIN_SetWindowGrab(_THIS, SDL_Window * window);
    8.18  extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
    8.19  extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
     9.1 --- a/src/video/x11/SDL_x11window.c	Tue Feb 15 22:51:29 2011 -0800
     9.2 +++ b/src/video/x11/SDL_x11window.c	Tue Feb 15 23:07:14 2011 -0800
     9.3 @@ -845,12 +845,11 @@
     9.4      X11_ShowWindow(_this, window);
     9.5  }
     9.6  
     9.7 -static void
     9.8 -SetWindowFullscreen(_THIS, SDL_Window * window, SDL_bool fullscreen)
     9.9 +void
    9.10 +X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen)
    9.11  {
    9.12      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    9.13 -    SDL_DisplayData *displaydata =
    9.14 -        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    9.15 +    SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
    9.16      Display *display = data->videodata->display;
    9.17      Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
    9.18      Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
    9.19 @@ -894,16 +893,6 @@
    9.20  }
    9.21  
    9.22  void
    9.23 -X11_SetWindowFullscreen(_THIS, SDL_Window * window)
    9.24 -{
    9.25 -    if (FULLSCREEN_VISIBLE(window)) {
    9.26 -        SetWindowFullscreen(_this, window, SDL_TRUE);
    9.27 -    } else {
    9.28 -        SetWindowFullscreen(_this, window, SDL_FALSE);
    9.29 -    }
    9.30 -}
    9.31 -
    9.32 -void
    9.33  X11_SetWindowGrab(_THIS, SDL_Window * window)
    9.34  {
    9.35      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    10.1 --- a/src/video/x11/SDL_x11window.h	Tue Feb 15 22:51:29 2011 -0800
    10.2 +++ b/src/video/x11/SDL_x11window.h	Tue Feb 15 23:07:14 2011 -0800
    10.3 @@ -54,7 +54,7 @@
    10.4  extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
    10.5  extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
    10.6  extern void X11_RestoreWindow(_THIS, SDL_Window * window);
    10.7 -extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window);
    10.8 +extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
    10.9  extern void X11_SetWindowGrab(_THIS, SDL_Window * window);
   10.10  extern void X11_DestroyWindow(_THIS, SDL_Window * window);
   10.11  extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,