src/video/cocoa/SDL_cocoawindow.m
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 16:45:23 -0800
changeset 5375 16877f74123c
parent 5374 dacb4f5e0dd3
child 5376 183ec2d4485c
permissions -rw-r--r--
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
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@5371
   254
    SDL_SetMouseFocus(_data->window);
slouken@5371
   255
}
slouken@5371
   256
slouken@5371
   257
- (void)mouseExited:(NSEvent *)theEvent
slouken@5371
   258
{
slouken@5371
   259
    SDL_Window *window = _data->window;
slouken@5371
   260
slouken@5371
   261
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   262
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@5371
   263
            int x, y;
slouken@5371
   264
            NSPoint point;
slouken@5371
   265
            CGPoint cgpoint;
slouken@5371
   266
slouken@5371
   267
            point = [theEvent locationInWindow];
slouken@5371
   268
            point.y = window->h - point.y;
slouken@5371
   269
slouken@5371
   270
            SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@5371
   271
            SDL_GetMouseState(&x, &y);
slouken@5371
   272
            cgpoint.x = window->x + x;
slouken@5371
   273
            cgpoint.y = window->y + y;
slouken@5371
   274
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   275
        } else {
slouken@5371
   276
            SDL_SetMouseFocus(NULL);
slouken@5371
   277
        }
slouken@5371
   278
    }
slouken@5371
   279
}
slouken@5371
   280
slouken@1933
   281
- (void)mouseMoved:(NSEvent *)theEvent
slouken@1933
   282
{
slouken@3685
   283
    SDL_Window *window = _data->window;
slouken@1933
   284
slouken@5371
   285
#ifdef RELATIVE_MOTION
slouken@5371
   286
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
gzjjgod@5059
   287
        return;
slouken@5371
   288
    }
slouken@5371
   289
#endif
gzjjgod@5059
   290
slouken@5371
   291
    if (SDL_GetMouseFocus() == window) {
slouken@5371
   292
        NSPoint point;
slouken@5371
   293
slouken@5371
   294
        point = [theEvent locationInWindow];
slouken@5371
   295
        point.y = window->h - point.y;
slouken@5371
   296
slouken@4484
   297
        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
slouken@2059
   298
    }
slouken@1933
   299
}
slouken@1933
   300
slouken@1957
   301
- (void)mouseDragged:(NSEvent *)theEvent
slouken@1957
   302
{
slouken@1957
   303
    [self mouseMoved:theEvent];
slouken@1957
   304
}
slouken@1957
   305
slouken@1958
   306
- (void)rightMouseDragged:(NSEvent *)theEvent
slouken@1958
   307
{
slouken@1958
   308
    [self mouseMoved:theEvent];
slouken@1958
   309
}
slouken@1958
   310
slouken@1958
   311
- (void)otherMouseDragged:(NSEvent *)theEvent
slouken@1958
   312
{
slouken@1958
   313
    [self mouseMoved:theEvent];
slouken@1958
   314
}
slouken@1958
   315
slouken@1933
   316
- (void)scrollWheel:(NSEvent *)theEvent
slouken@1933
   317
{
gzjjgod@5057
   318
    Cocoa_HandleMouseWheel(_data->window, theEvent);
slouken@3688
   319
}
slouken@3688
   320
slouken@4673
   321
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
slouken@4673
   322
{
slouken@4673
   323
    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
slouken@4673
   324
}
slouken@4673
   325
slouken@4673
   326
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
slouken@4673
   327
{
slouken@4673
   328
    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
slouken@4673
   329
}
slouken@4673
   330
slouken@4673
   331
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
slouken@4673
   332
{
slouken@4673
   333
    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
slouken@4673
   334
}
slouken@4673
   335
slouken@4673
   336
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
slouken@4673
   337
{
slouken@4673
   338
    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
slouken@4673
   339
}
slouken@4673
   340
slouken@4673
   341
- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
slouken@4673
   342
{
slouken@4927
   343
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
slouken@4680
   344
    NSSet *touches = 0;
slouken@4680
   345
    NSEnumerator *enumerator;
slouken@4680
   346
    NSTouch *touch;
slouken@4673
   347
slouken@4680
   348
    switch (type) {
slouken@4680
   349
        case COCOA_TOUCH_DOWN:
slouken@4680
   350
            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
slouken@4680
   351
            break;
slouken@4680
   352
        case COCOA_TOUCH_UP:
slouken@4680
   353
        case COCOA_TOUCH_CANCELLED:
slouken@4680
   354
            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
slouken@4680
   355
            break;
slouken@4680
   356
        case COCOA_TOUCH_MOVE:
slouken@4680
   357
            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
slouken@4680
   358
            break;
slouken@4680
   359
    }
slouken@4680
   360
slouken@4680
   361
    enumerator = [touches objectEnumerator];
slouken@4680
   362
    touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   363
    while (touch) {
slouken@4680
   364
        SDL_TouchID touchId = (SDL_TouchID)[touch device];
slouken@4673
   365
        if (!SDL_GetTouch(touchId)) {
slouken@4673
   366
            SDL_Touch touch;
slouken@4673
   367
slouken@4673
   368
            touch.id = touchId;
slouken@4673
   369
            touch.x_min = 0;
slouken@4673
   370
            touch.x_max = 1;
jimtla@4678
   371
            touch.native_xres = touch.x_max - touch.x_min;
slouken@4673
   372
            touch.y_min = 0;
slouken@4673
   373
            touch.y_max = 1;
jimtla@4678
   374
            touch.native_yres = touch.y_max - touch.y_min;
slouken@4673
   375
            touch.pressure_min = 0;
slouken@4673
   376
            touch.pressure_max = 1;
jimtla@4678
   377
            touch.native_pressureres = touch.pressure_max - touch.pressure_min;
slouken@4673
   378
            
slouken@4673
   379
            if (SDL_AddTouch(&touch, "") < 0) {
slouken@4680
   380
                return;
slouken@4673
   381
            }
slouken@4673
   382
        } 
slouken@4687
   383
slouken@4687
   384
        SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
slouken@4673
   385
        float x = [touch normalizedPosition].x;
slouken@4673
   386
        float y = [touch normalizedPosition].y;
slouken@5261
   387
        /* Make the origin the upper left instead of the lower left */
slouken@5261
   388
        y = 1.0f - y;
slouken@4687
   389
slouken@4673
   390
        switch (type) {
slouken@4673
   391
        case COCOA_TOUCH_DOWN:
slouken@4673
   392
            SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
slouken@4673
   393
            break;
slouken@4673
   394
        case COCOA_TOUCH_UP:
slouken@4673
   395
        case COCOA_TOUCH_CANCELLED:
slouken@4673
   396
            SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   397
            break;
slouken@4673
   398
        case COCOA_TOUCH_MOVE:
slouken@4673
   399
            SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
slouken@4673
   400
            break;
slouken@4673
   401
        }
slouken@4673
   402
        
slouken@4673
   403
        touch = (NSTouch*)[enumerator nextObject];
slouken@4673
   404
    }
slouken@4927
   405
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 */
slouken@1933
   406
}
slouken@1933
   407
slouken@1933
   408
@end
slouken@1933
   409
slouken@1973
   410
@interface SDLWindow : NSWindow
slouken@1973
   411
/* These are needed for borderless/fullscreen windows */
slouken@1973
   412
- (BOOL)canBecomeKeyWindow;
slouken@1973
   413
- (BOOL)canBecomeMainWindow;
slouken@1973
   414
@end
slouken@1973
   415
slouken@1973
   416
@implementation SDLWindow
slouken@1973
   417
- (BOOL)canBecomeKeyWindow
slouken@1973
   418
{
slouken@1973
   419
    return YES;
slouken@1973
   420
}
slouken@1973
   421
slouken@1973
   422
- (BOOL)canBecomeMainWindow
slouken@1973
   423
{
slouken@1973
   424
    return YES;
slouken@1973
   425
}
slouken@1973
   426
@end
slouken@1973
   427
slouken@5371
   428
@interface SDLView : NSView { }
gzjjgod@4915
   429
@end
gzjjgod@4915
   430
gzjjgod@4915
   431
@implementation SDLView
gzjjgod@4915
   432
- (void)rightMouseDown:(NSEvent *)theEvent
gzjjgod@4915
   433
{
slouken@5371
   434
    [[self nextResponder] rightMouseDown:theEvent];
gzjjgod@4915
   435
}
gzjjgod@4915
   436
@end
gzjjgod@4915
   437
slouken@5249
   438
static unsigned int
slouken@5305
   439
GetWindowStyle(SDL_Window * window)
slouken@5249
   440
{
slouken@5249
   441
    unsigned int style;
slouken@5249
   442
slouken@5305
   443
	if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@5249
   444
        style = NSBorderlessWindowMask;
slouken@5305
   445
	} else {
slouken@5305
   446
		if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@5305
   447
			style = NSBorderlessWindowMask;
slouken@5305
   448
		} else {
slouken@5305
   449
			style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
slouken@5305
   450
		}
slouken@5305
   451
		if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5305
   452
			style |= NSResizableWindowMask;
slouken@5305
   453
		}
slouken@5305
   454
	}
slouken@5249
   455
    return style;
slouken@5249
   456
}
slouken@5249
   457
slouken@1933
   458
static int
slouken@1951
   459
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
slouken@1933
   460
{
slouken@1933
   461
    NSAutoreleasePool *pool;
slouken@1951
   462
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1933
   463
    SDL_WindowData *data;
slouken@1933
   464
slouken@1933
   465
    /* Allocate the window data */
slouken@5249
   466
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1933
   467
    if (!data) {
slouken@1933
   468
        SDL_OutOfMemory();
slouken@1933
   469
        return -1;
slouken@1933
   470
    }
slouken@3685
   471
    data->window = window;
slouken@3688
   472
    data->nswindow = nswindow;
slouken@1933
   473
    data->created = created;
slouken@1951
   474
    data->videodata = videodata;
slouken@1933
   475
slouken@1933
   476
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   477
slouken@1933
   478
    /* Create an event listener for the window */
slouken@1933
   479
    data->listener = [[Cocoa_WindowListener alloc] init];
slouken@1933
   480
slouken@1933
   481
    /* Fill in the SDL window with the window data */
slouken@1933
   482
    {
slouken@1933
   483
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@5371
   484
        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
gzjjgod@4915
   485
        [nswindow setContentView: contentView];
gzjjgod@4915
   486
        [contentView release];
gzjjgod@4915
   487
slouken@1933
   488
        ConvertNSRect(&rect);
slouken@5261
   489
        window->x = (int)rect.origin.x;
slouken@5261
   490
        window->y = (int)rect.origin.y;
slouken@5261
   491
        window->w = (int)rect.size.width;
slouken@5261
   492
        window->h = (int)rect.size.height;
slouken@1933
   493
    }
slouken@5371
   494
slouken@5371
   495
    /* Set up the listener after we create the view */
slouken@5371
   496
    [data->listener listen:data];
slouken@5371
   497
slouken@1933
   498
    if ([nswindow isVisible]) {
slouken@1933
   499
        window->flags |= SDL_WINDOW_SHOWN;
slouken@1933
   500
    } else {
slouken@1933
   501
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1933
   502
    }
slouken@1933
   503
    {
slouken@1933
   504
        unsigned int style = [nswindow styleMask];
slouken@1933
   505
slouken@1956
   506
        if ((style & ~NSResizableWindowMask) == NSBorderlessWindowMask) {
slouken@1933
   507
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1933
   508
        } else {
slouken@1933
   509
            window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1933
   510
        }
slouken@1933
   511
        if (style & NSResizableWindowMask) {
slouken@1933
   512
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1933
   513
        } else {
slouken@1933
   514
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1933
   515
        }
slouken@1933
   516
    }
slouken@1933
   517
    if ([nswindow isZoomed]) {
slouken@1933
   518
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1933
   519
    } else {
slouken@1933
   520
        window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1933
   521
    }
slouken@1933
   522
    if ([nswindow isMiniaturized]) {
slouken@1933
   523
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1933
   524
    } else {
slouken@1933
   525
        window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1933
   526
    }
slouken@1933
   527
    if ([nswindow isKeyWindow]) {
slouken@1933
   528
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@4465
   529
        SDL_SetKeyboardFocus(data->window);
slouken@1933
   530
slouken@1933
   531
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1933
   532
            /* FIXME */
slouken@1933
   533
        }
slouken@1933
   534
    }
slouken@1933
   535
slouken@1933
   536
    /* All done! */
slouken@1933
   537
    [pool release];
slouken@1933
   538
    window->driverdata = data;
slouken@1933
   539
    return 0;
slouken@1933
   540
}
slouken@1933
   541
slouken@1933
   542
int
slouken@1933
   543
Cocoa_CreateWindow(_THIS, SDL_Window * window)
slouken@1933
   544
{
slouken@3506
   545
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   546
    NSWindow *nswindow;
slouken@5246
   547
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   548
    NSRect rect;
slouken@3528
   549
    SDL_Rect bounds;
slouken@1933
   550
    unsigned int style;
slouken@1933
   551
slouken@3528
   552
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   553
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@3528
   554
        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
slouken@5246
   555
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
slouken@3528
   556
        rect.origin.x = bounds.x;
slouken@3528
   557
    } else {
slouken@5246
   558
        rect.origin.x = window->x;
slouken@1933
   559
    }
slouken@5249
   560
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@3528
   561
        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
slouken@5246
   562
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
slouken@3528
   563
        rect.origin.y = bounds.y;
slouken@3528
   564
    } else {
slouken@5246
   565
        rect.origin.y = window->y;
slouken@1933
   566
    }
slouken@1933
   567
    rect.size.width = window->w;
slouken@1933
   568
    rect.size.height = window->h;
slouken@1933
   569
    ConvertNSRect(&rect);
slouken@1933
   570
slouken@5305
   571
    style = GetWindowStyle(window);
slouken@1933
   572
slouken@3506
   573
    /* Figure out which screen to place this window */
slouken@3506
   574
    NSArray *screens = [NSScreen screens];
slouken@3506
   575
    NSScreen *screen = nil;
slouken@3506
   576
    NSScreen *candidate;
slouken@3525
   577
    int i, count = [screens count];
slouken@3525
   578
    for (i = 0; i < count; ++i) {
slouken@3529
   579
        candidate = [screens objectAtIndex:i];
slouken@3506
   580
        NSRect screenRect = [candidate frame];
slouken@3506
   581
        if (rect.origin.x >= screenRect.origin.x &&
slouken@3506
   582
            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
slouken@3506
   583
            rect.origin.y >= screenRect.origin.y &&
slouken@3506
   584
            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
slouken@3506
   585
            screen = candidate;
slouken@3506
   586
            rect.origin.x -= screenRect.origin.x;
slouken@3506
   587
            rect.origin.y -= screenRect.origin.y;
slouken@3506
   588
        }
slouken@3506
   589
    }
slouken@3506
   590
    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE screen:screen];
slouken@1933
   591
slouken@1933
   592
    [pool release];
slouken@1933
   593
slouken@1951
   594
    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
slouken@1933
   595
        [nswindow release];
slouken@1933
   596
        return -1;
slouken@1933
   597
    }
slouken@1933
   598
    return 0;
slouken@1933
   599
}
slouken@1933
   600
slouken@1933
   601
int
slouken@1933
   602
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1933
   603
{
slouken@1933
   604
    NSAutoreleasePool *pool;
slouken@1933
   605
    NSWindow *nswindow = (NSWindow *) data;
slouken@1933
   606
    NSString *title;
slouken@1933
   607
slouken@1933
   608
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   609
slouken@1933
   610
    /* Query the title from the existing window */
slouken@1933
   611
    title = [nswindow title];
slouken@1933
   612
    if (title) {
slouken@1933
   613
        window->title = SDL_strdup([title UTF8String]);
slouken@1933
   614
    }
slouken@1933
   615
slouken@1933
   616
    [pool release];
slouken@1933
   617
slouken@1951
   618
    return SetupWindowData(_this, window, nswindow, SDL_FALSE);
slouken@1933
   619
}
slouken@1933
   620
slouken@1933
   621
void
slouken@1933
   622
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1933
   623
{
slouken@1937
   624
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   625
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   626
    NSString *string;
slouken@1933
   627
slouken@1956
   628
    if(window->title) {
slouken@1956
   629
        string = [[NSString alloc] initWithUTF8String:window->title];
slouken@1956
   630
    } else {
slouken@1956
   631
        string = [[NSString alloc] init];
slouken@1956
   632
    }
slouken@1933
   633
    [nswindow setTitle:string];
slouken@1933
   634
    [string release];
slouken@1956
   635
slouken@1937
   636
    [pool release];
slouken@1933
   637
}
slouken@1933
   638
slouken@1933
   639
void
slouken@5375
   640
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@5375
   641
{
slouken@5375
   642
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5375
   643
    NSImage *nsimage = Cocoa_CreateImage(icon);
slouken@5375
   644
slouken@5375
   645
    if (nsimage) {
slouken@5375
   646
        [NSApp setApplicationIconImage:nsimage];
slouken@5375
   647
    }
slouken@5375
   648
slouken@5375
   649
    [pool release];
slouken@5375
   650
}
slouken@5375
   651
slouken@5375
   652
void
slouken@1933
   653
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1933
   654
{
slouken@1937
   655
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   656
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@5246
   657
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1933
   658
    NSRect rect;
slouken@3528
   659
    SDL_Rect bounds;
slouken@1933
   660
slouken@3528
   661
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   662
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@3528
   663
        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
slouken@3075
   664
    } else {
slouken@5246
   665
        rect.origin.x = window->x;
slouken@3075
   666
    }
slouken@5249
   667
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@3528
   668
        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
slouken@3075
   669
    } else {
slouken@5246
   670
        rect.origin.y = window->y;
slouken@3075
   671
    }
slouken@1933
   672
    rect.size.width = window->w;
slouken@1933
   673
    rect.size.height = window->h;
slouken@1933
   674
    ConvertNSRect(&rect);
slouken@1933
   675
    rect = [nswindow frameRectForContentRect:rect];
slouken@1933
   676
    [nswindow setFrameOrigin:rect.origin];
slouken@1937
   677
    [pool release];
slouken@1933
   678
}
slouken@1933
   679
slouken@1933
   680
void
slouken@1933
   681
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
slouken@1933
   682
{
slouken@1937
   683
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   684
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   685
    NSSize size;
slouken@1933
   686
slouken@1933
   687
    size.width = window->w;
slouken@1933
   688
    size.height = window->h;
slouken@1933
   689
    [nswindow setContentSize:size];
slouken@1937
   690
    [pool release];
slouken@1933
   691
}
slouken@1933
   692
slouken@1933
   693
void
slouken@1933
   694
Cocoa_ShowWindow(_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
slouken@1956
   699
    if (![nswindow isMiniaturized]) {
slouken@1956
   700
        [nswindow makeKeyAndOrderFront:nil];
slouken@1956
   701
    }
slouken@1937
   702
    [pool release];
slouken@1933
   703
}
slouken@1933
   704
slouken@1933
   705
void
slouken@1933
   706
Cocoa_HideWindow(_THIS, SDL_Window * window)
slouken@1933
   707
{
slouken@1956
   708
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   709
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   710
slouken@1956
   711
    [nswindow orderOut:nil];
slouken@1956
   712
    [pool release];
slouken@1933
   713
}
slouken@1933
   714
slouken@1933
   715
void
slouken@1933
   716
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
slouken@1933
   717
{
slouken@1937
   718
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   719
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   720
slouken@1933
   721
    [nswindow makeKeyAndOrderFront:nil];
slouken@1937
   722
    [pool release];
slouken@1933
   723
}
slouken@1933
   724
slouken@1933
   725
void
slouken@1933
   726
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1933
   727
{
slouken@1937
   728
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   729
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   730
slouken@1956
   731
    [nswindow zoom:nil];
slouken@1937
   732
    [pool release];
slouken@1933
   733
}
slouken@1933
   734
slouken@1933
   735
void
slouken@1933
   736
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1933
   737
{
slouken@1937
   738
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   739
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   740
slouken@1956
   741
    [nswindow miniaturize:nil];
slouken@1937
   742
    [pool release];
slouken@1933
   743
}
slouken@1933
   744
slouken@1933
   745
void
slouken@1933
   746
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
slouken@1933
   747
{
slouken@1956
   748
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3688
   749
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   750
slouken@1956
   751
    if ([nswindow isMiniaturized]) {
slouken@1956
   752
        [nswindow deminiaturize:nil];
slouken@1956
   753
    } else if ([nswindow isZoomed]) {
slouken@1956
   754
        [nswindow zoom:nil];
slouken@1956
   755
    }
slouken@1956
   756
    [pool release];
slouken@1933
   757
}
slouken@1933
   758
slouken@1933
   759
void
slouken@5305
   760
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
slouken@5249
   761
{
slouken@5249
   762
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@5249
   763
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@5249
   764
    NSWindow *nswindow = data->nswindow;
slouken@5249
   765
    NSRect rect;
slouken@5249
   766
slouken@5305
   767
    if (fullscreen) {
slouken@5249
   768
        SDL_Rect bounds;
slouken@5249
   769
slouken@5249
   770
        Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@5249
   771
        rect.origin.x = bounds.x;
slouken@5249
   772
        rect.origin.y = bounds.y;
slouken@5249
   773
        rect.size.width = bounds.w;
slouken@5249
   774
        rect.size.height = bounds.h;
slouken@5249
   775
        ConvertNSRect(&rect);
slouken@5249
   776
slouken@5361
   777
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5361
   778
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
slouken@5361
   779
        }
slouken@5361
   780
        [nswindow setFrameOrigin:rect.origin];
slouken@5261
   781
        [nswindow setContentSize:rect.size];
slouken@5249
   782
    } else {
slouken@5361
   783
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@5361
   784
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)GetWindowStyle(window)];
slouken@5361
   785
        }
slouken@5249
   786
slouken@5261
   787
        // This doesn't seem to do anything...
slouken@5261
   788
        //[nswindow setFrameOrigin:origin];
slouken@5249
   789
    }
slouken@5249
   790
slouken@5249
   791
#ifdef FULLSCREEN_TOGGLEABLE
slouken@5305
   792
    if (fullscreen) {
slouken@5249
   793
        /* OpenGL is rendering to the window, so make it visible! */
slouken@5249
   794
        [nswindow setLevel:CGShieldingWindowLevel()];
slouken@5249
   795
    } else {
slouken@5249
   796
        [nswindow setLevel:kCGNormalWindowLevel];
slouken@5249
   797
    }
slouken@5249
   798
#endif
slouken@5249
   799
    [nswindow makeKeyAndOrderFront:nil];
slouken@5249
   800
slouken@5249
   801
    [pool release];
slouken@5249
   802
}
slouken@5249
   803
slouken@5371
   804
NSPoint origin;
slouken@5249
   805
void
slouken@1933
   806
Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1933
   807
{
slouken@5371
   808
#ifdef RELATIVE_MOTION
slouken@5371
   809
    /* FIXME: work in progress
slouken@5371
   810
        You set relative mode by using the following code in conjunction with
slouken@5371
   811
        CGDisplayHideCursor(kCGDirectMainDisplay) and
slouken@5371
   812
        CGDisplayShowCursor(kCGDirectMainDisplay)
slouken@5371
   813
    */
slouken@1933
   814
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1933
   815
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   816
        CGAssociateMouseAndMouseCursorPosition(NO);
slouken@1933
   817
    } else {
slouken@5371
   818
        CGAssociateMouseAndMouseCursorPosition(YES);
slouken@1933
   819
    }
slouken@5371
   820
#else
slouken@5371
   821
    /* Move the cursor to the nearest point in the window */
slouken@5371
   822
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@5371
   823
        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@5371
   824
        int x, y;
slouken@5371
   825
        CGPoint cgpoint;
slouken@5371
   826
slouken@5371
   827
        SDL_GetMouseState(&x, &y);
slouken@5371
   828
        cgpoint.x = window->x + x;
slouken@5371
   829
        cgpoint.y = window->y + y;
slouken@5371
   830
        CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
   831
    }
slouken@5371
   832
#endif
slouken@1933
   833
}
slouken@1933
   834
slouken@1933
   835
void
slouken@1933
   836
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
slouken@1933
   837
{
slouken@1937
   838
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@1933
   839
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1933
   840
slouken@1933
   841
    if (data) {
slouken@1933
   842
        [data->listener close];
slouken@1933
   843
        [data->listener release];
slouken@1933
   844
        if (data->created) {
slouken@3688
   845
            [data->nswindow close];
slouken@1933
   846
        }
slouken@1933
   847
        SDL_free(data);
slouken@1933
   848
    }
slouken@1937
   849
    [pool release];
slouken@1933
   850
}
slouken@1933
   851
slouken@1933
   852
SDL_bool
slouken@1933
   853
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1933
   854
{
slouken@4900
   855
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
   856
slouken@1933
   857
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@4900
   858
        info->subsystem = SDL_SYSWM_COCOA;
slouken@5056
   859
        info->info.cocoa.window = nswindow;
slouken@1933
   860
        return SDL_TRUE;
slouken@1933
   861
    } else {
slouken@1933
   862
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1933
   863
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1933
   864
        return SDL_FALSE;
slouken@1933
   865
    }
slouken@1933
   866
}
slouken@1933
   867
slouken@1933
   868
/* vi: set ts=4 sw=4 expandtab: */