Mac: Added a hint to opt-out of new Spaces code.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 03 Mar 2014 21:25:16 -0500
changeset 829556f7e38ff0bc
parent 8294 7371078ee876
child 8296 cb13016bf07b
Mac: Added a hint to opt-out of new Spaces code.
include/SDL_hints.h
src/video/cocoa/SDL_cocoavideo.h
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/include/SDL_hints.h	Sun Mar 02 22:55:12 2014 -0500
     1.2 +++ b/include/SDL_hints.h	Mon Mar 03 21:25:16 2014 -0500
     1.3 @@ -348,6 +348,26 @@
     1.4  #define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT    "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable that dictates policy for fullscreen Spaces on Mac OS X.
     1.8 + *
     1.9 + *  This hint only applies to Mac OS X.
    1.10 + *
    1.11 + *  The variable can be set to the following values:
    1.12 + *    "0"       - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and
    1.13 + *                SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen"
    1.14 + *                button on their titlebars).
    1.15 + *    "1"       - Enable Spaces support (FULLSCREEN_DESKTOP will use them and
    1.16 + *                SDL_WINDOW_RESIZABLE windows will offer the "fullscreen"
    1.17 + *                button on their titlebars.
    1.18 + *
    1.19 + *  The default value is "1". Spaces are disabled regardless of this hint if
    1.20 + *   the OS isn't at least Mac OS X Lion (10.7). This hint must be set before
    1.21 + *   any windows are created.
    1.22 + */
    1.23 +#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES    "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
    1.24 +
    1.25 +
    1.26 +/**
    1.27   *  \brief  An enumeration of hint priorities
    1.28   */
    1.29  typedef enum
     2.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Sun Mar 02 22:55:12 2014 -0500
     2.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Mon Mar 03 21:25:16 2014 -0500
     2.3 @@ -46,6 +46,7 @@
     2.4  typedef struct SDL_VideoData
     2.5  {
     2.6      SInt32 osversion;
     2.7 +    int allow_spaces;
     2.8      unsigned int modifierFlags;
     2.9      void *key_layout;
    2.10      SDLTranslatorResponder *fieldEdit;
     3.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Sun Mar 02 22:55:12 2014 -0500
     3.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Mon Mar 03 21:25:16 2014 -0500
     3.3 @@ -148,9 +148,15 @@
     3.4  int
     3.5  Cocoa_VideoInit(_THIS)
     3.6  {
     3.7 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     3.8 +
     3.9      Cocoa_InitModes(_this);
    3.10      Cocoa_InitKeyboard(_this);
    3.11      Cocoa_InitMouse(_this);
    3.12 +
    3.13 +    const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
    3.14 +    data->allow_spaces = ( (data->osversion >= 0x1070) && (!hint || (*hint != '0')) );
    3.15 +
    3.16      return 0;
    3.17  }
    3.18  
     4.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Mar 02 22:55:12 2014 -0500
     4.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Mar 03 21:25:16 2014 -0500
     4.3 @@ -38,6 +38,7 @@
     4.4  #include "SDL_cocoashape.h"
     4.5  #include "SDL_cocoamouse.h"
     4.6  #include "SDL_cocoaopengl.h"
     4.7 +#include "SDL_assert.h"
     4.8  
     4.9  /* #define DEBUG_COCOAWINDOW */
    4.10  
    4.11 @@ -121,9 +122,7 @@
    4.12  {
    4.13      unsigned int style;
    4.14  
    4.15 -    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    4.16 -        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    4.17 -    } else if (window->flags & SDL_WINDOW_FULLSCREEN) {
    4.18 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    4.19          style = NSBorderlessWindowMask;
    4.20      } else {
    4.21          if (window->flags & SDL_WINDOW_BORDERLESS) {
    4.22 @@ -262,11 +261,12 @@
    4.23  {
    4.24      SDL_Window *window = _data->window;
    4.25      NSWindow *nswindow = _data->nswindow;
    4.26 +    SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
    4.27  
    4.28 -    if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
    4.29 +    if (!videodata->allow_spaces) {
    4.30 +        return NO;  /* Spaces are forcibly disabled. */
    4.31 +    } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
    4.32          return NO;  /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
    4.33 -    } else if (![nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
    4.34 -        return NO;  /* No Spaces support? Older Mac OS X? */
    4.35      } else if (state == isFullscreenSpace) {
    4.36          return YES;  /* already there. */
    4.37      }
    4.38 @@ -281,7 +281,7 @@
    4.39      }
    4.40      inFullscreenTransition = YES;
    4.41  
    4.42 -    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDid[Enter|Exit]FullScreen. */
    4.43 +    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
    4.44      [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    4.45      [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
    4.46      return YES;
    4.47 @@ -987,6 +987,7 @@
    4.48  int
    4.49  Cocoa_CreateWindow(_THIS, SDL_Window * window)
    4.50  {
    4.51 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    4.52      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.53      NSWindow *nswindow;
    4.54      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    4.55 @@ -1031,7 +1032,9 @@
    4.56      }
    4.57      [nswindow setBackgroundColor:[NSColor blackColor]];
    4.58  
    4.59 -    if ([nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
    4.60 +    if (videodata->allow_spaces) {
    4.61 +        SDL_assert(videodata->osversion >= 0x1070);
    4.62 +        SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
    4.63          /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
    4.64          if (window->flags & SDL_WINDOW_RESIZABLE) {
    4.65              /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */