Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Feb 2011 00:25:44 -0800
changeset 52497a963be087ef
parent 5248 ff2564c24045
child 5250 f908e06b3c96
Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.

There are still some problems with the ConvertNSRect() calculations when switching video modes, which causes wierd window positioning issues, and the fullscreen window is still minimized on exit.
src/events/SDL_windowevents.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/android/SDL_androidwindow.c
src/video/cocoa/SDL_cocoamodes.m
src/video/cocoa/SDL_cocoaopengl.h
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/events/SDL_windowevents.c	Thu Feb 10 22:49:14 2011 -0800
     1.2 +++ b/src/events/SDL_windowevents.c	Fri Feb 11 00:25:44 2011 -0800
     1.3 @@ -82,24 +82,35 @@
     1.4          SDL_OnWindowHidden(window);
     1.5          break;
     1.6      case SDL_WINDOWEVENT_MOVED:
     1.7 -        if (window->flags & SDL_WINDOW_FULLSCREEN) {
     1.8 +        if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
     1.9 +            SDL_WINDOWPOS_ISUNDEFINED(data2)) {
    1.10              return 0;
    1.11          }
    1.12 -        if (data1 == SDL_WINDOWPOS_UNDEFINED) {
    1.13 -            data1 = window->x;
    1.14 -        }
    1.15 -        if (data2 == SDL_WINDOWPOS_UNDEFINED) {
    1.16 -            data2 = window->y;
    1.17 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.18 +            window->fullscreen.x = data1;
    1.19 +            window->fullscreen.y = data1;
    1.20 +        } else {
    1.21 +            window->windowed.x = data1;
    1.22 +            window->windowed.y = data1;
    1.23          }
    1.24          if (data1 == window->x && data2 == window->y) {
    1.25              return 0;
    1.26          }
    1.27          window->x = data1;
    1.28          window->y = data2;
    1.29 +
    1.30 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.31 +            /* Do we really want to do this? */
    1.32 +            return 0;
    1.33 +        }
    1.34          break;
    1.35      case SDL_WINDOWEVENT_RESIZED:
    1.36          if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.37 -            return 0;
    1.38 +            window->fullscreen.w = data1;
    1.39 +            window->fullscreen.h = data1;
    1.40 +        } else {
    1.41 +            window->windowed.w = data1;
    1.42 +            window->windowed.h = data1;
    1.43          }
    1.44          if (data1 == window->w && data2 == window->h) {
    1.45              return 0;
    1.46 @@ -107,6 +118,11 @@
    1.47          window->w = data1;
    1.48          window->h = data2;
    1.49          SDL_OnWindowResized(window);
    1.50 +
    1.51 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.52 +            /* Do we really want to do this? */
    1.53 +            return 0;
    1.54 +        }
    1.55          break;
    1.56      case SDL_WINDOWEVENT_MINIMIZED:
    1.57          if (window->flags & SDL_WINDOW_MINIMIZED) {
     2.1 --- a/src/render/opengles/SDL_render_gles.c	Thu Feb 10 22:49:14 2011 -0800
     2.2 +++ b/src/render/opengles/SDL_render_gles.c	Fri Feb 11 00:25:44 2011 -0800
     2.3 @@ -40,9 +40,6 @@
     2.4  
     2.5  /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
     2.6  
     2.7 -/* Used to re-create the window with OpenGL capability */
     2.8 -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
     2.9 -
    2.10  static const float inv255f = 1.0f / 255.0f;
    2.11  
    2.12  static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
    2.13 @@ -146,14 +143,6 @@
    2.14      SDL_Renderer *renderer;
    2.15      GLES_RenderData *data;
    2.16      GLint value;
    2.17 -    Uint32 window_flags;
    2.18 -
    2.19 -    window_flags = SDL_GetWindowFlags(window);
    2.20 -    if (!(window_flags & SDL_WINDOW_OPENGL)) {
    2.21 -        if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
    2.22 -            return NULL;
    2.23 -        }
    2.24 -    }
    2.25  
    2.26      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    2.27      if (!renderer) {
     3.1 --- a/src/render/opengles2/SDL_render_gles2.c	Thu Feb 10 22:49:14 2011 -0800
     3.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Fri Feb 11 00:25:44 2011 -0800
     3.3 @@ -1085,27 +1085,16 @@
     3.4  
     3.5  #define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
     3.6  
     3.7 -/* Used to re-create the window with OpenGL capability */
     3.8 -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
     3.9 -
    3.10  static SDL_Renderer *
    3.11  GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
    3.12  {
    3.13      SDL_Renderer *renderer;
    3.14      GLES2_DriverContext *rdata;
    3.15 -    Uint32 window_flags;
    3.16      GLint nFormats;
    3.17  #ifndef ZUNE_HD
    3.18      GLboolean hasCompiler;
    3.19  #endif
    3.20  
    3.21 -    window_flags = SDL_GetWindowFlags(window);
    3.22 -    if (!(window_flags & SDL_WINDOW_OPENGL)) {
    3.23 -        if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
    3.24 -            return NULL;
    3.25 -        }
    3.26 -    }
    3.27 -
    3.28      /* Create the renderer struct */
    3.29      renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
    3.30      if (!renderer) {
     4.1 --- a/src/video/SDL_sysvideo.h	Thu Feb 10 22:49:14 2011 -0800
     4.2 +++ b/src/video/SDL_sysvideo.h	Fri Feb 11 00:25:44 2011 -0800
     4.3 @@ -72,6 +72,20 @@
     4.4      const void *magic;
     4.5      Uint32 id;
     4.6      char *title;
     4.7 +
     4.8 +    /* The fullscreen values */
     4.9 +    struct {
    4.10 +        int x, y;
    4.11 +        int w, h;
    4.12 +    } fullscreen;
    4.13 +
    4.14 +    /* The windowed values */
    4.15 +    struct {
    4.16 +        int x, y;
    4.17 +        int w, h;
    4.18 +    } windowed;
    4.19 +
    4.20 +    /* The public values */
    4.21      int x, y;
    4.22      int w, h;
    4.23      Uint32 flags;
    4.24 @@ -106,7 +120,6 @@
    4.25      SDL_DisplayMode *display_modes;
    4.26      SDL_DisplayMode desktop_mode;
    4.27      SDL_DisplayMode current_mode;
    4.28 -    SDL_bool updating_fullscreen;
    4.29  
    4.30      SDL_Window *fullscreen_window;
    4.31  
    4.32 @@ -178,6 +191,8 @@
    4.33      void (*MaximizeWindow) (_THIS, SDL_Window * window);
    4.34      void (*MinimizeWindow) (_THIS, SDL_Window * window);
    4.35      void (*RestoreWindow) (_THIS, SDL_Window * window);
    4.36 +    void (*PrepWindowFullscreen) (_THIS, SDL_Window * window);
    4.37 +    void (*SetWindowFullscreen) (_THIS, SDL_Window * window);
    4.38      void (*SetWindowGrab) (_THIS, SDL_Window * window);
    4.39      void (*DestroyWindow) (_THIS, SDL_Window * window);
    4.40      int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
     5.1 --- a/src/video/SDL_video.c	Thu Feb 10 22:49:14 2011 -0800
     5.2 +++ b/src/video/SDL_video.c	Fri Feb 11 00:25:44 2011 -0800
     5.3 @@ -600,21 +600,21 @@
     5.4          SDL_VideoDisplay *display = &_this->displays[displayIndex];
     5.5  
     5.6          if (_this->GetDisplayBounds) {
     5.7 -            if (_this->GetDisplayBounds(_this, display, rect) < 0) {
     5.8 -                return -1;
     5.9 +            if (_this->GetDisplayBounds(_this, display, rect) == 0) {
    5.10 +                return 0;
    5.11              }
    5.12 +        }
    5.13 +
    5.14 +        /* Assume that the displays are left to right */
    5.15 +        if (displayIndex == 0) {
    5.16 +            rect->x = 0;
    5.17 +            rect->y = 0;
    5.18          } else {
    5.19 -            /* Assume that the displays are left to right */
    5.20 -            if (displayIndex == 0) {
    5.21 -                rect->x = 0;
    5.22 -                rect->y = 0;
    5.23 -            } else {
    5.24 -                SDL_GetDisplayBounds(displayIndex-1, rect);
    5.25 -                rect->x += rect->w;
    5.26 -            }
    5.27 -            rect->w = display->desktop_mode.w;
    5.28 -            rect->h = display->desktop_mode.h;
    5.29 +            SDL_GetDisplayBounds(displayIndex-1, rect);
    5.30 +            rect->x += rect->w;
    5.31          }
    5.32 +        rect->w = display->desktop_mode.w;
    5.33 +        rect->h = display->desktop_mode.h;
    5.34      }
    5.35      return 0;
    5.36  }
    5.37 @@ -1016,14 +1016,13 @@
    5.38  SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
    5.39  {
    5.40      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    5.41 +    SDL_Window *other;
    5.42  
    5.43 -    /* See if we're already processing a window */
    5.44 -    if (display->updating_fullscreen) {
    5.45 +    /* See if anything changed */
    5.46 +    if ((display->fullscreen_window == window) == attempt) {
    5.47          return;
    5.48      }
    5.49  
    5.50 -    display->updating_fullscreen = SDL_TRUE;
    5.51 -
    5.52      /* See if we even want to do anything here */
    5.53      if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
    5.54          (window->flags & SDL_WINDOW_SHOWN)) {
    5.55 @@ -1042,29 +1041,52 @@
    5.56  
    5.57      if (FULLSCREEN_VISIBLE(window)) {
    5.58          /* Hide any other fullscreen windows */
    5.59 -        if (display->fullscreen_window != window) {
    5.60 +        if (display->fullscreen_window &&
    5.61 +            display->fullscreen_window != window) {
    5.62              SDL_MinimizeWindow(display->fullscreen_window);
    5.63          }
    5.64      }
    5.65  
    5.66 -    display->updating_fullscreen = SDL_FALSE;
    5.67 +    /* See if there are any fullscreen windows */
    5.68 +    for (other = _this->windows; other; other = other->next) {
    5.69 +        if (FULLSCREEN_VISIBLE(other) &&
    5.70 +            SDL_GetDisplayForWindow(other) == display) {
    5.71 +            SDL_DisplayMode fullscreen_mode;
    5.72 +            if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
    5.73 +                if (_this->PrepWindowFullscreen) {
    5.74 +                    _this->PrepWindowFullscreen(_this, other);
    5.75 +                }
    5.76  
    5.77 -    /* See if there are any fullscreen windows */
    5.78 -    for (window = _this->windows; window; window = window->next) {
    5.79 -        if (FULLSCREEN_VISIBLE(window) &&
    5.80 -            SDL_GetDisplayForWindow(window) == display) {
    5.81 -            SDL_DisplayMode fullscreen_mode;
    5.82 -            if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
    5.83                  SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
    5.84 -                display->fullscreen_window = window;
    5.85 +
    5.86 +                if (_this->SetWindowFullscreen) {
    5.87 +                    _this->SetWindowFullscreen(_this, other);
    5.88 +                }
    5.89 +                display->fullscreen_window = other;
    5.90 +
    5.91 +                /* Generate a mode change events here */
    5.92 +                SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
    5.93 +                                    fullscreen_mode.w, fullscreen_mode.h);
    5.94                  return;
    5.95              }
    5.96          }
    5.97      }
    5.98  
    5.99      /* Nope, restore the desktop mode */
   5.100 +    if (_this->PrepWindowFullscreen) {
   5.101 +        _this->PrepWindowFullscreen(_this, window);
   5.102 +    }
   5.103 +
   5.104      SDL_SetDisplayModeForDisplay(display, NULL);
   5.105 +
   5.106 +    if (_this->SetWindowFullscreen) {
   5.107 +        _this->SetWindowFullscreen(_this, window);
   5.108 +    }
   5.109      display->fullscreen_window = NULL;
   5.110 +
   5.111 +    /* Generate a mode change events here */
   5.112 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
   5.113 +                        window->windowed.w, window->windowed.h);
   5.114  }
   5.115  
   5.116  SDL_Window *
   5.117 @@ -1084,6 +1106,11 @@
   5.118              return NULL;
   5.119          }
   5.120      }
   5.121 +
   5.122 +    /* Some platforms have OpenGL enabled by default */
   5.123 +#if (SDL_VIDEO_OPENGL && __MACOSX__) || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   5.124 +    flags |= SDL_WINDOW_OPENGL;
   5.125 +#endif
   5.126      if (flags & SDL_WINDOW_OPENGL) {
   5.127          if (!_this->GL_CreateContext) {
   5.128              SDL_SetError("No OpenGL support in video driver");
   5.129 @@ -1169,13 +1196,6 @@
   5.130          SDL_SetError("No OpenGL support in video driver");
   5.131          return -1;
   5.132      }
   5.133 -    if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
   5.134 -        if (flags & SDL_WINDOW_OPENGL) {
   5.135 -            SDL_GL_LoadLibrary(NULL);
   5.136 -        } else {
   5.137 -            SDL_GL_UnloadLibrary();
   5.138 -        }
   5.139 -    }
   5.140  
   5.141      if (window->flags & SDL_WINDOW_FOREIGN) {
   5.142          /* Can't destroy and re-create foreign windows, hrm */
   5.143 @@ -1184,10 +1204,29 @@
   5.144          flags &= ~SDL_WINDOW_FOREIGN;
   5.145      }
   5.146  
   5.147 +    /* Restore video mode, etc. */
   5.148 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   5.149 +
   5.150 +    /* Tear down the old native window */
   5.151 +    if (window->surface) {
   5.152 +        window->surface->refcount = 0;
   5.153 +        SDL_FreeSurface(window->surface);
   5.154 +    }
   5.155 +    if (_this->DestroyWindowFramebuffer) {
   5.156 +        _this->DestroyWindowFramebuffer(_this, window);
   5.157 +    }
   5.158      if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
   5.159          _this->DestroyWindow(_this, window);
   5.160      }
   5.161  
   5.162 +    if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
   5.163 +        if (flags & SDL_WINDOW_OPENGL) {
   5.164 +            SDL_GL_LoadLibrary(NULL);
   5.165 +        } else {
   5.166 +            SDL_GL_UnloadLibrary();
   5.167 +        }
   5.168 +    }
   5.169 +
   5.170      window->title = NULL;
   5.171      window->flags = (flags & allowed_flags);
   5.172  
   5.173 @@ -1396,13 +1435,13 @@
   5.174  {
   5.175      CHECK_WINDOW_MAGIC(window, );
   5.176  
   5.177 -    window->w = w;
   5.178 -    window->h = h;
   5.179 -
   5.180 -    if (_this->SetWindowSize) {
   5.181 -        _this->SetWindowSize(_this, window);
   5.182 +    /* FIXME: Should this change fullscreen modes? */
   5.183 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   5.184 +        if (_this->SetWindowSize) {
   5.185 +            _this->SetWindowSize(_this, window);
   5.186 +        }
   5.187 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
   5.188      }
   5.189 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
   5.190  }
   5.191  
   5.192  void
     6.1 --- a/src/video/android/SDL_androidwindow.c	Thu Feb 10 22:49:14 2011 -0800
     6.2 +++ b/src/video/android/SDL_androidwindow.c	Fri Feb 11 00:25:44 2011 -0800
     6.3 @@ -42,7 +42,6 @@
     6.4      window->h = Android_ScreenHeight;
     6.5  
     6.6      window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
     6.7 -    window->flags |= SDL_WINDOW_OPENGL;         /* window is always OpenGL */
     6.8      window->flags |= SDL_WINDOW_FULLSCREEN;     /* window is always fullscreen */
     6.9      window->flags |= SDL_WINDOW_SHOWN;          /* only one window on Android */
    6.10      window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */    
     7.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Thu Feb 10 22:49:14 2011 -0800
     7.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Fri Feb 11 00:25:44 2011 -0800
     7.3 @@ -299,19 +299,6 @@
     7.4          CGReleaseDisplayFadeReservation(fade_token);
     7.5      }
     7.6  
     7.7 -    [[NSApp mainWindow] makeKeyAndOrderFront: nil];
     7.8 -
     7.9 -#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
    7.10 -    /* 
    7.11 -        There is a bug in Cocoa where NSScreen doesn't synchronize
    7.12 -        with CGDirectDisplay, so the main screen's frame is wrong.
    7.13 -        As a result, coordinate translation produces incorrect results.
    7.14 -        We can hack around this bug by setting the screen rect
    7.15 -        ourselves. This hack should be removed if/when the bug is fixed.
    7.16 -    */
    7.17 -    [[NSScreen mainScreen] setFrame:NSMakeRect(0,0,mode->w,mode->h)]; 
    7.18 -#endif
    7.19 -
    7.20      return 0;
    7.21  
    7.22      /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
     8.1 --- a/src/video/cocoa/SDL_cocoaopengl.h	Thu Feb 10 22:49:14 2011 -0800
     8.2 +++ b/src/video/cocoa/SDL_cocoaopengl.h	Fri Feb 11 00:25:44 2011 -0800
     8.3 @@ -26,6 +26,9 @@
     8.4  
     8.5  #if SDL_VIDEO_OPENGL_CGL
     8.6  
     8.7 +/* Define this if you want to be able to toggle fullscreen mode seamlessly */
     8.8 +#define FULLSCREEN_TOGGLEABLE
     8.9 +
    8.10  struct SDL_GLDriverData
    8.11  {
    8.12      int initialized;
     9.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Thu Feb 10 22:49:14 2011 -0800
     9.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Fri Feb 11 00:25:44 2011 -0800
     9.3 @@ -81,9 +81,11 @@
     9.4  
     9.5      pool = [[NSAutoreleasePool alloc] init];
     9.6  
     9.7 +#ifndef FULLSCREEN_TOGGLEABLE
     9.8      if (window->flags & SDL_WINDOW_FULLSCREEN) {
     9.9          attr[i++] = NSOpenGLPFAFullScreen;
    9.10      }
    9.11 +#endif
    9.12  
    9.13      attr[i++] = NSOpenGLPFAColorSize;
    9.14      attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
    9.15 @@ -199,9 +201,12 @@
    9.16          SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
    9.17          NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
    9.18  
    9.19 +#ifndef FULLSCREEN_TOGGLEABLE
    9.20          if (window->flags & SDL_WINDOW_FULLSCREEN) {
    9.21              [nscontext setFullScreen];
    9.22 -        } else {
    9.23 +        } else
    9.24 +#endif
    9.25 +        {
    9.26              [nscontext setView:[windowdata->nswindow contentView]];
    9.27              [nscontext update];
    9.28          }
    10.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Thu Feb 10 22:49:14 2011 -0800
    10.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Fri Feb 11 00:25:44 2011 -0800
    10.3 @@ -90,6 +90,7 @@
    10.4      device->MaximizeWindow = Cocoa_MaximizeWindow;
    10.5      device->MinimizeWindow = Cocoa_MinimizeWindow;
    10.6      device->RestoreWindow = Cocoa_RestoreWindow;
    10.7 +    device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
    10.8      device->SetWindowGrab = Cocoa_SetWindowGrab;
    10.9      device->DestroyWindow = Cocoa_DestroyWindow;
   10.10      device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
    11.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Thu Feb 10 22:49:14 2011 -0800
    11.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Fri Feb 11 00:25:44 2011 -0800
    11.3 @@ -102,6 +102,7 @@
    11.4  extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
    11.5  extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
    11.6  extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
    11.7 +extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window);
    11.8  extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window);
    11.9  extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
   11.10  extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
    12.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 10 22:49:14 2011 -0800
    12.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Feb 11 00:25:44 2011 -0800
    12.3 @@ -398,6 +398,22 @@
    12.4  
    12.5  @end
    12.6  
    12.7 +static unsigned int
    12.8 +GetStyleMask(SDL_Window * window)
    12.9 +{
   12.10 +    unsigned int style;
   12.11 +
   12.12 +    if (window->flags & SDL_WINDOW_BORDERLESS) {
   12.13 +        style = NSBorderlessWindowMask;
   12.14 +    } else {
   12.15 +        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
   12.16 +    }
   12.17 +    if (window->flags & SDL_WINDOW_RESIZABLE) {
   12.18 +        style |= NSResizableWindowMask;
   12.19 +    }
   12.20 +    return style;
   12.21 +}
   12.22 +
   12.23  static int
   12.24  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
   12.25  {
   12.26 @@ -406,7 +422,7 @@
   12.27      SDL_WindowData *data;
   12.28  
   12.29      /* Allocate the window data */
   12.30 -    data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
   12.31 +    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
   12.32      if (!data) {
   12.33          SDL_OutOfMemory();
   12.34          return -1;
   12.35 @@ -424,7 +440,6 @@
   12.36  
   12.37      /* Fill in the SDL window with the window data */
   12.38      {
   12.39 -        SDL_Rect bounds;
   12.40          NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   12.41          NSView *contentView = [[SDLView alloc] initWithFrame: rect
   12.42                                                      listener: data->listener];
   12.43 @@ -495,16 +510,14 @@
   12.44      unsigned int style;
   12.45  
   12.46      Cocoa_GetDisplayBounds(_this, display, &bounds);
   12.47 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   12.48 -        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
   12.49 +    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
   12.50          rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
   12.51      } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
   12.52          rect.origin.x = bounds.x;
   12.53      } else {
   12.54          rect.origin.x = window->x;
   12.55      }
   12.56 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   12.57 -        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
   12.58 +    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
   12.59          rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
   12.60      } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
   12.61          rect.origin.y = bounds.y;
   12.62 @@ -515,14 +528,7 @@
   12.63      rect.size.height = window->h;
   12.64      ConvertNSRect(&rect);
   12.65  
   12.66 -    if (window->flags & SDL_WINDOW_BORDERLESS) {
   12.67 -        style = NSBorderlessWindowMask;
   12.68 -    } else {
   12.69 -        style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
   12.70 -    }
   12.71 -    if (window->flags & SDL_WINDOW_RESIZABLE) {
   12.72 -        style |= NSResizableWindowMask;
   12.73 -    }
   12.74 +    style = GetStyleMask(window);
   12.75  
   12.76      /* Figure out which screen to place this window */
   12.77      NSArray *screens = [NSScreen screens];
   12.78 @@ -600,14 +606,12 @@
   12.79      SDL_Rect bounds;
   12.80  
   12.81      Cocoa_GetDisplayBounds(_this, display, &bounds);
   12.82 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   12.83 -        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
   12.84 +    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
   12.85          rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
   12.86      } else {
   12.87          rect.origin.x = window->x;
   12.88      }
   12.89 -    if ((window->flags & SDL_WINDOW_FULLSCREEN)
   12.90 -        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
   12.91 +    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
   12.92          rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
   12.93      } else {
   12.94          rect.origin.y = window->y;
   12.95 @@ -700,6 +704,56 @@
   12.96  }
   12.97  
   12.98  void
   12.99 +Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window)
  12.100 +{
  12.101 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  12.102 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  12.103 +    NSWindow *nswindow = data->nswindow;
  12.104 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  12.105 +    NSRect rect;
  12.106 +    unsigned int style;
  12.107 +
  12.108 +    if (FULLSCREEN_VISIBLE(window)) {
  12.109 +        SDL_Rect bounds;
  12.110 +
  12.111 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
  12.112 +        rect.origin.x = bounds.x;
  12.113 +        rect.origin.y = bounds.y;
  12.114 +        rect.size.width = bounds.w;
  12.115 +        rect.size.height = bounds.h;
  12.116 +        ConvertNSRect(&rect);
  12.117 +
  12.118 +        style = NSBorderlessWindowMask;
  12.119 +    } else {
  12.120 +        rect.origin.x = window->windowed.x;
  12.121 +        rect.origin.y = window->windowed.y;
  12.122 +        rect.size.width = window->windowed.w;
  12.123 +        rect.size.height = window->windowed.h;
  12.124 +        /* FIXME: This calculation is wrong, we're changing the origin */
  12.125 +        ConvertNSRect(&rect);
  12.126 +
  12.127 +        style = GetStyleMask(window);
  12.128 +    }
  12.129 +
  12.130 +    [nswindow setStyleMask:style];
  12.131 +    [nswindow setContentSize:rect.size];
  12.132 +    rect = [nswindow frameRectForContentRect:rect];
  12.133 +    [nswindow setFrameOrigin:rect.origin];
  12.134 +
  12.135 +#ifdef FULLSCREEN_TOGGLEABLE
  12.136 +    if (FULLSCREEN_VISIBLE(window)) {
  12.137 +        /* OpenGL is rendering to the window, so make it visible! */
  12.138 +        [nswindow setLevel:CGShieldingWindowLevel()];
  12.139 +    } else {
  12.140 +        [nswindow setLevel:kCGNormalWindowLevel];
  12.141 +    }
  12.142 +#endif
  12.143 +    [nswindow makeKeyAndOrderFront:nil];
  12.144 +
  12.145 +    [pool release];
  12.146 +}
  12.147 +
  12.148 +void
  12.149  Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
  12.150  {
  12.151      if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
    13.1 --- a/src/video/uikit/SDL_uikitwindow.m	Thu Feb 10 22:49:14 2011 -0800
    13.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Fri Feb 11 00:25:44 2011 -0800
    13.3 @@ -64,7 +64,6 @@
    13.4      window->driverdata = data;
    13.5      
    13.6      window->flags &= ~SDL_WINDOW_RESIZABLE;        /* window is NEVER resizeable */
    13.7 -    window->flags |= SDL_WINDOW_OPENGL;            /* window is always OpenGL */
    13.8      window->flags |= SDL_WINDOW_FULLSCREEN;        /* window is always fullscreen */
    13.9      window->flags |= SDL_WINDOW_SHOWN;            /* only one window on iPod touch, always shown */
   13.10      window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */