Commit fbdf7429 authored by Sam Lantinga's avatar Sam Lantinga

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.
parent 0dd9ad21
......@@ -89,6 +89,10 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
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 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
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;
}
......
......@@ -76,6 +76,9 @@ struct SDL_Window
int w, h;
Uint32 flags;
/* Stored position and size for windowed mode */
SDL_Rect windowed;
SDL_DisplayMode fullscreen_mode;
SDL_Surface *surface;
......
......@@ -1087,6 +1087,11 @@ SDL_UpdateFullscreenMode(SDL_Window * window)
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);
}
......
......@@ -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 @@ static __inline__ void ConvertNSRect(NSRect *r)
- (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,17 +808,23 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
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) {
/* OpenGL is rendering to the window, so make it visible! */
......
......@@ -553,10 +553,6 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
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 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
} 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 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
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);
......
......@@ -43,8 +43,6 @@ typedef struct
WNDPROC wndproc;
SDL_bool created;
int mouse_pressed;
int windowed_x;
int windowed_y;
struct SDL_VideoData *videodata;
} SDL_WindowData;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment