src/video/cocoa/SDL_cocoawindow.m
changeset 6848 478ecc8a58b3
parent 6832 156e608ec4ef
child 6885 700f1b25f77f
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 11 17:25:58 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 11 17:39:52 2013 -0800
     1.3 @@ -507,6 +507,7 @@
     1.4  static int
     1.5  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
     1.6  {
     1.7 +    NSAutoreleasePool *pool;
     1.8      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     1.9      SDL_WindowData *data;
    1.10  
    1.11 @@ -521,297 +522,313 @@
    1.12      data->created = created;
    1.13      data->videodata = videodata;
    1.14  
    1.15 -    @autoreleasepool {
    1.16 -        /* Create an event listener for the window */
    1.17 -        data->listener = [[Cocoa_WindowListener alloc] init];
    1.18 +    pool = [[NSAutoreleasePool alloc] init];
    1.19  
    1.20 -        /* Fill in the SDL window with the window data */
    1.21 -        {
    1.22 -            NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.23 -            ConvertNSRect(&rect);
    1.24 -            window->x = (int)rect.origin.x;
    1.25 -            window->y = (int)rect.origin.y;
    1.26 -            window->w = (int)rect.size.width;
    1.27 -            window->h = (int)rect.size.height;
    1.28 +    /* Create an event listener for the window */
    1.29 +    data->listener = [[Cocoa_WindowListener alloc] init];
    1.30 +
    1.31 +    /* Fill in the SDL window with the window data */
    1.32 +    {
    1.33 +        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.34 +        ConvertNSRect(&rect);
    1.35 +        window->x = (int)rect.origin.x;
    1.36 +        window->y = (int)rect.origin.y;
    1.37 +        window->w = (int)rect.size.width;
    1.38 +        window->h = (int)rect.size.height;
    1.39 +    }
    1.40 +
    1.41 +    /* Set up the listener after we create the view */
    1.42 +    [data->listener listen:data];
    1.43 +
    1.44 +    if ([nswindow isVisible]) {
    1.45 +        window->flags |= SDL_WINDOW_SHOWN;
    1.46 +    } else {
    1.47 +        window->flags &= ~SDL_WINDOW_SHOWN;
    1.48 +    }
    1.49 +    {
    1.50 +        unsigned int style = [nswindow styleMask];
    1.51 +
    1.52 +        if (style == NSBorderlessWindowMask) {
    1.53 +            window->flags |= SDL_WINDOW_BORDERLESS;
    1.54 +        } else {
    1.55 +            window->flags &= ~SDL_WINDOW_BORDERLESS;
    1.56          }
    1.57 +        if (style & NSResizableWindowMask) {
    1.58 +            window->flags |= SDL_WINDOW_RESIZABLE;
    1.59 +        } else {
    1.60 +            window->flags &= ~SDL_WINDOW_RESIZABLE;
    1.61 +        }
    1.62 +    }
    1.63 +    /* isZoomed always returns true if the window is not resizable */
    1.64 +    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
    1.65 +        window->flags |= SDL_WINDOW_MAXIMIZED;
    1.66 +    } else {
    1.67 +        window->flags &= ~SDL_WINDOW_MAXIMIZED;
    1.68 +    }
    1.69 +    if ([nswindow isMiniaturized]) {
    1.70 +        window->flags |= SDL_WINDOW_MINIMIZED;
    1.71 +    } else {
    1.72 +        window->flags &= ~SDL_WINDOW_MINIMIZED;
    1.73 +    }
    1.74 +    if ([nswindow isKeyWindow]) {
    1.75 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
    1.76 +        SDL_SetKeyboardFocus(data->window);
    1.77 +    }
    1.78  
    1.79 -        /* Set up the listener after we create the view */
    1.80 -        [data->listener listen:data];
    1.81 -
    1.82 -        if ([nswindow isVisible]) {
    1.83 -            window->flags |= SDL_WINDOW_SHOWN;
    1.84 -        } else {
    1.85 -            window->flags &= ~SDL_WINDOW_SHOWN;
    1.86 -        }
    1.87 -        {
    1.88 -            unsigned int style = [nswindow styleMask];
    1.89 -
    1.90 -            if (style == NSBorderlessWindowMask) {
    1.91 -                window->flags |= SDL_WINDOW_BORDERLESS;
    1.92 -            } else {
    1.93 -                window->flags &= ~SDL_WINDOW_BORDERLESS;
    1.94 -            }
    1.95 -            if (style & NSResizableWindowMask) {
    1.96 -                window->flags |= SDL_WINDOW_RESIZABLE;
    1.97 -            } else {
    1.98 -                window->flags &= ~SDL_WINDOW_RESIZABLE;
    1.99 -            }
   1.100 -        }
   1.101 -        /* isZoomed always returns true if the window is not resizable */
   1.102 -        if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   1.103 -            window->flags |= SDL_WINDOW_MAXIMIZED;
   1.104 -        } else {
   1.105 -            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   1.106 -        }
   1.107 -        if ([nswindow isMiniaturized]) {
   1.108 -            window->flags |= SDL_WINDOW_MINIMIZED;
   1.109 -        } else {
   1.110 -            window->flags &= ~SDL_WINDOW_MINIMIZED;
   1.111 -        }
   1.112 -        if ([nswindow isKeyWindow]) {
   1.113 -            window->flags |= SDL_WINDOW_INPUT_FOCUS;
   1.114 -            SDL_SetKeyboardFocus(data->window);
   1.115 -        }
   1.116 -
   1.117 -        /* All done! */
   1.118 -        window->driverdata = data;
   1.119 -        return 0;
   1.120 -    }
   1.121 +    /* All done! */
   1.122 +    [pool release];
   1.123 +    window->driverdata = data;
   1.124 +    return 0;
   1.125  }
   1.126  
   1.127  int
   1.128  Cocoa_CreateWindow(_THIS, SDL_Window * window)
   1.129  {
   1.130 -    @autoreleasepool {
   1.131 -        NSWindow *nswindow;
   1.132 -        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
   1.133 -        NSRect rect;
   1.134 -        SDL_Rect bounds;
   1.135 -        unsigned int style;
   1.136 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.137 +    NSWindow *nswindow;
   1.138 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
   1.139 +    NSRect rect;
   1.140 +    SDL_Rect bounds;
   1.141 +    unsigned int style;
   1.142  
   1.143 -        Cocoa_GetDisplayBounds(_this, display, &bounds);
   1.144 -        rect.origin.x = window->x;
   1.145 -        rect.origin.y = window->y;
   1.146 -        rect.size.width = window->w;
   1.147 -        rect.size.height = window->h;
   1.148 -        ConvertNSRect(&rect);
   1.149 +    Cocoa_GetDisplayBounds(_this, display, &bounds);
   1.150 +    rect.origin.x = window->x;
   1.151 +    rect.origin.y = window->y;
   1.152 +    rect.size.width = window->w;
   1.153 +    rect.size.height = window->h;
   1.154 +    ConvertNSRect(&rect);
   1.155  
   1.156 -        style = GetWindowStyle(window);
   1.157 +    style = GetWindowStyle(window);
   1.158  
   1.159 -        /* Figure out which screen to place this window */
   1.160 -        NSArray *screens = [NSScreen screens];
   1.161 -        NSScreen *screen = nil;
   1.162 -        NSScreen *candidate;
   1.163 -        int i, count = [screens count];
   1.164 -        for (i = 0; i < count; ++i) {
   1.165 -            candidate = [screens objectAtIndex:i];
   1.166 -            NSRect screenRect = [candidate frame];
   1.167 -            if (rect.origin.x >= screenRect.origin.x &&
   1.168 -                rect.origin.x < screenRect.origin.x + screenRect.size.width &&
   1.169 -                rect.origin.y >= screenRect.origin.y &&
   1.170 -                rect.origin.y < screenRect.origin.y + screenRect.size.height) {
   1.171 -                screen = candidate;
   1.172 -                rect.origin.x -= screenRect.origin.x;
   1.173 -                rect.origin.y -= screenRect.origin.y;
   1.174 -            }
   1.175 +    /* Figure out which screen to place this window */
   1.176 +    NSArray *screens = [NSScreen screens];
   1.177 +    NSScreen *screen = nil;
   1.178 +    NSScreen *candidate;
   1.179 +    int i, count = [screens count];
   1.180 +    for (i = 0; i < count; ++i) {
   1.181 +        candidate = [screens objectAtIndex:i];
   1.182 +        NSRect screenRect = [candidate frame];
   1.183 +        if (rect.origin.x >= screenRect.origin.x &&
   1.184 +            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
   1.185 +            rect.origin.y >= screenRect.origin.y &&
   1.186 +            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
   1.187 +            screen = candidate;
   1.188 +            rect.origin.x -= screenRect.origin.x;
   1.189 +            rect.origin.y -= screenRect.origin.y;
   1.190          }
   1.191 -        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
   1.192 +    }
   1.193 +    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
   1.194  
   1.195 -        // Create a default view for this window
   1.196 -        rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   1.197 -        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
   1.198 -        [nswindow setContentView: contentView];
   1.199 -        [contentView release];
   1.200 +    // Create a default view for this window
   1.201 +    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   1.202 +    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
   1.203 +    [nswindow setContentView: contentView];
   1.204 +    [contentView release];
   1.205  
   1.206 -        if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
   1.207 -            [nswindow release];
   1.208 -            return -1;
   1.209 -        }
   1.210 -        return 0;
   1.211 +    [pool release];
   1.212 +
   1.213 +    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
   1.214 +        [nswindow release];
   1.215 +        return -1;
   1.216      }
   1.217 +    return 0;
   1.218  }
   1.219  
   1.220  int
   1.221  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   1.222  {
   1.223 +    NSAutoreleasePool *pool;
   1.224      NSWindow *nswindow = (NSWindow *) data;
   1.225      NSString *title;
   1.226  
   1.227 -    @autoreleasepool {
   1.228 -        /* Query the title from the existing window */
   1.229 -        title = [nswindow title];
   1.230 -        if (title) {
   1.231 -            window->title = SDL_strdup([title UTF8String]);
   1.232 -        }
   1.233 +    pool = [[NSAutoreleasePool alloc] init];
   1.234 +
   1.235 +    /* Query the title from the existing window */
   1.236 +    title = [nswindow title];
   1.237 +    if (title) {
   1.238 +        window->title = SDL_strdup([title UTF8String]);
   1.239      }
   1.240  
   1.241 +    [pool release];
   1.242 +
   1.243      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
   1.244  }
   1.245  
   1.246  void
   1.247  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
   1.248  {
   1.249 -    @autoreleasepool {
   1.250 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.251 -        NSString *string;
   1.252 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.253 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.254 +    NSString *string;
   1.255  
   1.256 -        if(window->title) {
   1.257 -            string = [[NSString alloc] initWithUTF8String:window->title];
   1.258 -        } else {
   1.259 -            string = [[NSString alloc] init];
   1.260 -        }
   1.261 -        [nswindow setTitle:string];
   1.262 -        [string release];
   1.263 +    if(window->title) {
   1.264 +        string = [[NSString alloc] initWithUTF8String:window->title];
   1.265 +    } else {
   1.266 +        string = [[NSString alloc] init];
   1.267      }
   1.268 +    [nswindow setTitle:string];
   1.269 +    [string release];
   1.270 +
   1.271 +    [pool release];
   1.272  }
   1.273  
   1.274  void
   1.275  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
   1.276  {
   1.277 -    @autoreleasepool {
   1.278 -        NSImage *nsimage = Cocoa_CreateImage(icon);
   1.279 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.280 +    NSImage *nsimage = Cocoa_CreateImage(icon);
   1.281  
   1.282 -        if (nsimage) {
   1.283 -            [NSApp setApplicationIconImage:nsimage];
   1.284 -        }
   1.285 +    if (nsimage) {
   1.286 +        [NSApp setApplicationIconImage:nsimage];
   1.287      }
   1.288 +
   1.289 +    [pool release];
   1.290  }
   1.291  
   1.292  void
   1.293  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
   1.294  {
   1.295 -    @autoreleasepool {
   1.296 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.297 -        NSRect rect;
   1.298 -        Uint32 moveHack;
   1.299 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.300 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.301 +    NSRect rect;
   1.302 +    Uint32 moveHack;
   1.303  
   1.304 -        rect.origin.x = window->x;
   1.305 -        rect.origin.y = window->y;
   1.306 -        rect.size.width = window->w;
   1.307 -        rect.size.height = window->h;
   1.308 -        ConvertNSRect(&rect);
   1.309 +    rect.origin.x = window->x;
   1.310 +    rect.origin.y = window->y;
   1.311 +    rect.size.width = window->w;
   1.312 +    rect.size.height = window->h;
   1.313 +    ConvertNSRect(&rect);
   1.314  
   1.315 -        moveHack = s_moveHack;
   1.316 -        s_moveHack = 0;
   1.317 -        [nswindow setFrameOrigin:rect.origin];
   1.318 -        s_moveHack = moveHack;
   1.319 +    moveHack = s_moveHack;
   1.320 +    s_moveHack = 0;
   1.321 +    [nswindow setFrameOrigin:rect.origin];
   1.322 +    s_moveHack = moveHack;
   1.323  
   1.324 -        if (window == _this->current_glwin) {
   1.325 -            [((NSOpenGLContext *) _this->current_glctx) update];
   1.326 -        }
   1.327 +    if (window == _this->current_glwin) {
   1.328 +        [((NSOpenGLContext *) _this->current_glctx) update];
   1.329      }
   1.330 +
   1.331 +    [pool release];
   1.332  }
   1.333  
   1.334  void
   1.335  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
   1.336  {
   1.337 -    @autoreleasepool {
   1.338 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.339 -        NSWindow *nswindow = windata->nswindow;
   1.340 -        NSSize size;
   1.341 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.342 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.343 +    NSWindow *nswindow = windata->nswindow;
   1.344 +    NSSize size;
   1.345  
   1.346 -        size.width = window->w;
   1.347 -        size.height = window->h;
   1.348 -        [nswindow setContentSize:size];
   1.349 +    size.width = window->w;
   1.350 +    size.height = window->h;
   1.351 +    [nswindow setContentSize:size];
   1.352  
   1.353 -        if (window == _this->current_glwin) {
   1.354 -            [((NSOpenGLContext *) _this->current_glctx) update];
   1.355 -        }
   1.356 +    if (window == _this->current_glwin) {
   1.357 +        [((NSOpenGLContext *) _this->current_glctx) update];
   1.358      }
   1.359 +
   1.360 +    [pool release];
   1.361  }
   1.362  
   1.363  void
   1.364  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
   1.365  {
   1.366 -    @autoreleasepool {
   1.367 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.368 -            
   1.369 -        NSSize minSize;
   1.370 -        minSize.width = window->min_w;
   1.371 -        minSize.height = window->min_h;
   1.372 -            
   1.373 -        [windata->nswindow setContentMinSize:minSize];
   1.374 -    }
   1.375 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.376 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.377 +        
   1.378 +    NSSize minSize;
   1.379 +    minSize.width = window->min_w;
   1.380 +    minSize.height = window->min_h;
   1.381 +        
   1.382 +    [windata->nswindow setContentMinSize:minSize];
   1.383 +    
   1.384 +    [pool release];
   1.385  }
   1.386  
   1.387  void
   1.388  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
   1.389  {
   1.390 -    @autoreleasepool {
   1.391 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.392 -            
   1.393 -        NSSize maxSize;
   1.394 -        maxSize.width = window->max_w;
   1.395 -        maxSize.height = window->max_h;
   1.396 -            
   1.397 -        [windata->nswindow setContentMaxSize:maxSize];
   1.398 -    }
   1.399 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.400 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   1.401 +        
   1.402 +    NSSize maxSize;
   1.403 +    maxSize.width = window->max_w;
   1.404 +    maxSize.height = window->max_h;
   1.405 +        
   1.406 +    [windata->nswindow setContentMaxSize:maxSize];
   1.407 +    
   1.408 +    [pool release];
   1.409  }
   1.410  
   1.411  void
   1.412  Cocoa_ShowWindow(_THIS, SDL_Window * window)
   1.413  {
   1.414 -    @autoreleasepool {
   1.415 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.416 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.417 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.418  
   1.419 -        if (![nswindow isMiniaturized]) {
   1.420 -            [nswindow makeKeyAndOrderFront:nil];
   1.421 -        }
   1.422 +    if (![nswindow isMiniaturized]) {
   1.423 +        [nswindow makeKeyAndOrderFront:nil];
   1.424      }
   1.425 +    [pool release];
   1.426  }
   1.427  
   1.428  void
   1.429  Cocoa_HideWindow(_THIS, SDL_Window * window)
   1.430  {
   1.431 -    @autoreleasepool {
   1.432 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.433 -        [nswindow orderOut:nil];
   1.434 -    }
   1.435 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.436 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.437 +
   1.438 +    [nswindow orderOut:nil];
   1.439 +    [pool release];
   1.440  }
   1.441  
   1.442  void
   1.443  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   1.444  {
   1.445 -    @autoreleasepool {
   1.446 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.447 -        [nswindow makeKeyAndOrderFront:nil];
   1.448 -    }
   1.449 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.450 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.451 +
   1.452 +    [nswindow makeKeyAndOrderFront:nil];
   1.453 +    [pool release];
   1.454  }
   1.455  
   1.456  void
   1.457  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   1.458  {
   1.459 -    @autoreleasepool {
   1.460 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.461 -        [nswindow zoom:nil];
   1.462 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.463 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.464  
   1.465 -        if (window == _this->current_glwin) {
   1.466 -            [((NSOpenGLContext *) _this->current_glctx) update];
   1.467 -        }
   1.468 +    [nswindow zoom:nil];
   1.469 +
   1.470 +    if (window == _this->current_glwin) {
   1.471 +        [((NSOpenGLContext *) _this->current_glctx) update];
   1.472      }
   1.473 +
   1.474 +    [pool release];
   1.475  }
   1.476  
   1.477  void
   1.478  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   1.479  {
   1.480 -    @autoreleasepool {
   1.481 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.482 -        [nswindow miniaturize:nil];
   1.483 -    }
   1.484 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.485 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.486 +
   1.487 +    [nswindow miniaturize:nil];
   1.488 +    [pool release];
   1.489  }
   1.490  
   1.491  void
   1.492  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   1.493  {
   1.494 -    @autoreleasepool {
   1.495 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.496 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.497 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.498  
   1.499 -        if ([nswindow isMiniaturized]) {
   1.500 -            [nswindow deminiaturize:nil];
   1.501 -        } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   1.502 -            [nswindow zoom:nil];
   1.503 -        }
   1.504 +    if ([nswindow isMiniaturized]) {
   1.505 +        [nswindow deminiaturize:nil];
   1.506 +    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   1.507 +        [nswindow zoom:nil];
   1.508      }
   1.509 +    [pool release];
   1.510  }
   1.511  
   1.512  static NSWindow *
   1.513 @@ -837,95 +854,96 @@
   1.514  {
   1.515      /* this message arrived in 10.6. You're out of luck on older OSes. */
   1.516  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
   1.517 -    @autoreleasepool {
   1.518 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.519 -        if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
   1.520 -            [nswindow setStyleMask:GetWindowStyle(window)];
   1.521 -            if (bordered) {
   1.522 -                Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
   1.523 -            }
   1.524 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.525 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.526 +    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
   1.527 +        [nswindow setStyleMask:GetWindowStyle(window)];
   1.528 +        if (bordered) {
   1.529 +            Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
   1.530          }
   1.531      }
   1.532 +    [pool release];
   1.533  #endif
   1.534  }
   1.535  
   1.536  void
   1.537  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.538  {
   1.539 -    @autoreleasepool {
   1.540 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.541 -        NSWindow *nswindow = data->nswindow;
   1.542 -        NSRect rect;
   1.543 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.544 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.545 +    NSWindow *nswindow = data->nswindow;
   1.546 +    NSRect rect;
   1.547  
   1.548 -        /* The view responder chain gets messed with during setStyleMask */
   1.549 -        if ([[nswindow contentView] nextResponder] == data->listener) {
   1.550 -            [[nswindow contentView] setNextResponder:nil];
   1.551 +    /* The view responder chain gets messed with during setStyleMask */
   1.552 +    if ([[nswindow contentView] nextResponder] == data->listener) {
   1.553 +        [[nswindow contentView] setNextResponder:nil];
   1.554 +    }
   1.555 +
   1.556 +    if (fullscreen) {
   1.557 +        SDL_Rect bounds;
   1.558 +
   1.559 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
   1.560 +        rect.origin.x = bounds.x;
   1.561 +        rect.origin.y = bounds.y;
   1.562 +        rect.size.width = bounds.w;
   1.563 +        rect.size.height = bounds.h;
   1.564 +        ConvertNSRect(&rect);
   1.565 +
   1.566 +        /* Hack to fix origin on Mac OS X 10.4 */
   1.567 +        NSRect screenRect = [[nswindow screen] frame];
   1.568 +        if (screenRect.size.height >= 1.0f) {
   1.569 +            rect.origin.y += (screenRect.size.height - rect.size.height);
   1.570          }
   1.571  
   1.572 -        if (fullscreen) {
   1.573 -            SDL_Rect bounds;
   1.574 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
   1.575 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
   1.576 +        } else {
   1.577 +            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
   1.578 +        }
   1.579 +    } else {
   1.580 +        rect.origin.x = window->windowed.x;
   1.581 +        rect.origin.y = window->windowed.y;
   1.582 +        rect.size.width = window->windowed.w;
   1.583 +        rect.size.height = window->windowed.h;
   1.584 +        ConvertNSRect(&rect);
   1.585  
   1.586 -            Cocoa_GetDisplayBounds(_this, display, &bounds);
   1.587 -            rect.origin.x = bounds.x;
   1.588 -            rect.origin.y = bounds.y;
   1.589 -            rect.size.width = bounds.w;
   1.590 -            rect.size.height = bounds.h;
   1.591 -            ConvertNSRect(&rect);
   1.592 -
   1.593 -            /* Hack to fix origin on Mac OS X 10.4 */
   1.594 -            NSRect screenRect = [[nswindow screen] frame];
   1.595 -            if (screenRect.size.height >= 1.0f) {
   1.596 -                rect.origin.y += (screenRect.size.height - rect.size.height);
   1.597 -            }
   1.598 -
   1.599 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
   1.600 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
   1.601 -            } else {
   1.602 -                nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
   1.603 -            }
   1.604 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
   1.605 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
   1.606          } else {
   1.607 -            rect.origin.x = window->windowed.x;
   1.608 -            rect.origin.y = window->windowed.y;
   1.609 -            rect.size.width = window->windowed.w;
   1.610 -            rect.size.height = window->windowed.h;
   1.611 -            ConvertNSRect(&rect);
   1.612 -
   1.613 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
   1.614 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
   1.615 -            } else {
   1.616 -                nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
   1.617 -            }
   1.618 -        }
   1.619 -
   1.620 -        /* The view responder chain gets messed with during setStyleMask */
   1.621 -        if ([[nswindow contentView] nextResponder] != data->listener) {
   1.622 -            [[nswindow contentView] setNextResponder:data->listener];
   1.623 -        }
   1.624 -
   1.625 -        s_moveHack = 0;
   1.626 -        [nswindow setFrameOrigin:rect.origin];
   1.627 -        [nswindow setContentSize:rect.size];
   1.628 -        s_moveHack = SDL_GetTicks();
   1.629 -
   1.630 -        /* When the window style changes the title is cleared */
   1.631 -        if (!fullscreen) {
   1.632 -            Cocoa_SetWindowTitle(_this, window);
   1.633 -        }
   1.634 -
   1.635 -    #ifdef FULLSCREEN_TOGGLEABLE
   1.636 -        if (SDL_ShouldAllowTopmost() && fullscreen) {
   1.637 -            /* OpenGL is rendering to the window, so make it visible! */
   1.638 -            [nswindow setLevel:CGShieldingWindowLevel()];
   1.639 -        } else {
   1.640 -            [nswindow setLevel:kCGNormalWindowLevel];
   1.641 -        }
   1.642 -    #endif
   1.643 -        [nswindow makeKeyAndOrderFront:nil];
   1.644 -
   1.645 -        if (window == _this->current_glwin) {
   1.646 -            [((NSOpenGLContext *) _this->current_glctx) update];
   1.647 +            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
   1.648          }
   1.649      }
   1.650 +
   1.651 +    /* The view responder chain gets messed with during setStyleMask */
   1.652 +    if ([[nswindow contentView] nextResponder] != data->listener) {
   1.653 +        [[nswindow contentView] setNextResponder:data->listener];
   1.654 +    }
   1.655 +
   1.656 +    s_moveHack = 0;
   1.657 +    [nswindow setFrameOrigin:rect.origin];
   1.658 +    [nswindow setContentSize:rect.size];
   1.659 +    s_moveHack = SDL_GetTicks();
   1.660 +
   1.661 +    /* When the window style changes the title is cleared */
   1.662 +    if (!fullscreen) {
   1.663 +        Cocoa_SetWindowTitle(_this, window);
   1.664 +    }
   1.665 +
   1.666 +#ifdef FULLSCREEN_TOGGLEABLE
   1.667 +    if (SDL_ShouldAllowTopmost() && fullscreen) {
   1.668 +        /* OpenGL is rendering to the window, so make it visible! */
   1.669 +        [nswindow setLevel:CGShieldingWindowLevel()];
   1.670 +    } else {
   1.671 +        [nswindow setLevel:kCGNormalWindowLevel];
   1.672 +    }
   1.673 +#endif
   1.674 +    [nswindow makeKeyAndOrderFront:nil];
   1.675 +
   1.676 +    if (window == _this->current_glwin) {
   1.677 +        [((NSOpenGLContext *) _this->current_glctx) update];
   1.678 +    }
   1.679 +
   1.680 +    [pool release];
   1.681  }
   1.682  
   1.683  int
   1.684 @@ -1009,18 +1027,18 @@
   1.685  void
   1.686  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
   1.687  {
   1.688 -    @autoreleasepool {
   1.689 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.690 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.691 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.692  
   1.693 -        if (data) {
   1.694 -            [data->listener close];
   1.695 -            [data->listener release];
   1.696 -            if (data->created) {
   1.697 -                [data->nswindow close];
   1.698 -            }
   1.699 -            SDL_free(data);
   1.700 +    if (data) {
   1.701 +        [data->listener close];
   1.702 +        [data->listener release];
   1.703 +        if (data->created) {
   1.704 +            [data->nswindow close];
   1.705          }
   1.706 +        SDL_free(data);
   1.707      }
   1.708 +    [pool release];
   1.709  }
   1.710  
   1.711  SDL_bool