src/video/cocoa/SDL_cocoawindow.m
author Jørgen P. Tjernø <jorgen@uberent.com>
Mon, 24 Nov 2014 11:46:20 -0800
changeset 9237 2cc90bb31777
parent 9236 a845edf98a80
child 9419 9763f689bced
permissions -rw-r--r--
Mac: Add drag & drop support. Fixes bug https://bugzilla.libsdl.org/show_bug.cgi?id=2757 Thanks to Alex Szpakowski for the patch!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8111
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     7
  arising from the use of this software.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    11
  freely, subject to the following restrictions:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8083
diff changeset
    21
#include "../../SDL_internal.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5873
diff changeset
    23
#if SDL_VIDEO_DRIVER_COCOA
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5873
diff changeset
    24
8083
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    25
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    26
# error SDL for Mac OS X must be built with a 10.7 SDK or above.
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    27
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    28
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_syswm.h"
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
    30
#include "SDL_timer.h"  /* For SDL_GetTicks() */
7915
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
    31
#include "SDL_hints.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../SDL_sysvideo.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "../../events/SDL_keyboard_c.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "../../events/SDL_mouse_c.h"
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
    35
#include "../../events/SDL_touch_c.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "../../events/SDL_windowevents_c.h"
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    37
#include "../../events/SDL_dropevents_c.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#include "SDL_cocoavideo.h"
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 3688
diff changeset
    39
#include "SDL_cocoashape.h"
5057
bdff53ed6c8b Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5056
diff changeset
    40
#include "SDL_cocoamouse.h"
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7593
diff changeset
    41
#include "SDL_cocoaopengl.h"
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
    42
#include "SDL_assert.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
8261
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    44
/* #define DEBUG_COCOAWINDOW */
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    45
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    46
#ifdef DEBUG_COCOAWINDOW
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    47
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    48
#else
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    49
#define DLog(...) do { } while (0)
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    50
#endif
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    51
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    52
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
    53
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
    54
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
    55
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    56
@interface SDLWindow : NSWindow <NSDraggingDestination>
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    57
/* These are needed for borderless/fullscreen windows */
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    58
- (BOOL)canBecomeKeyWindow;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    59
- (BOOL)canBecomeMainWindow;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    60
- (void)sendEvent:(NSEvent *)event;
8809
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
    61
- (void)doCommandBySelector:(SEL)aSelector;
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    62
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    63
/* Handle drag-and-drop of files onto the SDL window. */
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    64
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    65
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    66
- (BOOL)wantsPeriodicDraggingUpdates;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    67
@end
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    68
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    69
@implementation SDLWindow
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
    70
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    71
- (BOOL)canBecomeKeyWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    72
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    73
    return YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    74
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    75
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    76
- (BOOL)canBecomeMainWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    77
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    78
    return YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    79
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    80
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    81
- (void)sendEvent:(NSEvent *)event
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    82
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    83
  [super sendEvent:event];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    84
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    85
  if ([event type] != NSLeftMouseUp) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    86
      return;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    87
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    88
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    89
  id delegate = [self delegate];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    90
  if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    91
      return;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    92
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    93
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    94
  if ([delegate isMoving]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    95
      [delegate windowDidFinishMoving];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    96
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    97
}
8809
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
    98
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
    99
/* We'll respond to selectors by doing nothing so we don't beep.
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   100
 * The escape key gets converted to a "cancel" selector, etc.
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   101
 */
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   102
- (void)doCommandBySelector:(SEL)aSelector
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   103
{
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   104
    /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
054ec268f363 Fixed escape cancelling fullscreen mode now that the SDL window is the first res
Sam Lantinga <slouken@libsdl.org>
parents: 8801
diff changeset
   105
}
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   106
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   107
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   108
{
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   109
    return NSDragOperationGeneric;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   110
}
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   111
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   112
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   113
{
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   114
    NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   115
    NSNumber *isAlias = nil;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   116
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   117
    if (fileURL == nil) {
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   118
        return NO;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   119
    }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   120
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   121
    /* Functionality for resolving URL aliases was added with OS X 10.6. */
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   122
    if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   123
        [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   124
    }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   125
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   126
    /* If the URL is an alias, resolve it. */
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   127
    if ([isAlias boolValue]) {
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   128
        NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   129
        NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   130
        if (bookmark != nil) {
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   131
            NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   132
                                                           options:opts
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   133
                                                     relativeToURL:nil
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   134
                                               bookmarkDataIsStale:nil
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   135
                                                             error:nil];
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   136
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   137
            if (resolvedURL != nil) {
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   138
                fileURL = resolvedURL;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   139
            }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   140
        }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   141
    }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   142
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   143
    return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   144
}
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   145
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   146
- (BOOL)wantsPeriodicDraggingUpdates
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   147
{
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   148
    return NO;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   149
}
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   150
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   151
@end
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   152
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   153
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   154
static Uint32 s_moveHack;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   155
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
   156
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
{
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   158
    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   161
static void
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   162
ScheduleContextUpdates(SDL_WindowData *data)
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   163
{
8258
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   164
    NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   165
    NSMutableArray *contexts = data->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   166
    @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   167
        for (SDLOpenGLContext *context in contexts) {
8258
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   168
            if (context == currentContext) {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   169
                [context update];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   170
            } else {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   171
                [context scheduleUpdate];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   172
            }
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   173
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   174
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   175
}
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   176
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   177
static int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   178
GetHintCtrlClickEmulateRightClick()
7915
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   179
{
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   180
	const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   181
	return hint != NULL && *hint != '0';
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   182
}
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   183
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   184
static unsigned int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   185
GetWindowStyle(SDL_Window * window)
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   186
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   187
    unsigned int style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   188
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   189
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   190
        style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   191
    } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   192
        if (window->flags & SDL_WINDOW_BORDERLESS) {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   193
            style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   194
        } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   195
            style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   196
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   197
        if (window->flags & SDL_WINDOW_RESIZABLE) {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   198
            style |= NSResizableWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   199
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   200
    }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   201
    return style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   202
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   203
7990
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   204
static SDL_bool
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   205
SetWindowStyle(SDL_Window * window, unsigned int style)
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   206
{
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   207
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   208
    NSWindow *nswindow = data->nswindow;
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   209
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   210
    if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   211
        return SDL_FALSE;
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   212
    }
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   213
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   214
    /* The view responder chain gets messed with during setStyleMask */
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   215
    if ([[nswindow contentView] nextResponder] == data->listener) {
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   216
        [[nswindow contentView] setNextResponder:nil];
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   217
    }
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   218
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   219
    [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   220
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   221
    /* The view responder chain gets messed with during setStyleMask */
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   222
    if ([[nswindow contentView] nextResponder] != data->listener) {
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   223
        [[nswindow contentView] setNextResponder:data->listener];
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   224
    }
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   225
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   226
    return SDL_TRUE;
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   227
}
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   228
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   229
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
@implementation Cocoa_WindowListener
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
- (void)listen:(SDL_WindowData *)data
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
    NSNotificationCenter *center;
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   235
    NSWindow *window = data->nswindow;
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   236
    NSView *view = [window contentView];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
    _data = data;
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   239
    observingVisible = YES;
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   240
    wasCtrlLeft = NO;
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   241
    wasVisible = [window isVisible];
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   242
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   243
    inFullscreenTransition = NO;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   244
    pendingWindowOperation = PENDING_OPERATION_NONE;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   245
    isMoving = NO;
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   246
    isDragAreaRunning = NO;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   250
    if ([window delegate] != nil) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   251
        [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   252
        [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   253
        [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   254
        [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   255
        [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   256
        [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   257
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   258
        [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   259
        [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   260
        [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   261
        [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   262
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   263
        [window setDelegate:self];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   264
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   266
    /* Haven't found a delegate / notification that triggers when the window is
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   267
     * ordered out (is not visible any more). You can be ordered out without
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   268
     * minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   269
     */
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   270
    [window addObserver:self
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   271
             forKeyPath:@"visible"
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   272
                options:NSKeyValueObservingOptionNew
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   273
                context:NULL];
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   274
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   275
    [window setNextResponder:self];
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   276
    [window setAcceptsMouseMovedEvents:YES];
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   277
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   278
    [view setNextResponder:self];
6108
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   279
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   280
    if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   281
        [view setAcceptsTouchEvents:YES];
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   282
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   285
- (void)observeValueForKeyPath:(NSString *)keyPath
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   286
                      ofObject:(id)object
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   287
                        change:(NSDictionary *)change
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   288
                       context:(void *)context
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   289
{
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   290
    if (!observingVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   291
        return;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   292
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   293
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   294
    if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   295
        int newVisibility = [[change objectForKey:@"new"] intValue];
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   296
        if (newVisibility) {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   297
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   298
        } else {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   299
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   300
        }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   301
    }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   302
}
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   303
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   304
-(void) pauseVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   305
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   306
    observingVisible = NO;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   307
    wasVisible = [_data->nswindow isVisible];
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   308
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   309
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   310
-(void) resumeVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   311
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   312
    BOOL isVisible = [_data->nswindow isVisible];
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   313
    observingVisible = YES;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   314
    if (wasVisible != isVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   315
        if (isVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   316
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   317
        } else {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   318
            SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   319
        }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   320
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   321
        wasVisible = isVisible;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   322
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   323
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   324
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   325
-(BOOL) setFullscreenSpace:(BOOL) state
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   326
{
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   327
    SDL_Window *window = _data->window;
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   328
    NSWindow *nswindow = _data->nswindow;
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   329
    SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   330
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   331
    if (!videodata->allow_spaces) {
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   332
        return NO;  /* Spaces are forcibly disabled. */
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   333
    } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
8292
2b0736ab4d5f Mac: only programmatically create Spaces if we're FULLSCREEN_DESKTOP.
Ryan C. Gordon <icculus@icculus.org>
parents: 8291
diff changeset
   334
        return NO;  /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
8798
2703c0c19f45 Fixed bug 2479 - [OS X] SDL_SetWindowFullscreen fails to switch to windowed
Sam Lantinga <slouken@libsdl.org>
parents: 8738
diff changeset
   335
    } else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
2703c0c19f45 Fixed bug 2479 - [OS X] SDL_SetWindowFullscreen fails to switch to windowed
Sam Lantinga <slouken@libsdl.org>
parents: 8738
diff changeset
   336
        return NO;  /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   337
    } else if (state == isFullscreenSpace) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   338
        return YES;  /* already there. */
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   339
    }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   340
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   341
    if (inFullscreenTransition) {
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   342
        if (state) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   343
            [self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   344
        } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   345
            [self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   346
        }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   347
        return YES;
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   348
    }
7968
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   349
    inFullscreenTransition = YES;
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   350
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   351
    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   352
    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   353
    [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   354
    return YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   355
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   356
7968
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   357
-(BOOL) isInFullscreenSpace
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   358
{
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   359
    return isFullscreenSpace;
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   360
}
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   361
8c0afe77a1b2 Added a hint SDL_HINT_VIDEO_FULLSCREEN_SPACES to specify that windows go fullscreen into their own spaces on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 7967
diff changeset
   362
-(BOOL) isInFullscreenSpaceTransition
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   363
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   364
    return inFullscreenTransition;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   365
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   366
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   367
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   368
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   369
    pendingWindowOperation = operation;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   370
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   371
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
- (void)close
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
    NSNotificationCenter *center;
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   375
    NSWindow *window = _data->nswindow;
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   376
    NSView *view = [window contentView];
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   377
    NSArray *windows = nil;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   381
    if ([window delegate] != self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   382
        [center removeObserver:self name:NSWindowDidExposeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   383
        [center removeObserver:self name:NSWindowDidMoveNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   384
        [center removeObserver:self name:NSWindowDidResizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   385
        [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   386
        [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   387
        [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   388
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   389
        [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   390
        [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   391
        [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   392
        [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   393
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   394
        [window setDelegate:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   395
    }
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   396
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   397
    [window removeObserver:self forKeyPath:@"visible"];
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   398
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   399
    if ([window nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   400
        [window setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   401
    }
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   402
    if ([view nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   403
        [view setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   404
    }
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   405
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   406
    /* Make the next window in the z-order Key. If we weren't the foreground
7535
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   407
       when closed, this is a no-op.
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   408
       !!! FIXME: Note that this is a hack, and there are corner cases where
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   409
       !!! FIXME:  this fails (such as the About box). The typical nib+RunLoop
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   410
       !!! FIXME:  handles this for Cocoa apps, but we bypass all that in SDL.
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   411
       !!! FIXME:  We should remove this code when we find a better way to
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   412
       !!! FIXME:  have the system do this for us. See discussion in
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   413
       !!! FIXME:   http://bugzilla.libsdl.org/show_bug.cgi?id=1825
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   414
    */
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   415
    windows = [NSApp orderedWindows];
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   416
    for (NSWindow *win in windows) {
8111
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   417
        if (win == window) {
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   418
            continue;
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   419
        }
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   420
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   421
        [win makeKeyAndOrderFront:self];
8111
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   422
        break;
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   423
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   426
- (BOOL)isMoving
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   427
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   428
    return isMoving;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   429
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   430
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   431
-(void) setPendingMoveX:(int)x Y:(int)y
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   432
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   433
    pendingWindowWarpX = x;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   434
    pendingWindowWarpY = y;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   435
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   436
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   437
- (void)windowDidFinishMoving
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   438
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   439
    if ([self isMoving]) {
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   440
        isMoving = NO;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   441
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   442
        SDL_Mouse *mouse = SDL_GetMouse();
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   443
        if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   444
            mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   445
            pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   446
        }
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   447
        if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) {
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   448
            mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   449
        }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   450
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   451
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   452
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
- (BOOL)windowShouldClose:(id)sender
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
{
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   455
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
    return NO;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
- (void)windowDidExpose:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
{
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   461
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   464
- (void)windowWillMove:(NSNotification *)aNotification
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   465
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   466
    if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   467
        pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   468
        isMoving = YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   469
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   470
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   471
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
- (void)windowDidMove:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
    int x, y;
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   475
    SDL_Window *window = _data->window;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   476
    NSWindow *nswindow = _data->nswindow;
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
   477
    BOOL fullscreen = window->flags & FULLSCREEN_MASK;
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   478
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
   479
    ConvertNSRect([nswindow screen], fullscreen, &rect);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   480
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   481
    if (s_moveHack) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   482
        SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   483
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   484
        s_moveHack = 0;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   485
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   486
        if (blockMove) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   487
            /* Cocoa is adjusting the window in response to a mode change */
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   488
            rect.origin.x = window->x;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   489
            rect.origin.y = window->y;
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
   490
            ConvertNSRect([nswindow screen], fullscreen, &rect);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   491
            [nswindow setFrameOrigin:rect.origin];
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   492
            return;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   493
        }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   494
    }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   495
3507
3712547eac4f The window positions are relative to the origin of the windowing system (upper left of the primary display).
Sam Lantinga <slouken@libsdl.org>
parents: 3506
diff changeset
   496
    x = (int)rect.origin.x;
3712547eac4f The window positions are relative to the origin of the windowing system (upper left of the primary display).
Sam Lantinga <slouken@libsdl.org>
parents: 3506
diff changeset
   497
    y = (int)rect.origin.y;
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   498
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   499
    ScheduleContextUpdates(_data);
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   500
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   501
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
- (void)windowDidResize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
{
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   506
    if (inFullscreenTransition) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   507
        /* We'll take care of this at the end of the transition */
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   508
        return;
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   509
    }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   510
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   511
    SDL_Window *window = _data->window;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   512
    NSWindow *nswindow = _data->nswindow;
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   513
    int x, y, w, h;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   514
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
8801
98173814b673 Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode
Sam Lantinga <slouken@libsdl.org>
parents: 8798
diff changeset
   515
    ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   516
    x = (int)rect.origin.x;
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   517
    y = (int)rect.origin.y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
    w = (int)rect.size.width;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    h = (int)rect.size.height;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   520
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   521
    if (SDL_IsShapedWindow(window)) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   522
        Cocoa_ResizeWindowShape(window);
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   523
    }
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   524
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   525
    ScheduleContextUpdates(_data);
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   526
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   527
    /* The window can move during a resize event, such as when maximizing
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   528
       or resizing from a corner */
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   529
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   530
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   531
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   532
    const BOOL zoomed = [nswindow isZoomed];
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   533
    if (!zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   534
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   535
    } else if (zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   536
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   537
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
- (void)windowDidMiniaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
{
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   542
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
{
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   547
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
- (void)windowDidBecomeKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
{
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   552
    SDL_Window *window = _data->window;
7271
963d2ba35cfe Mac: Fix incorrect relative jump on focus / start.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7270
diff changeset
   553
    SDL_Mouse *mouse = SDL_GetMouse();
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   554
    if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   555
        mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   556
    }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   557
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   558
    /* We're going to get keyboard events, since we're key. */
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   559
    SDL_SetKeyboardFocus(window);
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   560
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   561
    /* If we just gained focus we need the updated mouse position */
7271
963d2ba35cfe Mac: Fix incorrect relative jump on focus / start.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7270
diff changeset
   562
    if (!mouse->relative_mode) {
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   563
        NSPoint point;
5396
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   564
        int x, y;
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   565
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   566
        point = [_data->nswindow mouseLocationOutsideOfEventStream];
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   567
        x = (int)point.x;
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   568
        y = (int)(window->h - point.y);
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   569
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   570
        if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   571
            SDL_SendMouseMotion(window, 0, 0, x, y);
5396
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   572
        }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   573
    }
1962
c92e5f3e68d9 Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
   574
4503
524dfefd554c Added an event when the clipboard is updated, triggered after the window gains the keyboard focus.
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   575
    /* Check to see if someone updated the clipboard */
524dfefd554c Added an event when the clipboard is updated, triggered after the window gains the keyboard focus.
Sam Lantinga <slouken@libsdl.org>
parents: 4498
diff changeset
   576
    Cocoa_CheckClipboardUpdate(_data->videodata);
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   577
8293
b96005b05c90 Mac: Don't lose the menu/dock when switching back to a resizable window Space.
Ryan C. Gordon <icculus@icculus.org>
parents: 8292
diff changeset
   578
    if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   579
        [NSMenu setMenuBarVisible:NO];
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   580
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
- (void)windowDidResignKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
{
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   585
    SDL_Mouse *mouse = SDL_GetMouse();
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   586
    if (mouse->relative_mode && !mouse->relative_mode_warp) {
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   587
        mouse->SetRelativeMouseMode(SDL_FALSE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   588
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   589
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   590
    /* Some other window will get mouse events, since we're not key. */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
   591
    if (SDL_GetMouseFocus() == _data->window) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
   592
        SDL_SetMouseFocus(NULL);
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   593
    }
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   594
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   595
    /* Some other window will get keyboard events, since we're not key. */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
   596
    if (SDL_GetKeyboardFocus() == _data->window) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
   597
        SDL_SetKeyboardFocus(NULL);
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3688
diff changeset
   598
    }
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   599
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   600
    if (isFullscreenSpace) {
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   601
        [NSMenu setMenuBarVisible:YES];
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   602
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   605
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   606
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   607
    SDL_Window *window = _data->window;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   608
7990
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   609
    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   610
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   611
    isFullscreenSpace = YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   612
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   613
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   614
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   615
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   616
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   617
    SDL_Window *window = _data->window;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   618
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   619
    inFullscreenTransition = NO;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   620
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   621
    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   622
        pendingWindowOperation = PENDING_OPERATION_NONE;
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   623
        [self setFullscreenSpace:NO];
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   624
    } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   625
        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   626
            [NSMenu setMenuBarVisible:NO];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   627
        }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   628
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   629
        pendingWindowOperation = PENDING_OPERATION_NONE;
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   630
        /* Force the size change event in case it was delivered earlier
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   631
           while the window was still animating into place.
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   632
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   633
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   634
        window->h = 0;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   635
        [self windowDidResize:aNotification];
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   636
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   637
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   638
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   639
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   640
{
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   641
    SDL_Window *window = _data->window;
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   642
7990
a05a48e493c0 Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
Sam Lantinga <slouken@libsdl.org>
parents: 7970
diff changeset
   643
    SetWindowStyle(window, GetWindowStyle(window));
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   644
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   645
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   646
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   647
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   648
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   649
- (void)windowDidExitFullScreen:(NSNotification *)aNotification
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   650
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   651
    SDL_Window *window = _data->window;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   652
    NSWindow *nswindow = _data->nswindow;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   653
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   654
    inFullscreenTransition = NO;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   655
8618
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   656
    [nswindow setLevel:kCGNormalWindowLevel];
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   657
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   658
    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   659
        pendingWindowOperation = PENDING_OPERATION_NONE;
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   660
        [self setFullscreenSpace:YES];
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   661
    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   662
        pendingWindowOperation = PENDING_OPERATION_NONE;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   663
        [nswindow miniaturize:nil];
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   664
    } else {
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   665
        /* Adjust the fullscreen toggle button and readd menu now that we're here. */
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   666
        if (window->flags & SDL_WINDOW_RESIZABLE) {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   667
            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   668
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   669
        } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   670
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   671
        }
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   672
        [NSMenu setMenuBarVisible:YES];
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   673
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   674
        pendingWindowOperation = PENDING_OPERATION_NONE;
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   675
        /* Force the size change event in case it was delivered earlier
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   676
           while the window was still animating into place.
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   677
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   678
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   679
        window->h = 0;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   680
        [self windowDidResize:aNotification];
8622
957fbefc8556 Mac: Make sure window is still showing when we exit a fullscreen space.
Ryan C. Gordon <icculus@icculus.org>
parents: 8618
diff changeset
   681
8623
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   682
        /* FIXME: Why does the window get hidden? */
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   683
        if (window->flags & SDL_WINDOW_SHOWN) {
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   684
            Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   685
        }
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   686
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   687
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   688
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   689
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   690
{
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   691
    if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   692
        return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   693
    } else {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   694
        return proposedOptions;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   695
    }
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   696
}
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   697
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   698
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   699
/* We'll respond to key events by doing nothing so we don't beep.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   700
 * We could handle key messages here, but we lose some in the NSApp dispatch,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   701
 * where they get converted to action messages, etc.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   702
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   703
- (void)flagsChanged:(NSEvent *)theEvent
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   704
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   705
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   706
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   707
- (void)keyDown:(NSEvent *)theEvent
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   708
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   709
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   710
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   711
- (void)keyUp:(NSEvent *)theEvent
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   712
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   713
    /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   714
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   715
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   716
/* We'll respond to selectors by doing nothing so we don't beep.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   717
 * The escape key gets converted to a "cancel" selector, etc.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   718
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   719
- (void)doCommandBySelector:(SEL)aSelector
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   720
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   721
    /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   722
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   723
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   724
- (BOOL)processHitTest:(NSEvent *)theEvent
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   725
{
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   726
    SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   727
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   728
    if (_data->window->hit_test) {  /* if no hit-test, skip this. */
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   729
        const NSPoint location = [theEvent locationInWindow];
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   730
        const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   731
        const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   732
        if (rc == SDL_HITTEST_DRAGGABLE) {
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   733
            if (!isDragAreaRunning) {
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   734
                isDragAreaRunning = YES;
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   735
                [_data->nswindow setMovableByWindowBackground:YES];
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   736
            }
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   737
            return YES;  /* dragging! */
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   738
        }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   739
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   740
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   741
    if (isDragAreaRunning) {
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   742
        isDragAreaRunning = NO;
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   743
        [_data->nswindow setMovableByWindowBackground:NO];
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   744
        return YES;  /* was dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   745
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   746
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   747
    return NO;  /* not a special area, carry on. */
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   748
}
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   749
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
- (void)mouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   752
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   754
    if ([self processHitTest:theEvent]) {
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   755
        return;  /* dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   756
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   757
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   758
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   759
    case 0:
7915
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   760
        if (([theEvent modifierFlags] & NSControlKeyMask) &&
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
   761
		    GetHintCtrlClickEmulateRightClick()) {
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   762
            wasCtrlLeft = YES;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   763
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   764
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   765
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   766
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   767
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   768
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   769
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   770
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   771
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   772
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   773
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   774
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   775
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   776
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   777
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   778
    }
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   779
    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   781
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
- (void)rightMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   784
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
- (void)otherMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   789
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
- (void)mouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   794
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   796
    if ([self processHitTest:theEvent]) {
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   797
        return;  /* stopped dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   798
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   799
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   800
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   801
    case 0:
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   802
        if (wasCtrlLeft) {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   803
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   804
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   805
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   806
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   807
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   808
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   809
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   810
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   811
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   812
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   813
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   814
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   815
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   816
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   817
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   818
    }
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   819
    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   820
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   821
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   822
- (void)rightMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   823
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   824
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   825
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   826
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   827
- (void)otherMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   828
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   829
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   830
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   831
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   832
- (void)mouseMoved:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   833
{
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   834
    SDL_Mouse *mouse = SDL_GetMouse();
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3530
diff changeset
   835
    SDL_Window *window = _data->window;
5396
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   836
    NSPoint point;
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   837
    int x, y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   839
    if ([self processHitTest:theEvent]) {
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   840
        return;  /* dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   841
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   842
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   843
    if (mouse->relative_mode) {
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   844
        return;
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   845
    }
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   846
5396
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   847
    point = [theEvent locationInWindow];
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   848
    x = (int)point.x;
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   849
    y = (int)(window->h - point.y);
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   850
8929
7b459b49fa92 Flip this around to do the simpler condition first.
Ryan C. Gordon <icculus@icculus.org>
parents: 8738
diff changeset
   851
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
7b459b49fa92 Flip this around to do the simpler condition first.
Ryan C. Gordon <icculus@icculus.org>
parents: 8738
diff changeset
   852
        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   853
            if (x < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   854
                x = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   855
            } else if (x >= window->w) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   856
                x = window->w - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   857
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   858
            if (y < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   859
                y = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   860
            } else if (y >= window->h) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   861
                y = window->h - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   862
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   863
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   864
#if !SDL_MAC_NO_SANDBOX
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   865
            CGPoint cgpoint;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   866
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   867
            /* When SDL_MAC_NO_SANDBOX is set, this is handled by
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   868
             * SDL_cocoamousetap.m.
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   869
             */
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   870
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   871
            cgpoint.x = window->x + x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   872
            cgpoint.y = window->y + y;
7098
f4b2c6fb0258 Mac: Make mouse movement smooth at edge of window when grabbed.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7087
diff changeset
   873
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   874
            /* According to the docs, this was deprecated in 10.6, but it's still
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   875
             * around. The substitute requires a CGEventSource, but I'm not entirely
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   876
             * sure how we'd procure the right one for this event.
7098
f4b2c6fb0258 Mac: Make mouse movement smooth at edge of window when grabbed.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7087
diff changeset
   877
             */
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   878
            CGSetLocalEventsSuppressionInterval(0.0);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   879
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   880
            CGSetLocalEventsSuppressionInterval(0.25);
8261
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   881
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   882
            Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   883
#endif
5396
109b7c071f70 Tracking rectangles had some problems, it's easier to track things directly. (fixes bug 1149, 1147, 1146)
Sam Lantinga <slouken@libsdl.org>
parents: 5388
diff changeset
   884
        }
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   885
    }
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   886
    SDL_SendMouseMotion(window, 0, 0, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   887
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   888
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   889
- (void)mouseDragged:(NSEvent *)theEvent
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   890
{
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   891
    [self mouseMoved:theEvent];
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   892
}
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   893
1958
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   894
- (void)rightMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   895
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   896
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   897
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   898
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   899
- (void)otherMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   900
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   901
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   902
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   903
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   904
- (void)scrollWheel:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   905
{
5057
bdff53ed6c8b Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5056
diff changeset
   906
    Cocoa_HandleMouseWheel(_data->window, theEvent);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   907
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   908
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   909
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   910
{
9236
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   911
    NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   912
    int existingTouchCount = 0;
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   913
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   914
    for (NSTouch* touch in touches) {
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   915
        if ([touch phase] != NSTouchPhaseBegan) {
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   916
            existingTouchCount++;
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   917
        }
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   918
    }
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   919
    if (existingTouchCount == 0) {
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   920
        SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   921
        int numFingers = SDL_GetNumTouchFingers(touchID);
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   922
        DLog("Reset Lost Fingers: %d", numFingers);
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   923
        for (--numFingers; numFingers >= 0; --numFingers) {
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   924
            SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   925
            SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   926
        }
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   927
    }
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   928
a845edf98a80 Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Edward Rudd <urkle@outoforder.cc>
parents: 9086
diff changeset
   929
    DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   930
    [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   931
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   932
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   933
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   934
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   935
    [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   936
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   937
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   938
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   939
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   940
    [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   941
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   942
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   943
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   944
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   945
    [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   946
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   947
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   948
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   949
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   950
    NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   951
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   952
    for (NSTouch *touch in touches) {
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   953
        const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   954
        if (!SDL_GetTouch(touchId)) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   955
            if (SDL_AddTouch(touchId, "") < 0) {
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   956
                return;
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   957
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   958
        }
4687
257bdf117af8 Fixed so the origin of the touch events is the upper left.
Sam Lantinga <slouken@libsdl.org>
parents: 4680
diff changeset
   959
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   960
        const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   961
        float x = [touch normalizedPosition].x;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   962
        float y = [touch normalizedPosition].y;
5261
595814f561f7 There is only one width and height for the window. If those are changed during the course of a fullscreen mode change, then they'll stay that size when returning to windowed mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5253
diff changeset
   963
        /* Make the origin the upper left instead of the lower left */
595814f561f7 There is only one width and height for the window. If those are changed during the course of a fullscreen mode change, then they'll stay that size when returning to windowed mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5253
diff changeset
   964
        y = 1.0f - y;
4687
257bdf117af8 Fixed so the origin of the touch events is the upper left.
Sam Lantinga <slouken@libsdl.org>
parents: 4680
diff changeset
   965
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   966
        switch (phase) {
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   967
        case NSTouchPhaseBegan:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   968
            SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   969
            break;
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   970
        case NSTouchPhaseEnded:
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   971
        case NSTouchPhaseCancelled:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   972
            SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   973
            break;
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   974
        case NSTouchPhaseMoved:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   975
            SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   976
            break;
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   977
        default:
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   978
            break;
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   979
        }
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   980
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   981
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   982
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   983
@end
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   984
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   985
@interface SDLView : NSView
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   986
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   987
/* The default implementation doesn't pass rightMouseDown to responder chain */
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   988
- (void)rightMouseDown:(NSEvent *)theEvent;
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   989
- (BOOL)mouseDownCanMoveWindow;
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   990
@end
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   991
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   992
@implementation SDLView
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   993
- (void)rightMouseDown:(NSEvent *)theEvent
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   994
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5367
diff changeset
   995
    [[self nextResponder] rightMouseDown:theEvent];
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   996
}
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   997
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   998
- (BOOL)mouseDownCanMoveWindow
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   999
{
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset