Commit 9560b718 authored by Sam Lantinga's avatar Sam Lantinga

Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.

There are still some problems with the ConvertNSRect() calculations when switching video modes, which causes wierd window positioning issues, and the fullscreen window is still minimized on exit.
parent e3b131e1
...@@ -82,24 +82,35 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, ...@@ -82,24 +82,35 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
SDL_OnWindowHidden(window); SDL_OnWindowHidden(window);
break; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
if (window->flags & SDL_WINDOW_FULLSCREEN) { if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
SDL_WINDOWPOS_ISUNDEFINED(data2)) {
return 0; return 0;
} }
if (data1 == SDL_WINDOWPOS_UNDEFINED) { if (window->flags & SDL_WINDOW_FULLSCREEN) {
data1 = window->x; window->fullscreen.x = data1;
} window->fullscreen.y = data1;
if (data2 == SDL_WINDOWPOS_UNDEFINED) { } else {
data2 = window->y; window->windowed.x = data1;
window->windowed.y = data1;
} }
if (data1 == window->x && data2 == window->y) { if (data1 == window->x && data2 == window->y) {
return 0; return 0;
} }
window->x = data1; window->x = data1;
window->y = data2; window->y = data2;
if (window->flags & SDL_WINDOW_FULLSCREEN) {
/* Do we really want to do this? */
return 0;
}
break; break;
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
if (window->flags & SDL_WINDOW_FULLSCREEN) { if (window->flags & SDL_WINDOW_FULLSCREEN) {
return 0; window->fullscreen.w = data1;
window->fullscreen.h = data1;
} else {
window->windowed.w = data1;
window->windowed.h = data1;
} }
if (data1 == window->w && data2 == window->h) { if (data1 == window->w && data2 == window->h) {
return 0; return 0;
...@@ -107,6 +118,11 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, ...@@ -107,6 +118,11 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
window->w = data1; window->w = data1;
window->h = data2; window->h = data2;
SDL_OnWindowResized(window); SDL_OnWindowResized(window);
if (window->flags & SDL_WINDOW_FULLSCREEN) {
/* Do we really want to do this? */
return 0;
}
break; break;
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
if (window->flags & SDL_WINDOW_MINIMIZED) { if (window->flags & SDL_WINDOW_MINIMIZED) {
......
...@@ -40,9 +40,6 @@ glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) ...@@ -40,9 +40,6 @@ glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */ /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
/* Used to re-create the window with OpenGL capability */
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
static const float inv255f = 1.0f / 255.0f; static const float inv255f = 1.0f / 255.0f;
static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags); static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
...@@ -146,14 +143,6 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -146,14 +143,6 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_Renderer *renderer; SDL_Renderer *renderer;
GLES_RenderData *data; GLES_RenderData *data;
GLint value; GLint value;
Uint32 window_flags;
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL)) {
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
return NULL;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) { if (!renderer) {
......
...@@ -1085,27 +1085,16 @@ GLES2_RenderPresent(SDL_Renderer *renderer) ...@@ -1085,27 +1085,16 @@ GLES2_RenderPresent(SDL_Renderer *renderer)
#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B #define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
/* Used to re-create the window with OpenGL capability */
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
static SDL_Renderer * static SDL_Renderer *
GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
{ {
SDL_Renderer *renderer; SDL_Renderer *renderer;
GLES2_DriverContext *rdata; GLES2_DriverContext *rdata;
Uint32 window_flags;
GLint nFormats; GLint nFormats;
#ifndef ZUNE_HD #ifndef ZUNE_HD
GLboolean hasCompiler; GLboolean hasCompiler;
#endif #endif
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL)) {
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
return NULL;
}
}
/* Create the renderer struct */ /* Create the renderer struct */
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
if (!renderer) { if (!renderer) {
......
...@@ -72,6 +72,20 @@ struct SDL_Window ...@@ -72,6 +72,20 @@ struct SDL_Window
const void *magic; const void *magic;
Uint32 id; Uint32 id;
char *title; char *title;
/* The fullscreen values */
struct {
int x, y;
int w, h;
} fullscreen;
/* The windowed values */
struct {
int x, y;
int w, h;
} windowed;
/* The public values */
int x, y; int x, y;
int w, h; int w, h;
Uint32 flags; Uint32 flags;
...@@ -106,7 +120,6 @@ struct SDL_VideoDisplay ...@@ -106,7 +120,6 @@ struct SDL_VideoDisplay
SDL_DisplayMode *display_modes; SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode; SDL_DisplayMode desktop_mode;
SDL_DisplayMode current_mode; SDL_DisplayMode current_mode;
SDL_bool updating_fullscreen;
SDL_Window *fullscreen_window; SDL_Window *fullscreen_window;
...@@ -178,6 +191,8 @@ struct SDL_VideoDevice ...@@ -178,6 +191,8 @@ struct SDL_VideoDevice
void (*MaximizeWindow) (_THIS, SDL_Window * window); void (*MaximizeWindow) (_THIS, SDL_Window * window);
void (*MinimizeWindow) (_THIS, SDL_Window * window); void (*MinimizeWindow) (_THIS, SDL_Window * window);
void (*RestoreWindow) (_THIS, SDL_Window * window); void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*PrepWindowFullscreen) (_THIS, SDL_Window * window);
void (*SetWindowFullscreen) (_THIS, SDL_Window * window);
void (*SetWindowGrab) (_THIS, SDL_Window * window); void (*SetWindowGrab) (_THIS, SDL_Window * window);
void (*DestroyWindow) (_THIS, SDL_Window * window); void (*DestroyWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
......
...@@ -600,21 +600,21 @@ SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect) ...@@ -600,21 +600,21 @@ SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
SDL_VideoDisplay *display = &_this->displays[displayIndex]; SDL_VideoDisplay *display = &_this->displays[displayIndex];
if (_this->GetDisplayBounds) { if (_this->GetDisplayBounds) {
if (_this->GetDisplayBounds(_this, display, rect) < 0) { if (_this->GetDisplayBounds(_this, display, rect) == 0) {
return -1; return 0;
} }
}
/* Assume that the displays are left to right */
if (displayIndex == 0) {
rect->x = 0;
rect->y = 0;
} else { } else {
/* Assume that the displays are left to right */ SDL_GetDisplayBounds(displayIndex-1, rect);
if (displayIndex == 0) { rect->x += rect->w;
rect->x = 0;
rect->y = 0;
} else {
SDL_GetDisplayBounds(displayIndex-1, rect);
rect->x += rect->w;
}
rect->w = display->desktop_mode.w;
rect->h = display->desktop_mode.h;
} }
rect->w = display->desktop_mode.w;
rect->h = display->desktop_mode.h;
} }
return 0; return 0;
} }
...@@ -1016,14 +1016,13 @@ static void ...@@ -1016,14 +1016,13 @@ static void
SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
{ {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_Window *other;
/* See if we're already processing a window */ /* See if anything changed */
if (display->updating_fullscreen) { if ((display->fullscreen_window == window) == attempt) {
return; return;
} }
display->updating_fullscreen = SDL_TRUE;
/* See if we even want to do anything here */ /* See if we even want to do anything here */
if ((window->flags & SDL_WINDOW_FULLSCREEN) && if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
(window->flags & SDL_WINDOW_SHOWN)) { (window->flags & SDL_WINDOW_SHOWN)) {
...@@ -1042,29 +1041,52 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) ...@@ -1042,29 +1041,52 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
if (FULLSCREEN_VISIBLE(window)) { if (FULLSCREEN_VISIBLE(window)) {
/* Hide any other fullscreen windows */ /* Hide any other fullscreen windows */
if (display->fullscreen_window != window) { if (display->fullscreen_window &&
display->fullscreen_window != window) {
SDL_MinimizeWindow(display->fullscreen_window); SDL_MinimizeWindow(display->fullscreen_window);
} }
} }
display->updating_fullscreen = SDL_FALSE;
/* See if there are any fullscreen windows */ /* See if there are any fullscreen windows */
for (window = _this->windows; window; window = window->next) { for (other = _this->windows; other; other = other->next) {
if (FULLSCREEN_VISIBLE(window) && if (FULLSCREEN_VISIBLE(other) &&
SDL_GetDisplayForWindow(window) == display) { SDL_GetDisplayForWindow(other) == display) {
SDL_DisplayMode fullscreen_mode; SDL_DisplayMode fullscreen_mode;
if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
if (_this->PrepWindowFullscreen) {
_this->PrepWindowFullscreen(_this, other);
}
SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
display->fullscreen_window = window;
if (_this->SetWindowFullscreen) {
_this->SetWindowFullscreen(_this, other);
}
display->fullscreen_window = other;
/* Generate a mode change events here */
SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
fullscreen_mode.w, fullscreen_mode.h);
return; return;
} }
} }
} }
/* Nope, restore the desktop mode */ /* Nope, restore the desktop mode */
if (_this->PrepWindowFullscreen) {
_this->PrepWindowFullscreen(_this, window);
}
SDL_SetDisplayModeForDisplay(display, NULL); SDL_SetDisplayModeForDisplay(display, NULL);
if (_this->SetWindowFullscreen) {
_this->SetWindowFullscreen(_this, window);
}
display->fullscreen_window = NULL; display->fullscreen_window = NULL;
/* Generate a mode change events here */
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
window->windowed.w, window->windowed.h);
} }
SDL_Window * SDL_Window *
...@@ -1084,6 +1106,11 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) ...@@ -1084,6 +1106,11 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return NULL; return NULL;
} }
} }
/* Some platforms have OpenGL enabled by default */
#if (SDL_VIDEO_OPENGL && __MACOSX__) || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
flags |= SDL_WINDOW_OPENGL;
#endif
if (flags & SDL_WINDOW_OPENGL) { if (flags & SDL_WINDOW_OPENGL) {
if (!_this->GL_CreateContext) { if (!_this->GL_CreateContext) {
SDL_SetError("No OpenGL support in video driver"); SDL_SetError("No OpenGL support in video driver");
...@@ -1169,13 +1196,6 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) ...@@ -1169,13 +1196,6 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
SDL_SetError("No OpenGL support in video driver"); SDL_SetError("No OpenGL support in video driver");
return -1; return -1;
} }
if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
if (flags & SDL_WINDOW_OPENGL) {
SDL_GL_LoadLibrary(NULL);
} else {
SDL_GL_UnloadLibrary();
}
}
if (window->flags & SDL_WINDOW_FOREIGN) { if (window->flags & SDL_WINDOW_FOREIGN) {
/* Can't destroy and re-create foreign windows, hrm */ /* Can't destroy and re-create foreign windows, hrm */
...@@ -1184,10 +1204,29 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) ...@@ -1184,10 +1204,29 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
flags &= ~SDL_WINDOW_FOREIGN; flags &= ~SDL_WINDOW_FOREIGN;
} }
/* Restore video mode, etc. */
SDL_UpdateFullscreenMode(window, SDL_FALSE);
/* Tear down the old native window */
if (window->surface) {
window->surface->refcount = 0;
SDL_FreeSurface(window->surface);
}
if (_this->DestroyWindowFramebuffer) {
_this->DestroyWindowFramebuffer(_this, window);
}
if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) { if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
_this->DestroyWindow(_this, window); _this->DestroyWindow(_this, window);
} }
if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
if (flags & SDL_WINDOW_OPENGL) {
SDL_GL_LoadLibrary(NULL);
} else {
SDL_GL_UnloadLibrary();
}
}
window->title = NULL; window->title = NULL;
window->flags = (flags & allowed_flags); window->flags = (flags & allowed_flags);
...@@ -1396,13 +1435,13 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h) ...@@ -1396,13 +1435,13 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h)
{ {
CHECK_WINDOW_MAGIC(window, ); CHECK_WINDOW_MAGIC(window, );
window->w = w; /* FIXME: Should this change fullscreen modes? */
window->h = h; if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
if (_this->SetWindowSize) {
if (_this->SetWindowSize) { _this->SetWindowSize(_this, window);
_this->SetWindowSize(_this, window); }
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
} }
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
} }
void void
......
...@@ -42,7 +42,6 @@ Android_CreateWindow(_THIS, SDL_Window * window) ...@@ -42,7 +42,6 @@ Android_CreateWindow(_THIS, SDL_Window * window)
window->h = Android_ScreenHeight; window->h = Android_ScreenHeight;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */ window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
......
...@@ -299,19 +299,6 @@ Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) ...@@ -299,19 +299,6 @@ Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
CGReleaseDisplayFadeReservation(fade_token); CGReleaseDisplayFadeReservation(fade_token);
} }
[[NSApp mainWindow] makeKeyAndOrderFront: nil];
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
/*
There is a bug in Cocoa where NSScreen doesn't synchronize
with CGDirectDisplay, so the main screen's frame is wrong.
As a result, coordinate translation produces incorrect results.
We can hack around this bug by setting the screen rect
ourselves. This hack should be removed if/when the bug is fixed.
*/
[[NSScreen mainScreen] setFrame:NSMakeRect(0,0,mode->w,mode->h)];
#endif
return 0; return 0;
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */ /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#if SDL_VIDEO_OPENGL_CGL #if SDL_VIDEO_OPENGL_CGL
/* Define this if you want to be able to toggle fullscreen mode seamlessly */
#define FULLSCREEN_TOGGLEABLE
struct SDL_GLDriverData struct SDL_GLDriverData
{ {
int initialized; int initialized;
......
...@@ -81,9 +81,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -81,9 +81,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
#ifndef FULLSCREEN_TOGGLEABLE
if (window->flags & SDL_WINDOW_FULLSCREEN) { if (window->flags & SDL_WINDOW_FULLSCREEN) {
attr[i++] = NSOpenGLPFAFullScreen; attr[i++] = NSOpenGLPFAFullScreen;
} }
#endif
attr[i++] = NSOpenGLPFAColorSize; attr[i++] = NSOpenGLPFAColorSize;
attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8; attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
...@@ -199,9 +201,12 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) ...@@ -199,9 +201,12 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
NSOpenGLContext *nscontext = (NSOpenGLContext *)context; NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
#ifndef FULLSCREEN_TOGGLEABLE
if (window->flags & SDL_WINDOW_FULLSCREEN) { if (window->flags & SDL_WINDOW_FULLSCREEN) {
[nscontext setFullScreen]; [nscontext setFullScreen];
} else { } else
#endif
{
[nscontext setView:[windowdata->nswindow contentView]]; [nscontext setView:[windowdata->nswindow contentView]];
[nscontext update]; [nscontext update];
} }
......
...@@ -90,6 +90,7 @@ Cocoa_CreateDevice(int devindex) ...@@ -90,6 +90,7 @@ Cocoa_CreateDevice(int devindex)
device->MaximizeWindow = Cocoa_MaximizeWindow; device->MaximizeWindow = Cocoa_MaximizeWindow;
device->MinimizeWindow = Cocoa_MinimizeWindow; device->MinimizeWindow = Cocoa_MinimizeWindow;
device->RestoreWindow = Cocoa_RestoreWindow; device->RestoreWindow = Cocoa_RestoreWindow;
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGrab = Cocoa_SetWindowGrab; device->SetWindowGrab = Cocoa_SetWindowGrab;
device->DestroyWindow = Cocoa_DestroyWindow; device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo; device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
......
...@@ -102,6 +102,7 @@ extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window); ...@@ -102,6 +102,7 @@ extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window); extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window); extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window); extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window); extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window);
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window); extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
......
...@@ -398,6 +398,22 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -398,6 +398,22 @@ static __inline__ void ConvertNSRect(NSRect *r)
@end @end
static unsigned int
GetStyleMask(SDL_Window * window)
{
unsigned int style;
if (window->flags & SDL_WINDOW_BORDERLESS) {
style = NSBorderlessWindowMask;
} else {
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
}
if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= NSResizableWindowMask;
}
return style;
}
static int static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
{ {
...@@ -406,7 +422,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created ...@@ -406,7 +422,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
SDL_WindowData *data; SDL_WindowData *data;
/* Allocate the window data */ /* Allocate the window data */
data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
if (!data) { if (!data) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
...@@ -424,7 +440,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created ...@@ -424,7 +440,6 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
/* Fill in the SDL window with the window data */ /* Fill in the SDL window with the window data */
{ {
SDL_Rect bounds;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
NSView *contentView = [[SDLView alloc] initWithFrame: rect NSView *contentView = [[SDLView alloc] initWithFrame: rect
listener: data->listener]; listener: data->listener];
...@@ -495,16 +510,14 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window) ...@@ -495,16 +510,14 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
unsigned int style; unsigned int style;
Cocoa_GetDisplayBounds(_this, display, &bounds); Cocoa_GetDisplayBounds(_this, display, &bounds);
if ((window->flags & SDL_WINDOW_FULLSCREEN) if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
|| SDL_WINDOWPOS_ISCENTERED(window->x)) {
rect.origin.x = bounds.x + (bounds.w - window->w) / 2; rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) { } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
rect.origin.x = bounds.x; rect.origin.x = bounds.x;
} else { } else {
rect.origin.x = window->x; rect.origin.x = window->x;
} }
if ((window->flags & SDL_WINDOW_FULLSCREEN) if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
|| SDL_WINDOWPOS_ISCENTERED(window->y)) {
rect.origin.y = bounds.y + (bounds.h - window->h) / 2; rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) { } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
rect.origin.y = bounds.y; rect.origin.y = bounds.y;
...@@ -515,14 +528,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window) ...@@ -515,14 +528,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
rect.size.height = window->h; rect.size.height = window->h;
ConvertNSRect(&rect); ConvertNSRect(&rect);
if (window->flags & SDL_WINDOW_BORDERLESS) { style = GetStyleMask(window);
style = NSBorderlessWindowMask;
} else {
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
}
if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= NSResizableWindowMask;
}
/* Figure out which screen to place this window */ /* Figure out which screen to place this window */
NSArray *screens = [NSScreen screens]; NSArray *screens = [NSScreen screens];
...@@ -600,14 +606,12 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window) ...@@ -600,14 +606,12 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
SDL_Rect bounds; SDL_Rect bounds;
Cocoa_GetDisplayBounds(_this, display, &bounds); Cocoa_GetDisplayBounds(_this, display, &bounds);
if ((window->flags & SDL_WINDOW_FULLSCREEN) if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
|| SDL_WINDOWPOS_ISCENTERED(window->x)) {
rect.origin.x = bounds.x + (bounds.w - window->w) / 2; rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
} else { } else {
rect.origin.x = window->x; rect.origin.x = window->x;
} }
if ((window->flags & SDL_WINDOW_FULLSCREEN) if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
|| SDL_WINDOWPOS_ISCENTERED(window->y)) {
rect.origin.y = bounds.y + (bounds.h - window->h) / 2; rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
} else { } else {
rect.origin.y = window->y; rect.origin.y = window->y;
...@@ -699,6 +703,56 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window) ...@@ -699,6 +703,56 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
[pool release]; [pool release];
} }
void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data->nswindow;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
NSRect rect;
unsigned int style;
if (FULLSCREEN_VISIBLE(window)) {
SDL_Rect bounds;
Cocoa_GetDisplayBounds(_this, display, &bounds);
rect.origin.x = bounds.x;
rect.origin.y = bounds.y;
rect.size.width = bounds.w;
rect.size.height = bounds.h;
ConvertNSRect(&rect);
style = NSBorderlessWindowMask;
} 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;
/* FIXME: This calculation is wrong, we're changing the origin */
ConvertNSRect(&rect);
style = GetStyleMask(window);
}
[nswindow setStyleMask:style];
[nswindow setContentSize:rect.size];
rect = [nswindow frameRectForContentRect:rect];
[nswindow setFrameOrigin:rect.origin];
#ifdef FULLSCREEN_TOGGLEABLE
if (FULLSCREEN_VISIBLE(window)) {
/* OpenGL is rendering to the window, so make it visible! */
[nswindow setLevel:CGShieldingWindowLevel()];
} else {
[nswindow setLevel:kCGNormalWindowLevel];
}
#endif
[nswindow makeKeyAndOrderFront:nil];
[pool release];
}
void void
Cocoa_SetWindowGrab(_THIS, SDL_Window * window) Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
{ {
......
...@@ -64,7 +64,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo ...@@ -64,7 +64,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
window->driverdata = data; window->driverdata = data;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */ window->flags |= SDL_WINDOW_SHOWN; /* only one window on iPod touch, always shown */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
......
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