Restore the windowed position and size when coming back from fullscreen.
Also fixed problem where Cocoa would move the windows in response to the fullscreen mode change.
--- a/src/events/SDL_windowevents.c Thu Feb 24 23:42:58 2011 -0800
+++ b/src/events/SDL_windowevents.c Sat Feb 26 10:11:09 2011 -0800
@@ -89,6 +89,10 @@
SDL_WINDOWPOS_ISUNDEFINED(data2)) {
return 0;
}
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ window->windowed.x = data1;
+ window->windowed.y = data2;
+ }
if (data1 == window->x && data2 == window->y) {
return 0;
}
@@ -96,6 +100,10 @@
window->y = data2;
break;
case SDL_WINDOWEVENT_RESIZED:
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ window->windowed.w = data1;
+ window->windowed.h = data2;
+ }
if (data1 == window->w && data2 == window->h) {
return 0;
}
--- a/src/video/SDL_sysvideo.h Thu Feb 24 23:42:58 2011 -0800
+++ b/src/video/SDL_sysvideo.h Sat Feb 26 10:11:09 2011 -0800
@@ -76,6 +76,9 @@
int w, h;
Uint32 flags;
+ /* Stored position and size for windowed mode */
+ SDL_Rect windowed;
+
SDL_DisplayMode fullscreen_mode;
SDL_Surface *surface;
--- a/src/video/SDL_video.c Thu Feb 24 23:42:58 2011 -0800
+++ b/src/video/SDL_video.c Sat Feb 26 10:11:09 2011 -0800
@@ -1087,6 +1087,11 @@
static void
SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
{
+ window->windowed.x = window->x;
+ window->windowed.y = window->y;
+ window->windowed.w = window->w;
+ window->windowed.h = window->h;
+
if (flags & SDL_WINDOW_MAXIMIZED) {
SDL_MaximizeWindow(window);
}
--- a/src/video/cocoa/SDL_cocoawindow.m Thu Feb 24 23:42:58 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m Sat Feb 26 10:11:09 2011 -0800
@@ -22,6 +22,7 @@
#include "SDL_config.h"
#include "SDL_syswm.h"
+#include "SDL_timer.h" /* For SDL_GetTicks() */
#include "../SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
@@ -31,6 +32,9 @@
#include "SDL_cocoashape.h"
#include "SDL_cocoamouse.h"
+
+static Uint32 s_moveHack;
+
static __inline__ void ConvertNSRect(NSRect *r)
{
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
@@ -115,11 +119,29 @@
- (void)windowDidMove:(NSNotification *)aNotification
{
int x, y;
- NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+ NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect(&rect);
+
+ if (s_moveHack) {
+ SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
+
+ s_moveHack = 0;
+
+ if (blockMove) {
+ /* Cocoa is adjusting the window in response to a mode change */
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ ConvertNSRect(&rect);
+ [nswindow setFrameOrigin:rect.origin];
+ return;
+ }
+ }
+
x = (int)rect.origin.x;
y = (int)rect.origin.y;
- SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
}
- (void)windowDidResize:(NSNotification *)aNotification
@@ -786,16 +808,22 @@
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
}
- [nswindow setFrameOrigin:rect.origin];
- [nswindow setContentSize:rect.size];
} else {
+ rect.origin.x = window->windowed.x;
+ rect.origin.y = window->windowed.y;
+ rect.size.width = window->windowed.w;
+ rect.size.height = window->windowed.h;
+ ConvertNSRect(&rect);
+
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
}
+ }
- // This doesn't seem to do anything...
- //[nswindow setFrameOrigin:origin];
- }
+ s_moveHack = 0;
+ [nswindow setFrameOrigin:rect.origin];
+ [nswindow setContentSize:rect.size];
+ s_moveHack = SDL_GetTicks();
#ifdef FULLSCREEN_TOGGLEABLE
if (fullscreen) {
--- a/src/video/windows/SDL_windowswindow.c Thu Feb 24 23:42:58 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.c Sat Feb 26 10:11:09 2011 -0800
@@ -553,10 +553,6 @@
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;
@@ -564,8 +560,8 @@
} else {
rect.left = 0;
rect.top = 0;
- rect.right = window->w;
- rect.bottom = window->h;
+ rect.right = window->windowed.w;
+ rect.bottom = window->windowed.h;
#ifdef _WIN32_WCE
menu = FALSE;
#else
@@ -574,8 +570,8 @@
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;
+ x = window->windowed.x + rect.left;
+ y = window->windowed.y + rect.top;
}
SetWindowLong(hwnd, GWL_STYLE, style);
SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
--- a/src/video/windows/SDL_windowswindow.h Thu Feb 24 23:42:58 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.h Sat Feb 26 10:11:09 2011 -0800
@@ -43,8 +43,6 @@
WNDPROC wndproc;
SDL_bool created;
int mouse_pressed;
- int windowed_x;
- int windowed_y;
struct SDL_VideoData *videodata;
} SDL_WindowData;