Fixed bug #373 SDL-1.2
authorSam Lantinga
Sat, 14 Jul 2007 08:00:50 +0000
branchSDL-1.2
changeset 40650c76e6d1c3d6
parent 4064 940fddb81bea
child 4066 58a5055da431
Fixed bug #373

Patch contributed from Transgaming's Cider project
- create a window and view in fullscreen mode so the cursor can be set
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
     1.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Sat Jul 14 07:26:34 2007 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Sat Jul 14 08:00:50 2007 +0000
     1.3 @@ -367,6 +367,13 @@
     1.4              SDL_free (sw_buffers[0]);
     1.5          }
     1.6          
     1.7 +        /* If we still have a valid window, close it. */
     1.8 +        if ( qz_window ) {
     1.9 +            [ qz_window close ];
    1.10 +            [ qz_window release ];
    1.11 +            qz_window = nil;
    1.12 +            window_view = nil;
    1.13 +        }
    1.14          /* 
    1.15              Release the OpenGL context
    1.16              Do this first to avoid trash on the display before fade
    1.17 @@ -411,6 +418,8 @@
    1.18      boolean_t exact_match = 0;
    1.19      NSRect screen_rect;
    1.20      CGError error;
    1.21 +    NSRect contentRect;
    1.22 +    BOOL isCustom = NO;
    1.23      CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
    1.24      
    1.25      /* Fade to black to hide resolution-switching flicker (and garbage
    1.26 @@ -503,6 +512,59 @@
    1.27      if ( CGDisplayCanSetPalette (display_id) )
    1.28          current->flags |= SDL_HWPALETTE;
    1.29  
    1.30 +    /* The code below checks for any valid custom windows and views.  If none are
    1.31 +       available, then we create new ones.  Window/View code was added in FULLSCREEN
    1.32 +       so that special events like the changing of the cursor image would be handled
    1.33 +       ( only the front-most and active application can change the cursor appearance
    1.34 +       and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. )
    1.35 +    */
    1.36 +	/* Check for user-specified window and view */
    1.37 +    {
    1.38 +        char *windowPtrString = getenv ("SDL_NSWindowPointer");
    1.39 +        char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
    1.40 +    
    1.41 +        contentRect = NSMakeRect (0, 0, width, height);
    1.42 +	
    1.43 +        if (windowPtrString && viewPtrString) {
    1.44 +            /* Release any previous window */
    1.45 +            if ( qz_window ) {
    1.46 +                [ qz_window release ];
    1.47 +                qz_window = nil;
    1.48 +            }
    1.49 +            
    1.50 +            qz_window = (NSWindow*)atoi(windowPtrString);
    1.51 +            window_view = (NSQuickDrawView*)atoi(viewPtrString);
    1.52 +            isCustom = YES;
    1.53 +            /* 
    1.54 +                Retain reference to window because we
    1.55 +                might release it in QZ_UnsetVideoMode
    1.56 +            */
    1.57 +            [ qz_window retain ];
    1.58 +        }
    1.59 +    }
    1.60 +    /* Check if we should recreate the window */
    1.61 +    if (qz_window == nil) {
    1.62 +        /* Manually create a window, avoids having a nib file resource */
    1.63 +        qz_window = [ [ SDL_QuartzWindow alloc ] 
    1.64 +            initWithContentRect:contentRect
    1.65 +                styleMask:nil 
    1.66 +                    backing:NSBackingStoreBuffered
    1.67 +                        defer:NO ];
    1.68 +
    1.69 +        if (qz_window != nil) {
    1.70 +            [ qz_window setAcceptsMouseMovedEvents:YES ];
    1.71 +            [ qz_window setViewsNeedDisplay:NO ];
    1.72 +        }
    1.73 +    }
    1.74 +    /* We already have a window, just change its size */
    1.75 +    else {
    1.76 +        if (!isCustom) {
    1.77 +            [ qz_window setContentSize:contentRect.size ];
    1.78 +            current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
    1.79 +            [ window_view setFrameSize:contentRect.size ];
    1.80 +        }
    1.81 +    }
    1.82 +
    1.83      /* Setup OpenGL for a fullscreen context */
    1.84      if (flags & SDL_OPENGL) {
    1.85  
    1.86 @@ -513,6 +575,12 @@
    1.87              goto ERR_NO_GL;
    1.88          }
    1.89  
    1.90 +        /* Initialize the NSView and add it to our window.  The presence of a valid window and
    1.91 +           view allow the cursor to be changed whilst in fullscreen.*/
    1.92 +        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
    1.93 +        [ [ qz_window contentView ] addSubview:window_view ];	
    1.94 +        [ window_view release ];
    1.95 +
    1.96          ctx = [ gl_context cglContext ];
    1.97          err = CGLSetFullScreen (ctx);
    1.98  
     2.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sat Jul 14 07:26:34 2007 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sat Jul 14 08:00:50 2007 +0000
     2.3 @@ -105,7 +105,7 @@
     2.4  }
     2.5  
     2.6  BOOL QZ_IsMouseInWindow (_THIS) {
     2.7 -    if (qz_window == nil) return YES; /*fullscreen*/
     2.8 +    if (qz_window == nil || (mode_flags & SDL_FULLSCREEN)) return YES; /*fullscreen*/
     2.9      else {
    2.10          NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
    2.11          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" */