src/video/cocoa/SDL_cocoawindow.m
author Ryan C. Gordon <icculus@icculus.org>
Sat, 24 May 2014 18:23:56 -0400
changeset 8929 7b459b49fa92
parent 8738 354dabd2cb58
child 8931 44d8a2f4b431
permissions -rw-r--r--
Flip this around to do the simpler condition first.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8111
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     7
  arising from the use of this software.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    11
  freely, subject to the following restrictions:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5502
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8083
diff changeset
    21
#include "../../SDL_internal.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5873
diff changeset
    23
#if SDL_VIDEO_DRIVER_COCOA
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5873
diff changeset
    24
8083
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    25
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    26
# error SDL for Mac OS X must be built with a 10.7 SDK or above.
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    27
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
3782a12331d6 Bump SDL to build with 10.7 SDK.
Sam Lantinga <slouken@libsdl.org>
parents: 7990
diff changeset
    28
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_syswm.h"
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
    30
#include "SDL_timer.h"  /* For SDL_GetTicks() */
7915
86ad156a82ab Added SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK hint which controls whether ctrl+click should emulate a right click on OSX.
Sam Lantinga <slouken@libsdl.org>
parents: 7873
diff changeset
    31
#include "SDL_hints.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../SDL_sysvideo.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "../../events/SDL_keyboard_c.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "../../events/SDL_mouse_c.h"
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
    35
#include "../../events/SDL_touch_c.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "../../events/SDL_windowevents_c.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_cocoavideo.h"
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 3688
diff changeset
    38
#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
    39
#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
    40
#include "SDL_cocoaopengl.h"
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
    41
#include "SDL_assert.h"
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
8261
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    43
/* #define DEBUG_COCOAWINDOW */
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    44
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    45
#ifdef DEBUG_COCOAWINDOW
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    46
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    47
#else
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    48
#define DLog(...) do { } while (0)
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    49
#endif
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    50
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
    51
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    52
@interface SDLWindow : NSWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    53
/* These are needed for borderless/fullscreen windows */
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    54
- (BOOL)canBecomeKeyWindow;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    55
- (BOOL)canBecomeMainWindow;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    56
- (void)sendEvent:(NSEvent *)event;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    57
@end
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    58
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    59
@implementation SDLWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    60
- (BOOL)canBecomeKeyWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    61
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    62
    return YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    63
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    64
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    65
- (BOOL)canBecomeMainWindow
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    66
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    67
    return YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    68
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    69
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    70
- (void)sendEvent:(NSEvent *)event
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    71
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    72
  [super sendEvent:event];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    73
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    74
  if ([event type] != NSLeftMouseUp) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    75
      return;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    76
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    77
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    78
  id delegate = [self delegate];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    79
  if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    80
      return;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    81
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    82
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    83
  if ([delegate isMoving]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    84
      [delegate windowDidFinishMoving];
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    85
  }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    86
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    87
@end
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    88
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
    89
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
    90
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
    91
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
    92
static void ConvertNSRect(NSScreen *screen, NSRect *r)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
{
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
    94
    NSRect visibleScreen = [screen visibleFrame];
8738
354dabd2cb58 Mac: Correct the y-axis position after 94af945dbb57
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8729
diff changeset
    95
    r->origin.y = (visibleScreen.origin.y + visibleScreen.size.height) - r->origin.y - r->size.height;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    98
static void
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
    99
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
   100
{
8258
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   101
    NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   102
    NSMutableArray *contexts = data->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   103
    @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   104
        for (SDLOpenGLContext *context in contexts) {
8258
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   105
            if (context == currentContext) {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   106
                [context update];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   107
            } else {
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   108
                [context scheduleUpdate];
569354dec4e9 Mac: Immediately update current OpenGL context's shape.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8149
diff changeset
   109
            }
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   110
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   111
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   112
}
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   113
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   114
static int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   115
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
   116
{
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
   117
	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
   118
	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
   119
}
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
   120
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   121
static unsigned int
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   122
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
   123
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   124
    unsigned int style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   125
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   126
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   127
        style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   128
    } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   129
        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
   130
            style = NSBorderlessWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   131
        } else {
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   132
            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
   133
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   134
        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
   135
            style |= NSResizableWindowMask;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   136
        }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   137
    }
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   138
    return style;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   139
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   140
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
   141
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
   142
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
   143
{
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
   144
    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
   145
    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
   146
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
   147
    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
   148
        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
   149
    }
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
   150
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
   151
    /* 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
   152
    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
   153
        [[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
   154
    }
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
   155
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
   156
    [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
   157
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
   158
    /* 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
   159
    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
   160
        [[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
   161
    }
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
   162
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
   163
    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
   164
}
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
   165
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   166
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
@implementation Cocoa_WindowListener
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
- (void)listen:(SDL_WindowData *)data
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
    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
   172
    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
   173
    NSView *view = [window contentView];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    _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
   176
    observingVisible = YES;
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   177
    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
   178
    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
   179
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   180
    inFullscreenTransition = NO;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   181
    pendingWindowOperation = PENDING_OPERATION_NONE;
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   182
    isMoving = NO;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   186
    if ([window delegate] != nil) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   187
        [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
   188
        [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
   189
        [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
   190
        [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
   191
        [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
   192
        [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
   193
        [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   194
        [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
   195
        [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
   196
        [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
   197
        [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   198
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   199
        [window setDelegate:self];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   200
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   202
    /* 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
   203
     * 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
   204
     * 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
   205
     */
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   206
    [window addObserver:self
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   207
             forKeyPath:@"visible"
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   208
                options:NSKeyValueObservingOptionNew
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   209
                context:NULL];
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   210
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
   211
    [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
   212
    [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
   213
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
   214
    [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
   215
f3c34d321289 Don't call -[NSView setAcceptsTouchEvents] if the OS doesn't provide it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   216
    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
   217
        [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
   218
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   221
- (void)observeValueForKeyPath:(NSString *)keyPath
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   222
                      ofObject:(id)object
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   223
                        change:(NSDictionary *)change
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   224
                       context:(void *)context
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   225
{
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   226
    if (!observingVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   227
        return;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   228
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   229
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   230
    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
   231
        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
   232
        if (newVisibility) {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   233
            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
   234
        } else {
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   235
            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
   236
        }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   237
    }
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   238
}
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   239
7087
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   240
-(void) pauseVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   241
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   242
    observingVisible = NO;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   243
    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
   244
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   245
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   246
-(void) resumeVisibleObservation
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   247
{
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   248
    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
   249
    observingVisible = YES;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   250
    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
   251
        if (isVisible) {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   252
            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
   253
        } else {
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   254
            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
   255
        }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   256
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   257
        wasVisible = isVisible;
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   258
    }
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   259
}
5639ac726076 Fix Mac crash when creating fullscreen window introduced in 9d43403e9fc5.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7085
diff changeset
   260
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   261
-(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
   262
{
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   263
    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
   264
    NSWindow *nswindow = _data->nswindow;
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   265
    SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   266
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   267
    if (!videodata->allow_spaces) {
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   268
        return NO;  /* Spaces are forcibly disabled. */
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   269
    } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
8292
2b0736ab4d5f Mac: only programmatically create Spaces if we're FULLSCREEN_DESKTOP.
Ryan C. Gordon <icculus@icculus.org>
parents: 8291
diff changeset
   270
        return NO;  /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   271
    } else if (state == isFullscreenSpace) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   272
        return YES;  /* already there. */
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   273
    }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   274
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   275
    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
   276
        if (state) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   277
            [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
   278
        } else {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   279
            [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
   280
        }
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   281
        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
   282
    }
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
   283
    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
   284
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   285
    /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   286
    [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   287
    [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
   288
    return YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   289
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   290
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
   291
-(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
   292
{
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
   293
    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
   294
}
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
   295
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
   296
-(BOOL) isInFullscreenSpaceTransition
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   297
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   298
    return inFullscreenTransition;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   299
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   300
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   301
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   302
{
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   303
    pendingWindowOperation = operation;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   304
}
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   305
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
- (void)close
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
    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
   309
    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
   310
    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
   311
    NSArray *windows = nil;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    center = [NSNotificationCenter defaultCenter];
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   315
    if ([window delegate] != self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   316
        [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
   317
        [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
   318
        [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
   319
        [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
   320
        [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
   321
        [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
   322
        [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   323
        [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
   324
        [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
   325
        [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
   326
        [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   327
    } else {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   328
        [window setDelegate:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   329
    }
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
   330
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   331
    [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
   332
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   333
    if ([window nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   334
        [window setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   335
    }
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   336
    if ([view nextResponder] == self) {
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   337
        [view setNextResponder:nil];
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
   338
    }
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
   339
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   340
    /* 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
   341
       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
   342
       !!! 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
   343
       !!! 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
   344
       !!! 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
   345
       !!! 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
   346
       !!! 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
   347
       !!! 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
   348
    */
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
   349
    windows = [NSApp orderedWindows];
8111
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   350
    for (NSWindow *win in windows)
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   351
    {
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   352
        if (win == window) {
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   353
            continue;
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   354
        }
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   355
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
   356
        [win makeKeyAndOrderFront:self];
8111
426e78ce52e4 Mac: Don't give windows focus back when we're closing them.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8106
diff changeset
   357
        break;
7534
f0f5143b27cf Cocoa: Make the next-highest window gain focus when a window is closing.
Ryan C. Gordon <icculus@icculus.org>
parents: 7507
diff changeset
   358
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   361
- (BOOL)isMoving
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   362
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   363
    return isMoving;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   364
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   365
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   366
-(void) setPendingMoveX:(int)x Y:(int)y
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   367
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   368
    pendingWindowWarpX = x;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   369
    pendingWindowWarpY = y;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   370
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   371
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   372
- (void)windowDidFinishMoving
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   373
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   374
    if ([self isMoving])
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   375
    {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   376
        isMoving = NO;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   377
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   378
        SDL_Mouse *mouse = SDL_GetMouse();
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   379
        if (pendingWindowWarpX >= 0 && pendingWindowWarpY >= 0) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   380
            mouse->WarpMouse(_data->window, pendingWindowWarpX, pendingWindowWarpY);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   381
            pendingWindowWarpX = pendingWindowWarpY = -1;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   382
        }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   383
        if (mouse->relative_mode && SDL_GetMouseFocus() == _data->window) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   384
            mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   385
        }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   386
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   387
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   388
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
- (BOOL)windowShouldClose:(id)sender
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
{
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
   391
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    return NO;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
- (void)windowDidExpose:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
{
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
   397
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   400
- (void)windowWillMove:(NSNotification *)aNotification
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   401
{
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   402
    if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   403
        pendingWindowWarpX = pendingWindowWarpY = -1;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   404
        isMoving = YES;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   405
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   406
}
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   407
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
- (void)windowDidMove:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
{
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
    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
   411
    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
   412
    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
   413
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
   414
    ConvertNSRect([nswindow screen], &rect);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   415
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   416
    if (s_moveHack) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   417
        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
   418
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   419
        s_moveHack = 0;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   420
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   421
        if (blockMove) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   422
            /* 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
   423
            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
   424
            rect.origin.y = window->y;
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
   425
            ConvertNSRect([nswindow screen], &rect);
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   426
            [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
   427
            return;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   428
        }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   429
    }
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   430
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
   431
    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
   432
    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
   433
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   434
    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
   435
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5396
diff changeset
   436
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
- (void)windowDidResize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
{
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   441
    if (inFullscreenTransition) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   442
        /* We'll take care of this at the end of the transition */
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   443
        return;
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   444
    }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   445
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   446
    SDL_Window *window = _data->window;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   447
    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
   448
    int x, y, w, h;
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   449
    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
   450
    ConvertNSRect([nswindow screen], &rect);
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   451
    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
   452
    y = (int)rect.origin.y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    w = (int)rect.size.width;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
    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
   455
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   456
    if (SDL_IsShapedWindow(window)) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   457
        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
   458
    }
5564
7ed38a8ad304 Cocoa: Update the current GL context when its window moves or resizes.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   459
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   460
    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
   461
6231
5eecf59b698f Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
Sam Lantinga <slouken@libsdl.org>
parents: 6185
diff changeset
   462
    /* 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
   463
       or resizing from a corner */
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   464
    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
   465
    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
   466
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   467
    const BOOL zoomed = [nswindow isZoomed];
7566
b14d00c30095 Some fixes for SDL_MaximizeWindow().
Ryan C. Gordon <icculus@icculus.org>
parents: 7535
diff changeset
   468
    if (!zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   469
        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
   470
    } else if (zoomed) {
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   471
        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
   472
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
- (void)windowDidMiniaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
{
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
   477
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
{
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
   482
    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
- (void)windowDidBecomeKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
{
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   487
    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
   488
    SDL_Mouse *mouse = SDL_GetMouse();
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   489
    if (mouse->relative_mode && ![self isMoving]) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   490
        mouse->SetRelativeMouseMode(SDL_TRUE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   491
    }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   492
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   493
    /* 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
   494
    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
   495
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   496
    /* 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
   497
    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
   498
        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
   499
        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
   500
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
   501
        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
   502
        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
   503
        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
   504
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
   505
        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
   506
            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
   507
        }
5367
71fe70373e58 Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
Sam Lantinga <slouken@libsdl.org>
parents: 5361
diff changeset
   508
    }
1962
c92e5f3e68d9 Hack to stop the beeping
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
   509
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
   510
    /* 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
   511
    Cocoa_CheckClipboardUpdate(_data->videodata);
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   512
8293
b96005b05c90 Mac: Don't lose the menu/dock when switching back to a resizable window Space.
Ryan C. Gordon <icculus@icculus.org>
parents: 8292
diff changeset
   513
    if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   514
        [NSMenu setMenuBarVisible:NO];
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   515
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
- (void)windowDidResignKey:(NSNotification *)aNotification
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
{
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   520
    SDL_Mouse *mouse = SDL_GetMouse();
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   521
    if (mouse->relative_mode) {
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   522
        mouse->SetRelativeMouseMode(SDL_FALSE);
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   523
    }
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   524
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   525
    /* 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
   526
    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
   527
        SDL_SetMouseFocus(NULL);
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   528
    }
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   529
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   530
    /* 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
   531
    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
   532
        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
   533
    }
8288
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   534
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   535
    if (isFullscreenSpace) {
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   536
        [NSMenu setMenuBarVisible:YES];
4e3afa79b8d8 Mac: Manage menubar and dock as FULLSCREEN_DESKTOP windows become/resign key.
Ryan C. Gordon <icculus@icculus.org>
parents: 8284
diff changeset
   537
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   540
- (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
   541
{
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   542
    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
   543
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
   544
    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
   545
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   546
    isFullscreenSpace = YES;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   547
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   548
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   549
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   550
- (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
   551
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   552
    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
   553
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   554
    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
   555
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   556
    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   557
        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
   558
        [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
   559
    } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   560
        if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   561
            [NSMenu setMenuBarVisible:NO];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   562
        }
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   563
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   564
        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
   565
        /* 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
   566
           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
   567
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   568
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   569
        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
   570
        [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
   571
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   572
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   573
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   574
- (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
   575
{
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   576
    SDL_Window *window = _data->window;
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   577
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
   578
    SetWindowStyle(window, GetWindowStyle(window));
7964
56431f7d8f46 Fixed window resizing when entering and leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7963
diff changeset
   579
7967
75f04553360a Fullscreen space naming cleanup to avoid confusion with normal fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 7966
diff changeset
   580
    isFullscreenSpace = NO;
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   581
    inFullscreenTransition = YES;
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   582
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   583
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   584
- (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
   585
{
7965
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   586
    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
   587
    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
   588
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   589
    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
   590
8618
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   591
    [nswindow setLevel:kCGNormalWindowLevel];
06ee748d59b2 Fixed Mac OS X window level when leaving fullscreen mode
Sam Lantinga <slouken@libsdl.org>
parents: 8295
diff changeset
   592
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   593
    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   594
        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
   595
        [self setFullscreenSpace:YES];
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   596
    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   597
        pendingWindowOperation = PENDING_OPERATION_NONE;
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   598
        [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
   599
    } else {
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   600
        /* Adjust the fullscreen toggle button and readd menu now that we're here. */
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   601
        if (window->flags & SDL_WINDOW_RESIZABLE) {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   602
            /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   603
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   604
        } else {
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   605
            [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   606
        }
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   607
        [NSMenu setMenuBarVisible:YES];
8284
a2910aa6c056 Reworked fullscreen policy on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 8261
diff changeset
   608
7963
f06bbd9cd708 Fixed assertion failure when minimizing a fullscreen window.
Sam Lantinga <slouken@libsdl.org>
parents: 7961
diff changeset
   609
        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
   610
        /* 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
   611
           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
   612
         */
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   613
        window->w = 0;
d3cbe8ecb1af Fixed assertion when quickly toggling from fullscreen back to fullscreen:
Sam Lantinga <slouken@libsdl.org>
parents: 7964
diff changeset
   614
        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
   615
        [self windowDidResize:aNotification];
8622
957fbefc8556 Mac: Make sure window is still showing when we exit a fullscreen space.
Ryan C. Gordon <icculus@icculus.org>
parents: 8618
diff changeset
   616
8623
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   617
        /* FIXME: Why does the window get hidden? */
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   618
        if (window->flags & SDL_WINDOW_SHOWN) {
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   619
            Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
b4eee818b6fd Only show the window if it's supposed to be shown.
Sam Lantinga <slouken@libsdl.org>
parents: 8622
diff changeset
   620
        }
7961
c629882e0a81 Properly handle toggling fullscreen state when another fullscreen state change is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 7955
diff changeset
   621
    }
7952
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   622
}
5ac1a895b313 Added support for new style fullscreen transitions on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7948
diff changeset
   623
8291
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   624
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   625
{
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   626
    if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   627
        return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   628
    } else {
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   629
        return proposedOptions;
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   630
    }
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   631
}
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   632
36f8cf82d308 A bunch of fixes for the new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8288
diff changeset
   633
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   634
/* 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
   635
 * 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
   636
 * 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
   637
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   638
- (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
   639
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   640
    /*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
   641
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   642
- (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
   643
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   644
    /*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
   645
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   646
- (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
   647
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   648
    /*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
   649
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   650
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   651
/* 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
   652
 * 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
   653
 */
6514
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   654
- (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
   655
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   656
    /*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
   657
}
e94c2eaaa1ab Fixed beeping introduced when we started passing key events through the responder chain.
Sam Lantinga <slouken@libsdl.org>
parents: 6489
diff changeset
   658
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
- (void)mouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   661
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   663
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   664
    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
   665
        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
   666
		    GetHintCtrlClickEmulateRightClick()) {
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   667
            wasCtrlLeft = YES;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   668
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   669
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   670
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   671
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   672
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   673
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   674
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   675
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   676
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   677
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   678
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   679
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   680
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   681
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   682
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   683
    }
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
   684
    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
- (void)rightMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   689
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
- (void)otherMouseDown:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   694
    [self mouseDown:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   695
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
- (void)mouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   699
    int button;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   701
    switch ([theEvent buttonNumber]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   702
    case 0:
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   703
        if (wasCtrlLeft) {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   704
            button = SDL_BUTTON_RIGHT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   705
            wasCtrlLeft = NO;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   706
        } else {
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   707
            button = SDL_BUTTON_LEFT;
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7636
diff changeset
   708
        }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   709
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   710
    case 1:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   711
        button = SDL_BUTTON_RIGHT;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   712
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   713
    case 2:
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   714
        button = SDL_BUTTON_MIDDLE;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   715
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   716
    default:
5061
9e9940eae455 Fixed mouse button index for additional mouse buttons
Sam Lantinga <slouken@libsdl.org>
parents: 5059
diff changeset
   717
        button = [theEvent buttonNumber] + 1;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   718
        break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   719
    }
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
   720
    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   721
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
- (void)rightMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   724
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   725
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   726
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   728
- (void)otherMouseUp:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
{
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1958
diff changeset
   730
    [self mouseUp:theEvent];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
- (void)mouseMoved:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
{
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   735
    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
   736
    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
   737
    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
   738
    int x, y;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   739
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   740
    if (mouse->relative_mode) {
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   741
        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
   742
    }
5059
00d1fef487c5 Fix double mouse motion in OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5057
diff changeset
   743
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
   744
    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
   745
    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
   746
    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
   747
8929
7b459b49fa92 Flip this around to do the simpler condition first.
Ryan C. Gordon <icculus@icculus.org>
parents: 8738
diff changeset
   748
    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
7b459b49fa92 Flip this around to do the simpler condition first.
Ryan C. Gordon <icculus@icculus.org>
parents: 8738
diff changeset
   749
        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
   750
            if (x < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   751
                x = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   752
            } else if (x >= window->w) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   753
                x = window->w - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   754
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   755
            if (y < 0) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   756
                y = 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   757
            } else if (y >= window->h) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   758
                y = window->h - 1;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   759
            }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   760
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   761
#if !SDL_MAC_NO_SANDBOX
8260
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   762
            CGPoint cgpoint;
028ed8da2524 Mac: Improve moving relative mode windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8258
diff changeset
   763
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   764
            /* 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
   765
             * 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
   766
             */
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   767
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   768
            cgpoint.x = window->x + x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   769
            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
   770
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   771
            /* 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
   772
             * 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
   773
             * 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
   774
             */
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   775
            CGSetLocalEventsSuppressionInterval(0.0);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
   776
            CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
7113
7b4b596b3cfb Mac: Don't supress mousemoves after warp.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7098
diff changeset
   777
            CGSetLocalEventsSuppressionInterval(0.25);
8261
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   778
841b66e4397a Mac: Redo cursor warp handling.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8260
diff changeset
   779
            Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
7593
20298a0d8631 Mac: Better mouse-grab if you define SDL_MAC_NO_SANDBOX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7566
diff changeset
   780
#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
   781
        }
2059
4685ccd33d0e Fixed mouse enter/leave events for a single window.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   782
    }
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
   783
    SDL_SendMouseMotion(window, 0, 0, x, y);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   784
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   786
- (void)mouseDragged:(NSEvent *)theEvent
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   787
{
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   788
    [self mouseMoved:theEvent];
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   789
}
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   790
1958
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   791
- (void)rightMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   792
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   793
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   794
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   795
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   796
- (void)otherMouseDragged:(NSEvent *)theEvent
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   797
{
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   798
    [self mouseMoved:theEvent];
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   799
}
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
   800
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
- (void)scrollWheel:(NSEvent *)theEvent
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   802
{
5057
bdff53ed6c8b Fix mouse wheel events in fullscreen mode for OS X
Jjgod Jiang <gzjjgod@gmail.com>
parents: 5056
diff changeset
   803
    Cocoa_HandleMouseWheel(_data->window, theEvent);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   806
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   807
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   808
    [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
   809
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   810
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   811
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   812
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   813
    [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
   814
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   815
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   816
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   817
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   818
    [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
   819
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   820
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   821
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   822
{
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   823
    [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
   824
}
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   825
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   826
- (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
   827
{
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   828
    NSSet *touches = 0;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   829
    NSEnumerator *enumerator;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   830
    NSTouch *touch;
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   831
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   832
    switch (type) {
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   833
        case COCOA_TOUCH_DOWN:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   834
            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   835
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   836
        case COCOA_TOUCH_UP:
8106
4e3e41b2cbfb Mac: Trigger SDL_FINGERUP for all touches.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8093
diff changeset
   837
            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
4e3e41b2cbfb Mac: Trigger SDL_FINGERUP for all touches.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8093
diff changeset
   838
            break;
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   839
        case COCOA_TOUCH_CANCELLED:
8106
4e3e41b2cbfb Mac: Trigger SDL_FINGERUP for all touches.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 8093
diff changeset
   840
            touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil];
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   841
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   842
        case COCOA_TOUCH_MOVE:
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   843
            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   844
            break;
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   845
    }
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   846
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   847
    enumerator = [touches objectEnumerator];
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   848
    touch = (NSTouch*)[enumerator nextObject];
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   849
    while (touch) {
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   850
        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
   851
        if (!SDL_GetTouch(touchId)) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   852
            if (SDL_AddTouch(touchId, "") < 0) {
4680
229529693289 Fixed sending motion and finger up events
Sam Lantinga <slouken@libsdl.org>
parents: 4679
diff changeset
   853
                return;
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   854
            }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7158
diff changeset
   855
        }
4687
257bdf117af8 Fixed so the origin of the touch events is the upper left.
Sam Lantinga <slouken@libsdl.org>
parents: 4680
diff changeset
   856
6953
b83579d7d19a Fix compiler warning in Cocoa touch code
Sam Lantinga <slouken@libsdl.org>
parents: 6951
diff changeset
   857
        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
   858
        float x = [touch normalizedPosition].x;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   859
        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
   860
        /* 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
   861
        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
   862
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   863
        switch (type) {
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   864
        case COCOA_TOUCH_DOWN:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   865
            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
   866
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   867
        case COCOA_TOUCH_UP:
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   868
        case COCOA_TOUCH_CANCELLED:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   869
            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
   870
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   871
        case COCOA_TOUCH_MOVE:
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   872
            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
   873
            break;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   874
        }
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6950
diff changeset
   875
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   876
        touch = (NSTouch*)[enumerator nextObject];
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4503
diff changeset
   877
    }
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   878
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   879
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   880
@end
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   881
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   882
@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
   883
5379
78c071fe4c37 We can defer window creation.
Sam Lantinga <slouken@libsdl.org>
parents: 5378
diff changeset
   884
/* 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
   885
- (void)rightMouseDown:(NSEvent *)theEvent;
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   886
@end
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   887
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   888
@implementation SDLView
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   889
- (void)rightMouseDown:(NSEvent *)theEvent
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   890
{
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
   891
    [[self nextResponder] rightMouseDown:theEvent];
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   892
}
7158
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   893
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   894
- (void)resetCursorRects
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   895
{
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   896
    [super resetCursorRects];
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   897
    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
   898
7270
76df5476a6ce Mac: Hide cursor in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7205
diff changeset
   899
    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
   900
        [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
   901
                     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
   902
    } else {
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   903
        [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
   904
                     cursor:[NSCursor invisibleCursor]];
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   905
    }
ff52fba70795 Mac: Use cursor rects instead of NSCursor hide/unhide.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7113
diff changeset
   906
}
4915
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   907
@end
834ce48a19c2 Fix right mouse event handling in Cocoa
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4902
diff changeset
   908
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   909
static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   910
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   911
{
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
   912
    NSAutoreleasePool *pool;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   913
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   914
    SDL_WindowData *data;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   915
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   916
    /* 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
   917
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   918
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6953
diff changeset
   919
        return SDL_OutOfMemory();
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   920
    }
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
   921
    data->window = window;
3688
6512cba48440 Fixed Cocoa and OpenGL builds
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   922
    data->nswindow = nswindow;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
    data->created = created;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1937
diff changeset
   924
    data->videodata = videodata;
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   925
    data->nscontexts = [[NSMutableArray alloc] init];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
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
   927
    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
   928
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
   929
    /* 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
   930
    data->listener = [[Cocoa_WindowListener alloc] init];
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   931
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
   932
    /* 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
   933
    {
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
   934
        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
8729
94af945dbb57 Mac: SDL_SetWindowPosition is now relative to the menubar.
Jørgen P. Tjernø <jorgenpt@gmail.com>
parents: 8652
diff changeset
   935
        ConvertNSRect([nswindow screen], &rect);
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
   936
        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
   937
        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
   938
        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
   939
        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
   940
    }
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
   941
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
   942
    /* 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
   943
    [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
   944
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
   945
    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
   946
        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
   947
    } 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
   948
        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
   949
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   950
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
   951
    {
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
   952
        unsigned int style = [nswindow styleMask];
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   953
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
   954
        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
   955
            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
   956
        } 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
   957
            window->flags &= ~SDL_WINDOW_BORDERLESS;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   958
        }
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
   959
        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
   960
            window->flags |= SDL_WINDOW_RESIZABLE;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   961
        } 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
   962
            window->flags &= ~SDL_WINDOW_RESIZABLE;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   963
        }
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
   964
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   965
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
   966
    /* 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
   967
    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
   968
        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
   969
    } 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
   970
        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
   971
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   972
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
   973
    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
   974
        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
   975
    } 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
   976
        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
   977
    }
7084
9d43403e9fc5 Properly reflect hidden/shown windows on OSX.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   978
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
   979
    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
   980
        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
   981
        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
   982
    }
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6788
diff changeset
   983
7085
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   984
    /* 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
   985
     * 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
   986
     */
152cc7ddfa57 Mac no longer loses OpenGL context when window is hidden.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7084
diff changeset
   987
    [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
   988
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
   989
    /* 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
   990
    [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
   991
    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
   992
    return 0;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   993
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   994
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   995
int
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   996
Cocoa_CreateWindow(_THIS, SDL_Window * window)
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   997
{
8295
56f7e38ff0bc Mac: Added a hint to opt-out of new Spaces code.
Ryan C. Gordon <icculus@icculus.org>
parents: 8294
diff changeset
   998
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
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
   999
    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
  1000
    NSWindow *nswindow;