Commit 73b9604f authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug #373

Patch contributed from Transgaming's Cider project
- create a window and view in fullscreen mode so the cursor can be set

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402529
parent f162e3a2
......@@ -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
......@@ -411,6 +418,8 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
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
......@@ -503,6 +512,59 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
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) {
......@@ -513,6 +575,12 @@ static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int widt
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);
......
......@@ -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" */
......
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