src/video/cocoa/SDL_cocoawindow.m
author jimtla
Fri, 30 Jul 2010 23:18:35 +0400
changeset 4676 99b4560b7aa1
parent 4675 641c13b0ce5f
child 4678 f8431f66613d
permissions -rw-r--r--
Upgraded touchId/fingerId to long. Changed position variables to floats.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_syswm.h"
    25 #include "../SDL_sysvideo.h"
    26 #include "../../events/SDL_keyboard_c.h"
    27 #include "../../events/SDL_mouse_c.h"
    28 #include "../../events/SDL_touch_c.h"
    29 #include "../../events/SDL_windowevents_c.h"
    30 #include "SDL_cocoavideo.h"
    31 
    32 static __inline__ void ConvertNSRect(NSRect *r)
    33 {
    34     r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
    35 }
    36 
    37 @implementation Cocoa_WindowListener
    38 
    39 - (void)listen:(SDL_WindowData *)data
    40 {
    41     NSNotificationCenter *center;
    42 
    43     _data = data;
    44 
    45     center = [NSNotificationCenter defaultCenter];
    46 
    47     [_data->nswindow setNextResponder:self];
    48     if ([_data->nswindow delegate] != nil) {
    49         [center addObserver:self selector:@selector(windowDisExpose:) name:NSWindowDidExposeNotification object:_data->nswindow];
    50         [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:_data->nswindow];
    51         [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:_data->nswindow];
    52         [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:_data->nswindow];
    53         [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:_data->nswindow];
    54         [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:_data->nswindow];
    55         [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:_data->nswindow];
    56     } else {
    57         [_data->nswindow setDelegate:self];
    58     }
    59     [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
    60     [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
    61 
    62     [_data->nswindow setAcceptsMouseMovedEvents:YES];
    63     [[_data->nswindow contentView] setAcceptsTouchEvents:YES];
    64 }
    65 
    66 - (void)close
    67 {
    68     NSNotificationCenter *center;
    69 
    70     center = [NSNotificationCenter defaultCenter];
    71 
    72     [_data->nswindow setNextResponder:nil];
    73     if ([_data->nswindow delegate] != self) {
    74         [center removeObserver:self name:NSWindowDidExposeNotification object:_data->nswindow];
    75         [center removeObserver:self name:NSWindowDidMoveNotification object:_data->nswindow];
    76         [center removeObserver:self name:NSWindowDidResizeNotification object:_data->nswindow];
    77         [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:_data->nswindow];
    78         [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:_data->nswindow];
    79         [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:_data->nswindow];
    80         [center removeObserver:self name:NSWindowDidResignKeyNotification object:_data->nswindow];
    81     } else {
    82         [_data->nswindow setDelegate:nil];
    83     }
    84     [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    85     [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    86 }
    87 
    88 - (BOOL)windowShouldClose:(id)sender
    89 {
    90     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
    91     return NO;
    92 }
    93 
    94 - (void)windowDidExpose:(NSNotification *)aNotification
    95 {
    96     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
    97 }
    98 
    99 - (void)windowDidMove:(NSNotification *)aNotification
   100 {
   101     int x, y;
   102     NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
   103     ConvertNSRect(&rect);
   104     x = (int)rect.origin.x;
   105     y = (int)rect.origin.y;
   106     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
   107 }
   108 
   109 - (void)windowDidResize:(NSNotification *)aNotification
   110 {
   111     int w, h;
   112     NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
   113     w = (int)rect.size.width;
   114     h = (int)rect.size.height;
   115     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
   116 }
   117 
   118 - (void)windowDidMiniaturize:(NSNotification *)aNotification
   119 {
   120     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   121 }
   122 
   123 - (void)windowDidDeminiaturize:(NSNotification *)aNotification
   124 {
   125     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
   126 }
   127 
   128 - (void)windowDidBecomeKey:(NSNotification *)aNotification
   129 {
   130     /* We're going to get keyboard events, since we're key. */
   131     SDL_SetKeyboardFocus(_data->window);
   132 
   133     /* Check to see if someone updated the clipboard */
   134     Cocoa_CheckClipboardUpdate(_data->videodata);
   135 }
   136 
   137 - (void)windowDidResignKey:(NSNotification *)aNotification
   138 {
   139     /* Some other window will get mouse events, since we're not key. */
   140     if (SDL_GetMouseFocus() == _data->window) {
   141         SDL_SetMouseFocus(NULL);
   142     }
   143 
   144     /* Some other window will get keyboard events, since we're not key. */
   145     if (SDL_GetKeyboardFocus() == _data->window) {
   146         SDL_SetKeyboardFocus(NULL);
   147     }
   148 }
   149 
   150 - (void)windowDidHide:(NSNotification *)aNotification
   151 {
   152     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   153 }
   154 
   155 - (void)windowDidUnhide:(NSNotification *)aNotification
   156 {
   157     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
   158 }
   159 
   160 - (void)mouseDown:(NSEvent *)theEvent
   161 {
   162     int button;
   163 
   164     switch ([theEvent buttonNumber]) {
   165     case 0:
   166         button = SDL_BUTTON_LEFT;
   167         break;
   168     case 1:
   169         button = SDL_BUTTON_RIGHT;
   170         break;
   171     case 2:
   172         button = SDL_BUTTON_MIDDLE;
   173         break;
   174     default:
   175         button = [theEvent buttonNumber];
   176         break;
   177     }
   178     SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
   179 }
   180 
   181 - (void)rightMouseDown:(NSEvent *)theEvent
   182 {
   183     [self mouseDown:theEvent];
   184 }
   185 
   186 - (void)otherMouseDown:(NSEvent *)theEvent
   187 {
   188     [self mouseDown:theEvent];
   189 }
   190 
   191 - (void)mouseUp:(NSEvent *)theEvent
   192 {
   193     int button;
   194 
   195     switch ([theEvent buttonNumber]) {
   196     case 0:
   197         button = SDL_BUTTON_LEFT;
   198         break;
   199     case 1:
   200         button = SDL_BUTTON_RIGHT;
   201         break;
   202     case 2:
   203         button = SDL_BUTTON_MIDDLE;
   204         break;
   205     default:
   206         button = [theEvent buttonNumber];
   207         break;
   208     }
   209     SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
   210 }
   211 
   212 - (void)rightMouseUp:(NSEvent *)theEvent
   213 {
   214     [self mouseUp:theEvent];
   215 }
   216 
   217 - (void)otherMouseUp:(NSEvent *)theEvent
   218 {
   219     [self mouseUp:theEvent];
   220 }
   221 
   222 - (void)mouseMoved:(NSEvent *)theEvent
   223 {
   224     SDL_Window *window = _data->window;
   225     NSPoint point;
   226 
   227     point = [theEvent locationInWindow];
   228     point.y = window->h - point.y;
   229     if ( point.x < 0 || point.x >= window->w ||
   230          point.y < 0 || point.y >= window->h ) {
   231         if (SDL_GetMouseFocus() == window) {
   232             SDL_SetMouseFocus(NULL);
   233         }
   234     } else {
   235         SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
   236     }
   237 }
   238 
   239 - (void)mouseDragged:(NSEvent *)theEvent
   240 {
   241     [self mouseMoved:theEvent];
   242 }
   243 
   244 - (void)rightMouseDragged:(NSEvent *)theEvent
   245 {
   246     [self mouseMoved:theEvent];
   247 }
   248 
   249 - (void)otherMouseDragged:(NSEvent *)theEvent
   250 {
   251     [self mouseMoved:theEvent];
   252 }
   253 
   254 - (void)scrollWheel:(NSEvent *)theEvent
   255 {
   256     float x = [theEvent deltaX];
   257     float y = [theEvent deltaY];
   258 
   259     if (x > 0) {
   260         x += 0.9f;
   261     } else if (x < 0) {
   262         x -= 0.9f;
   263     }
   264     if (y > 0) {
   265         y += 0.9f;
   266     } else if (y < 0) {
   267         y -= 0.9f;
   268     }
   269     SDL_SendMouseWheel(_data->window, (int)x, (int)y);
   270 }
   271 
   272 - (void)touchesBeganWithEvent:(NSEvent *) theEvent
   273 {
   274     [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
   275 }
   276 
   277 - (void)touchesMovedWithEvent:(NSEvent *) theEvent
   278 {
   279     [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
   280 }
   281 
   282 - (void)touchesEndedWithEvent:(NSEvent *) theEvent
   283 {
   284     [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
   285 }
   286 
   287 - (void)touchesCancelledWithEvent:(NSEvent *) theEvent
   288 {
   289     [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
   290 }
   291 
   292 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
   293 {
   294     NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
   295 
   296     NSEnumerator *enumerator = [touches objectEnumerator];
   297     NSTouch *touch = (NSTouch*)[enumerator nextObject];
   298     while (touch) {
   299         long touchId = (long)[touch device];
   300         if (!SDL_GetTouch(touchId)) {
   301 	  printf("Adding touch: %li\n",touchId);
   302             SDL_Touch touch;
   303 
   304             touch.id = touchId;
   305             touch.x_min = 0;
   306             touch.x_max = 1;
   307             touch.xres = touch.x_max - touch.x_min;
   308             touch.y_min = 0;
   309             touch.y_max = 1;
   310             touch.yres = touch.y_max - touch.y_min;
   311             touch.pressure_min = 0;
   312             touch.pressure_max = 1;
   313             touch.pressureres = touch.pressure_max - touch.pressure_min;
   314             
   315             if (SDL_AddTouch(&touch, "") < 0) {
   316                 continue;
   317             }
   318 	    printf("Success, added touch: %lin",touchId);
   319         } 
   320         float x = [touch normalizedPosition].x;
   321         float y = [touch normalizedPosition].y;
   322         long fingerId = (long)[touch identity];
   323         switch (type) {
   324         case COCOA_TOUCH_DOWN:
   325             SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
   326             break;
   327         case COCOA_TOUCH_UP:
   328         case COCOA_TOUCH_CANCELLED:
   329             SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
   330             break;
   331         case COCOA_TOUCH_MOVE:
   332             SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
   333             break;
   334         }
   335         
   336         touch = (NSTouch*)[enumerator nextObject];
   337     }
   338 }
   339 
   340 @end
   341 
   342 @interface SDLWindow : NSWindow
   343 /* These are needed for borderless/fullscreen windows */
   344 - (BOOL)canBecomeKeyWindow;
   345 - (BOOL)canBecomeMainWindow;
   346 @end
   347 
   348 @implementation SDLWindow
   349 - (BOOL)canBecomeKeyWindow
   350 {
   351     return YES;
   352 }
   353 
   354 - (BOOL)canBecomeMainWindow
   355 {
   356     return YES;
   357 }
   358 @end
   359 
   360 static int
   361 SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
   362 {
   363     NSAutoreleasePool *pool;
   364     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
   365     SDL_VideoDisplay *display = window->display;
   366     SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
   367     SDL_WindowData *data;
   368 
   369     /* Allocate the window data */
   370     data = (SDL_WindowData *) SDL_malloc(sizeof(*data));
   371     if (!data) {
   372         SDL_OutOfMemory();
   373         return -1;
   374     }
   375     data->window = window;
   376     data->nswindow = nswindow;
   377     data->created = created;
   378     data->display = displaydata->display;
   379     data->videodata = videodata;
   380 
   381     pool = [[NSAutoreleasePool alloc] init];
   382 
   383     /* Create an event listener for the window */
   384     data->listener = [[Cocoa_WindowListener alloc] init];
   385     [data->listener listen:data];
   386 
   387     /* Fill in the SDL window with the window data */
   388     {
   389         SDL_Rect bounds;
   390         NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   391         ConvertNSRect(&rect);
   392         Cocoa_GetDisplayBounds(_this, display, &bounds);
   393         window->x = (int)rect.origin.x - bounds.x;
   394         window->y = (int)rect.origin.y - bounds.y;
   395         window->w = (int)rect.size.width;
   396         window->h = (int)rect.size.height;
   397     }
   398     if ([nswindow isVisible]) {
   399         window->flags |= SDL_WINDOW_SHOWN;
   400     } else {
   401         window->flags &= ~SDL_WINDOW_SHOWN;
   402     }
   403     {
   404         unsigned int style = [nswindow styleMask];
   405 
   406         if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) {
   407             window->flags |= SDL_WINDOW_BORDERLESS;
   408         } else {
   409             window->flags &= ~SDL_WINDOW_BORDERLESS;
   410         }
   411         if (style & NSResizableWindowMask) {
   412             window->flags |= SDL_WINDOW_RESIZABLE;
   413         } else {
   414             window->flags &= ~SDL_WINDOW_RESIZABLE;
   415         }
   416     }
   417     if ([nswindow isZoomed]) {
   418         window->flags |= SDL_WINDOW_MAXIMIZED;
   419     } else {
   420         window->flags &= ~SDL_WINDOW_MAXIMIZED;
   421     }
   422     if ([nswindow isMiniaturized]) {
   423         window->flags |= SDL_WINDOW_MINIMIZED;
   424     } else {
   425         window->flags &= ~SDL_WINDOW_MINIMIZED;
   426     }
   427     if ([nswindow isKeyWindow]) {
   428         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   429         SDL_SetKeyboardFocus(data->window);
   430 
   431         if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   432             /* FIXME */
   433         }
   434     }
   435 
   436     /* All done! */
   437     [pool release];
   438     window->driverdata = data;
   439     return 0;
   440 }
   441 
   442 int
   443 Cocoa_CreateWindow(_THIS, SDL_Window * window)
   444 {
   445     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   446     NSWindow *nswindow;
   447     SDL_VideoDisplay *display = window->display;
   448     NSRect rect;
   449     SDL_Rect bounds;
   450     unsigned int style;
   451 
   452     Cocoa_GetDisplayBounds(_this, display, &bounds);
   453     if ((window->flags & SDL_WINDOW_FULLSCREEN)
   454         || window->x == SDL_WINDOWPOS_CENTERED) {
   455         rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
   456     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   457         rect.origin.x = bounds.x;
   458     } else {
   459         rect.origin.x = bounds.x + window->x;
   460     }
   461     if ((window->flags & SDL_WINDOW_FULLSCREEN)
   462         || window->y == SDL_WINDOWPOS_CENTERED) {
   463         rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
   464     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   465         rect.origin.y = bounds.y;
   466     } else {
   467         rect.origin.y = bounds.y + window->y;
   468     }
   469     rect.size.width = window->w;
   470     rect.size.height = window->h;
   471     ConvertNSRect(&rect);
   472 
   473     if (window->flags & SDL_WINDOW_BORDERLESS) {
   474         style = NSBorderlessWindowMask;
   475     } else {
   476         style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
   477     }
   478     if (window->flags & SDL_WINDOW_RESIZABLE) {
   479         style |= NSResizableWindowMask;
   480     }
   481 
   482     /* Figure out which screen to place this window */
   483     NSArray *screens = [NSScreen screens];
   484     NSScreen *screen = nil;
   485     NSScreen *candidate;
   486     int i, count = [screens count];
   487     for (i = 0; i < count; ++i) {
   488         candidate = [screens objectAtIndex:i];
   489         NSRect screenRect = [candidate frame];
   490         if (rect.origin.x >= screenRect.origin.x &&
   491             rect.origin.x < screenRect.origin.x + screenRect.size.width &&
   492             rect.origin.y >= screenRect.origin.y &&
   493             rect.origin.y < screenRect.origin.y + screenRect.size.height) {
   494             screen = candidate;
   495             rect.origin.x -= screenRect.origin.x;
   496             rect.origin.y -= screenRect.origin.y;
   497         }
   498     }
   499     nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE screen:screen];
   500 
   501     [pool release];
   502 
   503     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
   504         [nswindow release];
   505         return -1;
   506     }
   507     return 0;
   508 }
   509 
   510 int
   511 Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   512 {
   513     NSAutoreleasePool *pool;
   514     NSWindow *nswindow = (NSWindow *) data;
   515     NSString *title;
   516 
   517     pool = [[NSAutoreleasePool alloc] init];
   518 
   519     /* Query the title from the existing window */
   520     title = [nswindow title];
   521     if (title) {
   522         window->title = SDL_strdup([title UTF8String]);
   523     }
   524 
   525     [pool release];
   526 
   527     return SetupWindowData(_this, window, nswindow, SDL_FALSE);
   528 }
   529 
   530 void
   531 Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
   532 {
   533     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   534     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   535     NSString *string;
   536 
   537     if(window->title) {
   538         string = [[NSString alloc] initWithUTF8String:window->title];
   539     } else {
   540         string = [[NSString alloc] init];
   541     }
   542     [nswindow setTitle:string];
   543     [string release];
   544 
   545     [pool release];
   546 }
   547 
   548 void
   549 Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
   550 {
   551     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   552     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   553     SDL_VideoDisplay *display = window->display;
   554     NSRect rect;
   555     SDL_Rect bounds;
   556 
   557     Cocoa_GetDisplayBounds(_this, display, &bounds);
   558     if ((window->flags & SDL_WINDOW_FULLSCREEN)
   559         || window->x == SDL_WINDOWPOS_CENTERED) {
   560         rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
   561     } else {
   562         rect.origin.x = bounds.x + window->x;
   563     }
   564     if ((window->flags & SDL_WINDOW_FULLSCREEN)
   565         || window->y == SDL_WINDOWPOS_CENTERED) {
   566         rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
   567     } else {
   568         rect.origin.y = bounds.y + window->y;
   569     }
   570     rect.size.width = window->w;
   571     rect.size.height = window->h;
   572     ConvertNSRect(&rect);
   573     rect = [nswindow frameRectForContentRect:rect];
   574     [nswindow setFrameOrigin:rect.origin];
   575     [pool release];
   576 }
   577 
   578 void
   579 Cocoa_SetWindowSize(_THIS, SDL_Window * window)
   580 {
   581     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   582     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   583     NSSize size;
   584 
   585     size.width = window->w;
   586     size.height = window->h;
   587     [nswindow setContentSize:size];
   588     [pool release];
   589 }
   590 
   591 void
   592 Cocoa_ShowWindow(_THIS, SDL_Window * window)
   593 {
   594     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   595     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   596 
   597     if (![nswindow isMiniaturized]) {
   598         [nswindow makeKeyAndOrderFront:nil];
   599     }
   600     [pool release];
   601 }
   602 
   603 void
   604 Cocoa_HideWindow(_THIS, SDL_Window * window)
   605 {
   606     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   607     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   608 
   609     [nswindow orderOut:nil];
   610     [pool release];
   611 }
   612 
   613 void
   614 Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   615 {
   616     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   617     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   618 
   619     [nswindow makeKeyAndOrderFront:nil];
   620     [pool release];
   621 }
   622 
   623 void
   624 Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   625 {
   626     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   627     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   628 
   629     [nswindow zoom:nil];
   630     [pool release];
   631 }
   632 
   633 void
   634 Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   635 {
   636     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   637     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   638 
   639     [nswindow miniaturize:nil];
   640     [pool release];
   641 }
   642 
   643 void
   644 Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   645 {
   646     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   647     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   648 
   649     if ([nswindow isMiniaturized]) {
   650         [nswindow deminiaturize:nil];
   651     } else if ([nswindow isZoomed]) {
   652         [nswindow zoom:nil];
   653     }
   654     [pool release];
   655 }
   656 
   657 void
   658 Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
   659 {
   660     if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
   661         (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   662         /* FIXME: Grab mouse */
   663     } else {
   664         /* FIXME: Release mouse */
   665     }
   666 }
   667 
   668 void
   669 Cocoa_DestroyWindow(_THIS, SDL_Window * window)
   670 {
   671     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   672     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   673 
   674     if (data) {
   675         [data->listener close];
   676         [data->listener release];
   677         if (data->created) {
   678             [data->nswindow close];
   679         }
   680         SDL_free(data);
   681     }
   682     [pool release];
   683 }
   684 
   685 SDL_bool
   686 Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   687 {
   688     //NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   689 
   690     if (info->version.major <= SDL_MAJOR_VERSION) {
   691         //info->window = nswindow;
   692         return SDL_TRUE;
   693     } else {
   694         SDL_SetError("Application not compiled with SDL %d.%d\n",
   695                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   696         return SDL_FALSE;
   697     }
   698 }
   699 
   700 /* vi: set ts=4 sw=4 expandtab: */