Fixed fullscreen modes with Cocoa video driver.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Aug 2006 08:55:37 +0000
changeset 197381255f93dfcd
parent 1972 a0e278364188
child 1974 70deaf574153
Fixed fullscreen modes with Cocoa video driver.
src/video/cocoa/SDL_cocoamodes.m
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Sun Aug 06 07:29:38 2006 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Sun Aug 06 08:55:37 2006 +0000
     1.3 @@ -23,6 +23,24 @@
     1.4  
     1.5  #include "SDL_cocoavideo.h"
     1.6  
     1.7 +/* 
     1.8 +    Add methods to get at private members of NSScreen. 
     1.9 +    Since there is a bug in Apple's screen switching code
    1.10 +    that does not update this variable when switching
    1.11 +    to fullscreen, we'll set it manually (but only for the
    1.12 +    main screen).
    1.13 +*/
    1.14 +@interface NSScreen (NSScreenAccess)
    1.15 +- (void) setFrame:(NSRect)frame;
    1.16 +@end
    1.17 +
    1.18 +@implementation NSScreen (NSScreenAccess)
    1.19 +- (void) setFrame:(NSRect)frame;
    1.20 +{
    1.21 +    _frame = frame;
    1.22 +}
    1.23 +@end
    1.24 +
    1.25  static void
    1.26  CG_SetError(const char *prefix, CGDisplayErr result)
    1.27  {
    1.28 @@ -164,6 +182,7 @@
    1.29          display.driverdata = displaydata;
    1.30          SDL_AddVideoDisplay(&display);
    1.31      }
    1.32 +    SDL_stack_free(displays);
    1.33  }
    1.34  
    1.35  static void
    1.36 @@ -220,11 +239,24 @@
    1.37          goto ERR_NO_SWITCH;
    1.38      }
    1.39  
    1.40 +    /* Hide the menu bar so it doesn't intercept events */
    1.41 +    HideMenuBar();
    1.42 +
    1.43      /* Fade in again (asynchronously) */
    1.44      if (fade_token != kCGDisplayFadeReservationInvalidToken) {
    1.45          CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
    1.46          CGReleaseDisplayFadeReservation(fade_token);
    1.47      }
    1.48 +
    1.49 +    /* 
    1.50 +        There is a bug in Cocoa where NSScreen doesn't synchronize
    1.51 +        with CGDirectDisplay, so the main screen's frame is wrong.
    1.52 +        As a result, coordinate translation produces incorrect results.
    1.53 +        We can hack around this bug by setting the screen rect
    1.54 +        ourselves. This hack should be removed if/when the bug is fixed.
    1.55 +    */
    1.56 +    [[NSScreen mainScreen] setFrame:NSMakeRect(0,0,mode->w,mode->h)]; 
    1.57 +
    1.58      return 0;
    1.59  
    1.60      /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
    1.61 @@ -253,6 +285,8 @@
    1.62          }
    1.63      }
    1.64      CGReleaseAllDisplays();
    1.65 +    ShowMenuBar();
    1.66 +
    1.67      _this->current_display = saved_display;
    1.68  }
    1.69  
     2.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Sun Aug 06 07:29:38 2006 +0000
     2.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Sun Aug 06 08:55:37 2006 +0000
     2.3 @@ -247,11 +247,6 @@
     2.4  
     2.5      /* End Wisdom from Apple Engineer section. --ryan. */
     2.6  
     2.7 -    /* FIXME: should this go somewhere else? */
     2.8 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
     2.9 -        [nscontext setFullScreen];
    2.10 -    }
    2.11 -
    2.12      [pool release];
    2.13      return nscontext;
    2.14  }
    2.15 @@ -267,8 +262,12 @@
    2.16          SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
    2.17          NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
    2.18  
    2.19 -        [nscontext setView:[windowdata->window contentView]];
    2.20 -        [nscontext update];
    2.21 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    2.22 +            [nscontext setFullScreen];
    2.23 +        } else {
    2.24 +            [nscontext setView:[windowdata->window contentView]];
    2.25 +            [nscontext update];
    2.26 +        }
    2.27          [nscontext makeCurrentContext];
    2.28      } else {
    2.29          [NSOpenGLContext clearCurrentContext];
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Aug 06 07:29:38 2006 +0000
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Aug 06 08:55:37 2006 +0000
     3.3 @@ -262,6 +262,24 @@
     3.4  
     3.5  @end
     3.6  
     3.7 +@interface SDLWindow : NSWindow
     3.8 +/* These are needed for borderless/fullscreen windows */
     3.9 +- (BOOL)canBecomeKeyWindow;
    3.10 +- (BOOL)canBecomeMainWindow;
    3.11 +@end
    3.12 +
    3.13 +@implementation SDLWindow
    3.14 +- (BOOL)canBecomeKeyWindow
    3.15 +{
    3.16 +    return YES;
    3.17 +}
    3.18 +
    3.19 +- (BOOL)canBecomeMainWindow
    3.20 +{
    3.21 +    return YES;
    3.22 +}
    3.23 +@end
    3.24 +
    3.25  static int
    3.26  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
    3.27  {
    3.28 @@ -379,7 +397,7 @@
    3.29          style |= NSResizableWindowMask;
    3.30      }
    3.31  
    3.32 -    nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
    3.33 +    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
    3.34  
    3.35      [pool release];
    3.36