[Commits] SDL: Fixed a host of issues with Windows fullscreen modes. Togg...

libsdl.org revision control commits-owner at libsdl.org
Tue Feb 15 23:08:09 PST 2011


details:   http://hg.libsdl.org/SDL/rev/75f5ff92ad08
changeset: 5305:75f5ff92ad08
user:      Sam Lantinga <slouken at libsdl.org>
date:      Tue Feb 15 23:07:14 2011 -0800
description:
Fixed a host of issues with Windows fullscreen modes.  Toggling fullscreen OpenGL works now in my test environment.

diffstat:

 src/video/SDL_sysvideo.h              |    2 +-
 src/video/SDL_video.c                 |   54 ++++---------
 src/video/cocoa/SDL_cocoawindow.h     |    2 +-
 src/video/cocoa/SDL_cocoawindow.m     |   31 ++++---
 src/video/windows/SDL_windowsmodes.c  |   79 ++++++++++++-------
 src/video/windows/SDL_windowsvideo.c  |    1 +
 src/video/windows/SDL_windowswindow.c |  125 ++++++++++++++++++++++---------
 src/video/windows/SDL_windowswindow.h |    3 +
 src/video/x11/SDL_x11window.c         |   17 +---
 src/video/x11/SDL_x11window.h         |    2 +-
 10 files changed, 184 insertions(+), 132 deletions(-)

diffs (657 lines):

diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/SDL_sysvideo.h
--- a/src/video/SDL_sysvideo.h	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/SDL_sysvideo.h	Tue Feb 15 23:07:14 2011 -0800
@@ -181,7 +181,7 @@
     void (*MinimizeWindow) (_THIS, SDL_Window * window);
     void (*RestoreWindow) (_THIS, SDL_Window * window);
     void (*PrepWindowFullscreen) (_THIS, SDL_Window * window);
-    void (*SetWindowFullscreen) (_THIS, SDL_Window * window);
+    void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     void (*SetWindowGrab) (_THIS, SDL_Window * window);
     void (*DestroyWindow) (_THIS, SDL_Window * window);
     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/SDL_video.c
--- a/src/video/SDL_video.c	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/SDL_video.c	Tue Feb 15 23:07:14 2011 -0800
@@ -1001,32 +1001,11 @@
 }
 
 static void
-SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
+SDL_UpdateFullscreenMode(SDL_Window * window)
 {
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_Window *other;
 
-    /* See if anything changed */
-    if ((display->fullscreen_window == window) == attempt) {
-        return;
-    }
-
-    /* See if we even want to do anything here */
-    if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
-        (window->flags & SDL_WINDOW_SHOWN)) {
-        if (attempt) {
-            /* We just gained some state, try to gain all states */
-            if (window->flags & SDL_WINDOW_MINIMIZED) {
-                SDL_RestoreWindow(window);
-            } else {
-                SDL_RaiseWindow(window);
-            }
-        } else {
-            /* We just lost some state, try to release all states */
-            SDL_MinimizeWindow(window);
-        }
-    }
-
     if (FULLSCREEN_VISIBLE(window)) {
         /* Hide any other fullscreen windows */
         if (display->fullscreen_window &&
@@ -1035,6 +1014,11 @@
         }
     }
 
+    /* See if anything needs to be done now */
+    if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
+        return;
+    }
+
     /* See if there are any fullscreen windows */
     for (other = _this->windows; other; other = other->next) {
         if (FULLSCREEN_VISIBLE(other) &&
@@ -1048,7 +1032,7 @@
                 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
 
                 if (_this->SetWindowFullscreen) {
-                    _this->SetWindowFullscreen(_this, other);
+                    _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
                 }
                 display->fullscreen_window = other;
 
@@ -1068,7 +1052,7 @@
     SDL_SetDisplayModeForDisplay(display, NULL);
 
     if (_this->SetWindowFullscreen) {
-        _this->SetWindowFullscreen(_this, window);
+        _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
     }
     display->fullscreen_window = NULL;
 }
@@ -1188,7 +1172,7 @@
     }
 
     /* Restore video mode, etc. */
-    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+    SDL_HideWindow(window);
 
     /* Tear down the old native window */
     if (window->surface) {
@@ -1373,10 +1357,10 @@
 {
     CHECK_WINDOW_MAGIC(window, );
 
-    if (x != SDL_WINDOWPOS_UNDEFINED) {
+    if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
         window->x = x;
     }
-    if (y != SDL_WINDOWPOS_UNDEFINED) {
+    if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
         window->y = y;
     }
     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
@@ -1569,13 +1553,11 @@
     }
     if (fullscreen) {
         window->flags |= SDL_WINDOW_FULLSCREEN;
-
-        SDL_UpdateFullscreenMode(window, SDL_TRUE);
     } else {
         window->flags &= ~SDL_WINDOW_FULLSCREEN;
+    }
+    SDL_UpdateFullscreenMode(window);
 
-        SDL_UpdateFullscreenMode(window, SDL_FALSE);
-    }
     return 0;
 }
 
@@ -1686,13 +1668,13 @@
 SDL_OnWindowShown(SDL_Window * window)
 {
     SDL_RaiseWindow(window);
-    SDL_UpdateFullscreenMode(window, SDL_TRUE);
+    SDL_UpdateFullscreenMode(window);
 }
 
 void
 SDL_OnWindowHidden(SDL_Window * window)
 {
-    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+    SDL_UpdateFullscreenMode(window);
 }
 
 void
@@ -1705,14 +1687,14 @@
 void
 SDL_OnWindowMinimized(SDL_Window * window)
 {
-    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+    SDL_UpdateFullscreenMode(window);
 }
 
 void
 SDL_OnWindowRestored(SDL_Window * window)
 {
     SDL_RaiseWindow(window);
-    SDL_UpdateFullscreenMode(window, SDL_TRUE);
+    SDL_UpdateFullscreenMode(window);
 }
 
 void
@@ -1763,7 +1745,7 @@
     CHECK_WINDOW_MAGIC(window, );
 
     /* Restore video mode, etc. */
-    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+    SDL_HideWindow(window);
 
     if (window->surface) {
         window->surface->flags &= ~SDL_DONTFREE;
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/cocoa/SDL_cocoawindow.h
--- a/src/video/cocoa/SDL_cocoawindow.h	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.h	Tue Feb 15 23:07:14 2011 -0800
@@ -102,7 +102,7 @@
 extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
 extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
 extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
-extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
 extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window);
 extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
 extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Feb 15 23:07:14 2011 -0800
@@ -399,18 +399,22 @@
 @end
 
 static unsigned int
-GetStyleMask(SDL_Window * window)
+GetWindowStyle(SDL_Window * window)
 {
     unsigned int style;
 
-    if (window->flags & SDL_WINDOW_BORDERLESS) {
+	if (window->flags & SDL_WINDOW_FULLSCREEN) {
         style = NSBorderlessWindowMask;
-    } else {
-        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
-    }
-    if (window->flags & SDL_WINDOW_RESIZABLE) {
-        style |= NSResizableWindowMask;
-    }
+	} else {
+		if (window->flags & SDL_WINDOW_BORDERLESS) {
+			style = NSBorderlessWindowMask;
+		} else {
+			style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
+		}
+		if (window->flags & SDL_WINDOW_RESIZABLE) {
+			style |= NSResizableWindowMask;
+		}
+	}
     return style;
 }
 
@@ -528,7 +532,7 @@
     rect.size.height = window->h;
     ConvertNSRect(&rect);
 
-    style = GetStyleMask(window);
+    style = GetWindowStyle(window);
 
     /* Figure out which screen to place this window */
     NSArray *screens = [NSScreen screens];
@@ -704,15 +708,14 @@
 }
 
 void
-Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window)
+Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = data->nswindow;
     NSRect rect;
 
-    if (FULLSCREEN_VISIBLE(window)) {
-        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+    if (fullscreen) {
         SDL_Rect bounds;
 
         Cocoa_GetDisplayBounds(_this, display, &bounds);
@@ -726,14 +729,14 @@
         [nswindow setContentSize:rect.size];
         [nswindow setFrameOrigin:rect.origin];
     } else {
-        [nswindow setStyleMask:GetStyleMask(window)];
+        [nswindow setStyleMask:GetWindowStyle(window)];
 
         // This doesn't seem to do anything...
         //[nswindow setFrameOrigin:origin];
     }
 
 #ifdef FULLSCREEN_TOGGLEABLE
-    if (FULLSCREEN_VISIBLE(window)) {
+    if (fullscreen) {
         /* OpenGL is rendering to the window, so make it visible! */
         [nswindow setLevel:CGShieldingWindowLevel()];
     } else {
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/windows/SDL_windowsmodes.c
--- a/src/video/windows/SDL_windowsmodes.c	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/windows/SDL_windowsmodes.c	Tue Feb 15 23:07:14 2011 -0800
@@ -131,10 +131,6 @@
             }
         }
     }
-    if (SDL_ISPIXELFORMAT_INDEXED(mode->format)) {
-        /* We don't support palettized modes now */
-        return SDL_FALSE;
-    }
     return SDL_TRUE;
 }
 
@@ -170,35 +166,58 @@
 int
 WIN_InitModes(_THIS)
 {
+    int pass;
     DWORD i, j, count;
     DISPLAY_DEVICE device;
 
     device.cb = sizeof(device);
-    for (i = 0;; ++i) {
-        TCHAR DeviceName[32];
 
-        if (!EnumDisplayDevices(NULL, i, &device, 0)) {
-            break;
-        }
-        if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
-            continue;
-        }
-        SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
-#ifdef DEBUG_MODES
-        printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
-#endif
-        count = 0;
-        for (j = 0;; ++j) {
-            if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
+    /* Get the primary display in the first pass */
+    for (pass = 0; pass < 2; ++pass) {
+        for (i = 0; ; ++i) {
+            TCHAR DeviceName[32];
+
+            if (!EnumDisplayDevices(NULL, i, &device, 0)) {
                 break;
             }
             if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
                 continue;
             }
-            count += WIN_AddDisplay(device.DeviceName);
-        }
-        if (count == 0) {
-            WIN_AddDisplay(DeviceName);
+            if (pass == 0) {
+                if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
+                    continue;
+                }
+            } else {
+                if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
+                    continue;
+                }
+            }
+            SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
+#ifdef DEBUG_MODES
+            printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
+#endif
+            count = 0;
+            for (j = 0; ; ++j) {
+                if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
+                    break;
+                }
+                if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
+                    continue;
+                }
+                if (pass == 0) {
+                    if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
+                        continue;
+                    }
+                } else {
+                    if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
+                        continue;
+                    }
+                }
+                count += WIN_AddDisplay(device.DeviceName);
+            }
+            if (count == 0) {
+                WIN_AddDisplay(DeviceName);
+            }
         }
     }
     if (_this->num_displays == 0) {
@@ -211,7 +230,7 @@
 int
 WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
 {
-    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
+    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
 
 #ifdef _WIN32_WCE
     // WINCE: DEVMODE.dmPosition not found, or may be mingw32ce bug
@@ -239,6 +258,10 @@
         if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) {
             break;
         }
+        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
+            /* We don't support palettized modes now */
+            continue;
+        }
         if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
             if (!SDL_AddDisplayMode(display, &mode)) {
                 SDL_free(mode.driverdata);
@@ -265,9 +288,7 @@
     status =
         ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode,
                                 NULL, CDS_FULLSCREEN, NULL);
-    if (status == DISP_CHANGE_SUCCESSFUL) {
-        return 0;
-    } else {
+    if (status != DISP_CHANGE_SUCCESSFUL) {
         const char *reason = "Unknown reason";
         switch (status) {
         case DISP_CHANGE_BADFLAGS:
@@ -286,12 +307,14 @@
         SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
         return -1;
     }
+    EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
+    return 0;
 }
 
 void
 WIN_QuitModes(_THIS)
 {
-    ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+    /* All fullscreen windows should have restored modes by now */
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/windows/SDL_windowsvideo.c
--- a/src/video/windows/SDL_windowsvideo.c	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/windows/SDL_windowsvideo.c	Tue Feb 15 23:07:14 2011 -0800
@@ -124,6 +124,7 @@
     device->MaximizeWindow = WIN_MaximizeWindow;
     device->MinimizeWindow = WIN_MinimizeWindow;
     device->RestoreWindow = WIN_RestoreWindow;
+    device->SetWindowFullscreen = WIN_SetWindowFullscreen;
     device->SetWindowGrab = WIN_SetWindowGrab;
     device->DestroyWindow = WIN_DestroyWindow;
     device->GetWindowWMInfo = WIN_GetWindowWMInfo;
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/windows/SDL_windowswindow.c
--- a/src/video/windows/SDL_windowswindow.c	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Tue Feb 15 23:07:14 2011 -0800
@@ -42,6 +42,33 @@
 static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
 static ATOM SDL_HelperWindowClass = 0;
 
+#define STYLE_BASIC         (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
+#define STYLE_FULLSCREEN    (WS_POPUP)
+#define STYLE_BORDERLESS    (WS_POPUP)
+#define STYLE_NORMAL        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
+#define STYLE_RESIZABLE     (WS_THICKFRAME | WS_MAXIMIZEBOX)
+#define STYLE_MASK          (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
+
+static DWORD
+GetWindowStyle(SDL_Window * window)
+{
+    DWORD style = 0;
+
+	if (window->flags & SDL_WINDOW_FULLSCREEN) {
+        style |= STYLE_FULLSCREEN;
+	} else {
+		if (window->flags & SDL_WINDOW_BORDERLESS) {
+            style |= STYLE_BORDERLESS;
+		} else {
+            style |= STYLE_NORMAL;
+		}
+		if (window->flags & SDL_WINDOW_RESIZABLE) {
+            style |= STYLE_RESIZABLE;
+		}
+	}
+    return style;
+}
+
 static int
 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
 {
@@ -168,19 +195,11 @@
     HWND hwnd;
     RECT rect;
     SDL_Rect bounds;
-    DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+    DWORD style = STYLE_BASIC;
     int x, y;
     int w, h;
-
-    if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
-        style |= WS_POPUP;
-    } else {
-        style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
-    }
-    if ((window->flags & SDL_WINDOW_RESIZABLE)
-        && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
-        style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
-    }
+    
+    style |= GetWindowStyle(window);
 
     /* Figure out what the window area will be */
     rect.left = 0;
@@ -192,16 +211,7 @@
     h = (rect.bottom - rect.top);
 
     WIN_GetDisplayBounds(_this, display, &bounds);
-    if (window->flags & SDL_WINDOW_FULLSCREEN) {
-        /* The bounds when this window is visible is the fullscreen mode */
-        SDL_DisplayMode fullscreen_mode;
-        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
-            bounds.w = fullscreen_mode.w;
-            bounds.h = fullscreen_mode.h;
-        }
-    }
-    if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = bounds.x + (bounds.w - w) / 2;
     } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         if (bounds.x == 0) {
@@ -212,8 +222,7 @@
     } else {
         x = window->x + rect.left;
     }
-    if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = bounds.y + (bounds.h - h) / 2;
     } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         if (bounds.x == 0) {
@@ -232,7 +241,6 @@
         WIN_SetError("Couldn't create window");
         return -1;
     }
-	//RegisterTouchWindow(hwnd, 0);
 
     WIN_PumpEvents(_this);
 
@@ -394,22 +402,12 @@
     h = (rect.bottom - rect.top);
 
     WIN_GetDisplayBounds(_this, display, &bounds);
-    if (window->flags & SDL_WINDOW_FULLSCREEN) {
-        /* The bounds when this window is visible is the fullscreen mode */
-        SDL_DisplayMode fullscreen_mode;
-        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
-            bounds.w = fullscreen_mode.w;
-            bounds.h = fullscreen_mode.h;
-        }
-    }
-    if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = bounds.x + (bounds.w - w) / 2;
     } else {
         x = window->x + rect.left;
     }
-    if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = bounds.y + (bounds.h - h) / 2;
     } else {
         y = window->y + rect.top;
@@ -541,7 +539,7 @@
 
 #ifdef _WIN32_WCE
     if((window->flags & SDL_WINDOW_FULLSCREEN) && videodata->SHFullScreen)
-	videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
+        videodata->SHFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
 #endif
 }
 
@@ -554,6 +552,59 @@
 }
 
 void
+WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    HWND hwnd = data->hwnd;
+    RECT rect;
+    SDL_Rect bounds;
+    DWORD style;
+    HWND top;
+    BOOL menu;
+    int x, y;
+    int w, h;
+
+    if (fullscreen) {
+        top = HWND_TOPMOST;
+    } else {
+        top = HWND_NOTOPMOST;
+    }
+    style = GetWindowLong(hwnd, GWL_STYLE);
+    style &= ~STYLE_MASK;
+    style |= GetWindowStyle(window);
+
+    WIN_GetDisplayBounds(_this, display, &bounds);
+
+    if (fullscreen) {
+        /* Save the windowed position */
+        data->windowed_x = window->x;
+        data->windowed_y = window->y;
+
+        x = bounds.x;
+        y = bounds.y;
+        w = bounds.w;
+        h = bounds.h;
+    } else {
+        rect.left = 0;
+        rect.top = 0;
+        rect.right = window->w;
+        rect.bottom = window->h;
+#ifdef _WIN32_WCE
+        menu = FALSE;
+#else
+        menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
+#endif
+        AdjustWindowRectEx(&rect, style, menu, 0);
+        w = (rect.right - rect.left);
+        h = (rect.bottom - rect.top);
+        x = data->windowed_x + rect.left;
+        y = data->windowed_y + rect.top;
+    }
+    SetWindowLong(hwnd, GWL_STYLE, style);
+    SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
+}
+
+void
 WIN_SetWindowGrab(_THIS, SDL_Window * window)
 {
     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/windows/SDL_windowswindow.h
--- a/src/video/windows/SDL_windowswindow.h	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.h	Tue Feb 15 23:07:14 2011 -0800
@@ -43,6 +43,8 @@
     WNDPROC wndproc;
     SDL_bool created;
     int mouse_pressed;
+    int windowed_x;
+    int windowed_y;
     struct SDL_VideoData *videodata;
 } SDL_WindowData;
 
@@ -58,6 +60,7 @@
 extern void WIN_MaximizeWindow(_THIS, SDL_Window * window);
 extern void WIN_MinimizeWindow(_THIS, SDL_Window * window);
 extern void WIN_RestoreWindow(_THIS, SDL_Window * window);
+extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
 extern void WIN_SetWindowGrab(_THIS, SDL_Window * window);
 extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
 extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/x11/SDL_x11window.c
--- a/src/video/x11/SDL_x11window.c	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/x11/SDL_x11window.c	Tue Feb 15 23:07:14 2011 -0800
@@ -845,12 +845,11 @@
     X11_ShowWindow(_this, window);
 }
 
-static void
-SetWindowFullscreen(_THIS, SDL_Window * window, SDL_bool fullscreen)
+void
+X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-    SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+    SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
     Display *display = data->videodata->display;
     Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
     Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
@@ -894,16 +893,6 @@
 }
 
 void
-X11_SetWindowFullscreen(_THIS, SDL_Window * window)
-{
-    if (FULLSCREEN_VISIBLE(window)) {
-        SetWindowFullscreen(_this, window, SDL_TRUE);
-    } else {
-        SetWindowFullscreen(_this, window, SDL_FALSE);
-    }
-}
-
-void
 X11_SetWindowGrab(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
diff -r 59e6e16351e6 -r 75f5ff92ad08 src/video/x11/SDL_x11window.h
--- a/src/video/x11/SDL_x11window.h	Tue Feb 15 22:51:29 2011 -0800
+++ b/src/video/x11/SDL_x11window.h	Tue Feb 15 23:07:14 2011 -0800
@@ -54,7 +54,7 @@
 extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
 extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
 extern void X11_RestoreWindow(_THIS, SDL_Window * window);
-extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window);
+extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
 extern void X11_SetWindowGrab(_THIS, SDL_Window * window);
 extern void X11_DestroyWindow(_THIS, SDL_Window * window);
 extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,


More information about the commits mailing list