Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
authorSam Lantinga <slouken@libsdl.org>
Tue, 12 Nov 2013 01:52:54 -0800
changeset 79688c0afe77a1b2
parent 7967 75f04553360a
child 7969 72405c8b7dba
Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
include/SDL_hints.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/include/SDL_hints.h	Tue Nov 12 00:32:29 2013 -0800
     1.2 +++ b/include/SDL_hints.h	Tue Nov 12 01:52:54 2013 -0800
     1.3 @@ -178,6 +178,16 @@
     1.4   */
     1.5  #define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS   "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
     1.6  
     1.7 +/**
     1.8 + *  \brief Set whether windows go fullscreen in their own spaces on Mac OS X
     1.9 + *
    1.10 + *  This variable can be set to the following values:
    1.11 + *    "0"       - Fullscreen windows will use the classic fullscreen mode
    1.12 + *    "1"       - Fullscreen windows will use fullscreen spaces
    1.13 + *
    1.14 + *  By default SDL will use the classic fullscreen mode.
    1.15 + */
    1.16 +#define SDL_HINT_VIDEO_FULLSCREEN_SPACES   "SDL_VIDEO_FULLSCREEN_SPACES"
    1.17  
    1.18  /**
    1.19   *  \brief  A variable controlling whether the idle timer is disabled on iOS.
     2.1 --- a/src/video/SDL_video.c	Tue Nov 12 00:32:29 2013 -0800
     2.2 +++ b/src/video/SDL_video.c	Tue Nov 12 01:52:54 2013 -0800
     2.3 @@ -112,6 +112,13 @@
     2.4          return retval; \
     2.5      }
     2.6  
     2.7 +
     2.8 +#ifdef __MACOSX__
     2.9 +/* Support for Mac OS X fullscreen spaces */
    2.10 +extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state);
    2.11 +#endif
    2.12 +
    2.13 +
    2.14  /* Support for framebuffer emulation using an accelerated renderer */
    2.15  
    2.16  #define SDL_WINDOWTEXTUREDATA   "_SDL_WindowTextureData"
    2.17 @@ -1080,9 +1087,17 @@
    2.18  static void
    2.19  SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
    2.20  {
    2.21 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    2.22 +    SDL_VideoDisplay *display;
    2.23      SDL_Window *other;
    2.24  
    2.25 +#ifdef __MACOSX__
    2.26 +    if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
    2.27 +        return;
    2.28 +    }
    2.29 +#endif
    2.30 +
    2.31 +    display = SDL_GetDisplayForWindow(window);
    2.32 +
    2.33      if (fullscreen) {
    2.34          /* Hide any other fullscreen windows */
    2.35          if (display->fullscreen_window &&
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Tue Nov 12 00:32:29 2013 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Tue Nov 12 01:52:54 2013 -0800
     3.3 @@ -49,7 +49,8 @@
     3.4  -(void) pauseVisibleObservation;
     3.5  -(void) resumeVisibleObservation;
     3.6  -(BOOL) setFullscreenSpace:(BOOL) state;
     3.7 --(BOOL) isInFullscreenTransition;
     3.8 +-(BOOL) isInFullscreenSpace;
     3.9 +-(BOOL) isInFullscreenSpaceTransition;
    3.10  -(void) addPendingWindowOperation:(PendingWindowOperation) operation;
    3.11  -(void) close;
    3.12  
     4.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Nov 12 00:32:29 2013 -0800
     4.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Nov 12 01:52:54 2013 -0800
     4.3 @@ -189,9 +189,7 @@
     4.4  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
     4.5      SDL_Window *window = _data->window;
     4.6      NSWindow *nswindow = _data->nswindow;
     4.7 -    BOOL canSetSpace = NO;
     4.8  
     4.9 -    /* Make sure the window supports switching to fullscreen spaces */
    4.10      if (![nswindow respondsToSelector: @selector(collectionBehavior)]) {
    4.11          return NO;
    4.12      }
    4.13 @@ -199,22 +197,6 @@
    4.14          return NO;
    4.15      }
    4.16  
    4.17 -    pendingWindowOperation = PENDING_OPERATION_NONE;
    4.18 -
    4.19 -    /* We can enter fullscreen spaces for "fullscreen desktop" */
    4.20 -    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    4.21 -        canSetSpace = YES;
    4.22 -    }
    4.23 -
    4.24 -    /* We can always leave fullscreen spaces */
    4.25 -    if (!state && isFullscreenSpace) {
    4.26 -        canSetSpace = YES;
    4.27 -    }
    4.28 -
    4.29 -    if (!canSetSpace) {
    4.30 -        return NO;
    4.31 -    }
    4.32 -
    4.33      if (state == isFullscreenSpace) {
    4.34          return YES;
    4.35      }
    4.36 @@ -227,6 +209,14 @@
    4.37          }
    4.38          return YES;
    4.39      }
    4.40 +    inFullscreenTransition = YES;
    4.41 +
    4.42 +    /* Update the flags here so the state change is available immediately */
    4.43 +    if (state) {
    4.44 +        window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    4.45 +    } else {
    4.46 +        window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
    4.47 +    }
    4.48  
    4.49      [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
    4.50      return YES;
    4.51 @@ -235,7 +225,12 @@
    4.52  #endif /* SDK >= 10.7 */
    4.53  }
    4.54  
    4.55 --(BOOL) isInFullscreenTransition
    4.56 +-(BOOL) isInFullscreenSpace
    4.57 +{
    4.58 +    return isFullscreenSpace;
    4.59 +}
    4.60 +
    4.61 +-(BOOL) isInFullscreenSpaceTransition
    4.62  {
    4.63      return inFullscreenTransition;
    4.64  }
    4.65 @@ -429,13 +424,8 @@
    4.66      SDL_Window *window = _data->window;
    4.67      NSWindow *nswindow = _data->nswindow;
    4.68  
    4.69 -    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
    4.70 -        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    4.71 -            [nswindow setStyleMask:(NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)];
    4.72 -        } else {
    4.73 -            [nswindow setStyleMask:NSBorderlessWindowMask];
    4.74 -        }
    4.75 -    }
    4.76 +    window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    4.77 +    [nswindow setStyleMask:(NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)];
    4.78  
    4.79      isFullscreenSpace = YES;
    4.80      inFullscreenTransition = YES;
    4.81 @@ -444,7 +434,6 @@
    4.82  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    4.83  {
    4.84      SDL_Window *window = _data->window;
    4.85 -    NSWindow *nswindow = _data->nswindow;
    4.86  
    4.87      inFullscreenTransition = NO;
    4.88  
    4.89 @@ -467,12 +456,8 @@
    4.90      SDL_Window *window = _data->window;
    4.91      NSWindow *nswindow = _data->nswindow;
    4.92  
    4.93 -    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
    4.94 -        Uint32 flags = window->flags;
    4.95 -        window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
    4.96 -        [nswindow setStyleMask:GetWindowStyle(window)];
    4.97 -        window->flags = flags;
    4.98 -    }
    4.99 +    window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
   4.100 +    [nswindow setStyleMask:GetWindowStyle(window)];
   4.101  
   4.102      isFullscreenSpace = NO;
   4.103      inFullscreenTransition = YES;
   4.104 @@ -925,7 +910,10 @@
   4.105      [nswindow setBackgroundColor:[NSColor blackColor]];
   4.106  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
   4.107      if ([nswindow respondsToSelector:@selector(setCollectionBehavior:)]) {
   4.108 -        [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
   4.109 +        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_FULLSCREEN_SPACES);
   4.110 +        if (hint && SDL_atoi(hint) > 0) {
   4.111 +            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
   4.112 +        }
   4.113      }
   4.114  #endif
   4.115  
   4.116 @@ -1139,7 +1127,7 @@
   4.117      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   4.118      NSWindow *nswindow = data->nswindow;
   4.119  
   4.120 -    if ([data->listener isInFullscreenTransition]) {
   4.121 +    if ([data->listener isInFullscreenSpaceTransition]) {
   4.122          [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
   4.123      } else {
   4.124          [nswindow miniaturize:nil];
   4.125 @@ -1196,9 +1184,10 @@
   4.126  }
   4.127  
   4.128  
   4.129 -static void
   4.130 -Cocoa_SetWindowFullscreen_OldStyle(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   4.131 +void
   4.132 +Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   4.133  {
   4.134 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   4.135      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   4.136      NSWindow *nswindow = data->nswindow;
   4.137      NSRect rect;
   4.138 @@ -1272,17 +1261,6 @@
   4.139      }
   4.140  
   4.141      ScheduleContextUpdates(data);
   4.142 -}
   4.143 -
   4.144 -void
   4.145 -Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   4.146 -{
   4.147 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   4.148 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   4.149 -
   4.150 -    if (![data->listener setFullscreenSpace:(fullscreen ? YES : NO)]) {
   4.151 -        Cocoa_SetWindowFullscreen_OldStyle(_this, window, display, fullscreen);
   4.152 -    }
   4.153  
   4.154      [pool release];
   4.155  }
   4.156 @@ -1404,6 +1382,24 @@
   4.157      }
   4.158  }
   4.159  
   4.160 +SDL_bool
   4.161 +Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
   4.162 +{
   4.163 +    SDL_bool succeeded = SDL_FALSE;
   4.164 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
   4.165 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   4.166 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   4.167 +
   4.168 +    if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
   4.169 +        succeeded = SDL_TRUE;
   4.170 +    }
   4.171 +
   4.172 +    [pool release];
   4.173 +#endif /* SDK 10.7+ */
   4.174 +
   4.175 +    return succeeded;
   4.176 +}
   4.177 +
   4.178  #endif /* SDL_VIDEO_DRIVER_COCOA */
   4.179  
   4.180  /* vi: set ts=4 sw=4 expandtab: */