src/video/cocoa/SDL_cocoawindow.m
changeset 8284 a2910aa6c056
parent 8261 841b66e4397a
child 8288 4e3afa79b8d8
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Mar 02 02:00:40 2014 -0500
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Mar 02 12:45:51 2014 -0500
     1.3 @@ -121,7 +121,9 @@
     1.4  {
     1.5      unsigned int style;
     1.6  
     1.7 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
     1.8 +    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
     1.9 +        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    1.10 +    } else if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.11          style = NSBorderlessWindowMask;
    1.12      } else {
    1.13          if (window->flags & SDL_WINDOW_BORDERLESS) {
    1.14 @@ -256,20 +258,17 @@
    1.15      }
    1.16  }
    1.17  
    1.18 --(BOOL) setFullscreenSpace:(BOOL) state;
    1.19 +-(BOOL) setFullscreenSpace:(BOOL) state
    1.20  {
    1.21      SDL_Window *window = _data->window;
    1.22      NSWindow *nswindow = _data->nswindow;
    1.23  
    1.24 -    if (![nswindow respondsToSelector: @selector(collectionBehavior)]) {
    1.25 -        return NO;
    1.26 -    }
    1.27 -    if ([nswindow collectionBehavior] != NSWindowCollectionBehaviorFullScreenPrimary) {
    1.28 -        return NO;
    1.29 -    }
    1.30 -
    1.31 -    if (state == isFullscreenSpace) {
    1.32 -        return YES;
    1.33 +    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
    1.34 +        return NO;  /* we only allow this on FULLSCREEN_DESKTOP windows. */
    1.35 +    } else if (![nswindow respondsToSelector: @selector(setCollectionBehavior:)]) {
    1.36 +        return NO;  /* No Spaces support? Older Mac OS X? */
    1.37 +    } else if (state == isFullscreenSpace) {
    1.38 +        return YES;  /* already there. */
    1.39      }
    1.40  
    1.41      if (inFullscreenTransition) {
    1.42 @@ -282,13 +281,8 @@
    1.43      }
    1.44      inFullscreenTransition = YES;
    1.45  
    1.46 -    /* Update the flags here so the state change is available immediately */
    1.47 -    if (state) {
    1.48 -        window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.49 -    } else {
    1.50 -        window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.51 -    }
    1.52 -
    1.53 +    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDid[Enter|Exit]FullScreen. */
    1.54 +    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    1.55      [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
    1.56      return YES;
    1.57  }
    1.58 @@ -443,6 +437,11 @@
    1.59  
    1.60  - (void)windowDidResize:(NSNotification *)aNotification
    1.61  {
    1.62 +    if (inFullscreenTransition) {
    1.63 +        /* We'll take care of this at the end of the transition */
    1.64 +        return;
    1.65 +    }
    1.66 +
    1.67      SDL_Window *window = _data->window;
    1.68      NSWindow *nswindow = _data->nswindow;
    1.69      int x, y, w, h;
    1.70 @@ -453,11 +452,6 @@
    1.71      w = (int)rect.size.width;
    1.72      h = (int)rect.size.height;
    1.73  
    1.74 -    if (inFullscreenTransition) {
    1.75 -        /* We'll take care of this at the end of the transition */
    1.76 -        return;
    1.77 -    }
    1.78 -
    1.79      if (SDL_IsShapedWindow(window)) {
    1.80          Cocoa_ResizeWindowShape(window);
    1.81      }
    1.82 @@ -538,7 +532,6 @@
    1.83  {
    1.84      SDL_Window *window = _data->window;
    1.85  
    1.86 -    window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.87      SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
    1.88  
    1.89      isFullscreenSpace = YES;
    1.90 @@ -548,6 +541,7 @@
    1.91  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    1.92  {
    1.93      SDL_Window *window = _data->window;
    1.94 +    NSWindow *nswindow = _data->nswindow;
    1.95  
    1.96      inFullscreenTransition = NO;
    1.97  
    1.98 @@ -555,6 +549,12 @@
    1.99          pendingWindowOperation = PENDING_OPERATION_NONE;
   1.100          [self setFullscreenSpace:NO];
   1.101      } else {
   1.102 +        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
   1.103 +            /* Remove the fullscreen toggle button and menu now that we're here. */
   1.104 +            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
   1.105 +            [NSMenu setMenuBarVisible:NO];
   1.106 +        }
   1.107 +
   1.108          pendingWindowOperation = PENDING_OPERATION_NONE;
   1.109          /* Force the size change event in case it was delivered earlier
   1.110             while the window was still animating into place.
   1.111 @@ -569,7 +569,6 @@
   1.112  {
   1.113      SDL_Window *window = _data->window;
   1.114  
   1.115 -    window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
   1.116      SetWindowStyle(window, GetWindowStyle(window));
   1.117  
   1.118      isFullscreenSpace = NO;
   1.119 @@ -590,6 +589,12 @@
   1.120          pendingWindowOperation = PENDING_OPERATION_NONE;
   1.121          [nswindow miniaturize:nil];
   1.122      } else {
   1.123 +        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
   1.124 +            /* Remove the fullscreen toggle button and readd menu now that we're here. */
   1.125 +            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
   1.126 +            [NSMenu setMenuBarVisible:YES];
   1.127 +        }
   1.128 +
   1.129          pendingWindowOperation = PENDING_OPERATION_NONE;
   1.130          /* Force the size change event in case it was delivered earlier
   1.131             while the window was still animating into place.
   1.132 @@ -1007,9 +1012,11 @@
   1.133          return -1;
   1.134      }
   1.135      [nswindow setBackgroundColor:[NSColor blackColor]];
   1.136 -    if ([nswindow respondsToSelector:@selector(setCollectionBehavior:)]) {
   1.137 -        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_FULLSCREEN_SPACES);
   1.138 -        if (hint && SDL_atoi(hint) > 0) {
   1.139 +
   1.140 +    if ([nswindow respondsToSelector: @selector(setCollectionBehavior:)]) {
   1.141 +        /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
   1.142 +        if (window->flags & SDL_WINDOW_RESIZABLE) {
   1.143 +            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
   1.144              [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
   1.145          }
   1.146      }