Skip to content

Commit

Permalink
Fixed bug #373
Browse files Browse the repository at this point in the history
Patch contributed from Transgaming's Cider project
- create a window and view in fullscreen mode so the cursor can be set
  • Loading branch information
slouken committed Jul 14, 2007
1 parent 31a58a8 commit 3a71f44
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -367,6 +367,13 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop) {
SDL_free (sw_buffers[0]);
}

/* If we still have a valid window, close it. */
if ( qz_window ) {
[ qz_window close ];
[ qz_window release ];
qz_window = nil;
window_view = nil;
}
/*
Release the OpenGL context
Do this first to avoid trash on the display before fade
Expand Down Expand Up @@ -411,6 +418,8 @@ static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop) {
boolean_t exact_match = 0;
NSRect screen_rect;
CGError error;
NSRect contentRect;
BOOL isCustom = NO;
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;

/* Fade to black to hide resolution-switching flicker (and garbage
Expand Down Expand Up @@ -503,6 +512,59 @@ other blitting while waiting on the VBL (and hence results in higher framerates)
if ( CGDisplayCanSetPalette (display_id) )
current->flags |= SDL_HWPALETTE;

/* The code below checks for any valid custom windows and views. If none are
available, then we create new ones. Window/View code was added in FULLSCREEN
so that special events like the changing of the cursor image would be handled
( only the front-most and active application can change the cursor appearance
and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. )
*/
/* Check for user-specified window and view */
{
char *windowPtrString = getenv ("SDL_NSWindowPointer");
char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");

contentRect = NSMakeRect (0, 0, width, height);

if (windowPtrString && viewPtrString) {
/* Release any previous window */
if ( qz_window ) {
[ qz_window release ];
qz_window = nil;
}

qz_window = (NSWindow*)atoi(windowPtrString);
window_view = (NSQuickDrawView*)atoi(viewPtrString);
isCustom = YES;
/*
Retain reference to window because we
might release it in QZ_UnsetVideoMode
*/
[ qz_window retain ];
}
}
/* Check if we should recreate the window */
if (qz_window == nil) {
/* Manually create a window, avoids having a nib file resource */
qz_window = [ [ SDL_QuartzWindow alloc ]
initWithContentRect:contentRect
styleMask:nil
backing:NSBackingStoreBuffered
defer:NO ];

if (qz_window != nil) {
[ qz_window setAcceptsMouseMovedEvents:YES ];
[ qz_window setViewsNeedDisplay:NO ];
}
}
/* We already have a window, just change its size */
else {
if (!isCustom) {
[ qz_window setContentSize:contentRect.size ];
current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
[ window_view setFrameSize:contentRect.size ];
}
}

/* Setup OpenGL for a fullscreen context */
if (flags & SDL_OPENGL) {

Expand All @@ -513,6 +575,12 @@ other blitting while waiting on the VBL (and hence results in higher framerates)
goto ERR_NO_GL;
}

/* Initialize the NSView and add it to our window. The presence of a valid window and
view allow the cursor to be changed whilst in fullscreen.*/
window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
[ [ qz_window contentView ] addSubview:window_view ];
[ window_view release ];

ctx = [ gl_context cglContext ];
err = CGLSetFullScreen (ctx);

Expand Down
2 changes: 1 addition & 1 deletion src/video/quartz/SDL_QuartzWM.m
Expand Up @@ -105,7 +105,7 @@ void QZ_HideMouse (_THIS) {
}

BOOL QZ_IsMouseInWindow (_THIS) {
if (qz_window == nil) return YES; /*fullscreen*/
if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/
else {
NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */
Expand Down

0 comments on commit 3a71f44

Please sign in to comment.