src/video/cocoa/SDL_cocoawindow.m
author Alex Szpakowski <slime73@gmail.com>
Sun, 01 May 2016 19:51:10 -0300
changeset 10158 941261e0db9f
parent 10140 6dd5f49e4a77
child 10159 d41acf6379f6
permissions -rw-r--r--
Mac: replaced a deprecated CGSetLocalEventsSuppressionInterval call that I missed in commit f0645cd8fd39
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
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9983
diff changeset
     3
  Copyright (C) 1997-2016 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
{
10140
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    83
    [super sendEvent:event];
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    84
10140
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    85
    if ([event type] != NSLeftMouseUp) {
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    86
        return;
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    87
    }
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    88
10140
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    89
    id delegate = [self delegate];
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    90
    if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    91
        return;
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    92
    }
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    93
10140
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    94
    if ([delegate isMoving]) {
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    95
        [delegate windowDidFinishMoving];
6dd5f49e4a77 Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
Alex Szpakowski <slime73@gmail.com>
parents: 10028
diff changeset
    96
    }
8260
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
{
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   109
    if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   110
        return NSDragOperationGeneric;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   111
    }
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   112
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   113
    return NSDragOperationNone; /* no idea what to do with this, reject it. */
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   114
}
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   115
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   116
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   117
{ @autoreleasepool
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   118
{
10022
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   119
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   120
    NSPasteboard *pasteboard = [sender draggingPasteboard];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   121
    NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   122
    NSString *desiredType = [pasteboard availableTypeFromArray:types];
10022
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   123
    SDL_Window *sdlwindow = nil;
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   124
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   125
    if (desiredType == nil) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   126
        return NO;  /* can't accept anything that's being dropped here. */
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   127
    }
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   128
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   129
    NSData *data = [pasteboard dataForType:desiredType];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   130
    if (data == nil) {
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   131
        return NO;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   132
    }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   133
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   134
    SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   135
    NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   136
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   137
    for (NSString *path in array) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   138
        NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   139
        NSNumber *isAlias = nil;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   140
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   141
        /* Functionality for resolving URL aliases was added with OS X 10.6. */
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   142
        if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   143
            [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   144
        }
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   145
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   146
        /* If the URL is an alias, resolve it. */
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   147
        if ([isAlias boolValue]) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   148
            NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   149
            NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   150
            if (bookmark != nil) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   151
                NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   152
                                                               options:opts
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   153
                                                         relativeToURL:nil
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   154
                                                   bookmarkDataIsStale:nil
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   155
                                                                 error:nil];
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   156
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   157
                if (resolvedURL != nil) {
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   158
                    fileURL = resolvedURL;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   159
                }
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   160
            }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   161
        }
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   162
10022
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   163
        /* !!! FIXME: is there a better way to do this? */
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   164
        if (_this) {
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   165
            for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   166
                NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow;
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   167
                if (nswindow == self) {
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   168
                    break;
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   169
                }
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   170
            }
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   171
        }
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   172
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   173
        if (!SDL_SendDropFile(sdlwindow, [[fileURL path] UTF8String])) {
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   174
            return NO;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   175
        }
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   176
    }
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   177
10022
30807689ca1b Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
Ryan C. Gordon <icculus@icculus.org>
parents: 10010
diff changeset
   178
    SDL_SendDropComplete(sdlwindow);
9795
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   179
    return YES;
63c4d6f1f85f Cocoa: support drag-and-drop of multiple objects.
Ryan C. Gordon <icculus@icculus.org>
parents: 9790
diff changeset
   180
}}
9237
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   181
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   182
- (BOOL)wantsPeriodicDraggingUpdates
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   183
{
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   184
    return NO;
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   185
}
2cc90bb31777 Mac: Add drag & drop support.
Jørgen P. Tjernø <jorgen@uberent.com>
parents: 9236
diff changeset
   186
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   187
@end
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   188
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   189
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   190
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
   191
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
   192
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
{
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   194
    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
   195
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   197
static void
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   198
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
   199
{
8258
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   200
    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
   201
    NSMutableArray *contexts = data->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   202
    @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   203
        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
   204
            if (context == currentContext) {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   205
                [context update];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   206
            } else {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   207
                [context scheduleUpdate];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   208
            }
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   209
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   210
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   211
}
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   212
10010
cc07869515b2 Added a few FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   213
/* !!! FIXME: this should use a hint callback. */
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   214
static int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   215
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
   216
{
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
   217
	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
   218
	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
   219
}
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
   220
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   221
static unsigned int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   222
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
   223
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   224
    unsigned int style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   225
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   226
    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
   227
        style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   228
    } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   229
        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
   230
            style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   231
        } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   232
            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
   233
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   234
        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
   235
            style |= NSResizableWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   236
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   237
    }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   238
    return style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   239
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   240
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
   241
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
   242
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
   243
{
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
   244
    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
   245
    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
   246
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
   247
    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
   248
        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
   249
    }
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
   250
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
   251
    /* 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
   252
    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
   253
        [[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
   254
    }
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
   255
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
   256
    [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
   257
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
   258
    /* 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
   259
    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
   260
        [[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
   261
    }
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
   262
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
   263
    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
   264
}
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
   265
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   266
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
@implementation Cocoa_WindowListener
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
- (void)listen:(SDL_WindowData *)data
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    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
   272
    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
   273
    NSView *view = [window contentView];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
    _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
   276
    observingVisible = YES;
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   277
    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
   278
    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
   279
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   280
    inFullscreenTransition = NO;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   281
    pendingWindowOperation = PENDING_OPERATION_NONE;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   282
    isMoving = NO;
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   283
    isDragAreaRunning = NO;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   287
    if ([window delegate] != nil) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   288
        [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
   289
        [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
   290
        [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
   291
        [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
   292
        [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
   293
        [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
   294
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
9643
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   295
        [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   296
        [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
   297
        [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
   298
        [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
   299
        [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   300
        [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   301
        [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   302
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   303
        [window setDelegate:self];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   304
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   306
    /* 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
   307
     * 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
   308
     * 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
   309
     */
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   310
    [window addObserver:self
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   311
             forKeyPath:@"visible"
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   312
                options:NSKeyValueObservingOptionNew
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   313
                context:NULL];
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   314
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
   315
    [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
   316
    [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
   317
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
   318
    [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
   319
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   320
    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
   321
        [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
   322
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   325
- (void)observeValueForKeyPath:(NSString *)keyPath
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   326
                      ofObject:(id)object
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   327
                        change:(NSDictionary *)change
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   328
                       context:(void *)context
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   329
{
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   330
    if (!observingVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   331
        return;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   332
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   333
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   334
    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
   335
        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
   336
        if (newVisibility) {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   337
            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
   338
        } else {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   339
            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
   340
        }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   341
    }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   342
}
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   343
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   344
-(void) pauseVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   345
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   346
    observingVisible = NO;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   347
    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
   348
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   349
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   350
-(void) resumeVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   351
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   352
    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
   353
    observingVisible = YES;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   354
    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
   355
        if (isVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   356
            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
   357
        } else {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   358
            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
   359
        }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   360
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   361
        wasVisible = isVisible;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   362
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   363
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   364
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   365
-(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
   366
{
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   367
    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
   368
    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
   369
    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
   370
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   371
    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
   372
        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
   373
    } 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
   374
        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
   375
    } 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
   376
        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
   377
    } else if (state == isFullscreenSpace) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   378
        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
   379
    }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   380
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   381
    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
   382
        if (state) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   383
            [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
   384
        } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   385
            [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
   386
        }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   387
        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
   388
    }
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
   389
    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
   390
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   391
    /* 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
   392
    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   393
    [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
   394
    return YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   395
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   396
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
   397
-(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
   398
{
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
   399
    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
   400
}
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
   401
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
   402
-(BOOL) isInFullscreenSpaceTransition
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   403
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   404
    return inFullscreenTransition;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   405
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   406
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   407
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   408
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   409
    pendingWindowOperation = operation;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   410
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   411
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
- (void)close
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    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
   415
    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
   416
    NSView *view = [window contentView];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   420
    if ([window delegate] != self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   421
        [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
   422
        [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
   423
        [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
   424
        [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
   425
        [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
   426
        [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
   427
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
9643
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   428
        [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   429
        [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
   430
        [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
   431
        [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
   432
        [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   433
        [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   434
        [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   435
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   436
        [window setDelegate:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   437
    }
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
   438
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   439
    [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
   440
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   441
    if ([window nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   442
        [window setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   443
    }
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   444
    if ([view nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   445
        [view setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   446
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   449
- (BOOL)isMoving
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
    return isMoving;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   452
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   453
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   454
-(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
   455
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   456
    pendingWindowWarpX = x;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   457
    pendingWindowWarpY = y;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   458
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   459
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   460
- (void)windowDidFinishMoving
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   461
{
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   462
    if ([self isMoving]) {
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   463
        isMoving = NO;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   464
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   465
        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
   466
        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
   467
            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
   468
            pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   469
        }
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   470
        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
   471
            mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   472
        }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   473
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   474
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   475
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
- (BOOL)windowShouldClose:(id)sender
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
{
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
   478
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
    return NO;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
- (void)windowDidExpose:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
{
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
   484
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   487
- (void)windowWillMove:(NSNotification *)aNotification
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   488
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   489
    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
   490
        pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   491
        isMoving = YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   492
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   493
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   494
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
- (void)windowDidMove:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
    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
   498
    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
   499
    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
   500
    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
   501
    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
   502
    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
   503
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   504
    if (s_moveHack) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   505
        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
   506
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   507
        s_moveHack = 0;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   508
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   509
        if (blockMove) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   510
            /* 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
   511
            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
   512
            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
   513
            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
   514
            [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
   515
            return;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   516
        }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   517
    }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   518
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
   519
    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
   520
    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
   521
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   522
    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
   523
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   524
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
- (void)windowDidResize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
{
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   529
    if (inFullscreenTransition) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   530
        /* 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
   531
        return;
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   532
    }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   533
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   534
    SDL_Window *window = _data->window;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   535
    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
   536
    int x, y, w, h;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   537
    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
   538
    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
   539
    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
   540
    y = (int)rect.origin.y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
    w = (int)rect.size.width;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
    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
   543
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   544
    if (SDL_IsShapedWindow(window)) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   545
        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
   546
    }
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   547
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   548
    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
   549
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   550
    /* 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
   551
       or resizing from a corner */
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   552
    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
   553
    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
   554
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   555
    const BOOL zoomed = [nswindow isZoomed];
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   556
    if (!zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   557
        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
   558
    } else if (zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   559
        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
   560
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
- (void)windowDidMiniaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
{
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
   565
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
{
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
   570
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
- (void)windowDidBecomeKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
{
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   575
    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
   576
    SDL_Mouse *mouse = SDL_GetMouse();
9628
065e4ddc8753 Cocoa: Fixed relative mouse mode when app loses/regains focus (thanks, Eric!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9623
diff changeset
   577
065e4ddc8753 Cocoa: Fixed relative mouse mode when app loses/regains focus (thanks, Eric!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9623
diff changeset
   578
    /* We're going to get keyboard events, since we're key. */
065e4ddc8753 Cocoa: Fixed relative mouse mode when app loses/regains focus (thanks, Eric!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9623
diff changeset
   579
    /* This needs to be done before restoring the relative mouse mode. */
065e4ddc8753 Cocoa: Fixed relative mouse mode when app loses/regains focus (thanks, Eric!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9623
diff changeset
   580
    SDL_SetKeyboardFocus(window);
065e4ddc8753 Cocoa: Fixed relative mouse mode when app loses/regains focus (thanks, Eric!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9623
diff changeset
   581
9086
c5e33f9a0d03 Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Sam Lantinga <slouken@libsdl.org>
parents: 9041
diff changeset
   582
    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
   583
        mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   584
    }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   585
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   586
    /* 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
   587
    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
   588
        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
   589
        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
   590
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
   591
        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
   592
        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
   593
        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
   594
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
   595
        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
   596
            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
   597
        }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   598
    }
1962
c92e5f3e68d9 Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
   599
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
   600
    /* 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
   601
    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
   602
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
   603
    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
   604
        [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
   605
    }
9972
734c90ea9990 Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
Ryan C. Gordon <icculus@icculus.org>
parents: 9933
diff changeset
   606
9973
4d8a561cf978 Sync up the caps/numlock state properly without sending key events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9972
diff changeset
   607
    /* On pre-10.6, you might have the capslock key state wrong now because we can't check here. */
9972
734c90ea9990 Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
Ryan C. Gordon <icculus@icculus.org>
parents: 9933
diff changeset
   608
    if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) {
734c90ea9990 Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
Ryan C. Gordon <icculus@icculus.org>
parents: 9933
diff changeset
   609
        const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
9973
4d8a561cf978 Sync up the caps/numlock state properly without sending key events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9972
diff changeset
   610
        _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags;
4d8a561cf978 Sync up the caps/numlock state properly without sending key events.
Ryan C. Gordon <icculus@icculus.org>
parents: 9972
diff changeset
   611
        SDL_ToggleModState(KMOD_CAPS, newflags != 0);
9972
734c90ea9990 Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground.
Ryan C. Gordon <icculus@icculus.org>
parents: 9933
diff changeset
   612
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
- (void)windowDidResignKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
{
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   617
    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
   618
    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
   619
        mouse->SetRelativeMouseMode(SDL_FALSE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   620
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   621
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   622
    /* 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
   623
    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
   624
        SDL_SetMouseFocus(NULL);
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   625
    }
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   626
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   627
    /* 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
   628
    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
   629
        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
   630
    }
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   631
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   632
    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
   633
        [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
   634
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
9643
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   637
- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   638
{
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   639
    NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   640
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   641
    if (inFullscreenTransition) {
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   642
        return;
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   643
    }
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   644
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   645
    if ([oldscale doubleValue] != [_data->nswindow backingScaleFactor]) {
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   646
        /* Force a resize event when the backing scale factor changes. */
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   647
        _data->window->w = 0;
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   648
        _data->window->h = 0;
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   649
        [self windowDidResize:aNotification];
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   650
    }
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   651
}
413b222c4b64 Mac: Send a window resize event when the window's backing scale factor changes.
Alex Szpakowski <slime73@gmail.com>
parents: 9628
diff changeset
   652
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   653
- (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
   654
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   655
    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
   656
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
   657
    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
   658
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   659
    isFullscreenSpace = YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   660
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   661
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   662
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   663
- (void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   664
{
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   665
    SDL_Window *window = _data->window;
9907
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   666
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   667
    if (window->is_destroying) {
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   668
        return;
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   669
    }
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   670
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   671
    SetWindowStyle(window, GetWindowStyle(window));
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   672
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   673
    isFullscreenSpace = NO;
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   674
    inFullscreenTransition = NO;
9905
fcf85090f816 more SDL fullscreen state tracking fixes, don't update fullscreen flags on failure to change fullscreen state
Sam Lantinga <slouken@libsdl.org>
parents: 9904
diff changeset
   675
    
fcf85090f816 more SDL fullscreen state tracking fixes, don't update fullscreen flags on failure to change fullscreen state
Sam Lantinga <slouken@libsdl.org>
parents: 9904
diff changeset
   676
    [self windowDidExitFullScreen:nil];
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   677
}
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   678
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   679
- (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
   680
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   681
    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
   682
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   683
    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
   684
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   685
    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   686
        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
   687
        [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
   688
    } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   689
        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
   690
            [NSMenu setMenuBarVisible:NO];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   691
        }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   692
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   693
        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
   694
        /* 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
   695
           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
   696
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   697
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   698
        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
   699
        [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
   700
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   701
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   702
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   703
- (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
   704
{
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   705
    SDL_Window *window = _data->window;
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   706
9932
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   707
    /* As of OS X 10.11, the window seems to need to be resizable when exiting
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   708
       a Space, in order for it to resize back to its windowed-mode size.
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   709
     */
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   710
    SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask);
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   711
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   712
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   713
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   714
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   715
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   716
- (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   717
{
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   718
    SDL_Window *window = _data->window;
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   719
    
9907
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   720
    if (window->is_destroying) {
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   721
        return;
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   722
    }
2048ad756970 one last SDL fix: restore menu bar if we destroy a fullscreen window without transitioning it back to a non-fullscreen window first
Sam Lantinga <slouken@libsdl.org>
parents: 9905
diff changeset
   723
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   724
    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   725
    
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   726
    isFullscreenSpace = YES;
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   727
    inFullscreenTransition = NO;
9905
fcf85090f816 more SDL fullscreen state tracking fixes, don't update fullscreen flags on failure to change fullscreen state
Sam Lantinga <slouken@libsdl.org>
parents: 9904
diff changeset
   728
    
fcf85090f816 more SDL fullscreen state tracking fixes, don't update fullscreen flags on failure to change fullscreen state
Sam Lantinga <slouken@libsdl.org>
parents: 9904
diff changeset
   729
    [self windowDidEnterFullScreen:nil];
9903
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   730
}
2bbb11de1e60 add hacky support for failed fullscreen transitions. SDL doesn't have the concept of a fullscreen transition that failed. if the user is actively changing spaces while the app goes fullscreen, it fails to go fullscreen; now it will just try again instead of hanging around with the wrong window styles.
Sam Lantinga <slouken@libsdl.org>
parents: 9897
diff changeset
   731
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   732
- (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
   733
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   734
    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
   735
    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
   736
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   737
    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
   738
9932
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   739
    SetWindowStyle(window, GetWindowStyle(window));
a6a953b6d0ce Mac: Fixed SDL_SetWindowFullscreen not restoring the window's original size when exiting a Space.
Alex Szpakowski <slime73@gmail.com>
parents: 9907
diff changeset
   740
8618
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   741
    [nswindow setLevel:kCGNormalWindowLevel];
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   742
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   743
    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   744
        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
   745
        [self setFullscreenSpace:YES];
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   746
    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   747
        pendingWindowOperation = PENDING_OPERATION_NONE;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   748
        [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
   749
    } else {
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   750
        /* 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
   751
        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
   752
            /* 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
   753
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   754
        } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   755
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   756
        }
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   757
        [NSMenu setMenuBarVisible:YES];
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   758
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   759
        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
   760
        /* 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
   761
           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
   762
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   763
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   764
        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
   765
        [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
   766
8623
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   767
        /* 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
   768
        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
   769
            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
   770
        }
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   771
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   772
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   773
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   774
-(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
   775
{
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   776
    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
   777
        return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   778
    } else {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   779
        return proposedOptions;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   780
    }
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   781
}
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   782
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   783
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   784
/* 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
   785
 * 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
   786
 * 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
   787
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   788
- (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
   789
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   790
    /*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
   791
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   792
- (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
   793
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   794
    /*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
   795
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   796
- (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
   797
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   798
    /*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
   799
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   800
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   801
/* 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
   802
 * 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
   803
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   804
- (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
   805
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   806
    /*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
   807
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   808
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   809
- (BOOL)processHitTest:(NSEvent *)theEvent
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   810
{
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   811
    SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   812
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   813
    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
   814
        const NSPoint location = [theEvent locationInWindow];
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   815
        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
   816
        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
   817
        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
   818
            if (!isDragAreaRunning) {
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   819
                isDragAreaRunning = YES;
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   820
                [_data->nswindow setMovableByWindowBackground:YES];
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   821
            }
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   822
            return YES;  /* dragging! */
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   823
        }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   824
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   825
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   826
    if (isDragAreaRunning) {
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   827
        isDragAreaRunning = NO;
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   828
        [_data->nswindow setMovableByWindowBackground:NO];
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   829
        return YES;  /* was dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   830
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   831
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   832
    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
   833
}
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   834
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
- (void)mouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   836
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   837
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
9685
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   839
    /* Ignore events that aren't inside the client area (i.e. title bar.) */
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   840
    if ([theEvent window]) {
9983
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   841
        NSRect windowRect = [[[theEvent window] contentView] frame];
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   842
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   843
        /* add one to size, since NSPointInRect is exclusive of the bottom
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   844
           edges, which mean it misses the top of the window by one pixel
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   845
           (as the origin is the bottom left). */
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   846
        windowRect.size.width += 1;
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   847
        windowRect.size.height += 1;
bbe9ef8c2ecb Mac: don't ignore mouse clicks on the top pixel of a window (thanks, Joshua!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9973
diff changeset
   848
9685
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   849
        if (!NSPointInRect([theEvent locationInWindow], windowRect)) {
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   850
            return;
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   851
        }
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   852
    }
525f13ccf27f Cocoa: ignore mouseDown events in a window's titlebar.
Ryan C. Gordon <icculus@icculus.org>
parents: 9679
diff changeset
   853
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   854
    if ([self processHitTest:theEvent]) {
10028
da668b612d10 Added SDL_WINDOWEVENT_HIT_TEST.
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   855
        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   856
        return;  /* dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   857
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   858
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   859
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   860
    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
   861
        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
   862
		    GetHintCtrlClickEmulateRightClick()) {
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   863
            wasCtrlLeft = YES;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   864
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   865
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   866
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   867
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   868
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   869
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   870
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   871
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   872
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   873
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   874
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   875
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   876
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   877
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   878
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   879
    }
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
   880
    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   881
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   882
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   883
- (void)rightMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   884
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   885
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   886
}
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
- (void)otherMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   889
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   890
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   891
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   892
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   893
- (void)mouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   894
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   895
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   896
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   897
    if ([self processHitTest:theEvent]) {
10028
da668b612d10 Added SDL_WINDOWEVENT_HIT_TEST.
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   898
        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   899
        return;  /* stopped dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   900
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   901
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   902
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   903
    case 0:
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   904
        if (wasCtrlLeft) {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   905
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   906
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   907
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   908
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   909
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   910
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   911
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   912
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   913
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   914
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   915
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   916
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   917
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   918
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   919
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   920
    }
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
   921
    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   922
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
- (void)rightMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   925
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   926
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   927
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   928
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   929
- (void)otherMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   930
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   931
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   932
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   934
- (void)mouseMoved:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   935
{
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   936
    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
   937
    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
   938
    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
   939
    int x, y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   940
8935
9d2f0236322b Changed drag area API to a hit-testing API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8931
diff changeset
   941
    if ([self processHitTest:theEvent]) {
10028
da668b612d10 Added SDL_WINDOWEVENT_HIT_TEST.
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   942
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
8931
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   943
        return;  /* dragging, drop event. */
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   944
    }
44d8a2f4b431 First shot at SDL_SetWindowDragAreas().
Ryan C. Gordon <icculus@icculus.org>
parents: 8929
diff changeset
   945
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   946
    if (mouse->relative_mode) {
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   947
        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
   948
    }
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   949
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
   950
    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
   951
    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
   952
    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
   953
8929
7b459b49fa92 Flip this around to do the simpler condition first.
Ryan C. Gordon <icculus@icculus.org>
parents: 8738
diff changeset
   954
    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
   955
        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
   956
            if (x < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   957
                x = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   958
            } else if (x >= window->w) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   959
                x = window->w - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   960
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   961
            if (y < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   962
                y = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   963
            } else if (y >= window->h) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   964
                y = window->h - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   965
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   966
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   967
#if !SDL_MAC_NO_SANDBOX
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   968
            CGPoint cgpoint;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   969
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   970
            /* 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
   971
             * 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
   972
             */
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   973
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   974
            cgpoint.x = window->x + x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   975
            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
   976
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   977
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
10158
941261e0db9f Mac: replaced a deprecated CGSetLocalEventsSuppressionInterval call that I missed in commit f0645cd8fd39
Alex Szpakowski <slime73@gmail.com>
parents: 10140
diff changeset
   978
            CGAssociateMouseAndMouseCursorPosition(YES);
8261
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   979
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   980
            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
   981
#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
   982
        }
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   983
    }
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
   984
    SDL_SendMouseMotion(window, 0, 0, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   985
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   986
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   987
- (void)mouseDragged:(NSEvent *)theEvent
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   988
{
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   989
    [self mouseMoved:theEvent];