src/video/cocoa/SDL_cocoawindow.m
author Sam Lantinga <slouken@libsdl.org>
Thu, 14 Nov 2013 22:26:49 -0800
changeset 7990 a05a48e493c0
parent 7970 6dc794be47aa
child 8083 3782a12331d6
permissions -rw-r--r--
Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register philhassey On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register. Steps to Reproduce: 1. Open a windowed window on OS/X. (With the border on.) 2. e.button.button will give values 1,2,3 depending on which mouse button I click. 3. Call SDL_SetWindowBordered to disable the border. 4. e.button.button will only give values 1,2. 3 (right mouse button) stops coming through. Expected result: I expect all mouse buttons to register.
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
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6848
diff changeset
     3
  Copyright (C) 1997-2013 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
*/
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
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
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#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
    26
#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
    27
#include "SDL_hints.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "../SDL_sysvideo.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "../../events/SDL_keyboard_c.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#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
    31
#include "../../events/SDL_touch_c.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../../events/SDL_windowevents_c.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_cocoavideo.h"
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 3688
diff changeset
    34
#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
    35
#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
    36
#include "SDL_cocoaopengl.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
7746
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    38
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    39
/* Taken from AppKit/NSOpenGLView.h in 10.8 SDK. */
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    40
@interface NSView (NSOpenGLSurfaceResolution)
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    41
- (BOOL)wantsBestResolutionOpenGLSurface;
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    42
- (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag;
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    43
@end
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
    44
#endif
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
    45
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
    46
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
    47
7771
4434498bf4b9 Fixed bug 2121 - GCC throws error on SDL_FORCE_INLINE when compiling with -ansi
Sam Lantinga <slouken@libsdl.org>
parents: 7746
diff changeset
    48
static void ConvertNSRect(NSRect *r)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    53
static void
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    54
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
    55
{
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    56
    NSMutableArray *contexts = data->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    57
    @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    58
        for (SDLOpenGLContext *context in contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    59
            [context scheduleUpdate];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    60
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    61
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    62
}
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    63
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    64
static int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    65
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
    66
{
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
    67
	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
    68
	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
    69
}
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
    70
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    71
static unsigned int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    72
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
    73
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    74
    unsigned int style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    75
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    76
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    77
        style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    78
    } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    79
        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
    80
            style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    81
        } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    82
            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
    83
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    84
        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
    85
            style |= NSResizableWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    86
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    87
    }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    88
    return style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    89
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    90
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
    91
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
    92
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
    93
{
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
    94
    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
    95
    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
    96
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
    97
    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
    98
        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
    99
    }
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
   100
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
   101
    /* 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
   102
    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
   103
        [[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
   104
    }
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
   105
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
   106
    [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
   107
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
   108
    /* 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
   109
    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
   110
        [[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
   111
    }
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
   112
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
   113
    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
   114
}
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
   115
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   116
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
@implementation Cocoa_WindowListener
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
- (void)listen:(SDL_WindowData *)data
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    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
   122
    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
   123
    NSView *view = [window contentView];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    _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
   126
    observingVisible = YES;
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   127
    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
   128
    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
   129
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   130
    inFullscreenTransition = NO;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   131
    pendingWindowOperation = PENDING_OPERATION_NONE;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   135
    if ([window delegate] != nil) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   136
        [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
   137
        [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
   138
        [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
   139
        [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
   140
        [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
   141
        [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
   142
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   143
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   144
        [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
   145
        [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
   146
        [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
   147
        [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   148
#endif /* Mac OS X 10.7+ */
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   149
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   150
        [window setDelegate:self];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   151
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   153
    /* 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
   154
     * 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
   155
     * 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
   156
     */
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   157
    [window addObserver:self
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   158
             forKeyPath:@"visible"
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   159
                options:NSKeyValueObservingOptionNew
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   160
                context:NULL];
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   161
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
   162
    [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
   163
    [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
   164
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
   165
    [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
   166
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   167
    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
   168
        [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
   169
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   172
- (void)observeValueForKeyPath:(NSString *)keyPath
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   173
                      ofObject:(id)object
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   174
                        change:(NSDictionary *)change
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   175
                       context:(void *)context
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   176
{
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   177
    if (!observingVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   178
        return;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   179
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   180
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   181
    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
   182
        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
   183
        if (newVisibility) {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   184
            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
   185
        } else {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   186
            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
   187
        }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   188
    }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   189
}
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   190
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   191
-(void) pauseVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   192
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   193
    observingVisible = NO;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   194
    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
   195
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   196
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   197
-(void) resumeVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   198
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   199
    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
   200
    observingVisible = YES;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   201
    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
   202
        if (isVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   203
            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
   204
        } else {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   205
            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
   206
        }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   207
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   208
        wasVisible = isVisible;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   209
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   210
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   211
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   212
-(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
   213
{
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   214
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   215
    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
   216
    NSWindow *nswindow = _data->nswindow;
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   217
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   218
    if (![nswindow respondsToSelector: @selector(collectionBehavior)]) {
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   219
        return NO;
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   220
    }
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   221
    if ([nswindow collectionBehavior] != NSWindowCollectionBehaviorFullScreenPrimary) {
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   222
        return NO;
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   223
    }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   224
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   225
    if (state == isFullscreenSpace) {
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   226
        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
   227
    }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   228
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   229
    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
   230
        if (state) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   231
            [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
   232
        } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   233
            [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
   234
        }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   235
        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
   236
    }
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
   237
    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
   238
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
   239
    /* Update the flags here so the state change is available immediately */
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
   240
    if (state) {
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
   241
        window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
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
   242
    } else {
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
   243
        window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
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
   244
    }
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   245
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   246
    [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
   247
    return YES;
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   248
#else
7970
6dc794be47aa Fixed build error with SDK < 10.7
Sam Lantinga <slouken@libsdl.org>
parents: 7969
diff changeset
   249
    return NO;
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   250
#endif /* SDK >= 10.7 */
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   251
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   252
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
   253
-(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
   254
{
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
   255
    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
   256
}
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
   257
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
   258
-(BOOL) isInFullscreenSpaceTransition
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   259
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   260
    return inFullscreenTransition;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   261
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   262
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   263
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   264
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   265
    pendingWindowOperation = operation;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   266
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   267
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
- (void)close
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    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
   271
    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
   272
    NSView *view = [window contentView];
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   273
    NSArray *windows = nil;
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
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   277
    if ([window delegate] != self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   278
        [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
   279
        [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
   280
        [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
   281
        [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
   282
        [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
   283
        [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
   284
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   285
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   286
        [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
   287
        [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
   288
        [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
   289
        [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   290
#endif /* Mac OS X 10.7+ */
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   291
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   292
        [window setDelegate:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   293
    }
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
   294
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   295
    [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
   296
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   297
    if ([window nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   298
        [window setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   299
    }
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   300
    if ([view nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   301
        [view setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   302
    }
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   303
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   304
    /* Make the next window in the z-order Key. If we weren't the foreground
7535
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   305
       when closed, this is a no-op.
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   306
       !!! FIXME: Note that this is a hack, and there are corner cases where
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   307
       !!! FIXME:  this fails (such as the About box). The typical nib+RunLoop
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   308
       !!! FIXME:  handles this for Cocoa apps, but we bypass all that in SDL.
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   309
       !!! FIXME:  We should remove this code when we find a better way to
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   310
       !!! FIXME:  have the system do this for us. See discussion in
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   311
       !!! FIXME:   http://bugzilla.libsdl.org/show_bug.cgi?id=1825
c515121a3df7 Added a FIXME discussion to last commit.
Ryan C. Gordon <icculus@icculus.org>
parents: 7534
diff changeset
   312
    */
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   313
    windows = [NSApp orderedWindows];
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   314
    if ([windows count] > 0) {
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   315
        NSWindow *win = (NSWindow *) [windows objectAtIndex:0];
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   316
        [win makeKeyAndOrderFront:self];
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   317
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
- (BOOL)windowShouldClose:(id)sender
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
{
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
   322
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    return NO;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
- (void)windowDidExpose:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
{
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
   328
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
- (void)windowDidMove:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    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
   334
    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
   335
    NSWindow *nswindow = _data->nswindow;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   336
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    ConvertNSRect(&rect);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   338
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   339
    if (s_moveHack) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   340
        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
   341
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   342
        s_moveHack = 0;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   343
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   344
        if (blockMove) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   345
            /* 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
   346
            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
   347
            rect.origin.y = window->y;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   348
            ConvertNSRect(&rect);
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   349
            [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
   350
            return;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   351
        }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   352
    }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   353
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
   354
    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
   355
    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
   356
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   357
    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
   358
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   359
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
- (void)windowDidResize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
{
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   364
    SDL_Window *window = _data->window;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   365
    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
   366
    int x, y, w, h;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   367
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   368
    ConvertNSRect(&rect);
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   369
    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
   370
    y = (int)rect.origin.y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
    w = (int)rect.size.width;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    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
   373
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   374
    if (inFullscreenTransition) {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   375
        /* We'll take care of this at the end of the transition */
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   376
        return;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   377
    }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   378
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   379
    if (SDL_IsShapedWindow(window)) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   380
        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
   381
    }
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   382
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   383
    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
   384
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   385
    /* 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
   386
       or resizing from a corner */
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   387
    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
   388
    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
   389
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   390
    const BOOL zoomed = [nswindow isZoomed];
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   391
    if (!zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   392
        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
   393
    } else if (zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   394
        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
   395
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
- (void)windowDidMiniaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
{
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
   400
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
{
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
   405
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
- (void)windowDidBecomeKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
{
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   410
    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
   411
    SDL_Mouse *mouse = SDL_GetMouse();
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   412
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   413
    /* We're going to get keyboard events, since we're key. */
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   414
    SDL_SetKeyboardFocus(window);
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   415
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   416
    /* 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
   417
    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
   418
        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
   419
        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
   420
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
   421
        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
   422
        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
   423
        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
   424
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
   425
        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
   426
            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
   427
        }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   428
    }
1962
c92e5f3e68d9 Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
   429
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
   430
    /* 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
   431
    Cocoa_CheckClipboardUpdate(_data->videodata);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
- (void)windowDidResignKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
{
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   436
    /* 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
   437
    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
   438
        SDL_SetMouseFocus(NULL);
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   439
    }
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   440
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   441
    /* 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
   442
    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
   443
        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
   444
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   447
- (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
   448
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   449
    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
   450
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
   451
    window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
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
   452
    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
   453
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   454
    isFullscreenSpace = YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   455
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   456
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   457
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   458
- (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
   459
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   460
    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
   461
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   462
    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
   463
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   464
    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   465
        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
   466
        [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
   467
    } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   468
        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
   469
        /* 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
   470
           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
   471
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   472
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   473
        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
   474
        [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
   475
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   476
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   477
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   478
- (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
   479
{
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   480
    SDL_Window *window = _data->window;
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   481
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
   482
    window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
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
   483
    SetWindowStyle(window, GetWindowStyle(window));
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   484
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   485
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   486
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   487
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   488
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   489
- (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
   490
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   491
    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
   492
    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
   493
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   494
    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
   495
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   496
    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   497
        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
   498
        [self setFullscreenSpace:YES];
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   499
    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   500
        pendingWindowOperation = PENDING_OPERATION_NONE;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   501
        [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
   502
    } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   503
        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
   504
        /* 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
   505
           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
   506
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   507
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   508
        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
   509
        [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
   510
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   511
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   512
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   513
/* 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
   514
 * 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
   515
 * 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
   516
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   517
- (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
   518
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   519
    /*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
   520
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   521
- (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
   522
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   523
    /*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
   524
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   525
- (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
   526
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   527
    /*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
   528
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   529
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   530
/* 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
   531
 * 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
   532
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   533
- (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
   534
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   535
    /*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
   536
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   537
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
- (void)mouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   540
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   542
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   543
    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
   544
        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
   545
		    GetHintCtrlClickEmulateRightClick()) {
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   546
            wasCtrlLeft = YES;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   547
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   548
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   549
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   550
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   551
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   552
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   553
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   554
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   555
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   556
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   557
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   558
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   559
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   560
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   561
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   562
    }
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
   563
    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
- (void)rightMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   568
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
- (void)otherMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   573
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
- (void)mouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   578
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   580
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   581
    case 0:
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   582
        if (wasCtrlLeft) {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   583
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   584
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   585
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   586
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   587
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   588
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   589
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   590
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   591
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   592
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   593
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   594
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   595
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   596
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   597
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   598
    }
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
   599
    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
- (void)rightMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   604
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
- (void)otherMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   609
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
- (void)mouseMoved:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
{
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   614
    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
   615
    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
   616
    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
   617
    int x, y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   619
    if (mouse->relative_mode) {
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   620
        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
   621
    }
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   622
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
   623
    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
   624
    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
   625
    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
   626
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
   627
    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
   628
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   629
            CGPoint cgpoint;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   630
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   631
            if (x < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   632
                x = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   633
            } else if (x >= window->w) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   634
                x = window->w - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   635
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   636
            if (y < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   637
                y = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   638
            } else if (y >= window->h) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   639
                y = window->h - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   640
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   641
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   642
#if !SDL_MAC_NO_SANDBOX
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   643
            /* 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
   644
             * 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
   645
             */
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   646
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   647
            cgpoint.x = window->x + x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   648
            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
   649
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   650
            /* According to the docs, this was deprecated in 10.6, but it's still
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   651
             * around. The substitute requires a CGEventSource, but I'm not entirely
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   652
             * sure how we'd procure the right one for this event.
7098
f4b2c6fb0258 Mac: Make mouse movement smooth at edge of window when grabbed.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7087
diff changeset
   653
             */
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   654
            CGSetLocalEventsSuppressionInterval(0.0);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   655
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   656
            CGSetLocalEventsSuppressionInterval(0.25);
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   657
#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
   658
        }
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   659
    }
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
   660
    SDL_SendMouseMotion(window, 0, 0, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   663
- (void)mouseDragged:(NSEvent *)theEvent
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   664
{
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   665
    [self mouseMoved:theEvent];
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   666
}
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   667
1958
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   668
- (void)rightMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   669
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   670
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   671
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   672
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   673
- (void)otherMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   674
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   675
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   676
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   677
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
- (void)scrollWheel:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
{
5057
bdff53ed6c8b Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5056
diff changeset
   680
    Cocoa_HandleMouseWheel(_data->window, theEvent);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   683
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   684
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   685
    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   686
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   687
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   688
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   689
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   690
    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   691
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   692
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   693
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   694
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   695
    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   696
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   697
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   698
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   699
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   700
    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   701
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   702
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   703
- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   704
{
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   705
    NSSet *touches = 0;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   706
    NSEnumerator *enumerator;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   707
    NSTouch *touch;
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   708
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   709
    switch (type) {
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   710
        case COCOA_TOUCH_DOWN:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   711
            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   712
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   713
        case COCOA_TOUCH_UP:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   714
        case COCOA_TOUCH_CANCELLED:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   715
            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   716
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   717
        case COCOA_TOUCH_MOVE:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   718
            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   719
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   720
    }
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   721
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   722
    enumerator = [touches objectEnumerator];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   723
    touch = (NSTouch*)[enumerator nextObject];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   724
    while (touch) {
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   725
        const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   726
        if (!SDL_GetTouch(touchId)) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   727
            if (SDL_AddTouch(touchId, "") < 0) {
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   728
                return;
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   729
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   730
        }
4687
257bdf117af8 Fixed so the origin of the touch events is the upper left.
Sam Lantinga <slouken@libsdl.org>
parents: 4680
diff changeset
   731
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   732
        const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   733
        float x = [touch normalizedPosition].x;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   734
        float y = [touch normalizedPosition].y;
5261
595814f561f7 There is only one width and height for the window. If those are changed during the course of a fullscreen mode change, then they'll stay that size when returning to windowed mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5253
diff changeset
   735
        /* Make the origin the upper left instead of the lower left */
595814f561f7 There is only one width and height for the window. If those are changed during the course of a fullscreen mode change, then they'll stay that size when returning to windowed mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5253
diff changeset
   736
        y = 1.0f - y;
4687
257bdf117af8 Fixed so the origin of the touch events is the upper left.
Sam Lantinga <slouken@libsdl.org>
parents: 4680
diff changeset
   737
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   738
        switch (type) {
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   739
        case COCOA_TOUCH_DOWN:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   740
            SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   741
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   742
        case COCOA_TOUCH_UP:
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   743
        case COCOA_TOUCH_CANCELLED:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   744
            SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   745
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   746
        case COCOA_TOUCH_MOVE:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   747
            SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   748
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   749
        }
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   750
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   751
        touch = (NSTouch*)[enumerator nextObject];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   752
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
@end
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   757
@interface SDLWindow : NSWindow
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   758
/* These are needed for borderless/fullscreen windows */
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   759
- (BOOL)canBecomeKeyWindow;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   760
- (BOOL)canBecomeMainWindow;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   761
@end
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   762
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   763
@implementation SDLWindow
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   764
- (BOOL)canBecomeKeyWindow
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   765
{
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   766
    return YES;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   767
}
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   768
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   769
- (BOOL)canBecomeMainWindow
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   770
{
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   771
    return YES;
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   772
}
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   773
@end
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1962
diff changeset
   774
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   775
@interface SDLView : NSView
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   776
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   777
/* The default implementation doesn't pass rightMouseDown to responder chain */
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   778
- (void)rightMouseDown:(NSEvent *)theEvent;
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   779
@end
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   780
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   781
@implementation SDLView
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   782
- (void)rightMouseDown:(NSEvent *)theEvent
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   783
{
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
   784
    [[self nextResponder] rightMouseDown:theEvent];
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   785
}
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   786
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   787
- (void)resetCursorRects
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   788
{
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   789
    [super resetCursorRects];
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   790
    SDL_Mouse *mouse = SDL_GetMouse();
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   791
7270
76df5476a6ce Mac: Hide cursor in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7205
diff changeset
   792
    if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   793
        [self addCursorRect:[self bounds]
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   794
                     cursor:mouse->cur_cursor->driverdata];
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   795
    } else {
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   796
        [self addCursorRect:[self bounds]
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   797
                     cursor:[NSCursor invisibleCursor]];
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   798
    }
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   799
}
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   800
@end
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   801
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   803
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   805
    NSAutoreleasePool *pool;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   806
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
    SDL_WindowData *data;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   808
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   809
    /* Allocate the window data */
5249
7a963be087ef Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
   810
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6953
diff changeset
   812
        return SDL_OutOfMemory();
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
    }
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
   814
    data->window = window;
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   815
    data->nswindow = nswindow;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   816
    data->created = created;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   817
    data->videodata = videodata;
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   818
    data->nscontexts = [[NSMutableArray alloc] init];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   819
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   820
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   821
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   822
    /* Create an event listener for the window */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   823
    data->listener = [[Cocoa_WindowListener alloc] init];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   824
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   825
    /* Fill in the SDL window with the window data */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   826
    {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   827
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   828
        ConvertNSRect(&rect);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   829
        window->x = (int)rect.origin.x;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   830
        window->y = (int)rect.origin.y;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   831
        window->w = (int)rect.size.width;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   832
        window->h = (int)rect.size.height;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   833
    }
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
   834
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   835
    /* Set up the listener after we create the view */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   836
    [data->listener listen:data];
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
   837
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   838
    if ([nswindow isVisible]) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   839
        window->flags |= SDL_WINDOW_SHOWN;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   840
    } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   841
        window->flags &= ~SDL_WINDOW_SHOWN;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   842
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   843
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   844
    {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   845
        unsigned int style = [nswindow styleMask];
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   846
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   847
        if (style == NSBorderlessWindowMask) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   848
            window->flags |= SDL_WINDOW_BORDERLESS;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   849
        } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   850
            window->flags &= ~SDL_WINDOW_BORDERLESS;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   851
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   852
        if (style & NSResizableWindowMask) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   853
            window->flags |= SDL_WINDOW_RESIZABLE;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   854
        } else {
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   855
            window->flags &= ~SDL_WINDOW_RESIZABLE;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   856
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   857
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   858
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   859
    /* isZoomed always returns true if the window is not resizable */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   860
    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   861
        window->flags |= SDL_WINDOW_MAXIMIZED;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   862
    } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   863
        window->flags &= ~SDL_WINDOW_MAXIMIZED;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   864
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   865
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   866
    if ([nswindow isMiniaturized]) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   867
        window->flags |= SDL_WINDOW_MINIMIZED;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   868
    } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   869
        window->flags &= ~SDL_WINDOW_MINIMIZED;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   870
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   871
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   872
    if ([nswindow isKeyWindow]) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   873
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   874
        SDL_SetKeyboardFocus(data->window);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   875
    }
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   876
7085
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   877
    /* Prevents the window's "window device" from being destroyed when it is
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   878
     * hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   879
     */
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   880
    [nswindow setOneShot:NO];
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   881
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   882
    /* All done! */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   883
    [pool release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   884
    window->driverdata = data;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   885
    return 0;
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
int
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   889
Cocoa_CreateWindow(_THIS, SDL_Window * window)
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   890
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   891
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   892
    NSWindow *nswindow;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   893
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   894
    NSRect rect;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   895
    SDL_Rect bounds;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   896
    unsigned int style;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   897
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   898
    Cocoa_GetDisplayBounds(_this, display, &bounds);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   899
    rect.origin.x = window->x;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   900
    rect.origin.y = window->y;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   901
    rect.size.width = window->w;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   902
    rect.size.height = window->h;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   903
    ConvertNSRect(&rect);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   904
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   905
    style = GetWindowStyle(window);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   906
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   907
    /* Figure out which screen to place this window */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   908
    NSArray *screens = [NSScreen screens];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   909
    NSScreen *screen = nil;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   910
    NSScreen *candidate;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   911
    int i, count = [screens count];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   912
    for (i = 0; i < count; ++i) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   913
        candidate = [screens objectAtIndex:i];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   914
        NSRect screenRect = [candidate frame];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   915
        if (rect.origin.x >= screenRect.origin.x &&
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   916
            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   917
            rect.origin.y >= screenRect.origin.y &&
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   918
            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   919
            screen = candidate;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   920
            rect.origin.x -= screenRect.origin.x;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   921
            rect.origin.y -= screenRect.origin.y;
3506
e829b6098435 Added support for placing windows on different displays
Sam Lantinga <slouken@libsdl.org>
parents: 3414
diff changeset
   922
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   923
    }
7946
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   924
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   925
    @try {
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   926
        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   927
    }
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   928
    @catch (NSException *e) {
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   929
        SDL_SetError("%s", [[e reason] UTF8String]);
7948
64e133a8b15e Fixed pool memory leak
Sam Lantinga <slouken@libsdl.org>
parents: 7946
diff changeset
   930
        [pool release];
7946
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   931
        return -1;
57c34a54b7c2 Fixed bug 2176 - SDL_CreateWindow(w=INT_MAX, h=INT_MAX) causes program to hang
Sam Lantinga <slouken@libsdl.org>
parents: 7915
diff changeset
   932
    }
7205
b1ca5be78064 Patched to compile on older Mac OS X devtools (thanks, D B!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7202
diff changeset
   933
    [nswindow setBackgroundColor:[NSColor blackColor]];
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   934
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   935
    if ([nswindow respondsToSelector:@selector(setCollectionBehavior:)]) {
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
   936
        const char *hint = SDL_GetHint(SDL_HINT_VIDEO_FULLSCREEN_SPACES);
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
   937
        if (hint && SDL_atoi(hint) > 0) {
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
   938
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
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
   939
        }
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   940
    }
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   941
#endif
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   942
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   943
    /* Create a default view for this window */
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   944
    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   945
    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
7746
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   946
7955
9446f2fbe4f0 Fixed compiling with older Mac OS X SDK
Sam Lantinga <slouken@libsdl.org>
parents: 7952
diff changeset
   947
    if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
7746
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   948
        if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   949
            [contentView setWantsBestResolutionOpenGLSurface:YES];
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   950
        }
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   951
    }
6a05d7352575 add in High DPI support (aka Retina)
Edward Rudd <urkle@outoforder.cc>
parents: 7740
diff changeset
   952
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   953
    [nswindow setContentView: contentView];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   954
    [contentView release];
6489
31449ea8f934 Fixed bug 1496 - SDLView not created for a Cocoa window, resulting in missing right mouse clicks
Sam Lantinga <slouken@libsdl.org>
parents: 6426
diff changeset
   955
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   956
    [pool release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   957
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   958
    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   959
        [nswindow release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   960
        return -1;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
    }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   962
    return 0;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   963
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   964
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   965
int
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   966
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   968
    NSAutoreleasePool *pool;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   969
    NSWindow *nswindow = (NSWindow *) data;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   970
    NSString *title;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   971
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   972
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   973
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   974
    /* Query the title from the existing window */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   975
    title = [nswindow title];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   976
    if (title) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   977
        window->title = SDL_strdup([title UTF8String]);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   978
    }
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   979
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   980
    [pool release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   981
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   982
    return SetupWindowData(_this, window, nswindow, SDL_FALSE);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   983
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   984
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   985
void
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   986
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   987
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   988
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   989
    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   990
    NSString *string;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   991
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   992
    if(window->title) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   993
        string = [[NSString alloc] initWithUTF8String:window->title];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   994
    } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   995
        string = [[NSString alloc] init];
1956
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   996
    }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   997
    [nswindow setTitle:string];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   998
    [string release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   999
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
  1000
    [pool release];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1001
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1002
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1003
void
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5374
diff changeset
  1004
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5374
diff changeset
  1005
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: