src/video/cocoa/SDL_cocoawindow.m
author Ryan C. Gordon <icculus@icculus.org>
Sun, 22 Mar 2015 01:25:12 -0400
changeset 9419 9763f689bced
parent 9237 2cc90bb31777
child 9474 067b78126485
permissions -rw-r--r--
Cocoa: Handle more cases of lost focus when Key window closes (thanks, Alex!).

Sort of fixes Bugzilla #1825 a little more. It's an ongoing effort. :)
slouken@1933
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@1933
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1933
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1933
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1933
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1933
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_COCOA
slouken@6044
    24
slouken@8083
    25
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
slouken@8083
    26
# error SDL for Mac OS X must be built with a 10.7 SDK or above.
slouken@8083
    27
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
slouken@8083
    28
slouken@1933
    29
#include "SDL_syswm.h"
slouken@5398
    30
#include "SDL_timer.h"  /* For SDL_GetTicks() */
slouken@7915
    31
#include "SDL_hints.h"
slouken@1933
    32
#include "../SDL_sysvideo.h"
slouken@1933
    33
#include "../../events/SDL_keyboard_c.h"
slouken@1933
    34
#include "../../events/SDL_mouse_c.h"
slouken@4673
    35
#include "../../events/SDL_touch_c.h"
slouken@1933
    36
#include "../../events/SDL_windowevents_c.h"
jorgen@9237
    37
#include "../../events/SDL_dropevents_c.h"
slouken@1933
    38
#include "SDL_cocoavideo.h"
eligottlieb@4811
    39
#include "SDL_cocoashape.h"
gzjjgod@5057
    40
#include "SDL_cocoamouse.h"
jorgen@7594
    41
#include "SDL_cocoaopengl.h"
icculus@8295
    42
#include "SDL_assert.h"
slouken@1933
    43
jorgen@8261
    44
/* #define DEBUG_COCOAWINDOW */
jorgen@8261
    45
jorgen@8261
    46
#ifdef DEBUG_COCOAWINDOW
jorgen@8261
    47
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
jorgen@8261
    48
#else
jorgen@8261
    49
#define DLog(...) do { } while (0)
jorgen@8261
    50
#endif
jorgen@8261
    51
jorgen@8261
    52
slouken@8801
    53
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
slouken@8801
    54
slouken@8801
    55
jorgen@9237
    56
@interface SDLWindow : NSWindow <NSDraggingDestination>
jorgen@8260
    57
/* These are needed for borderless/fullscreen windows */
jorgen@8260
    58
- (BOOL)canBecomeKeyWindow;
jorgen@8260
    59
- (BOOL)canBecomeMainWindow;
jorgen@8260
    60
- (void)sendEvent:(NSEvent *)event;
slouken@8809
    61
- (void)doCommandBySelector:(SEL)aSelector;
jorgen@9237
    62
jorgen@9237
    63
/* Handle drag-and-drop of files onto the SDL window. */
jorgen@9237
    64
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
jorgen@9237
    65
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
jorgen@9237
    66
- (BOOL)wantsPeriodicDraggingUpdates;
jorgen@8260
    67
@end
jorgen@8260
    68
jorgen@8260
    69
@implementation SDLWindow
jorgen@9237
    70
jorgen@8260
    71
- (BOOL)canBecomeKeyWindow
jorgen@8260
    72
{
jorgen@8260
    73
    return YES;
jorgen@8260
    74
}
jorgen@8260
    75
jorgen@8260
    76
- (BOOL)canBecomeMainWindow
jorgen@8260
    77
{
jorgen@8260
    78
    return YES;
jorgen@8260
    79
}
jorgen@8260
    80
jorgen@8260
    81
- (void)sendEvent:(NSEvent *)event
jorgen@8260
    82
{
jorgen@8260
    83
  [super sendEvent:event];
jorgen@8260
    84
jorgen@8260
    85
  if ([event type] != NSLeftMouseUp) {
jorgen@8260
    86
      return;
jorgen@8260
    87
  }
jorgen@8260
    88
jorgen@8260
    89
  id delegate = [self delegate];
jorgen@8260
    90
  if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
jorgen@8260
    91
      return;
jorgen@8260
    92
  }
jorgen@8260
    93
jorgen@8260
    94
  if ([delegate isMoving]) {
jorgen@8260
    95
      [delegate windowDidFinishMoving];
jorgen@8260
    96
  }
jorgen@8260
    97
}
slouken@8809
    98
slouken@8809
    99
/* We'll respond to selectors by doing nothing so we don't beep.
slouken@8809
   100
 * The escape key gets converted to a "cancel" selector, etc.
slouken@8809
   101
 */
slouken@8809
   102
- (void)doCommandBySelector:(SEL)aSelector
slouken@8809
   103
{
slouken@8809
   104
    /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
slouken@8809
   105
}
jorgen@9237
   106
jorgen@9237
   107
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
jorgen@9237
   108
{
jorgen@9237
   109
    return NSDragOperationGeneric;
jorgen@9237
   110
}
jorgen@9237
   111
jorgen@9237
   112
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
jorgen@9237
   113
{
jorgen@9237
   114
    NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
jorgen@9237
   115
    NSNumber *isAlias = nil;
jorgen@9237
   116
jorgen@9237
   117
    if (fileURL == nil) {
jorgen@9237
   118
        return NO;
jorgen@9237
   119
    }
jorgen@9237
   120
jorgen@9237
   121
    /* Functionality for resolving URL aliases was added with OS X 10.6. */
jorgen@9237
   122
    if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
jorgen@9237
   123
        [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
jorgen@9237
   124
    }
jorgen@9237
   125
jorgen@9237
   126
    /* If the URL is an alias, resolve it. */
jorgen@9237
   127
    if ([isAlias boolValue]) {
jorgen@9237
   128
        NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
jorgen@9237
   129
        NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
jorgen@9237
   130
        if (bookmark != nil) {
jorgen@9237
   131
            NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
jorgen@9237
   132
                                                           options:opts
jorgen@9237
   133
                                                     relativeToURL:nil
jorgen@9237
   134
                                               bookmarkDataIsStale:nil
jorgen@9237
   135
                                                             error:nil];
jorgen@9237
   136
jorgen@9237
   137
            if (resolvedURL != nil) {
jorgen@9237
   138
                fileURL = resolvedURL;
jorgen@9237
   139
            }
jorgen@9237
   140
        }
jorgen@9237
   141
    }
jorgen@9237
   142
jorgen@9237
   143
    return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
jorgen@9237
   144
}
jorgen@9237
   145
jorgen@9237
   146
- (BOOL)wantsPeriodicDraggingUpdates
jorgen@9237
   147
{
jorgen@9237
   148
    return NO;
jorgen@9237
   149
}
jorgen@9237
   150
jorgen@8260
   151
@end
jorgen@8260
   152
jorgen@8260
   153
slouken@5398
   154
static Uint32 s_moveHack;
slouken@5398
   155
slouken@8801
   156
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
slouken@1933
   157
{
slouken@9086
   158
    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
slouken@1933
   159
}
slouken@1933
   160
slouken@7952
   161
static void
slouken@7952
   162
ScheduleContextUpdates(SDL_WindowData *data)
jorgen@7595
   163
{
jorgen@8258
   164
    NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
jorgen@7595
   165
    NSMutableArray *contexts = data->nscontexts;
jorgen@7595
   166
    @synchronized (contexts) {
jorgen@7595
   167
        for (SDLOpenGLContext *context in contexts) {
jorgen@8258
   168
            if (context == currentContext) {
jorgen@8258
   169
                [context update];
jorgen@8258
   170
            } else {
jorgen@8258
   171
                [context scheduleUpdate];
jorgen@8258
   172
            }
jorgen@7595
   173
        }
jorgen@7595
   174
    }
jorgen@7595
   175
}
jorgen@7595
   176
slouken@7952
   177
static int
slouken@7952
   178
GetHintCtrlClickEmulateRightClick()
slouken@7915
   179
{
slouken@7915
   180
	const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
slouken@7915
   181
	return hint != NULL && *hint != '0';
slouken@7915
   182
}
slouken@7915
   183
slouken@7952
   184
static unsigned int
slouken@7952
   185
GetWindowStyle(SDL_Window * window)
slouken@7952
   186
{
slouken@7952
   187
    unsigned int style;
slouken@7952
   188
icculus@8295
   189
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@7952
   190
        style = NSBorderlessWindowMask;
slouken@7952
   191
    } else {
slouken@7952
   192
        if (window->flags & SDL_WINDOW_BORDERLESS) {
slouken@7952
   193
            style = NSBorderlessWindowMask;
slouken@7952
   194
        } else {
slouken@7952
   195
            style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
slouken@7952
   196
        }
slouken@7952
   197
        if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@7952
   198
            style |= NSResizableWindowMask;
slouken@7952
   199
        }
slouken@7952
   200
    }
slouken@7952
   201
    return style;
slouken@7952
   202
}
slouken@7952
   203
slouken@7990
   204
static SDL_bool
slouken@7990
   205
SetWindowStyle(SDL_Window * window, unsigned int style)
slouken@7990
   206
{
slouken@7990
   207
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@7990
   208
    NSWindow *nswindow = data->nswindow;
slouken@7990
   209
slouken@7990
   210
    if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@7990
   211
        return SDL_FALSE;
slouken@7990
   212
    }
slouken@7990
   213
slouken@7990
   214
    /* The view responder chain gets messed with during setStyleMask */
slouken@7990
   215
    if ([[nswindow contentView] nextResponder] == data->listener) {
slouken@7990
   216
        [[nswindow contentView] setNextResponder:nil];
slouken@7990
   217
    }
slouken@7990
   218
slouken@7990
   219
    [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
slouken@7990
   220
slouken@7990
   221
    /* The view responder chain gets messed with during setStyleMask */
slouken@7990
   222
    if ([[nswindow contentView] nextResponder] != data->listener) {
slouken@7990
   223
        [[nswindow contentView] setNextResponder:data->listener];
slouken@7990
   224
    }
slouken@7990
   225
slouken@7990
   226
    return SDL_TRUE;
slouken@7990
   227
}
slouken@7990
   228
slouken@7952
   229
slouken@1933
   230
@implementation Cocoa_WindowListener
slouken@1933
   231
slouken@1933
   232
- (void)listen:(SDL_WindowData *)data
slouken@1933
   233
{
slouken@1933
   234
    NSNotificationCenter *center;
slouken@5371
   235
    NSWindow *window = data->nswindow;
slouken@5371
   236
    NSView *view = [window contentView];
slouken@1933
   237
slouken@1933
   238
    _data = data;
jorgen@7087
   239
    observingVisible = YES;
slouken@7740
   240
    wasCtrlLeft = NO;
jorgen@7087
   241
    wasVisible = [window isVisible];
slouken@7967
   242
    isFullscreenSpace = NO;
slouken@7952
   243
    inFullscreenTransition = NO;
slouken@7963
   244
    pendingWindowOperation = PENDING_OPERATION_NONE;
jorgen@8260
   245
    isMoving = NO;
icculus@8931
   246
    isDragAreaRunning = NO;
slouken@1933
   247
slouken@1933
   248
    center = [NSNotificationCenter defaultCenter];
slouken@1933
   249
slouken@5374
   250
    if ([window delegate] != nil) {
slouken@5374
   251
        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
slouken@5374
   252
        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
slouken@5374
   253
        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
slouken@5374
   254
        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
   255
        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
   256
        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
   257
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
slouken@7952
   258
        [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
slouken@7952
   259
        [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
slouken@7952
   260
        [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
slouken@7952
   261
        [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
slouken@5374
   262
    } else {
slouken@5374
   263
        [window setDelegate:self];
slouken@5374
   264
    }
slouken@1933
   265
slouken@7191
   266
    /* Haven't found a delegate / notification that triggers when the window is
slouken@7191
   267
     * ordered out (is not visible any more). You can be ordered out without
slouken@7191
   268
     * minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
slouken@7191
   269
     */
jorgen@7084
   270
    [window addObserver:self
jorgen@7084
   271
             forKeyPath:@"visible"
jorgen@7084
   272
                options:NSKeyValueObservingOptionNew
jorgen@7084
   273
                context:NULL];
jorgen@7084
   274
slouken@5371
   275
    [window setNextResponder:self];
slouken@5371
   276
    [window setAcceptsMouseMovedEvents:YES];
slouken@5371
   277
slouken@5371
   278
    [view setNextResponder:self];
icculus@6108
   279
icculus@6108
   280
    if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
icculus@6108
   281
        [view setAcceptsTouchEvents:YES];
icculus@6108
   282
    }
slouken@1933
   283
}
slouken@1933
   284
jorgen@7084
   285
- (void)observeValueForKeyPath:(NSString *)keyPath
jorgen@7084
   286
                      ofObject:(id)object
jorgen@7084
   287
                        change:(NSDictionary *)change
jorgen@7084
   288
                       context:(void *)context
jorgen@7084
   289
{
jorgen@7087
   290
    if (!observingVisible) {
jorgen@7087
   291
        return;
jorgen@7087
   292
    }
jorgen@7087
   293
jorgen@7084
   294
    if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
jorgen@7084
   295
        int newVisibility = [[change objectForKey:@"new"] intValue];
jorgen@7084
   296
        if (newVisibility) {
jorgen@7084
   297
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
jorgen@7084
   298
        } else {
jorgen@7084
   299
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
jorgen@7084
   300
        }
jorgen@7084
   301
    }
jorgen@7084
   302
}
jorgen@7084
   303
jorgen@7087
   304
-(void) pauseVisibleObservation
jorgen@7087
   305
{
jorgen@7087
   306
    observingVisible = NO;
jorgen@7087
   307
    wasVisible = [_data->nswindow isVisible];
jorgen@7087
   308
}
jorgen@7087
   309
jorgen@7087
   310
-(void) resumeVisibleObservation
jorgen@7087
   311
{
jorgen@7087
   312
    BOOL isVisible = [_data->nswindow isVisible];
jorgen@7087
   313
    observingVisible = YES;
jorgen@7087
   314
    if (wasVisible != isVisible) {
jorgen@7087
   315
        if (isVisible) {
jorgen@7087
   316
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
jorgen@7087
   317
        } else {
jorgen@7087
   318
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
jorgen@7087
   319
        }
jorgen@7087
   320
jorgen@7087
   321
        wasVisible = isVisible;
jorgen@7087
   322
    }
jorgen@7087
   323
}
jorgen@7087
   324
icculus@8284
   325
-(BOOL) setFullscreenSpace:(BOOL) state
slouken@7961
   326
{
slouken@7961
   327
    SDL_Window *window = _data->window;
slouken@7961
   328
    NSWindow *nswindow = _data->nswindow;
icculus@8295
   329
    SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
slouken@7961
   330
icculus@8295
   331
    if (!videodata->allow_spaces) {
icculus@8295
   332
        return NO;  /* Spaces are forcibly disabled. */
icculus@8295
   333
    } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
icculus@8292
   334
        return NO;  /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
slouken@8798
   335
    } else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
slouken@8798
   336
        return NO;  /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
icculus@8284
   337
    } else if (state == isFullscreenSpace) {
icculus@8284
   338
        return YES;  /* already there. */
slouken@7961
   339
    }
slouken@7961
   340
slouken@7961
   341
    if (inFullscreenTransition) {
slouken@7961
   342
        if (state) {
slouken@7963
   343
            [self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
slouken@7961
   344
        } else {
slouken@7963
   345
            [self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
slouken@7961
   346
        }
slouken@7961
   347
        return YES;
slouken@7961
   348
    }
slouken@7968
   349
    inFullscreenTransition = YES;
slouken@7968
   350
icculus@8295
   351
    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
icculus@8284
   352
    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
slouken@7965
   353
    [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
slouken@7961
   354
    return YES;
slouken@7952
   355
}
slouken@7952
   356
slouken@7968
   357
-(BOOL) isInFullscreenSpace
slouken@7968
   358
{
slouken@7968
   359
    return isFullscreenSpace;
slouken@7968
   360
}
slouken@7968
   361
slouken@7968
   362
-(BOOL) isInFullscreenSpaceTransition
slouken@7963
   363
{
slouken@7963
   364
    return inFullscreenTransition;
slouken@7963
   365
}
slouken@7963
   366
slouken@7963
   367
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
slouken@7963
   368
{
slouken@7963
   369
    pendingWindowOperation = operation;
slouken@7963
   370
}
slouken@7963
   371
slouken@1933
   372
- (void)close
slouken@1933
   373
{
slouken@1933
   374
    NSNotificationCenter *center;
slouken@5371
   375
    NSWindow *window = _data->nswindow;
slouken@5371
   376
    NSView *view = [window contentView];
slouken@1933
   377
slouken@1933
   378
    center = [NSNotificationCenter defaultCenter];
slouken@1933
   379
slouken@5374
   380
    if ([window delegate] != self) {
slouken@5374
   381
        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
slouken@5374
   382
        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
slouken@5374
   383
        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
slouken@5374
   384
        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
slouken@5374
   385
        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
slouken@5374
   386
        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
slouken@5374
   387
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
slouken@7952
   388
        [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
slouken@7952
   389
        [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
slouken@7952
   390
        [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
slouken@7952
   391
        [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
slouken@5374
   392
    } else {
slouken@5374
   393
        [window setDelegate:nil];
slouken@5374
   394
    }
slouken@5371
   395
slouken@7961
   396
    [window removeObserver:self forKeyPath:@"visible"];
jorgen@7084
   397
slouken@5374
   398
    if ([window nextResponder] == self) {
slouken@5374
   399
        [window setNextResponder:nil];
slouken@5374
   400
    }
slouken@5374
   401
    if ([view nextResponder] == self) {
slouken@5374
   402
        [view setNextResponder:nil];
slouken@5374
   403
    }
slouken@1933
   404
}
slouken@1933
   405
jorgen@8260
   406
- (BOOL)isMoving
jorgen@8260
   407
{
jorgen@8260
   408
    return isMoving;
jorgen@8260
   409
}
jorgen@8260
   410
jorgen@8260
   411
-(void) setPendingMoveX:(int)x Y:(int)y
jorgen@8260
   412
{
jorgen@8260
   413
    pendingWindowWarpX = x;
jorgen@8260
   414
    pendingWindowWarpY = y;
jorgen@8260
   415
}
jorgen@8260
   416
jorgen@8260
   417
- (void)windowDidFinishMoving
jorgen@8260
   418
{
slouken@8986
   419
    if ([self isMoving]) {
jorgen@8260
   420
        isMoving = NO;
jorgen@8260
   421
jorgen@8260
   422
        SDL_Mouse *mouse = SDL_GetMouse();
slouken@9086
   423
        if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
slouken@9086
   424
            mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
slouken@9086
   425
            pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
jorgen@8260
   426
        }
slouken@9086
   427
        if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) {
jorgen@8260
   428
            mouse->SetRelativeMouseMode(SDL_TRUE);
jorgen@8260
   429
        }
jorgen@8260
   430
    }
jorgen@8260
   431
}
jorgen@8260
   432
slouken@1933
   433
- (BOOL)windowShouldClose:(id)sender
slouken@1933
   434
{
slouken@3685
   435
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1933
   436
    return NO;
slouken@1933
   437
}
slouken@1933
   438
slouken@1933
   439
- (void)windowDidExpose:(NSNotification *)aNotification
slouken@1933
   440
{
slouken@3685
   441
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
slouken@1933
   442
}
slouken@1933
   443
jorgen@8260
   444
- (void)windowWillMove:(NSNotification *)aNotification
jorgen@8260
   445
{
jorgen@8260
   446
    if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
slouken@9086
   447
        pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
jorgen@8260
   448
        isMoving = YES;
jorgen@8260
   449
    }
jorgen@8260
   450
}
jorgen@8260
   451
slouken@1933
   452
- (void)windowDidMove:(NSNotification *)aNotification
slouken@1933
   453
{
slouken@1933
   454
    int x, y;
slouken@5398
   455
    SDL_Window *window = _data->window;
slouken@5398
   456
    NSWindow *nswindow = _data->nswindow;
slouken@8801
   457
    BOOL fullscreen = window->flags & FULLSCREEN_MASK;
slouken@5398
   458
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@8801
   459
    ConvertNSRect([nswindow screen], fullscreen, &rect);
slouken@5398
   460
slouken@5398
   461
    if (s_moveHack) {
slouken@5398
   462
        SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
slouken@5398
   463
slouken@5398
   464
        s_moveHack = 0;
slouken@5398
   465
slouken@5398
   466
        if (blockMove) {
slouken@5398
   467
            /* Cocoa is adjusting the window in response to a mode change */
slouken@5398
   468
            rect.origin.x = window->x;
slouken@5398
   469
            rect.origin.y = window->y;
slouken@8801
   470
            ConvertNSRect([nswindow screen], fullscreen, &rect);
slouken@5398
   471
            [nswindow setFrameOrigin:rect.origin];
slouken@5398
   472
            return;
slouken@5398
   473
        }
slouken@5398
   474
    }
slouken@5398
   475
slouken@3507
   476
    x = (int)rect.origin.x;
slouken@3507
   477
    y = (int)rect.origin.y;
icculus@5564
   478
jorgen@7595
   479
    ScheduleContextUpdates(_data);
icculus@5564
   480
slouken@5398
   481
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1933
   482
}
slouken@1933
   483
slouken@1933
   484
- (void)windowDidResize:(NSNotification *)aNotification
slouken@1933
   485
{
icculus@8284
   486
    if (inFullscreenTransition) {
icculus@8284
   487
        /* We'll take care of this at the end of the transition */
icculus@8284
   488
        return;
icculus@8284
   489
    }
icculus@8284
   490
slouken@7963
   491
    SDL_Window *window = _data->window;
slouken@7963
   492
    NSWindow *nswindow = _data->nswindow;
slouken@6231
   493
    int x, y, w, h;
slouken@7963
   494
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@8801
   495
    ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
slouken@6231
   496
    x = (int)rect.origin.x;
slouken@6231
   497
    y = (int)rect.origin.y;
slouken@1933
   498
    w = (int)rect.size.width;
slouken@1933
   499
    h = (int)rect.size.height;
slouken@7952
   500
slouken@7963
   501
    if (SDL_IsShapedWindow(window)) {
slouken@7963
   502
        Cocoa_ResizeWindowShape(window);
slouken@7952
   503
    }
icculus@5564
   504
jorgen@7595
   505
    ScheduleContextUpdates(_data);
icculus@5564
   506
slouken@6231
   507
    /* The window can move during a resize event, such as when maximizing
slouken@6231
   508
       or resizing from a corner */
slouken@7963
   509
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@7963
   510
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
icculus@7566
   511
slouken@7963
   512
    const BOOL zoomed = [nswindow isZoomed];
icculus@7566
   513
    if (!zoomed) {
slouken@7963
   514
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
icculus@7566
   515
    } else if (zoomed) {
slouken@7963
   516
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
icculus@7566
   517
    }
slouken@1933
   518
}
slouken@1933
   519
slouken@1933
   520
- (void)windowDidMiniaturize:(NSNotification *)aNotification
slouken@1933
   521
{
slouken@3685
   522
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1933
   523
}
slouken@1933
   524
slouken@1933
   525
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
slouken@1933
   526
{
slouken@3685
   527
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1933
   528
}
slouken@1933
   529
slouken@1933
   530
- (void)windowDidBecomeKey:(NSNotification *)aNotification
slouken@1933
   531
{
slouken@5367
   532
    SDL_Window *window = _data->window;
jorgen@7271
   533
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@9086
   534
    if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
jorgen@8260
   535
        mouse->SetRelativeMouseMode(SDL_TRUE);
jorgen@8260
   536
    }
slouken@5367
   537
slouken@3688
   538
    /* We're going to get keyboard events, since we're key. */
slouken@5367
   539
    SDL_SetKeyboardFocus(window);
slouken@5367
   540
slouken@5367
   541
    /* If we just gained focus we need the updated mouse position */
jorgen@7271
   542
    if (!mouse->relative_mode) {
slouken@5367
   543
        NSPoint point;
slouken@5396
   544
        int x, y;
slouken@5396
   545
slouken@5396
   546
        point = [_data->nswindow mouseLocationOutsideOfEventStream];
slouken@5396
   547
        x = (int)point.x;
slouken@5396
   548
        y = (int)(window->h - point.y);
slouken@5396
   549
slouken@5396
   550
        if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
slouken@6950
   551
            SDL_SendMouseMotion(window, 0, 0, x, y);
slouken@5396
   552
        }
slouken@5367
   553
    }
slouken@1962
   554
slouken@4503
   555
    /* Check to see if someone updated the clipboard */
slouken@4503
   556
    Cocoa_CheckClipboardUpdate(_data->videodata);
icculus@8288
   557
icculus@8293
   558
    if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
icculus@8288
   559
        [NSMenu setMenuBarVisible:NO];
icculus@8288
   560
    }
slouken@1933
   561
}
slouken@1933
   562
slouken@1933
   563
- (void)windowDidResignKey:(NSNotification *)aNotification
slouken@1933
   564
{
jorgen@8260
   565
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@9086
   566
    if (mouse->relative_mode && !mouse->relative_mode_warp) {
jorgen@8260
   567
        mouse->SetRelativeMouseMode(SDL_FALSE);
jorgen@8260
   568
    }
jorgen@8260
   569
slouken@2059
   570
    /* Some other window will get mouse events, since we're not key. */
slouken@4465
   571
    if (SDL_GetMouseFocus() == _data->window) {
slouken@4465
   572
        SDL_SetMouseFocus(NULL);
slouken@2059
   573
    }
slouken@2059
   574
slouken@2059
   575
    /* Some other window will get keyboard events, since we're not key. */
slouken@4465
   576
    if (SDL_GetKeyboardFocus() == _data->window) {
slouken@4465
   577
        SDL_SetKeyboardFocus(NULL);
slouken@4465
   578
    }
icculus@8288
   579
icculus@8288
   580
    if (isFullscreenSpace) {
icculus@8288
   581
        [NSMenu setMenuBarVisible:YES];
icculus@8288
   582
    }
slouken@1933
   583
}
slouken@1933
   584
slouken@7952
   585
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
slouken@7952
   586
{
slouken@7952
   587
    SDL_Window *window = _data->window;
slouken@7952
   588
slouken@7990
   589
    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
slouken@7965
   590
slouken@7967
   591
    isFullscreenSpace = YES;
slouken@7952
   592
    inFullscreenTransition = YES;
slouken@7952
   593
}
slouken@7952
   594
slouken@7952
   595
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
slouken@7952
   596
{
slouken@7965
   597
    SDL_Window *window = _data->window;
slouken@7965
   598
slouken@7952
   599
    inFullscreenTransition = NO;
slouken@7961
   600
slouken@7963
   601
    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
slouken@7963
   602
        pendingWindowOperation = PENDING_OPERATION_NONE;
slouken@7967
   603
        [self setFullscreenSpace:NO];
slouken@7961
   604
    } else {
icculus@8284
   605
        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
icculus@8284
   606
            [NSMenu setMenuBarVisible:NO];
icculus@8284
   607
        }
icculus@8284
   608
slouken@7963
   609
        pendingWindowOperation = PENDING_OPERATION_NONE;
slouken@7965
   610
        /* Force the size change event in case it was delivered earlier
slouken@7965
   611
           while the window was still animating into place.
slouken@7965
   612
         */
slouken@7965
   613
        window->w = 0;
slouken@7965
   614
        window->h = 0;
slouken@7961
   615
        [self windowDidResize:aNotification];
slouken@7961
   616
    }
slouken@7952
   617
}
slouken@7952
   618
slouken@7952
   619
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
slouken@7952
   620
{
slouken@7964
   621
    SDL_Window *window = _data->window;
slouken@7964
   622
slouken@7990
   623
    SetWindowStyle(window, GetWindowStyle(window));
slouken@7964
   624
slouken@7967
   625
    isFullscreenSpace = NO;
slouken@7952
   626
    inFullscreenTransition = YES;
slouken@7952
   627
}
slouken@7952
   628
slouken@7952
   629
- (void)windowDidExitFullScreen:(NSNotification *)aNotification
slouken@7952
   630
{
slouken@7965
   631
    SDL_Window *window = _data->window;
slouken@7952
   632
    NSWindow *nswindow = _data->nswindow;
slouken@7952
   633
slouken@7952
   634
    inFullscreenTransition = NO;
slouken@7961
   635
slouken@8618
   636
    [nswindow setLevel:kCGNormalWindowLevel];
slouken@8618
   637
slouken@7963
   638
    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
slouken@7963
   639
        pendingWindowOperation = PENDING_OPERATION_NONE;
slouken@7967
   640
        [self setFullscreenSpace:YES];
slouken@7963
   641
    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
slouken@7963
   642
        pendingWindowOperation = PENDING_OPERATION_NONE;
slouken@7963
   643
        [nswindow miniaturize:nil];
slouken@7961
   644
    } else {
icculus@8291
   645
        /* Adjust the fullscreen toggle button and readd menu now that we're here. */
icculus@8291
   646
        if (window->flags & SDL_WINDOW_RESIZABLE) {
icculus@8291
   647
            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
icculus@8291
   648
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
icculus@8291
   649
        } else {
icculus@8284
   650
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
icculus@8284
   651
        }
icculus@8291
   652
        [NSMenu setMenuBarVisible:YES];
icculus@8284
   653
slouken@7963
   654
        pendingWindowOperation = PENDING_OPERATION_NONE;
slouken@7965
   655
        /* Force the size change event in case it was delivered earlier
slouken@7965
   656
           while the window was still animating into place.
slouken@7965
   657
         */
slouken@7965
   658
        window->w = 0;
slouken@7965
   659
        window->h = 0;
slouken@7961
   660
        [self windowDidResize:aNotification];
icculus@8622
   661
slouken@8623
   662
        /* FIXME: Why does the window get hidden? */
slouken@8623
   663
        if (window->flags & SDL_WINDOW_SHOWN) {
slouken@8623
   664
            Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
slouken@8623
   665
        }
slouken@7961
   666
    }
slouken@7952
   667
}
slouken@7952
   668
icculus@8291
   669
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
icculus@8291
   670
{
icculus@8291
   671
    if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
icculus@8291
   672
        return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
icculus@8291
   673
    } else {
icculus@8291
   674
        return proposedOptions;
icculus@8291
   675
    }
icculus@8291
   676
}
icculus@8291
   677
icculus@8291
   678
slouken@7191
   679
/* We'll respond to key events by doing nothing so we don't beep.
slouken@7191
   680
 * We could handle key messages here, but we lose some in the NSApp dispatch,
slouken@7191
   681
 * where they get converted to action messages, etc.
slouken@7191
   682
 */
slouken@6514
   683
- (void)flagsChanged:(NSEvent *)theEvent
slouken@6514
   684
{
slouken@7191
   685
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
slouken@6514
   686
}
slouken@6514
   687
- (void)keyDown:(NSEvent *)theEvent
slouken@6514
   688
{
slouken@7191
   689
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
slouken@6514
   690
}
slouken@6514
   691
- (void)keyUp:(NSEvent *)theEvent
slouken@6514
   692
{
slouken@7191
   693
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
slouken@6514
   694
}
slouken@6514
   695
slouken@7191
   696
/* We'll respond to selectors by doing nothing so we don't beep.
slouken@7191
   697
 * The escape key gets converted to a "cancel" selector, etc.
slouken@7191
   698
 */
slouken@6514
   699
- (void)doCommandBySelector:(SEL)aSelector
slouken@6514
   700
{
slouken@7191
   701
    /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
slouken@6514
   702
}
slouken@6514
   703
icculus@8935
   704
- (BOOL)processHitTest:(NSEvent *)theEvent
icculus@8931
   705
{
icculus@8935
   706
    SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
icculus@8931
   707
icculus@8935
   708
    if (_data->window->hit_test) {  /* if no hit-test, skip this. */
icculus@8931
   709
        const NSPoint location = [theEvent locationInWindow];
icculus@8931
   710
        const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
icculus@8935
   711
        const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
icculus@8935
   712
        if (rc == SDL_HITTEST_DRAGGABLE) {
icculus@8935
   713
            if (!isDragAreaRunning) {
icculus@8935
   714
                isDragAreaRunning = YES;
icculus@8935
   715
                [_data->nswindow setMovableByWindowBackground:YES];
icculus@8931
   716
            }
icculus@8935
   717
            return YES;  /* dragging! */
icculus@8931
   718
        }
icculus@8931
   719
    }
icculus@8931
   720
icculus@8931
   721
    if (isDragAreaRunning) {
icculus@8931
   722
        isDragAreaRunning = NO;
icculus@8931
   723
        [_data->nswindow setMovableByWindowBackground:NO];
icculus@8931
   724
        return YES;  /* was dragging, drop event. */
icculus@8931
   725
    }
icculus@8931
   726
icculus@8935
   727
    return NO;  /* not a special area, carry on. */
icculus@8931
   728
}
icculus@8931
   729
slouken@1933
   730
- (void)mouseDown:(NSEvent *)theEvent
slouken@1933
   731
{
slouken@1959
   732
    int button;
slouken@1933
   733
icculus@8935
   734
    if ([self processHitTest:theEvent]) {
icculus@8931
   735
        return;  /* dragging, drop event. */
icculus@8931
   736
    }
icculus@8931
   737
slouken@1959
   738
    switch ([theEvent buttonNumber]) {
slouken@1959
   739
    case 0:
slouken@7915
   740
        if (([theEvent modifierFlags] & NSControlKeyMask) &&
slouken@7915
   741
		    GetHintCtrlClickEmulateRightClick()) {
slouken@7740
   742
            wasCtrlLeft = YES;
slouken@7740
   743
            button = SDL_BUTTON_RIGHT;
slouken@7740
   744
        } else {
slouken@7740
   745
            wasCtrlLeft = NO;
slouken@7740
   746
            button = SDL_BUTTON_LEFT;
slouken@7740
   747
        }
slouken@1959
   748
        break;
slouken@1959
   749
    case 1:
slouken@1959
   750
        button = SDL_BUTTON_RIGHT;
slouken@1959
   751
        break;
slouken@1959
   752
    case 2:
slouken@1959
   753
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   754
        break;
slouken@1959
   755
    default:
slouken@5061
   756
        button = [theEvent buttonNumber] + 1;
slouken@1959
   757
        break;
slouken@1959
   758
    }
slouken@6950
   759
    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
slouken@1933
   760
}
slouken@1933
   761
slouken@1933
   762
- (void)rightMouseDown:(NSEvent *)theEvent
slouken@1933
   763
{
slouken@1959
   764
    [self mouseDown:theEvent];
slouken@1933
   765
}
slouken@1933
   766
slouken@1933
   767
- (void)otherMouseDown:(NSEvent *)theEvent
slouken@1933
   768
{
slouken@1959
   769
    [self mouseDown:theEvent];
slouken@1933
   770
}
slouken@1933
   771
slouken@1933
   772
- (void)mouseUp:(NSEvent *)theEvent
slouken@1933
   773
{
slouken@1959
   774
    int button;
slouken@1933
   775
icculus@8935
   776
    if ([self processHitTest:theEvent]) {
icculus@8931
   777
        return;  /* stopped dragging, drop event. */
icculus@8931
   778
    }
icculus@8931
   779
slouken@1959
   780
    switch ([theEvent buttonNumber]) {
slouken@1959
   781
    case 0:
slouken@7740
   782
        if (wasCtrlLeft) {
slouken@7740
   783
            button = SDL_BUTTON_RIGHT;
slouken@7740
   784
            wasCtrlLeft = NO;
slouken@7740
   785
        } else {
slouken@7740
   786
            button = SDL_BUTTON_LEFT;
slouken@7740
   787
        }
slouken@1959
   788
        break;
slouken@1959
   789
    case 1:
slouken@1959
   790
        button = SDL_BUTTON_RIGHT;
slouken@1959
   791
        break;
slouken@1959
   792
    case 2:
slouken@1959
   793
        button = SDL_BUTTON_MIDDLE;
slouken@1959
   794
        break;
slouken@1959
   795
    default:
slouken@5061
   796
        button = [theEvent buttonNumber] + 1;
slouken@1959
   797
        break;
slouken@1959
   798
    }
slouken@6950
   799
    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
slouken@1933
   800
}
slouken@1933
   801
slouken@1933
   802
- (void)rightMouseUp:(NSEvent *)theEvent
slouken@1933
   803
{
slouken@1959
   804
    [self mouseUp:theEvent];
slouken@1933
   805
}
slouken@1933
   806
slouken@1933
   807
- (void)otherMouseUp:(NSEvent *)theEvent
slouken@1933
   808
{
slouken@1959
   809
    [self mouseUp:theEvent];
slouken@1933
   810
}
slouken@1933
   811
slouken@1933
   812
- (void)mouseMoved:(NSEvent *)theEvent
slouken@1933
   813
{
slouken@5406
   814
    SDL_Mouse *mouse = SDL_GetMouse();
slouken@3685
   815
    SDL_Window *window = _data->window;
slouken@5396
   816
    NSPoint point;
slouken@5396
   817
    int x, y;
slouken@1933
   818
icculus@8935
   819
    if ([self processHitTest:theEvent]) {
icculus@8931
   820
        return;  /* dragging, drop event. */
icculus@8931
   821
    }
icculus@8931
   822
slouken@5406
   823
    if (mouse->relative_mode) {
gzjjgod@5059
   824
        return;
slouken@5371
   825
    }
gzjjgod@5059
   826
slouken@5396
   827
    point = [theEvent locationInWindow];
slouken@5396
   828
    x = (int)point.x;
slouken@5396
   829
    y = (int)(window->h - point.y);
slouken@5371
   830
icculus@8929
   831
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
icculus@8929
   832
        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
slouken@6666
   833
            if (x < 0) {
slouken@6666
   834
                x = 0;
slouken@6666
   835
            } else if (x >= window->w) {
slouken@6666
   836
                x = window->w - 1;
slouken@6666
   837
            }
slouken@6666
   838
            if (y < 0) {
slouken@6666
   839
                y = 0;
slouken@6666
   840
            } else if (y >= window->h) {
slouken@6666
   841
                y = window->h - 1;
slouken@6666
   842
            }
slouken@6666
   843
jorgen@7593
   844
#if !SDL_MAC_NO_SANDBOX
jorgen@8260
   845
            CGPoint cgpoint;
jorgen@8260
   846
jorgen@7593
   847
            /* When SDL_MAC_NO_SANDBOX is set, this is handled by
jorgen@7593
   848
             * SDL_cocoamousetap.m.
jorgen@7593
   849
             */
jorgen@7593
   850
slouken@6666
   851
            cgpoint.x = window->x + x;
slouken@6666
   852
            cgpoint.y = window->y + y;
jorgen@7098
   853
jorgen@7113
   854
            /* According to the docs, this was deprecated in 10.6, but it's still
jorgen@7113
   855
             * around. The substitute requires a CGEventSource, but I'm not entirely
jorgen@7113
   856
             * sure how we'd procure the right one for this event.
jorgen@7098
   857
             */
jorgen@7113
   858
            CGSetLocalEventsSuppressionInterval(0.0);
slouken@6666
   859
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
jorgen@7113
   860
            CGSetLocalEventsSuppressionInterval(0.25);
jorgen@8261
   861
jorgen@8261
   862
            Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
jorgen@7593
   863
#endif
slouken@5396
   864
        }
slouken@2059
   865
    }
slouken@6950
   866
    SDL_SendMouseMotion(window, 0, 0, x, y);
slouken@1933
   867
}
slouken@1933
   868
slouken@1957
   869
- (void)mouseDragged:(NSEvent *)theEvent
slouken@1957
   870
{
slouken@1957
   871
    [self mouseMoved:theEvent];
slouken@1957
   872
}
slouken@1957
   873
slouken@1958
   874
- (void)rightMouseDragged:(NSEvent *)theEvent
slouken@1958
   875
{
slouken@1958
   876
    [self mouseMoved:theEvent];
slouken@1958
   877
}
slouken@1958
   878
slouken@1958
   879
- (void)otherMouseDragged:(NSEvent *)theEvent
slouken@1958
   880
{
slouken@1958
   881
    [self mouseMoved:theEvent];
slouken@1958
   882
}
slouken@1958
   883
slouken@1933
   884
- (void)scrollWheel:(NSEvent *)theEvent
slouken@1933
   885
{
gzjjgod@5057
   886
    Cocoa_HandleMouseWheel(_data->window, theEvent);
slouken@3688
   887
}
slouken@3688
   888
slouken@4673
   889
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
slouken@4673
   890
{
urkle@9236
   891
    NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
urkle@9236
   892
    int existingTouchCount = 0;
urkle@9236
   893
urkle@9236
   894
    for (NSTouch* touch in touches) {
urkle@9236
   895
        if ([touch phase] != NSTouchPhaseBegan) {
urkle@9236
   896
            existingTouchCount++;
urkle@9236
   897
        }
urkle@9236
   898
    }
urkle@9236
   899
    if (existingTouchCount == 0) {
urkle@9236
   900
        SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
urkle@9236
   901
        int numFingers = SDL_GetNumTouchFingers(touchID);
urkle@9236
   902
        DLog("Reset Lost Fingers: %d", numFingers);
urkle@9236
   903
        for (--numFingers; numFingers >= 0; --numFingers) {
urkle@9236
   904
            SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
urkle@9236
   905
            SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
urkle@9236
   906
        }
urkle@9236
   907
    }
urkle@9236
   908
urkle@9236
   909
    DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
slouken@8986
   910
    [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
slouken@4673
   911
}
slouken@4673
   912
slouken@4673
   913
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
slouken@4673
   914
{
slouken@8986
   915
    [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
slouken@4673
   916
}
slouken@4673
   917
slouken@4673
   918
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
slouken@4673
   919
{
slouken@8986
   920
    [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
slouken@4673
   921
}
slouken@4673
   922
slouken@4673
   923
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
slouken@4673
   924
{
slouken@8986
   925
    [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
slouken@4673
   926
}
slouken@4673
   927
slouken@8986
   928
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
slouken@4673
   929
{
slouken@8986
   930
    NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
slouken@4673
   931
slouken@8986
   932
    for (NSTouch *touch in touches) {
slouken@6953
   933
        const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
slouken@4673
   934
        if (!SDL_GetTouch(touchId)) {
slouken@6951
   935
            if (SDL_AddTouch(touchId, "") < 0) {
slouken@4680
   936
                return;
slouken@4673
   937
            }
slouken@7191
   938
        }
slouken@4687
   939
slouken@6953
   940
        const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
slouken@4673
   941
        float x = [touch normalizedPosition].x;
slouken@4673
   942
        float y = [touch normalizedPosition].y;
slouken@5261
   943
        /* Make the origin the upper left instead of the lower left */
slouken@5261
   944
        y = 1.0f - y;
slouken@4687
   945
slouken@8986
   946
        switch (phase) {
slouken@8986
   947
        case NSTouchPhaseBegan:
slouken@6951
   948
            SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
slouken@4673
   949
            break;
slouken@8986
   950
        case NSTouchPhaseEnded:
slouken@8986
   951
        case NSTouchPhaseCancelled:
slouken@6951
   952
            SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
slouken@4673
   953
            break;
slouken@8986
   954
        case NSTouchPhaseMoved:
slouken@6951
   955
            SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
slouken@4673
   956
            break;
slouken@8986
   957
        default:
slouken@8986
   958
            break;
slouken@4673
   959
        }
slouken@4673
   960
    }
slouken@1933
   961
}
slouken@1933
   962
slouken@1933
   963
@end
slouken@1933
   964
slouken@5379
   965
@interface SDLView : NSView
jorgen@7158
   966
slouken@5379
   967
/* The default implementation doesn't pass rightMouseDown to responder chain */
slouken@5379
   968
- (void)rightMouseDown:(NSEvent *)theEvent;
icculus@8931
   969
- (BOOL)mouseDownCanMoveWindow;
gzjjgod@4915
   970
@end
gzjjgod@4915
   971
gzjjgod@4915
   972
@implementation SDLView
gzjjgod@4915
   973
- (void)rightMouseDown:(NSEvent *)theEvent
gzjjgod@4915
   974
{
slouken@5371
   975
    [[self nextResponder] rightMouseDown:theEvent];
gzjjgod@4915
   976
}
jorgen@7158
   977
icculus@8931
   978
- (BOOL)mouseDownCanMoveWindow
icculus@8931
   979
{
icculus@8931
   980
    /* Always say YES, but this doesn't do anything until we call
icculus@8931
   981
       -[NSWindow setMovableByWindowBackground:YES], which we ninja-toggle
icculus@8931
   982
       during mouse events when we're using a drag area. */
icculus@8931
   983
    return YES;
icculus@8931
   984
}
icculus@8931
   985
jorgen@7158
   986
- (void)resetCursorRects
jorgen@7158
   987
{
jorgen@7158
   988
    [super resetCursorRects];
jorgen@7158
   989
    SDL_Mouse *mouse = SDL_GetMouse();
jorgen@7158
   990
jorgen@7270
   991
    if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
jorgen@7158
   992
        [self addCursorRect:[self bounds]
jorgen@7158
   993
                     cursor:mouse->cur_cursor->driverdata];
jorgen@7158
   994
    } else {
jorgen@7158
   995
        [self addCursorRect:[self bounds]
jorgen@7158
   996
                     cursor:[NSCursor invisibleCursor]];
jorgen@7158
   997
    }
jorgen@7158
   998
}
gzjjgod@4915
   999
@end
gzjjgod@4915
  1000
slouken@1933
  1001
static int
slouken@1951
  1002
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
slouken@1933
  1003
{
slouken@6848
  1004
    NSAutoreleasePool *pool;
slouken@1951
  1005
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1933
  1006
    SDL_WindowData *data;
slouken@1933
  1007
slouken@1933
  1008
    /* Allocate the window data */
slouken@8926
  1009
    window->driverdata = data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1933
  1010
    if (!data) {
icculus@7037
  1011
        return SDL_OutOfMemory();
slouken@1933
  1012
    }
slouken@3685
  1013
    data->window = window;
slouken@3688
  1014
    data->nswindow = nswindow;
slouken@1933
  1015
    data->created = created;
slouken@1951
  1016
    data->videodata = videodata;
jorgen@7595
  1017
    data->nscontexts = [[NSMutableArray alloc] init];
slouken@1933
  1018
slouken@6848
  1019
    pool = [[NSAutoreleasePool alloc] init];
slouken@1933
  1020
slouken@6848
  1021
    /* Create an event listener for the window */
slouken@6848
  1022
    data->listener = [[Cocoa_WindowListener alloc] init];
slouken@6848
  1023
slouken@6848
  1024
    /* Fill in the SDL window with the window data */
slouken@6848
  1025
    {
slouken@6848
  1026
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@8801
  1027
        ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
slouken@6848
  1028
        window->x = (int)rect.origin.x;
slouken@6848
  1029
        window->y = (int)rect.origin.y;
slouken@6848
  1030
        window->w = (int)rect.size.width;
slouken@6848
  1031
        window->h = (int)rect.size.height;
slouken@6848
  1032
    }
slouken@6848
  1033
slouken@6848
  1034
    /* Set up the listener after we create the view */
slouken@6848
  1035
    [data->listener listen:data];
slouken@6848
  1036
slouken@6848
  1037
    if ([nswindow isVisible]) {
slouken@6848
  1038
        window->flags |= SDL_WINDOW_SHOWN;
slouken@6848
  1039
    } else {
slouken@6848
  1040
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@6848
  1041
    }
jorgen@7084
  1042
slouken@6848
  1043
    {
slouken@6848
  1044
        unsigned int style = [nswindow styleMask];
slouken@6848
  1045
slouken@6848
  1046
        if (style == NSBorderlessWindowMask) {
slouken@6848
  1047
            window->flags |= SDL_WINDOW_BORDERLESS;
slouken@6848
  1048
        } else {
slouken@6848
  1049
            window->flags &= ~SDL_WINDOW_BORDERLESS;
alexey@6832
  1050
        }
slouken@6848
  1051
        if (style & NSResizableWindowMask) {
slouken@6848
  1052
            window->flags |= SDL_WINDOW_RESIZABLE;
slouken@6848
  1053
        } else {
slouken@6848
  1054
            window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@6848
  1055
        }
slouken@6848
  1056
    }
jorgen@7084
  1057
slouken@6848
  1058
    /* isZoomed always returns true if the window is not resizable */
slouken@6848
  1059
    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
slouken@6848
  1060
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@6848
  1061
    } else {
slouken@6848
  1062
        window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@6848
  1063
    }
jorgen@7084
  1064
slouken@6848
  1065
    if ([nswindow isMiniaturized]) {
slouken@6848
  1066
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@6848
  1067
    } else {
slouken@6848
  1068
        window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@6848
  1069
    }
jorgen@7084
  1070
slouken@6848
  1071
    if ([nswindow isKeyWindow]) {
slouken@6848
  1072
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@6848
  1073
        SDL_SetKeyboardFocus(data->window);
slouken@6848
  1074
    }
slouken@1933
  1075
jorgen@7085
  1076
    /* Prevents the window's "window device" from being destroyed when it is
jorgen@7085
  1077
     * hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
jorgen@7085
  1078
     */
jorgen@7085
  1079
    [nswindow setOneShot:NO];
jorgen@7085
  1080
slouken@6848
  1081
    /* All done! */
slouken@6848
  1082
    [pool release];
slouken@6848
  1083
    window->driverdata = data;
slouken@6848
  1084
    return 0;
slouken@1933
  1085
}
slouken@1933
  1086
slouken@1933
  1087
int
slouken@1933
  1088
Cocoa_CreateWindow(_THIS, SDL_Window * window)
slouken@1933
  1089
{
icculus@8295
  1090
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@6848
  1091
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1092
    NSWindow *nswindow;
slouken@6848
  1093
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@6848
  1094
    NSRect rect;
slouken@6848
  1095
    SDL_Rect bounds;
slouken@6848
  1096
    unsigned int style;
slouken@8986
  1097
    NSArray *screens = [NSScreen screens];
slouken@1933
  1098
slouken@6848
  1099
    Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@6848
  1100
    rect.origin.x = window->x;
slouken@6848
  1101
    rect.origin.y = window->y;
slouken@6848
  1102
    rect.size.width = window->w;
slouken@6848
  1103
    rect.size.height = window->h;
slouken@8986
  1104
    ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
slouken@1933
  1105
slouken@6848
  1106
    style = GetWindowStyle(window);
slouken@1933
  1107
slouken@6848
  1108
    /* Figure out which screen to place this window */
slouken@6848
  1109
    NSScreen *screen = nil;
slouken@8986
  1110
    for (NSScreen *candidate in screens) {
slouken@6848
  1111
        NSRect screenRect = [candidate frame];
slouken@6848
  1112
        if (rect.origin.x >= screenRect.origin.x &&
slouken@6848
  1113
            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
slouken@6848
  1114
            rect.origin.y >= screenRect.origin.y &&
slouken@6848
  1115
            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
slouken@6848
  1116
            screen = candidate;
slouken@6848
  1117
            rect.origin.x -= screenRect.origin.x;
slouken@6848
  1118
            rect.origin.y -= screenRect.origin.y;
slouken@3506
  1119
        }
slouken@6848
  1120
    }
slouken@7946
  1121
slouken@7946
  1122
    @try {
slouken@7946
  1123
        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
slouken@7946
  1124
    }
slouken@7946
  1125
    @catch (NSException *e) {
slouken@7946
  1126
        SDL_SetError("%s", [[e reason] UTF8String]);
slouken@7948
  1127
        [pool release];
slouken@7946
  1128
        return -1;
slouken@7946
  1129
    }
icculus@7205
  1130
    [nswindow setBackgroundColor:[NSColor blackColor]];
icculus@8284
  1131
icculus@8295
  1132
    if (videodata->allow_spaces) {
slouken@8986
  1133
        SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
icculus@8295
  1134
        SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
icculus@8284
  1135
        /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
icculus@8284
  1136
        if (window->flags & SDL_WINDOW_RESIZABLE) {
icculus@8284
  1137
            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
slouken@7968
  1138
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
slouken@7968
  1139
        }
slouken@7955
  1140
    }
alexey@6832
  1141
slouken@7191
  1142
    /* Create a default view for this window */
slouken@6848
  1143
    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
slouken@6848
  1144
    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
urkle@7746
  1145
slouken@7955
  1146
    if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
urkle@7746
  1147
        if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
urkle@7746
  1148
            [contentView setWantsBestResolutionOpenGLSurface:YES];
urkle@7746
  1149
        }
urkle@7746
  1150
    }
urkle@7746
  1151
slouken@6848
  1152
    [nswindow setContentView: contentView];
slouken@6848
  1153
    [contentView release];
alexey@6832
  1154
jorgen@9237
  1155
    /* Allow files and folders to be dragged onto the window by users */
jorgen@9237
  1156
    [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
jorgen@9237
  1157
slouken@6848
  1158
    [pool release];
slouken@6848
  1159
slouken@6848
  1160
    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
slouken@6848
  1161
        [nswindow release];
slouken@6848
  1162
        return -1;
slouken@3506
  1163
    }
slouken@6848
  1164
    return 0;
slouken@1933
  1165
}
slouken@1933
  1166
slouken@1933
  1167
int
slouken@1933
  1168
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1933
  1169
{
slouken@6848
  1170
    NSAutoreleasePool *pool;
slouken@1933
  1171
    NSWindow *nswindow = (NSWindow *) data;
slouken@1933
  1172
    NSString *title;
slouken@1933
  1173
slouken@6848
  1174
    pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1175
slouken@6848
  1176
    /* Query the title from the existing window */
slouken@6848
  1177
    title = [nswindow title];
slouken@6848
  1178
    if (title) {
slouken@6848
  1179
        window->title = SDL_strdup([title UTF8String]);
slouken@1933
  1180
    }
slouken@1933
  1181
slouken@6848
  1182
    [pool release];
slouken@6848
  1183
slouken@1951
  1184
    return SetupWindowData(_this, window, nswindow, SDL_FALSE);
slouken@1933
  1185
}
slouken@1933
  1186
slouken@1933
  1187
void
slouken@1933
  1188
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1933
  1189
{
slouken@6848
  1190
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1191
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@6848
  1192
    NSString *string;
slouken@1933
  1193
slouken@6848
  1194
    if(window->title) {
slouken@6848
  1195
        string = [[NSString alloc] initWithUTF8String:window->title];
slouken@6848
  1196
    } else {
slouken@6848
  1197
        string = [[NSString alloc] init];
slouken@1956
  1198
    }
slouken@6848
  1199
    [nswindow setTitle:string];
slouken@6848
  1200
    [string release];
slouken@6848
  1201
slouken@6848
  1202
    [pool release];
slouken@1933
  1203
}
slouken@1933
  1204
slouken@1933
  1205
void
slouken@5375
  1206
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@5375
  1207
{
slouken@6848
  1208
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1209
    NSImage *nsimage = Cocoa_CreateImage(icon);
slouken@5375
  1210
slouken@6848
  1211
    if (nsimage) {
slouken@6848
  1212
        [NSApp setApplicationIconImage:nsimage];
slouken@5375
  1213
    }
slouken@6848
  1214
slouken@6848
  1215
    [pool release];
slouken@5375
  1216
}
slouken@5375
  1217
slouken@5375
  1218
void
slouken@1933
  1219
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1933
  1220
{
slouken@6848
  1221
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jorgen@7594
  1222
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
jorgen@7594
  1223
    NSWindow *nswindow = windata->nswindow;
slouken@6848
  1224
    NSRect rect;
slouken@6848
  1225
    Uint32 moveHack;
slouken@1933
  1226
slouken@6848
  1227
    rect.origin.x = window->x;
slouken@6848
  1228
    rect.origin.y = window->y;
slouken@6848
  1229
    rect.size.width = window->w;
slouken@6848
  1230
    rect.size.height = window->h;
slouken@8801
  1231
    ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
slouken@5478
  1232
slouken@6848
  1233
    moveHack = s_moveHack;
slouken@6848
  1234
    s_moveHack = 0;
slouken@6848
  1235
    [nswindow setFrameOrigin:rect.origin];
slouken@6848
  1236
    s_moveHack = moveHack;
slouken@5478
  1237
jorgen@7595
  1238
    ScheduleContextUpdates(windata);
slouken@6848
  1239
slouken@6848
  1240
    [pool release];
slouken@1933
  1241
}
slouken@1933
  1242
slouken@1933
  1243
void
slouken@1933
  1244
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
slouken@1933
  1245
{
slouken@6848
  1246
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1247
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
slouken@6848
  1248
    NSWindow *nswindow = windata->nswindow;
slouken@6848
  1249
    NSSize size;
slouken@1933
  1250
slouken@6848
  1251
    size.width = window->w;
slouken@6848
  1252
    size.height = window->h;
slouken@6848
  1253
    [nswindow setContentSize:size];
icculus@5564
  1254
jorgen@7595
  1255
    ScheduleContextUpdates(windata);
slouken@6848
  1256
slouken@6848
  1257
    [pool release];
slouken@1933
  1258
}
slouken@1933
  1259
slouken@1933
  1260
void
stopiccot@6681
  1261
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
stopiccot@6681
  1262
{
slouken@6848
  1263
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1264
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
slouken@7191
  1265
slouken@6848
  1266
    NSSize minSize;
slouken@6848
  1267
    minSize.width = window->min_w;
slouken@6848
  1268
    minSize.height = window->min_h;
slouken@7191
  1269
slouken@6848
  1270
    [windata->nswindow setContentMinSize:minSize];
slouken@7191
  1271
slouken@6848
  1272
    [pool release];
slouken@6788
  1273
}
slouken@6788
  1274
slouken@6788
  1275
void
slouken@6788
  1276
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
slouken@6788
  1277
{
slouken@6848
  1278
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1279
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
slouken@7191
  1280
slouken@6848
  1281
    NSSize maxSize;
slouken@6848
  1282
    maxSize.width = window->max_w;
slouken@6848
  1283
    maxSize.height = window->max_h;
slouken@7191
  1284
slouken@6848
  1285
    [windata->nswindow setContentMaxSize:maxSize];
slouken@7191
  1286
slouken@6848
  1287
    [pool release];
stopiccot@6681
  1288
}
stopiccot@6681
  1289
stopiccot@6681
  1290
void
slouken@1933
  1291
Cocoa_ShowWindow(_THIS, SDL_Window * window)
slouken@1933
  1292
{
slouken@6848
  1293
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jorgen@7087
  1294
    SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
jorgen@7087
  1295
    NSWindow *nswindow = windowData->nswindow;
slouken@1933
  1296
slouken@6848
  1297
    if (![nswindow isMiniaturized]) {
jorgen@7087
  1298
        [windowData->listener pauseVisibleObservation];
slouken@6848
  1299
        [nswindow makeKeyAndOrderFront:nil];
jorgen@7087
  1300
        [windowData->listener resumeVisibleObservation];
slouken@1956
  1301
    }
slouken@6848
  1302
    [pool release];
slouken@1933
  1303
}
slouken@1933
  1304
slouken@1933
  1305
void
slouken@1933
  1306
Cocoa_HideWindow(_THIS, SDL_Window * window)
slouken@1933
  1307
{
slouken@6848
  1308
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1309
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@6848
  1310
slouken@6848
  1311
    [nswindow orderOut:nil];
slouken@6848
  1312
    [pool release];
slouken@1933
  1313
}
slouken@1933
  1314
slouken@1933
  1315
void
slouken@1933
  1316
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
slouken@1933
  1317
{
slouken@6848
  1318
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jorgen@7087
  1319
    SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
jorgen@7087
  1320
    NSWindow *nswindow = windowData->nswindow;
slouken@6848
  1321
slouken@7771
  1322
    /* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
slouken@7771
  1323
       a minimized or hidden window, so check for that before showing it.
slouken@7771
  1324
     */
jorgen@7087
  1325
    [windowData->listener pauseVisibleObservation];
jorgen@7469
  1326
    if (![nswindow isMiniaturized] && [nswindow isVisible]) {
alfred@9041
  1327
        [NSApp activateIgnoringOtherApps:YES];
jorgen@7469
  1328
        [nswindow makeKeyAndOrderFront:nil];
jorgen@7469
  1329
    }
jorgen@7087
  1330
    [windowData->listener resumeVisibleObservation];
jorgen@7087
  1331
slouken@6848
  1332
    [pool release];
slouken@1933
  1333
}
slouken@1933
  1334
slouken@1933
  1335
void
slouken@1933
  1336
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1933
  1337
{
slouken@6848
  1338
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jorgen@7594
  1339
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
jorgen@7594
  1340
    NSWindow *nswindow = windata->nswindow;
slouken@1933
  1341
slouken@6848
  1342
    [nswindow zoom:nil];
slouken@6848
  1343
jorgen@7595
  1344
    ScheduleContextUpdates(windata);
slouken@6848
  1345
slouken@6848
  1346
    [pool release];
slouken@1933
  1347
}
slouken@1933
  1348
slouken@1933
  1349
void
slouken@1933
  1350
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1933
  1351
{
slouken@6848
  1352
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@7963
  1353
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@7963
  1354
    NSWindow *nswindow = data->nswindow;
slouken@6848
  1355
slouken@7968
  1356
    if ([data->listener isInFullscreenSpaceTransition]) {
slouken@7963
  1357
        [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
slouken@7963
  1358
    } else {
slouken@7963
  1359
        [nswindow miniaturize:nil];
slouken@7963
  1360
    }
slouken@6848
  1361
    [pool release];
slouken@1933
  1362
}
slouken@1933
  1363
slouken@1933
  1364
void
slouken@1933
  1365
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
slouken@1933
  1366
{
slouken@6848
  1367
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1368
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
  1369
slouken@6848
  1370
    if ([nswindow isMiniaturized]) {
slouken@6848
  1371
        [nswindow deminiaturize:nil];
slouken@6848
  1372
    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
slouken@6848
  1373
        [nswindow zoom:nil];
slouken@1956
  1374
    }
slouken@6848
  1375
    [pool release];
slouken@1933
  1376
}
slouken@1933
  1377
slouken@5400
  1378
static NSWindow *
slouken@5400
  1379
Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
slouken@5400
  1380
{
slouken@5400
  1381
    if (!data->created) {
slouken@5400
  1382
        /* Don't mess with other people's windows... */
slouken@5400
  1383
        return nswindow;
slouken@5400
  1384
    }
slouken@5400
  1385
slouken@5400
  1386
    [data->listener close];
jorgen@7085
  1387
    data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
slouken@5400
  1388
    [data->nswindow setContentView:[nswindow contentView]];
jorgen@9237
  1389
    [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
jorgen@7085
  1390
    /* See comment in SetupWindowData. */
jorgen@7085
  1391
    [data->nswindow setOneShot:NO];
slouken@5400
  1392
    [data->listener listen:data];
slouken@5400
  1393
slouken@5400
  1394
    [nswindow close];
slouken@5400
  1395
slouken@5400
  1396
    return data->nswindow;
slouken@5400
  1397
}
slouken@5400
  1398
slouken@1933
  1399
void
icculus@6422
  1400
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
icculus@6422
  1401
{
slouken@6848
  1402
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@7990
  1403
    if (SetWindowStyle(window, GetWindowStyle(window))) {
slouken@6848
  1404
        if (bordered) {
slouken@7191
  1405
            Cocoa_SetWindowTitle(_this, window);  /* this got blanked out. */
icculus@6426
  1406
        }
icculus@6422
  1407
    }
slouken@6848
  1408
    [pool release];
icculus@6422
  1409
}
icculus@6422
  1410
slouken@7952
  1411
slouken@7968
  1412
void
slouken@7968
  1413
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
slouken@7952
  1414
{
slouken@7968
  1415
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1416
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@6848
  1417
    NSWindow *nswindow = data->nswindow;
slouken@6848
  1418
    NSRect rect;
slouken@5249
  1419
slouken@6848
  1420
    /* The view responder chain gets messed with during setStyleMask */
slouken@6848
  1421
    if ([[nswindow contentView] nextResponder] == data->listener) {
slouken@6848
  1422
        [[nswindow contentView] setNextResponder:nil];
slouken@6848
  1423
    }
slouken@6848
  1424
slouken@6848
  1425
    if (fullscreen) {
slouken@6848
  1426
        SDL_Rect bounds;
slouken@6848
  1427
slouken@6848
  1428
        Cocoa_GetDisplayBounds(_this, display, &bounds);
slouken@6848
  1429
        rect.origin.x = bounds.x;
slouken@6848
  1430
        rect.origin.y = bounds.y;
slouken@6848
  1431
        rect.size.width = bounds.w;
slouken@6848
  1432
        rect.size.height = bounds.h;
slouken@8801
  1433
        ConvertNSRect([nswindow screen], fullscreen, &rect);
slouken@6848
  1434
slouken@6848
  1435
        /* Hack to fix origin on Mac OS X 10.4 */
slouken@6848
  1436
        NSRect screenRect = [[nswindow screen] frame];
slouken@6848
  1437
        if (screenRect.size.height >= 1.0f) {
slouken@6848
  1438
            rect.origin.y += (screenRect.size.height - rect.size.height);
slouken@5401
  1439
        }
slouken@5401
  1440
slouken@6848
  1441
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@6848
  1442
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
slouken@6848
  1443
        } else {
slouken@6848
  1444
            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
slouken@6848
  1445
        }
slouken@6848
  1446
    } else {
slouken@6848
  1447
        rect.origin.x = window->windowed.x;
slouken@6848
  1448
        rect.origin.y = window->windowed.y;
slouken@6848
  1449
        rect.size.width = window->windowed.w;
slouken@6848
  1450
        rect.size.height = window->windowed.h;
slouken@8801
  1451
        ConvertNSRect([nswindow screen], fullscreen, &rect);
alexey@6832
  1452
slouken@6848
  1453
        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
slouken@6848
  1454
            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
slouken@5400
  1455
        } else {
slouken@6848
  1456
            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
slouken@5361
  1457
        }
slouken@5398
  1458
    }
slouken@6848
  1459
slouken@6848
  1460
    /* The view responder chain gets messed with during setStyleMask */
slouken@6848
  1461
    if ([[nswindow contentView] nextResponder] != data->listener) {
slouken@6848
  1462
        [[nswindow contentView] setNextResponder:data->listener];
slouken@6848
  1463
    }
slouken@6848
  1464
slouken@6848
  1465
    s_moveHack = 0;
slouken@7873
  1466
    [nswindow setContentSize:rect.size];
slouken@6848
  1467
    [nswindow setFrameOrigin:rect.origin];
slouken@6848
  1468
    s_moveHack = SDL_GetTicks();
slouken@6848
  1469
slouken@6848
  1470
    /* When the window style changes the title is cleared */
slouken@6848
  1471
    if (!fullscreen) {
slouken@6848
  1472
        Cocoa_SetWindowTitle(_this, window);
slouken@6848
  1473
    }
slouken@6848
  1474
slouken@6848
  1475
    if (SDL_ShouldAllowTopmost() && fullscreen) {
slouken@6848
  1476
        /* OpenGL is rendering to the window, so make it visible! */
slouken@6848
  1477
        [nswindow setLevel:CGShieldingWindowLevel()];
slouken@6848
  1478
    } else {
slouken@6848
  1479
        [nswindow setLevel:kCGNormalWindowLevel];
slouken@6848
  1480
    }
jorgen@7087
  1481
jorgen@7636
  1482
    if ([nswindow isVisible] || fullscreen) {
jorgen@7636
  1483
        [data->listener pauseVisibleObservation];
jorgen@7636
  1484
        [nswindow makeKeyAndOrderFront:nil];
jorgen@7636
  1485
        [data->listener resumeVisibleObservation];
jorgen@7636
  1486
    }
slouken@6848
  1487
jorgen@7595
  1488
    ScheduleContextUpdates(data);
slouken@6848
  1489
slouken@6848
  1490
    [pool release];
slouken@5249
  1491
}
slouken@5249
  1492
slouken@5466
  1493
int
slouken@5466
  1494
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
slouken@5466
  1495
{
slouken@5466
  1496
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5466
  1497
    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
slouken@5466
  1498
    const uint32_t tableSize = 256;
slouken@5466
  1499
    CGGammaValue redTable[tableSize];
slouken@5466
  1500
    CGGammaValue greenTable[tableSize];
slouken@5466
  1501
    CGGammaValue blueTable[tableSize];
slouken@5466
  1502
    uint32_t i;
slouken@5466
  1503
    float inv65535 = 1.0f / 65535.0f;
slouken@5466
  1504
slouken@5466
  1505
    /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
slouken@5466
  1506
    for (i = 0; i < 256; i++) {
slouken@5466
  1507
        redTable[i] = ramp[0*256+i] * inv65535;
slouken@5466
  1508
        greenTable[i] = ramp[1*256+i] * inv65535;
slouken@5466
  1509
        blueTable[i] = ramp[2*256+i] * inv65535;
slouken@5466
  1510
    }
slouken@5466
  1511
slouken@5466
  1512
    if (CGSetDisplayTransferByTable(display_id, tableSize,
slouken@5466
  1513
                                    redTable, greenTable, blueTable) != CGDisplayNoErr) {
icculus@7037
  1514
        return SDL_SetError("CGSetDisplayTransferByTable()");
slouken@5466
  1515
    }
slouken@5466
  1516
    return 0;
slouken@5466
  1517
}
slouken@5466
  1518
slouken@5466
  1519
int
slouken@5466
  1520
Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
slouken@5466
  1521
{
slouken@5466
  1522
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5466
  1523
    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
slouken@5466
  1524
    const uint32_t tableSize = 256;
slouken@5466
  1525
    CGGammaValue redTable[tableSize];
slouken@5466
  1526
    CGGammaValue greenTable[tableSize];
slouken@5466
  1527
    CGGammaValue blueTable[tableSize];
slouken@5466
  1528
    uint32_t i, tableCopied;
slouken@5466
  1529
slouken@5466
  1530
    if (CGGetDisplayTransferByTable(display_id, tableSize,
slouken@5466
  1531
                                    redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
icculus@7037
  1532
        return SDL_SetError("CGGetDisplayTransferByTable()");
slouken@5466
  1533
    }
slouken@5466
  1534
slouken@5466
  1535
    for (i = 0; i < tableCopied; i++) {
slouken@5466
  1536
        ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
slouken@5466
  1537
        ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
slouken@5466
  1538
        ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
slouken@5466
  1539
    }
slouken@5466
  1540
    return 0;
slouken@5466
  1541
}
slouken@5466
  1542
slouken@5249
  1543
void
slouken@6662
  1544
Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
slouken@1933
  1545
{
slouken@5371
  1546
    /* Move the cursor to the nearest point in the window */
jorgen@8260
  1547
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
jorgen@8260
  1548
    if (grabbed && data && ![data->listener isMoving]) {
slouken@5371
  1549
        int x, y;
slouken@5371
  1550
        CGPoint cgpoint;
slouken@5371
  1551
slouken@5371
  1552
        SDL_GetMouseState(&x, &y);
slouken@5371
  1553
        cgpoint.x = window->x + x;
slouken@5371
  1554
        cgpoint.y = window->y + y;
jorgen@8261
  1555
jorgen@8261
  1556
        Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
jorgen@8261
  1557
jorgen@8261
  1558
        DLog("Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
slouken@5371
  1559
        CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
slouken@5371
  1560
    }
slouken@7191
  1561
icculus@8652
  1562
    if ( data && (window->flags & SDL_WINDOW_FULLSCREEN) ) {
slouken@7191
  1563
        if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@7191
  1564
            /* OpenGL is rendering to the window, so make it visible! */
slouken@7191
  1565
            [data->nswindow setLevel:CGShieldingWindowLevel()];
slouken@7191
  1566
        } else {
slouken@7191
  1567
            [data->nswindow setLevel:kCGNormalWindowLevel];
slouken@7191
  1568
        }
slouken@7191
  1569
    }
slouken@1933
  1570
}
slouken@1933
  1571
slouken@1933
  1572
void
slouken@1933
  1573
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
slouken@1933
  1574
{
slouken@6848
  1575
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@6848
  1576
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1933
  1577
slouken@6848
  1578
    if (data) {
slouken@6848
  1579
        [data->listener close];
slouken@6848
  1580
        [data->listener release];
slouken@6848
  1581
        if (data->created) {
slouken@6848
  1582
            [data->nswindow close];
slouken@1933
  1583
        }
jorgen@7595
  1584
jorgen@7595
  1585
        NSArray *contexts = [[data->nscontexts copy] autorelease];
jorgen@7595
  1586
        for (SDLOpenGLContext *context in contexts) {
jorgen@7595
  1587
            /* Calling setWindow:NULL causes the context to remove itself from the context list. */            
jorgen@7595
  1588
            [context setWindow:NULL];
jorgen@7595
  1589
        }
jorgen@7595
  1590
        [data->nscontexts release];
jorgen@7595
  1591
slouken@6848
  1592
        SDL_free(data);
slouken@1933
  1593
    }
slouken@8978
  1594
    window->driverdata = NULL;
slouken@8978
  1595
slouken@6848
  1596
    [pool release];
slouken@1933
  1597
}
slouken@1933
  1598
slouken@1933
  1599
SDL_bool
slouken@1933
  1600
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1933
  1601
{
slouken@4900
  1602
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
slouken@1933
  1603
slouken@1933
  1604
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@4900
  1605
        info->subsystem = SDL_SYSWM_COCOA;
slouken@5056
  1606
        info->info.cocoa.window = nswindow;
slouken@1933
  1607
        return SDL_TRUE;
slouken@1933
  1608
    } else {
slouken@1933
  1609
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1933
  1610
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1933
  1611
        return SDL_FALSE;
slouken@1933
  1612
    }
slouken@1933
  1613
}
slouken@1933
  1614
slouken@7968
  1615
SDL_bool
slouken@7969
  1616
Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
slouken@7969
  1617
{
slouken@7969
  1618
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@7969
  1619
slouken@7969
  1620
    if ([data->listener isInFullscreenSpace]) {
slouken@7969
  1621
        return SDL_TRUE;
slouken@7969
  1622
    } else {
slouken@7969
  1623
        return SDL_FALSE;
slouken@7969
  1624
    }
slouken@7969
  1625
}
slouken@7969
  1626
slouken@7969
  1627
SDL_bool
slouken@7968
  1628
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
slouken@7968
  1629
{
slouken@7968
  1630
    SDL_bool succeeded = SDL_FALSE;
slouken@7968
  1631
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@7968
  1632
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@7968
  1633
slouken@7968
  1634
    if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
slouken@7968
  1635
        succeeded = SDL_TRUE;
slouken@8810
  1636
slouken@8810
  1637
        /* Wait for the transition to complete, so application changes
slouken@8810
  1638
           take effect properly (e.g. setting the window size, etc.)
slouken@8810
  1639
         */
slouken@8810
  1640
        const int limit = 10000;
slouken@8810
  1641
        int count = 0;
slouken@8810
  1642
        while ([data->listener isInFullscreenSpaceTransition]) {
slouken@8810
  1643
            if ( ++count == limit ) {
slouken@8810
  1644
                /* Uh oh, transition isn't completing. Should we assert? */
slouken@8810
  1645
                break;
slouken@8810
  1646
            }
slouken@8810
  1647
            SDL_Delay(1);
slouken@8810
  1648
            SDL_PumpEvents();
slouken@8810
  1649
        }
slouken@7968
  1650
    }
slouken@7968
  1651
slouken@7968
  1652
    [pool release];
slouken@7968
  1653
slouken@7968
  1654
    return succeeded;
slouken@7968
  1655
}
slouken@7968
  1656
icculus@8931
  1657
int
icculus@8935
  1658
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
icculus@8931
  1659
{
icculus@8931
  1660
    return 0;  /* just succeed, the real work is done elsewhere. */
icculus@8931
  1661
}
icculus@8931
  1662
slouken@6044
  1663
#endif /* SDL_VIDEO_DRIVER_COCOA */
slouken@6044
  1664
slouken@1933
  1665
/* vi: set ts=4 sw=4 expandtab: */