Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed fullscreen modes with Cocoa video driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 6, 2006
1 parent dcab033 commit 905c987
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
34 changes: 34 additions & 0 deletions src/video/cocoa/SDL_cocoamodes.m
Expand Up @@ -23,6 +23,24 @@

#include "SDL_cocoavideo.h"

/*
Add methods to get at private members of NSScreen.
Since there is a bug in Apple's screen switching code
that does not update this variable when switching
to fullscreen, we'll set it manually (but only for the
main screen).
*/
@interface NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
@end

@implementation NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
{
_frame = frame;
}
@end

static void
CG_SetError(const char *prefix, CGDisplayErr result)
{
Expand Down Expand Up @@ -164,6 +182,7 @@
display.driverdata = displaydata;
SDL_AddVideoDisplay(&display);
}
SDL_stack_free(displays);
}

static void
Expand Down Expand Up @@ -220,11 +239,24 @@
goto ERR_NO_SWITCH;
}

/* Hide the menu bar so it doesn't intercept events */
HideMenuBar();

/* Fade in again (asynchronously) */
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
CGReleaseDisplayFadeReservation(fade_token);
}

/*
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)];

return 0;

/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
Expand Down Expand Up @@ -253,6 +285,8 @@
}
}
CGReleaseAllDisplays();
ShowMenuBar();

_this->current_display = saved_display;
}

Expand Down
13 changes: 6 additions & 7 deletions src/video/cocoa/SDL_cocoaopengl.m
Expand Up @@ -247,11 +247,6 @@ - (CGLContextObj)CGLContextObj;

/* End Wisdom from Apple Engineer section. --ryan. */

/* FIXME: should this go somewhere else? */
if (window->flags & SDL_WINDOW_FULLSCREEN) {
[nscontext setFullScreen];
}

[pool release];
return nscontext;
}
Expand All @@ -267,8 +262,12 @@ - (CGLContextObj)CGLContextObj;
SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;

[nscontext setView:[windowdata->window contentView]];
[nscontext update];
if (window->flags & SDL_WINDOW_FULLSCREEN) {
[nscontext setFullScreen];
} else {
[nscontext setView:[windowdata->window contentView]];
[nscontext update];
}
[nscontext makeCurrentContext];
} else {
[NSOpenGLContext clearCurrentContext];
Expand Down
20 changes: 19 additions & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -262,6 +262,24 @@ - (void)scrollWheel:(NSEvent *)theEvent

@end

@interface SDLWindow : NSWindow
/* These are needed for borderless/fullscreen windows */
- (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow;
@end

@implementation SDLWindow
- (BOOL)canBecomeKeyWindow
{
return YES;
}

- (BOOL)canBecomeMainWindow
{
return YES;
}
@end

static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
{
Expand Down Expand Up @@ -379,7 +397,7 @@ - (void)scrollWheel:(NSEvent *)theEvent
style |= NSResizableWindowMask;
}

nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];

[pool release];

Expand Down

0 comments on commit 905c987

Please sign in to comment.