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