src/video/cocoa/SDL_cocoawindow.m
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 21:32:11 -0800
changeset 5379 78c071fe4c37
parent 5378 738a96883fa6
child 5380 2de85077eb0b
permissions -rw-r--r--
We can defer window creation.
Added documentation for why we need an SDLView
slouken@1933
     1
/*
slouken@1933
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@1933
     4
slouken@1933
     5
    This library is free software; you can redistribute it and/or
slouken@1933
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1933
     7
    License as published by the Free Software Foundation; either
slouken@1933
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1933
     9
slouken@1933
    10
    This library is distributed in the hope that it will be useful,
slouken@1933
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1933
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1933
    13
    Lesser General Public License for more details.
slouken@1933
    14
slouken@1933
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1933
    16
    License along with this library; if not, write to the Free Software
slouken@1933
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1933
    18
slouken@1933
    19
    Sam Lantinga
slouken@1933
    20
    slouken@libsdl.org
slouken@1933
    21
*/
slouken@1933
    22
#include "SDL_config.h"
slouken@1933
    23
slouken@1933
    24
#include "SDL_syswm.h"
slouken@1933
    25
#include "../SDL_sysvideo.h"
slouken@1933
    26
#include "../../events/SDL_keyboard_c.h"
slouken@1933
    27
#include "../../events/SDL_mouse_c.h"
slouken@4673
    28
#include "../../events/SDL_touch_c.h"
slouken@1933
    29
#include "../../events/SDL_windowevents_c.h"
slouken@1933
    30
#include "SDL_cocoavideo.h"
eligottlieb@4811
    31
#include "SDL_cocoashape.h"
gzjjgod@5057
    32
#include "SDL_cocoamouse.h"
slouken@1933
    33
slouken@1933
    34
static __inline__ void ConvertNSRect(NSRect *r)
slouken@1933
    35
{
slouken@1933
    36
    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
slouken@1933
    37
}
slouken@1933
    38
slouken@1933
    39
@implementation Cocoa_WindowListener
slouken@1933
    40
slouken@1933
    41
- (void)listen:(SDL_WindowData *)data
slouken@1933
    42
{
slouken@1933
    43
    NSNotificationCenter *center;
slouken@5371
    44
    NSWindow *window = data->nswindow;
slouken@5371
    45
    NSView *view = [window contentView];
slouken@1933
    46
slouken@1933
    47
    _data = data;
slouken@1933
    48
slouken@1933
    49
    center = [NSNotificationCenter defaultCenter];
slouken@1933
    50
slouken@5374
    51
    if ([window delegate] != nil) {
slouken@5374
    52
        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
slouken@5374
    53
        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
slouken@5374
    54
        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
slouken@5374
    55
        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
    56
        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
    57
        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
    58
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
slouken@5374
    59
    } else {
slouken@5374
    60
        [window setDelegate:self];
slouken@5374
    61
    }
slouken@1933
    62
    [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
slouken@1933
    63
    [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
slouken@1933
    64
slouken@5371
    65
    [window setNextResponder:self];
slouken@5371
    66
    [window setAcceptsMouseMovedEvents:YES];
slouken@5371
    67
slouken@5371
    68
    [view setNextResponder:self];
slouken@5371
    69
    [view addTrackingRect:[view visibleRect] owner:self userData:nil assumeInside:NO];
slouken@4927
    70
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@5371
    71
    [view setAcceptsTouchEvents:YES];
slouken@4925
    72
#endif
slouken@1933
    73
}
slouken@1933
    74
slouken@1933
    75
- (void)close
slouken@1933
    76
{
slouken@1933
    77
    NSNotificationCenter *center;
slouken@5371
    78
    NSWindow *window = _data->nswindow;
slouken@5371
    79
    NSView *view = [window contentView];
slouken@1933
    80
slouken@1933
    81
    center = [NSNotificationCenter defaultCenter];
slouken@1933
    82
slouken@5374
    83
    if ([window delegate] != self) {
slouken@5374
    84
        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
slouken@5374
    85
        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
slouken@5374
    86
        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
slouken@5374
    87
        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
    88
        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
    89
        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
    90
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
slouken@5374
    91
    } else {
slouken@5374
    92
        [window setDelegate:nil];
slouken@5374
    93
    }
slouken@1933
    94
    [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
slouken@1933
    95
    [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
slouken@5371
    96
slouken@5374
    97
    if ([window nextResponder] == self) {
slouken@5374
    98
        [window setNextResponder:nil];
slouken@5374
    99
    }
slouken@5374
   100
    if ([view nextResponder] == self) {
slouken@5374
   101
        [view setNextResponder:nil];
slouken@5374
   102
    }
slouken@1933
   103
}
slouken@1933
   104
slouken@1933
   105
- (BOOL)windowShouldClose:(id)sender
slouken@1933
   106
{
slouken@3685
   107
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1933
   108
    return NO;
slouken@1933
   109
}
slouken@1933
   110
slouken@1933
   111
- (void)windowDidExpose:(NSNotification *)aNotification
slouken@1933
   112
{
slouken@3685
   113
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1933
   114
}
slouken@1933
   115
slouken@1933
   116
- (void)windowDidMove:(NSNotification *)aNotification
slouken@1933
   117
{
slouken@1933
   118
    int x, y;
slouken@3688
   119
    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
slouken@1933
   120
    ConvertNSRect(&rect);
slouken@3507
   121
    x = (int)rect.origin.x;
slouken@3507
   122
    y = (int)rect.origin.y;
slouken@3685
   123
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1933
   124
}
slouken@1933
   125
slouken@1933
   126
- (void)windowDidResize:(NSNotification *)aNotification
slouken@1933
   127
{
slouken@1933
   128
    int w, h;
slouken@3688
   129
    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
slouken@1933
   130
    w = (int)rect.size.width;
slouken@1933
   131
    h = (int)rect.size.height;
slouken@4937
   132
    if (SDL_IsShapedWindow(_data->window))
slouken@4937
   133
        Cocoa_ResizeWindowShape(_data->window);
slouken@3685
   134
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
slouken@1933
   135
}
slouken@1933
   136
slouken@1933
   137
- (void)windowDidMiniaturize:(NSNotification *)aNotification
slouken@1933
   138
{
slouken@3685
   139
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1933
   140
}
slouken@1933
   141
slouken@1933
   142
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
slouken@1933
   143
{
slouken@3685
   144
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1933
   145
}
slouken@1933
   146
slouken@1933
   147
- (void)windowDidBecomeKey:(NSNotification *)aNotification
slouken@1933
   148
{
slouken@5367
   149
    SDL_Window *window = _data->window;
slouken@5367
   150
slouken@3688
   151
    /* We're going to get keyboard events, since we're key. */
slouken@5367
   152
    SDL_SetKeyboardFocus(window);
slouken@5367
   153
slouken@5367
   154
    /* If we just gained focus we need the updated mouse position */
slouken@5371
   155
    if (SDL_GetMouseFocus() == window) {
slouken@5367
   156
        NSPoint point;
slouken@5367
   157
        point = [NSEvent mouseLocation];
slouken@5367
   158
        point = [_data->nswindow convertScreenToBase:point];
slouken@5367
   159
        point.y = window->h - point.y;
slouken@5367
   160
        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@5367
   161
    }
slouken@1962
   162
slouken@4503
   163
    /* Check to see if someone updated the clipboard */
slouken@4503
   164
    Cocoa_CheckClipboardUpdate(_data->videodata);
slouken@1933
   165
}
slouken@1933
   166
slouken@1933
   167
- (void)windowDidResignKey:(NSNotification *)aNotification
slouken@1933
   168
{
slouken@2059
   169
    /* Some other window will get mouse events, since we're not key. */
slouken@4465
   170
    if (SDL_GetMouseFocus() == _data->window) {
slouken@4465
   171
        SDL_SetMouseFocus(NULL);
slouken@2059
   172
    }
slouken@2059
   173
slouken@2059
   174
    /* Some other window will get keyboard events, since we're not key. */
slouken@4465
   175
    if (SDL_GetKeyboardFocus() == _data->window) {
slouken@4465
   176
        SDL_SetKeyboardFocus(NULL);
slouken@4465
   177
    }
slouken@1933
   178
}
slouken@1933
   179
slouken@1933
   180
- (void)windowDidHide:(NSNotification *)aNotification
slouken@1933
   181
{
slouken@3685
   182
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1933
   183
}
slouken@1933
   184
slouken@1933
   185
- (void)windowDidUnhide:(NSNotification *)aNotification
slouken@1933
   186
{
slouken@3685
   187
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1933
   188
}
slouken@1933
   189
slouken@1933
   190
- (void)mouseDown:(NSEvent *)theEvent
slouken@1933
   191
{
slouken@1959
   192
    int button;
slouken@1933
   193
slouken@1959
   194
    switch ([theEvent buttonNumber]) {
slouken@1959
   195
    case 0:
slouken@1959
   196
        button = SDL_BUTTON_LEFT;
slouken@1959
   197
        break;
slouken@1959
   198
    case 1:
slouken@1959
   199
        button = SDL_BUTTON_RIGHT;
slouken@1959
   200
        break;
slouken@1959
   201
    case 2:
slouken@1959
   202
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   203
        break;
slouken@1959
   204
    default:
slouken@5061
   205
        button = [theEvent buttonNumber] + 1;
slouken@1959
   206
        break;
slouken@1959
   207
    }
slouken@4484
   208
    SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
slouken@1933
   209
}
slouken@1933
   210
slouken@1933
   211
- (void)rightMouseDown:(NSEvent *)theEvent
slouken@1933
   212
{
slouken@1959
   213
    [self mouseDown:theEvent];
slouken@1933
   214
}
slouken@1933
   215
slouken@1933
   216
- (void)otherMouseDown:(NSEvent *)theEvent
slouken@1933
   217
{
slouken@1959
   218
    [self mouseDown:theEvent];
slouken@1933
   219
}
slouken@1933
   220
slouken@1933
   221
- (void)mouseUp:(NSEvent *)theEvent
slouken@1933
   222
{
slouken@1959
   223
    int button;
slouken@1933
   224
slouken@1959
   225
    switch ([theEvent buttonNumber]) {
slouken@1959
   226
    case 0:
slouken@1959
   227
        button = SDL_BUTTON_LEFT;
slouken@1959
   228
        break;
slouken@1959
   229
    case 1:
slouken@1959
   230
        button = SDL_BUTTON_RIGHT;
slouken@1959
   231
        break;
slouken@1959
   232
    case 2:
slouken@1959
   233
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   234
        break;
slouken@1959
   235
    default:
slouken@5061
   236
        button = [theEvent buttonNumber] + 1;
slouken@1959
   237
        break;
slouken@1959
   238
    }
slouken@4484
   239
    SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
slouken@1933
   240
}
slouken@1933
   241
slouken@1933
   242
- (void)rightMouseUp:(NSEvent *)theEvent
slouken@1933
   243
{
slouken@1959
   244
    [self mouseUp:theEvent];
slouken@1933
   245
}
slouken@1933
   246
slouken@1933
   247
- (void)otherMouseUp:(NSEvent *)theEvent
slouken@1933
   248
{
slouken@1959
   249
    [self mouseUp:theEvent];
slouken@1933
   250
}
slouken@1933
   251
slouken@5371
   252
- (void)mouseEntered:(NSEvent *)theEvent
slouken@5371
   253
{
slouken@5376
   254
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@5376
   255
slouken@5371
   256
    SDL_SetMouseFocus(_data->window);
slouken@5376
   257
slouken@5376
   258
    if (!mouse->cursor_shown) {
slouken@5376
   259
        [NSCursor hide];
slouken@5376
   260
    }
slouken@5371
   261
}
slouken@5371
   262
slouken@5371
   263
- (void)mouseExited:(NSEvent *)theEvent
slouken@5371
   264
{
slouken@5371
   265
    SDL_Window *window = _data->window;
slouken@5376
   266
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@5371
   267
slouken@5371
   268
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   269
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@5371
   270
            int x, y;
slouken@5371
   271
            NSPoint point;
slouken@5371
   272
            CGPoint cgpoint;
slouken@5371
   273
slouken@5371
   274
            point = [theEvent locationInWindow];
slouken@5371
   275
            point.y = window->h - point.y;
slouken@5371
   276
slouken@5371
   277
            SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@5371
   278
            SDL_GetMouseState(&x, &y);
slouken@5371
   279
            cgpoint.x = window->x + x;
slouken@5371
   280
            cgpoint.y = window->y + y;
slouken@5371
   281
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   282
        } else {
slouken@5371
   283
            SDL_SetMouseFocus(NULL);
slouken@5371
   284
        }
slouken@5371
   285
    }
slouken@5376
   286
slouken@5376
   287
    if (!mouse->cursor_shown) {
slouken@5376
   288
        [NSCursor unhide];
slouken@5376
   289
    }
slouken@5371
   290
}
slouken@5371
   291
slouken@1933
   292
- (void)mouseMoved:(NSEvent *)theEvent
slouken@1933
   293
{
slouken@3685
   294
    SDL_Window *window = _data->window;
slouken@1933
   295
slouken@5371
   296
#ifdef RELATIVE_MOTION
slouken@5371
   297
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
gzjjgod@5059
   298
        return;
slouken@5371
   299
    }
slouken@5371
   300
#endif
gzjjgod@5059
   301
slouken@5371
   302
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   303
        NSPoint point;
slouken@5371
   304
slouken@5371
   305
        point = [theEvent locationInWindow];
slouken@5371
   306
        point.y = window->h - point.y;
slouken@5371
   307
slouken@4484
   308
        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@2059
   309
    }
slouken@1933
   310
}
slouken@1933
   311
slouken@1957
   312
- (void)mouseDragged:(NSEvent *)theEvent
slouken@1957
   313
{
slouken@1957
   314
    [self mouseMoved:theEvent];
slouken@1957
   315
}
slouken@1957
   316
slouken@1958
   317
- (void)rightMouseDragged:(NSEvent *)theEvent
slouken@1958
   318
{
slouken@1958
   319
    [self mouseMoved:theEvent];
slouken@1958
   320
}
slouken@1958
   321
slouken@1958
   322
- (void)otherMouseDragged:(NSEvent *)theEvent
slouken@1958
   323
{
slouken@1958
   324
    [self mouseMoved:theEvent];
slouken@1958
   325
}
slouken@1958
   326
slouken@1933
   327
- (void)scrollWheel:(NSEvent *)theEvent
slouken@1933
   328
{
gzjjgod@5057
   329
    Cocoa_HandleMouseWheel(_data->window, theEvent);
slouken@3688
   330
}
slouken@3688
   331
slouken@4673
   332
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
slouken@4673
   333
{
slouken@4673
   334
    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
slouken@4673
   335
}
slouken@4673
   336
slouken@4673
   337
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
slouken@4673
   338
{
slouken@4673
   339
    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
slouken@4673
   340
}
slouken@4673
   341
slouken@4673
   342
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
slouken@4673
   343
{
slouken@4673
   344
    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
slouken@4673
   345
}
slouken@4673
   346
slouken@4673
   347
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
slouken@4673
   348
{
slouken@4673
   349
    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
slouken@4673
   350
}
slouken@4673
   351
slouken@4673
   352
- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
slouken@4673
   353
{
slouken@4927
   354
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@4680
   355
    NSSet *touches = 0;
slouken@4680
   356
    NSEnumerator *enumerator;
slouken@4680
   357
    NSTouch *touch;
slouken@4673
   358
slouken@4680
   359
    switch (type) {
slouken@4680
   360
        case COCOA_TOUCH_DOWN:
slouken@4680
   361
            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
slouken@4680
   362
            break;
slouken@4680
   363
        case COCOA_TOUCH_UP:
slouken@4680
   364
        case COCOA_TOUCH_CANCELLED:
slouken@4680
   365
            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
slouken@4680
   366
            break;
slouken@4680
   367
        case COCOA_TOUCH_MOVE:
slouken@4680
   368
            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
slouken@4680
   369
            break;
slouken@4680
   370
    }
slouken@4680
   371
slouken@4680
   372
    enumerator = [touches objectEnumerator];
slouken@4680
   373
    touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   374
    while (touch) {
slouken@4680
   375
        SDL_TouchID touchId = (SDL_TouchID)[touch device];
slouken@4673
   376
        if (!SDL_GetTouch(touchId)) {
slouken@4673
   377
            SDL_Touch touch;
slouken@4673
   378
slouken@4673
   379
            touch.id = touchId;
slouken@4673
   380
            touch.x_min = 0;
slouken@4673
   381
            touch.x_max = 1;
jimtla@4678
   382
            touch.native_xres = touch.x_max - touch.x_min;
slouken@4673
   383
            touch.y_min = 0;
slouken@4673
   384
            touch.y_max = 1;
jimtla@4678
   385
            touch.native_yres = touch.y_max - touch.y_min;
slouken@4673
   386
            touch.pressure_min = 0;
slouken@4673
   387
            touch.pressure_max = 1;
jimtla@4678
   388
            touch.native_pressureres = touch.pressure_max - touch.pressure_min;
slouken@4673
   389
            
slouken@4673
   390
            if (SDL_AddTouch(&touch, "") < 0) {
slouken@4680
   391
                return;
slouken@4673
   392
            }
slouken@4673
   393
        } 
slouken@4687
   394
slouken@4687
   395
        SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
slouken@4673
   396
        float x = [touch normalizedPosition].x;
slouken@4673
   397
        float y = [touch normalizedPosition].y;
slouken@5261
   398
        /* Make the origin the upper left instead of the lower left */
slouken@5261
   399
        y = 1.0f - y;
slouken@4687
   400
slouken@4673
   401
        switch (type) {
slouken@4673
   402
        case COCOA_TOUCH_DOWN:
slouken@4673
   403
            SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
slouken@4673
   404
            break;
slouken@4673
   405
        case COCOA_TOUCH_UP:
slouken@4673
   406
        case COCOA_TOUCH_CANCELLED:
slouken@4673
   407
            SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   408
            break;
slouken@4673
   409
        case COCOA_TOUCH_MOVE:
slouken@4673
   410
            SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   411
            break;
slouken@4673
   412
        }
slouken@4673
   413
        
slouken@4673
   414
        touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   415
    }
slouken@4927
   416
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 */
slouken@1933
   417
}
slouken@1933
   418
slouken@1933
   419
@end
slouken@1933
   420
slouken@1973
   421
@interface SDLWindow : NSWindow
slouken@1973
   422
/* These are needed for borderless/fullscreen windows */
slouken@1973
   423
- (BOOL)canBecomeKeyWindow;
slouken@1973
   424
- (BOOL)canBecomeMainWindow;
slouken@1973
   425
@end
slouken@1973
   426
slouken@1973
   427
@implementation SDLWindow
slouken@1973
   428
- (BOOL)canBecomeKeyWindow
slouken@1973
   429
{
slouken@1973
   430
    return YES;
slouken@1973
   431
}
slouken@1973
   432
slouken@1973
   433
- (BOOL)canBecomeMainWindow
slouken@1973
   434
{
slouken@1973
   435
    return YES;
slouken@1973
   436
}
slouken@1973
   437
@end
slouken@1973
   438
slouken@5379
   439
@interface SDLView : NSView
slouken@5379
   440
/* The default implementation doesn't pass rightMouseDown to responder chain */
slouken@5379
   441
- (void)rightMouseDown:(NSEvent *)theEvent;
gzjjgod@4915
   442
@end
gzjjgod@4915
   443
gzjjgod@4915
   444
@implementation SDLView
gzjjgod@4915
   445
- (void)rightMouseDown:(NSEvent *)theEvent
gzjjgod@4915
   446
{
slouken@5371
   447
    [[self nextResponder] rightMouseDown:theEvent];
gzjjgod@4915
   448
}
gzjjgod@4915
   449
@end
gzjjgod@4915
   450
slouken@5249
   451
static unsigned int
slouken@5305
   452
GetWindowStyle(SDL_Window * window)
slouken@5249
   453
{
slouken@5249
   454
    unsigned int style;
slouken@5249
   455
slouken@5305
   456
	if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@5249
   457
        style = NSBorderlessWindowMask;
slouken@5305
   458
	} else {
slouken@5305
   459
		if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@5305
   460
			style = NSBorderlessWindowMask;
slouken@5305
   461
		} else {
slouken@5305
   462
			style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
slouken@5305
   463
		}
slouken@5305
   464
		if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5305
   465
			style |= NSResizableWindowMask;
slouken@5305
   466
		}
slouken@5305
   467
	}
slouken@5249
   468
    return style;
slouken@5249
   469
}
slouken@5249
   470
slouken@1933
   471
static int
slouken@1951
   472
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
slouken@1933
   473
{
slouken@1933
   474
    NSAutoreleasePool *pool;
slouken@1951
   475
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1933
   476
    SDL_WindowData *data;
slouken@1933
   477
slouken@1933
   478
    /* Allocate the window data */
slouken@5249
   479
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1933
   480
    if (!data) {
slouken@1933
   481
        SDL_OutOfMemory();
slouken@1933
   482
        return -1;
slouken@1933
   483
    }
slouken@3685
   484
    data->window = window;
slouken@3688
   485
    data->nswindow = nswindow;
slouken@1933
   486
    data->created = created;
slouken@1951
   487
    data->videodata = videodata;
slouken@1933
   488
slouken@1933
   489
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   490
slouken@1933
   491
    /* Create an event listener for the window */
slouken@1933
   492
    data->listener = [[Cocoa_WindowListener alloc] init];
slouken@1933
   493
slouken@1933
   494
    /* Fill in the SDL window with the window data */
slouken@1933
   495
    {
slouken@1933
   496
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@5371
   497
        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
gzjjgod@4915
   498
        [nswindow setContentView: contentView];
gzjjgod@4915
   499
        [contentView release];
gzjjgod@4915
   500
slouken@1933
   501
        ConvertNSRect(&rect);
slouken@5261
   502
        window->x = (int)rect.origin.x;
slouken@5261
   503
        window->y = (int)rect.origin.y;
slouken@5261
   504
        window->w = (int)rect.size.width;
slouken@5261
   505
        window->h = (int)rect.size.height;
slouken@1933
   506
    }
slouken@5371
   507
slouken@5371
   508
    /* Set up the listener after we create the view */
slouken@5371
   509
    [data->listener listen:data];
slouken@5371
   510
slouken@1933
   511
    if ([nswindow isVisible]) {
slouken@1933
   512
        window->flags |= SDL_WINDOW_SHOWN;
slouken@1933
   513
    } else {
slouken@1933
   514
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1933
   515
    }
slouken@1933
   516
    {
slouken@1933
   517
        unsigned int style = [nswindow styleMask];
slouken@1933
   518
slouken@1956
   519
        if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) {
slouken@1933
   520
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1933
   521
        } else {
slouken@1933
   522
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1933
   523
        }
slouken@1933
   524
        if (style & NSResizableWindowMask) {
slouken@1933
   525
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1933
   526
        } else {
slouken@1933
   527
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1933
   528
        }
slouken@1933
   529
    }
slouken@1933
   530
    if ([nswindow isZoomed]) {
slouken@1933
   531
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1933
   532
    } else {
slouken@1933
   533
        window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1933
   534
    }
slouken@1933
   535
    if ([nswindow isMiniaturized]) {
slouken@1933
   536
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1933
   537
    } else {
slouken@1933
   538
        window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1933
   539
    }
slouken@1933
   540
    if ([nswindow isKeyWindow]) {
slouken@1933
   541
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@4465
   542
        SDL_SetKeyboardFocus(data->window);
slouken@1933
   543
slouken@1933
   544
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1933
   545
            /* FIXME */
slouken@1933
   546
        }
slouken@1933
   547
    }
slouken@1933
   548
slouken@1933
   549
    /* All done! */
slouken@1933
   550
    [pool release];
slouken@1933
   551
    window->driverdata = data;
slouken@1933
   552
    return 0;
slouken@1933
   553
}
slouken@1933
   554
slouken@1933
   555
int
slouken@1933
   556
Cocoa_CreateWindow(_THIS, SDL_Window * window)
slouken@1933
   557
{
slouken@3506
   558
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   559
    NSWindow *nswindow;
slouken@5246
   560
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   561
    NSRect rect;
slouken@3528
   562
    SDL_Rect bounds;
slouken@1933
   563
    unsigned int style;
slouken@1933
   564
slouken@3528
   565
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   566
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@3528
   567
        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
slouken@5246
   568
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
slouken@3528
   569
        rect.origin.x = bounds.x;
slouken@3528
   570
    } else {
slouken@5246
   571
        rect.origin.x = window->x;
slouken@1933
   572
    }
slouken@5249
   573
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@3528
   574
        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
slouken@5246
   575
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
slouken@3528
   576
        rect.origin.y = bounds.y;
slouken@3528
   577
    } else {
slouken@5246
   578
        rect.origin.y = window->y;
slouken@1933
   579
    }
slouken@1933
   580
    rect.size.width = window->w;
slouken@1933
   581
    rect.size.height = window->h;
slouken@1933
   582
    ConvertNSRect(&rect);
slouken@1933
   583
slouken@5305
   584
    style = GetWindowStyle(window);
slouken@1933
   585
slouken@3506
   586
    /* Figure out which screen to place this window */
slouken@3506
   587
    NSArray *screens = [NSScreen screens];
slouken@3506
   588
    NSScreen *screen = nil;
slouken@3506
   589
    NSScreen *candidate;
slouken@3525
   590
    int i, count = [screens count];
slouken@3525
   591
    for (i = 0; i < count; ++i) {
slouken@3529
   592
        candidate = [screens objectAtIndex:i];
slouken@3506
   593
        NSRect screenRect = [candidate frame];
slouken@3506
   594
        if (rect.origin.x >= screenRect.origin.x &&
slouken@3506
   595
            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
slouken@3506
   596
            rect.origin.y >= screenRect.origin.y &&
slouken@3506
   597
            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
slouken@3506
   598
            screen = candidate;
slouken@3506
   599
            rect.origin.x -= screenRect.origin.x;
slouken@3506
   600
            rect.origin.y -= screenRect.origin.y;
slouken@3506
   601
        }
slouken@3506
   602
    }
slouken@5379
   603
    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
slouken@1933
   604
slouken@1933
   605
    [pool release];
slouken@1933
   606
slouken@1951
   607
    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
slouken@1933
   608
        [nswindow release];
slouken@1933
   609
        return -1;
slouken@1933
   610
    }
slouken@1933
   611
    return 0;
slouken@1933
   612
}
slouken@1933
   613
slouken@1933
   614
int
slouken@1933
   615
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1933
   616
{
slouken@1933
   617
    NSAutoreleasePool *pool;
slouken@1933
   618
    NSWindow *nswindow = (NSWindow *) data;
slouken@1933
   619
    NSString *title;
slouken@1933
   620
slouken@1933
   621
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   622
slouken@1933
   623
    /* Query the title from the existing window */
slouken@1933
   624
    title = [nswindow title];
slouken@1933
   625
    if (title) {
slouken@1933
   626
        window->title = SDL_strdup([title UTF8String]);
slouken@1933
   627
    }
slouken@1933
   628
slouken@1933
   629
    [pool release];
slouken@1933
   630
slouken@1951
   631
    return SetupWindowData(_this, window, nswindow, SDL_FALSE);
slouken@1933
   632
}
slouken@1933
   633
slouken@1933
   634
void
slouken@1933
   635
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1933
   636
{
slouken@1937
   637
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   638
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   639
    NSString *string;
slouken@1933
   640
slouken@1956
   641
    if(window->title) {
slouken@1956
   642
        string = [[NSString alloc] initWithUTF8String:window->title];
slouken@1956
   643
    } else {
slouken@1956
   644
        string = [[NSString alloc] init];
slouken@1956
   645
    }
slouken@1933
   646
    [nswindow setTitle:string];
slouken@1933
   647
    [string release];
slouken@1956
   648
slouken@1937
   649
    [pool release];
slouken@1933
   650
}
slouken@1933
   651
slouken@1933
   652
void
slouken@5375
   653
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@5375
   654
{
slouken@5375
   655
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5375
   656
    NSImage *nsimage = Cocoa_CreateImage(icon);
slouken@5375
   657
slouken@5375
   658
    if (nsimage) {
slouken@5375
   659
        [NSApp setApplicationIconImage:nsimage];
slouken@5375
   660
    }
slouken@5375
   661
slouken@5375
   662
    [pool release];
slouken@5375
   663
}
slouken@5375
   664
slouken@5375
   665
void
slouken@1933
   666
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1933
   667
{
slouken@1937
   668
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   669
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@5246
   670
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   671
    NSRect rect;
slouken@3528
   672
    SDL_Rect bounds;
slouken@1933
   673
slouken@3528
   674
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   675
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@3528
   676
        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
slouken@3075
   677
    } else {
slouken@5246
   678
        rect.origin.x = window->x;
slouken@3075
   679
    }
slouken@5249
   680
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@3528
   681
        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
slouken@3075
   682
    } else {
slouken@5246
   683
        rect.origin.y = window->y;
slouken@3075
   684
    }
slouken@1933
   685
    rect.size.width = window->w;
slouken@1933
   686
    rect.size.height = window->h;
slouken@1933
   687
    ConvertNSRect(&rect);
slouken@1933
   688
    rect = [nswindow frameRectForContentRect:rect];
slouken@1933
   689
    [nswindow setFrameOrigin:rect.origin];
slouken@1937
   690
    [pool release];
slouken@1933
   691
}
slouken@1933
   692
slouken@1933
   693
void
slouken@1933
   694
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
slouken@1933
   695
{
slouken@1937
   696
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   697
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   698
    NSSize size;
slouken@1933
   699
slouken@1933
   700
    size.width = window->w;
slouken@1933
   701
    size.height = window->h;
slouken@1933
   702
    [nswindow setContentSize:size];
slouken@1937
   703
    [pool release];
slouken@1933
   704
}
slouken@1933
   705
slouken@1933
   706
void
slouken@1933
   707
Cocoa_ShowWindow(_THIS, SDL_Window * window)
slouken@1933
   708
{
slouken@1937
   709
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   710
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   711
slouken@1956
   712
    if (![nswindow isMiniaturized]) {
slouken@1956
   713
        [nswindow makeKeyAndOrderFront:nil];
slouken@1956
   714
    }
slouken@1937
   715
    [pool release];
slouken@1933
   716
}
slouken@1933
   717
slouken@1933
   718
void
slouken@1933
   719
Cocoa_HideWindow(_THIS, SDL_Window * window)
slouken@1933
   720
{
slouken@1956
   721
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   722
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   723
slouken@1956
   724
    [nswindow orderOut:nil];
slouken@1956
   725
    [pool release];
slouken@1933
   726
}
slouken@1933
   727
slouken@1933
   728
void
slouken@1933
   729
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
slouken@1933
   730
{
slouken@1937
   731
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   732
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   733
slouken@1933
   734
    [nswindow makeKeyAndOrderFront:nil];
slouken@1937
   735
    [pool release];
slouken@1933
   736
}
slouken@1933
   737
slouken@1933
   738
void
slouken@1933
   739
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1933
   740
{
slouken@1937
   741
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   742
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   743
slouken@1956
   744
    [nswindow zoom:nil];
slouken@1937
   745
    [pool release];
slouken@1933
   746
}
slouken@1933
   747
slouken@1933
   748
void
slouken@1933
   749
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1933
   750
{
slouken@1937
   751
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   752
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   753
slouken@1956
   754
    [nswindow miniaturize:nil];
slouken@1937
   755
    [pool release];
slouken@1933
   756
}
slouken@1933
   757
slouken@1933
   758
void
slouken@1933
   759
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
slouken@1933
   760
{
slouken@1956
   761
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   762
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   763
slouken@1956
   764
    if ([nswindow isMiniaturized]) {
slouken@1956
   765
        [nswindow deminiaturize:nil];
slouken@1956
   766
    } else if ([nswindow isZoomed]) {
slouken@1956
   767
        [nswindow zoom:nil];
slouken@1956
   768
    }
slouken@1956
   769
    [pool release];
slouken@1933
   770
}
slouken@1933
   771
slouken@1933
   772
void
slouken@5305
   773
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
slouken@5249
   774
{
slouken@5249
   775
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5249
   776
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@5249
   777
    NSWindow *nswindow = data->nswindow;
slouken@5249
   778
    NSRect rect;
slouken@5249
   779
slouken@5305
   780
    if (fullscreen) {
slouken@5249
   781
        SDL_Rect bounds;
slouken@5249
   782
slouken@5249
   783
        Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   784
        rect.origin.x = bounds.x;
slouken@5249
   785
        rect.origin.y = bounds.y;
slouken@5249
   786
        rect.size.width = bounds.w;
slouken@5249
   787
        rect.size.height = bounds.h;
slouken@5249
   788
        ConvertNSRect(&rect);
slouken@5249
   789
slouken@5361
   790
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5361
   791
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
slouken@5361
   792
        }
slouken@5361
   793
        [nswindow setFrameOrigin:rect.origin];
slouken@5261
   794
        [nswindow setContentSize:rect.size];
slouken@5249
   795
    } else {
slouken@5361
   796
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5378
   797
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
slouken@5361
   798
        }
slouken@5249
   799
slouken@5261
   800
        // This doesn't seem to do anything...
slouken@5261
   801
        //[nswindow setFrameOrigin:origin];
slouken@5249
   802
    }
slouken@5249
   803
slouken@5249
   804
#ifdef FULLSCREEN_TOGGLEABLE
slouken@5305
   805
    if (fullscreen) {
slouken@5249
   806
        /* OpenGL is rendering to the window, so make it visible! */
slouken@5249
   807
        [nswindow setLevel:CGShieldingWindowLevel()];
slouken@5249
   808
    } else {
slouken@5249
   809
        [nswindow setLevel:kCGNormalWindowLevel];
slouken@5249
   810
    }
slouken@5249
   811
#endif
slouken@5249
   812
    [nswindow makeKeyAndOrderFront:nil];
slouken@5249
   813
slouken@5249
   814
    [pool release];
slouken@5249
   815
}
slouken@5249
   816
slouken@5371
   817
NSPoint origin;
slouken@5249
   818
void
slouken@1933
   819
Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1933
   820
{
slouken@5371
   821
#ifdef RELATIVE_MOTION
slouken@5371
   822
    /* FIXME: work in progress
slouken@5371
   823
        You set relative mode by using the following code in conjunction with
slouken@5371
   824
        CGDisplayHideCursor(kCGDirectMainDisplay) and
slouken@5371
   825
        CGDisplayShowCursor(kCGDirectMainDisplay)
slouken@5371
   826
    */
slouken@1933
   827
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1933
   828
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   829
        CGAssociateMouseAndMouseCursorPosition(NO);
slouken@1933
   830
    } else {
slouken@5371
   831
        CGAssociateMouseAndMouseCursorPosition(YES);
slouken@1933
   832
    }
slouken@5371
   833
#else
slouken@5371
   834
    /* Move the cursor to the nearest point in the window */
slouken@5371
   835
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@5371
   836
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   837
        int x, y;
slouken@5371
   838
        CGPoint cgpoint;
slouken@5371
   839
slouken@5371
   840
        SDL_GetMouseState(&x, &y);
slouken@5371
   841
        cgpoint.x = window->x + x;
slouken@5371
   842
        cgpoint.y = window->y + y;
slouken@5371
   843
        CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   844
    }
slouken@5371
   845
#endif
slouken@1933
   846
}
slouken@1933
   847
slouken@1933
   848
void
slouken@1933
   849
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
slouken@1933
   850
{
slouken@1937
   851
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   852
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1933
   853
slouken@1933
   854
    if (data) {
slouken@1933
   855
        [data->listener close];
slouken@1933
   856
        [data->listener release];
slouken@1933
   857
        if (data->created) {
slouken@3688
   858
            [data->nswindow close];
slouken@1933
   859
        }
slouken@1933
   860
        SDL_free(data);
slouken@1933
   861
    }
slouken@1937
   862
    [pool release];
slouken@1933
   863
}
slouken@1933
   864
slouken@1933
   865
SDL_bool
slouken@1933
   866
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1933
   867
{
slouken@4900
   868
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   869
slouken@1933
   870
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@4900
   871
        info->subsystem = SDL_SYSWM_COCOA;
slouken@5056
   872
        info->info.cocoa.window = nswindow;
slouken@1933
   873
        return SDL_TRUE;
slouken@1933
   874
    } else {
slouken@1933
   875
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1933
   876
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1933
   877
        return SDL_FALSE;
slouken@1933
   878
    }
slouken@1933
   879
}
slouken@1933
   880
slouken@1933
   881
/* vi: set ts=4 sw=4 expandtab: */