2006-07-24 05:03:02 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2015-05-26 06:27:46 -07:00
|
|
|
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2006-07-24 05:03:02 +00:00
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../../SDL_internal.h"
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_COCOA
|
|
|
|
|
2013-12-27 10:18:11 -08:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
|
|
|
# error SDL for Mac OS X must be built with a 10.7 SDK or above.
|
|
|
|
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
#include "SDL_syswm.h"
|
2011-02-26 10:11:09 -08:00
|
|
|
#include "SDL_timer.h" /* For SDL_GetTicks() */
|
2013-11-08 14:04:51 -08:00
|
|
|
#include "SDL_hints.h"
|
2006-07-24 05:03:02 +00:00
|
|
|
#include "../SDL_sysvideo.h"
|
|
|
|
#include "../../events/SDL_keyboard_c.h"
|
|
|
|
#include "../../events/SDL_mouse_c.h"
|
2010-07-28 23:32:13 -07:00
|
|
|
#include "../../events/SDL_touch_c.h"
|
2006-07-24 05:03:02 +00:00
|
|
|
#include "../../events/SDL_windowevents_c.h"
|
2014-11-24 11:46:20 -08:00
|
|
|
#include "../../events/SDL_dropevents_c.h"
|
2006-07-24 05:03:02 +00:00
|
|
|
#include "SDL_cocoavideo.h"
|
2010-07-26 21:48:53 -04:00
|
|
|
#include "SDL_cocoashape.h"
|
2011-01-21 00:15:18 +01:00
|
|
|
#include "SDL_cocoamouse.h"
|
2013-08-07 16:29:21 -07:00
|
|
|
#include "SDL_cocoaopengl.h"
|
2014-03-03 21:25:16 -05:00
|
|
|
#include "SDL_assert.h"
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2014-02-26 11:35:02 -08:00
|
|
|
/* #define DEBUG_COCOAWINDOW */
|
|
|
|
|
|
|
|
#ifdef DEBUG_COCOAWINDOW
|
|
|
|
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DLog(...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-06-02 09:09:40 -07:00
|
|
|
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
|
|
|
|
|
|
|
|
|
2014-11-24 11:46:20 -08:00
|
|
|
@interface SDLWindow : NSWindow <NSDraggingDestination>
|
2014-02-25 17:27:41 -08:00
|
|
|
/* These are needed for borderless/fullscreen windows */
|
|
|
|
- (BOOL)canBecomeKeyWindow;
|
|
|
|
- (BOOL)canBecomeMainWindow;
|
|
|
|
- (void)sendEvent:(NSEvent *)event;
|
2014-06-04 01:56:14 -07:00
|
|
|
- (void)doCommandBySelector:(SEL)aSelector;
|
2014-11-24 11:46:20 -08:00
|
|
|
|
|
|
|
/* Handle drag-and-drop of files onto the SDL window. */
|
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
|
|
|
|
- (BOOL)wantsPeriodicDraggingUpdates;
|
2014-02-25 17:27:41 -08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SDLWindow
|
2014-11-24 11:46:20 -08:00
|
|
|
|
2014-02-25 17:27:41 -08:00
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
[super sendEvent:event];
|
|
|
|
|
|
|
|
if ([event type] != NSLeftMouseUp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
id delegate = [self delegate];
|
|
|
|
if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([delegate isMoving]) {
|
|
|
|
[delegate windowDidFinishMoving];
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:56:14 -07:00
|
|
|
|
|
|
|
/* We'll respond to selectors by doing nothing so we don't beep.
|
|
|
|
* The escape key gets converted to a "cancel" selector, etc.
|
|
|
|
*/
|
|
|
|
- (void)doCommandBySelector:(SEL)aSelector
|
|
|
|
{
|
|
|
|
/*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
|
|
|
|
}
|
2014-11-24 11:46:20 -08:00
|
|
|
|
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
|
|
|
|
NSNumber *isAlias = nil;
|
|
|
|
|
|
|
|
if (fileURL == nil) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
|
|
|
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
|
|
|
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the URL is an alias, resolve it. */
|
|
|
|
if ([isAlias boolValue]) {
|
|
|
|
NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
|
|
|
|
NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
|
|
|
|
if (bookmark != nil) {
|
|
|
|
NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
|
|
|
|
options:opts
|
|
|
|
relativeToURL:nil
|
|
|
|
bookmarkDataIsStale:nil
|
|
|
|
error:nil];
|
|
|
|
|
|
|
|
if (resolvedURL != nil) {
|
|
|
|
fileURL = resolvedURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)wantsPeriodicDraggingUpdates
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:27:41 -08:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
2011-02-26 10:11:09 -08:00
|
|
|
static Uint32 s_moveHack;
|
|
|
|
|
2014-06-02 09:09:40 -07:00
|
|
|
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Tim McDaniel
On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.
I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.
If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
2014-08-17 14:57:52 -07:00
|
|
|
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
static void
|
|
|
|
ScheduleContextUpdates(SDL_WindowData *data)
|
2013-08-07 16:29:25 -07:00
|
|
|
{
|
2014-02-25 15:28:12 -08:00
|
|
|
NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
|
2013-08-07 16:29:25 -07:00
|
|
|
NSMutableArray *contexts = data->nscontexts;
|
|
|
|
@synchronized (contexts) {
|
|
|
|
for (SDLOpenGLContext *context in contexts) {
|
2014-02-25 15:28:12 -08:00
|
|
|
if (context == currentContext) {
|
|
|
|
[context update];
|
|
|
|
} else {
|
|
|
|
[context scheduleUpdate];
|
|
|
|
}
|
2013-08-07 16:29:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
static int
|
|
|
|
GetHintCtrlClickEmulateRightClick()
|
2013-11-08 14:04:51 -08:00
|
|
|
{
|
|
|
|
const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
|
|
|
|
return hint != NULL && *hint != '0';
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
static unsigned int
|
|
|
|
GetWindowStyle(SDL_Window * window)
|
|
|
|
{
|
|
|
|
unsigned int style;
|
|
|
|
|
2014-03-03 21:25:16 -05:00
|
|
|
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
2013-11-11 02:53:00 -08:00
|
|
|
style = NSBorderlessWindowMask;
|
|
|
|
} else {
|
|
|
|
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
|
|
|
style = NSBorderlessWindowMask;
|
|
|
|
} else {
|
|
|
|
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
|
|
|
|
}
|
|
|
|
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
|
|
|
style |= NSResizableWindowMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2013-11-14 22:26:49 -08:00
|
|
|
static SDL_bool
|
|
|
|
SetWindowStyle(SDL_Window * window, unsigned int style)
|
|
|
|
{
|
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = data->nswindow;
|
|
|
|
|
|
|
|
if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The view responder chain gets messed with during setStyleMask */
|
|
|
|
if ([[nswindow contentView] nextResponder] == data->listener) {
|
|
|
|
[[nswindow contentView] setNextResponder:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
|
|
|
|
|
|
|
|
/* The view responder chain gets messed with during setStyleMask */
|
|
|
|
if ([[nswindow contentView] nextResponder] != data->listener) {
|
|
|
|
[[nswindow contentView] setNextResponder:data->listener];
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
@implementation Cocoa_WindowListener
|
|
|
|
|
|
|
|
- (void)listen:(SDL_WindowData *)data
|
|
|
|
{
|
|
|
|
NSNotificationCenter *center;
|
2011-02-21 10:50:53 -08:00
|
|
|
NSWindow *window = data->nswindow;
|
|
|
|
NSView *view = [window contentView];
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
_data = data;
|
2013-04-22 18:14:26 -07:00
|
|
|
observingVisible = YES;
|
2013-09-13 17:42:31 -07:00
|
|
|
wasCtrlLeft = NO;
|
2013-04-22 18:14:26 -07:00
|
|
|
wasVisible = [window isVisible];
|
2013-11-12 00:32:29 -08:00
|
|
|
isFullscreenSpace = NO;
|
2013-11-11 02:53:00 -08:00
|
|
|
inFullscreenTransition = NO;
|
2013-11-11 21:21:18 -08:00
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
2014-02-25 17:27:41 -08:00
|
|
|
isMoving = NO;
|
2014-05-27 01:27:42 -04:00
|
|
|
isDragAreaRunning = NO;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
center = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2011-02-21 15:25:49 -08:00
|
|
|
if ([window delegate] != nil) {
|
|
|
|
[center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
|
2015-05-26 21:51:47 -03:00
|
|
|
[center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
2013-11-11 02:53:00 -08:00
|
|
|
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
|
|
|
|
[center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
|
2011-02-21 15:25:49 -08:00
|
|
|
} else {
|
|
|
|
[window setDelegate:self];
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* Haven't found a delegate / notification that triggers when the window is
|
|
|
|
* ordered out (is not visible any more). You can be ordered out without
|
|
|
|
* minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
|
|
|
|
*/
|
2013-04-22 12:07:13 -07:00
|
|
|
[window addObserver:self
|
|
|
|
forKeyPath:@"visible"
|
|
|
|
options:NSKeyValueObservingOptionNew
|
|
|
|
context:NULL];
|
|
|
|
|
2011-02-21 10:50:53 -08:00
|
|
|
[window setNextResponder:self];
|
|
|
|
[window setAcceptsMouseMovedEvents:YES];
|
|
|
|
|
|
|
|
[view setNextResponder:self];
|
2011-12-09 02:32:21 -05:00
|
|
|
|
|
|
|
if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
|
|
|
|
[view setAcceptsTouchEvents:YES];
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 12:07:13 -07:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
|
|
|
change:(NSDictionary *)change
|
|
|
|
context:(void *)context
|
|
|
|
{
|
2013-04-22 18:14:26 -07:00
|
|
|
if (!observingVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-22 12:07:13 -07:00
|
|
|
if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
|
|
|
|
int newVisibility = [[change objectForKey:@"new"] intValue];
|
|
|
|
if (newVisibility) {
|
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
|
|
|
} else {
|
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 18:14:26 -07:00
|
|
|
-(void) pauseVisibleObservation
|
|
|
|
{
|
|
|
|
observingVisible = NO;
|
|
|
|
wasVisible = [_data->nswindow isVisible];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) resumeVisibleObservation
|
|
|
|
{
|
|
|
|
BOOL isVisible = [_data->nswindow isVisible];
|
|
|
|
observingVisible = YES;
|
|
|
|
if (wasVisible != isVisible) {
|
|
|
|
if (isVisible) {
|
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
|
|
|
} else {
|
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
wasVisible = isVisible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-02 12:45:51 -05:00
|
|
|
-(BOOL) setFullscreenSpace:(BOOL) state
|
2013-11-11 20:42:59 -08:00
|
|
|
{
|
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
NSWindow *nswindow = _data->nswindow;
|
2014-03-03 21:25:16 -05:00
|
|
|
SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
|
2013-11-11 20:42:59 -08:00
|
|
|
|
2014-03-03 21:25:16 -05:00
|
|
|
if (!videodata->allow_spaces) {
|
|
|
|
return NO; /* Spaces are forcibly disabled. */
|
|
|
|
} else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
2014-03-02 22:16:49 -05:00
|
|
|
return NO; /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
|
2014-06-02 09:01:10 -07:00
|
|
|
} else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
|
|
|
return NO; /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
|
2014-03-02 12:45:51 -05:00
|
|
|
} else if (state == isFullscreenSpace) {
|
|
|
|
return YES; /* already there. */
|
2013-11-11 20:42:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inFullscreenTransition) {
|
|
|
|
if (state) {
|
2013-11-11 21:21:18 -08:00
|
|
|
[self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
|
2013-11-11 20:42:59 -08:00
|
|
|
} else {
|
2013-11-11 21:21:18 -08:00
|
|
|
[self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
|
2013-11-11 20:42:59 -08:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
2013-11-12 01:52:54 -08:00
|
|
|
inFullscreenTransition = YES;
|
|
|
|
|
2014-03-03 21:25:16 -05:00
|
|
|
/* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
|
2014-03-02 12:45:51 -05:00
|
|
|
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
2013-11-11 22:43:05 -08:00
|
|
|
[nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
|
2013-11-11 20:42:59 -08:00
|
|
|
return YES;
|
2013-11-11 02:53:00 -08:00
|
|
|
}
|
|
|
|
|
2013-11-12 01:52:54 -08:00
|
|
|
-(BOOL) isInFullscreenSpace
|
|
|
|
{
|
|
|
|
return isFullscreenSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(BOOL) isInFullscreenSpaceTransition
|
2013-11-11 21:21:18 -08:00
|
|
|
{
|
|
|
|
return inFullscreenTransition;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
|
|
|
|
{
|
|
|
|
pendingWindowOperation = operation;
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
NSNotificationCenter *center;
|
2011-02-21 10:50:53 -08:00
|
|
|
NSWindow *window = _data->nswindow;
|
|
|
|
NSView *view = [window contentView];
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
center = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2011-02-21 15:25:49 -08:00
|
|
|
if ([window delegate] != self) {
|
|
|
|
[center removeObserver:self name:NSWindowDidExposeNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidMoveNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidResizeNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
|
2015-05-26 21:51:47 -03:00
|
|
|
[center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
2013-11-11 02:53:00 -08:00
|
|
|
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
|
|
|
|
[center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
|
2011-02-21 15:25:49 -08:00
|
|
|
} else {
|
|
|
|
[window setDelegate:nil];
|
|
|
|
}
|
2011-02-21 10:50:53 -08:00
|
|
|
|
2013-11-11 20:42:59 -08:00
|
|
|
[window removeObserver:self forKeyPath:@"visible"];
|
2013-04-22 12:07:13 -07:00
|
|
|
|
2011-02-21 15:25:49 -08:00
|
|
|
if ([window nextResponder] == self) {
|
|
|
|
[window setNextResponder:nil];
|
|
|
|
}
|
|
|
|
if ([view nextResponder] == self) {
|
|
|
|
[view setNextResponder:nil];
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 17:27:41 -08:00
|
|
|
- (BOOL)isMoving
|
|
|
|
{
|
|
|
|
return isMoving;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setPendingMoveX:(int)x Y:(int)y
|
|
|
|
{
|
|
|
|
pendingWindowWarpX = x;
|
|
|
|
pendingWindowWarpY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidFinishMoving
|
|
|
|
{
|
2014-07-07 12:48:25 -07:00
|
|
|
if ([self isMoving]) {
|
2014-02-25 17:27:41 -08:00
|
|
|
isMoving = NO;
|
|
|
|
|
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Tim McDaniel
On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.
I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.
If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
2014-08-17 14:57:52 -07:00
|
|
|
if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
|
|
|
|
mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
|
|
|
|
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
2014-02-25 17:27:41 -08:00
|
|
|
}
|
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Tim McDaniel
On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.
I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.
If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
2014-08-17 14:57:52 -07:00
|
|
|
if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) {
|
2014-02-25 17:27:41 -08:00
|
|
|
mouse->SetRelativeMouseMode(SDL_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
|
2006-07-24 05:03:02 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidExpose:(NSNotification *)aNotification
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 17:27:41 -08:00
|
|
|
- (void)windowWillMove:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
|
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Tim McDaniel
On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.
I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.
If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
2014-08-17 14:57:52 -07:00
|
|
|
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
2014-02-25 17:27:41 -08:00
|
|
|
isMoving = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
- (void)windowDidMove:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
int x, y;
|
2011-02-26 10:11:09 -08:00
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
NSWindow *nswindow = _data->nswindow;
|
2014-06-02 09:09:40 -07:00
|
|
|
BOOL fullscreen = window->flags & FULLSCREEN_MASK;
|
2011-02-26 10:11:09 -08:00
|
|
|
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
2011-02-26 10:11:09 -08:00
|
|
|
|
|
|
|
if (s_moveHack) {
|
|
|
|
SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
|
|
|
|
|
|
|
|
s_moveHack = 0;
|
|
|
|
|
|
|
|
if (blockMove) {
|
|
|
|
/* Cocoa is adjusting the window in response to a mode change */
|
|
|
|
rect.origin.x = window->x;
|
|
|
|
rect.origin.y = window->y;
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
2011-02-26 10:11:09 -08:00
|
|
|
[nswindow setFrameOrigin:rect.origin];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 12:08:34 +00:00
|
|
|
x = (int)rect.origin.x;
|
|
|
|
y = (int)rect.origin.y;
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(_data);
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2011-02-26 10:11:09 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)aNotification
|
|
|
|
{
|
2014-03-02 12:45:51 -05:00
|
|
|
if (inFullscreenTransition) {
|
|
|
|
/* We'll take care of this at the end of the transition */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
NSWindow *nswindow = _data->nswindow;
|
2012-01-18 22:22:54 -05:00
|
|
|
int x, y, w, h;
|
2013-11-11 21:21:18 -08:00
|
|
|
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
2012-01-18 22:22:54 -05:00
|
|
|
x = (int)rect.origin.x;
|
|
|
|
y = (int)rect.origin.y;
|
2006-07-24 05:03:02 +00:00
|
|
|
w = (int)rect.size.width;
|
|
|
|
h = (int)rect.size.height;
|
2013-11-11 02:53:00 -08:00
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
if (SDL_IsShapedWindow(window)) {
|
|
|
|
Cocoa_ResizeWindowShape(window);
|
2013-11-11 02:53:00 -08:00
|
|
|
}
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(_data);
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2012-01-18 22:22:54 -05:00
|
|
|
/* The window can move during a resize event, such as when maximizing
|
|
|
|
or resizing from a corner */
|
2013-11-11 21:21:18 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
|
2013-08-03 02:20:00 -04:00
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
const BOOL zoomed = [nswindow isZoomed];
|
2013-08-03 02:20:00 -04:00
|
|
|
if (!zoomed) {
|
2013-11-11 21:21:18 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
2013-08-03 02:20:00 -04:00
|
|
|
} else if (zoomed) {
|
2013-11-11 21:21:18 -08:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
2013-08-03 02:20:00 -04:00
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)aNotification
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
|
|
|
|
{
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)aNotification
|
|
|
|
{
|
2011-02-20 20:49:31 -08:00
|
|
|
SDL_Window *window = _data->window;
|
2013-06-04 14:54:49 -07:00
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
2011-02-20 20:49:31 -08:00
|
|
|
|
2006-10-28 16:41:54 +00:00
|
|
|
/* We're going to get keyboard events, since we're key. */
|
2015-05-26 11:38:04 -04:00
|
|
|
/* This needs to be done before restoring the relative mouse mode. */
|
2011-02-20 20:49:31 -08:00
|
|
|
SDL_SetKeyboardFocus(window);
|
|
|
|
|
2015-05-26 11:38:04 -04:00
|
|
|
if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
|
|
|
|
mouse->SetRelativeMouseMode(SDL_TRUE);
|
|
|
|
}
|
|
|
|
|
2011-02-20 20:49:31 -08:00
|
|
|
/* If we just gained focus we need the updated mouse position */
|
2013-06-04 14:54:49 -07:00
|
|
|
if (!mouse->relative_mode) {
|
2011-02-20 20:49:31 -08:00
|
|
|
NSPoint point;
|
2011-02-24 18:11:29 -08:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
point = [_data->nswindow mouseLocationOutsideOfEventStream];
|
|
|
|
x = (int)point.x;
|
|
|
|
y = (int)(window->h - point.y);
|
|
|
|
|
|
|
|
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
|
2013-03-02 20:44:16 -08:00
|
|
|
SDL_SendMouseMotion(window, 0, 0, x, y);
|
2011-02-24 18:11:29 -08:00
|
|
|
}
|
2011-02-20 20:49:31 -08:00
|
|
|
}
|
2010-07-08 22:54:03 -07:00
|
|
|
|
|
|
|
/* Check to see if someone updated the clipboard */
|
|
|
|
Cocoa_CheckClipboardUpdate(_data->videodata);
|
2014-03-02 15:35:24 -05:00
|
|
|
|
2014-03-02 22:51:31 -05:00
|
|
|
if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
2014-03-02 15:35:24 -05:00
|
|
|
[NSMenu setMenuBarVisible:NO];
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)aNotification
|
|
|
|
{
|
2014-02-25 17:27:41 -08:00
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different
Tim McDaniel
On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.
I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.
If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
2014-08-17 14:57:52 -07:00
|
|
|
if (mouse->relative_mode && !mouse->relative_mode_warp) {
|
2014-02-25 17:27:41 -08:00
|
|
|
mouse->SetRelativeMouseMode(SDL_FALSE);
|
|
|
|
}
|
|
|
|
|
2006-10-28 16:41:54 +00:00
|
|
|
/* Some other window will get mouse events, since we're not key. */
|
2010-05-09 20:47:22 -07:00
|
|
|
if (SDL_GetMouseFocus() == _data->window) {
|
|
|
|
SDL_SetMouseFocus(NULL);
|
2006-10-28 16:41:54 +00:00
|
|
|
}
|
2006-07-30 08:09:20 +00:00
|
|
|
|
2006-10-28 16:41:54 +00:00
|
|
|
/* Some other window will get keyboard events, since we're not key. */
|
2010-05-09 20:47:22 -07:00
|
|
|
if (SDL_GetKeyboardFocus() == _data->window) {
|
|
|
|
SDL_SetKeyboardFocus(NULL);
|
|
|
|
}
|
2014-03-02 15:35:24 -05:00
|
|
|
|
|
|
|
if (isFullscreenSpace) {
|
|
|
|
[NSMenu setMenuBarVisible:YES];
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2015-05-26 21:51:47 -03:00
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
|
|
|
|
|
|
|
|
if (inFullscreenTransition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([oldscale doubleValue] != [_data->nswindow backingScaleFactor]) {
|
|
|
|
/* Force a resize event when the backing scale factor changes. */
|
|
|
|
_data->window->w = 0;
|
|
|
|
_data->window->h = 0;
|
|
|
|
[self windowDidResize:aNotification];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
|
2013-11-14 22:26:49 -08:00
|
|
|
SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
|
2013-11-11 22:43:05 -08:00
|
|
|
|
2013-11-12 00:32:29 -08:00
|
|
|
isFullscreenSpace = YES;
|
2013-11-11 02:53:00 -08:00
|
|
|
inFullscreenTransition = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
|
|
|
|
{
|
2013-11-11 22:43:05 -08:00
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
inFullscreenTransition = NO;
|
2013-11-11 20:42:59 -08:00
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
|
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
2013-11-12 00:32:29 -08:00
|
|
|
[self setFullscreenSpace:NO];
|
2013-11-11 20:42:59 -08:00
|
|
|
} else {
|
2014-03-02 12:45:51 -05:00
|
|
|
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
|
|
|
[NSMenu setMenuBarVisible:NO];
|
|
|
|
}
|
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
2013-11-11 22:43:05 -08:00
|
|
|
/* Force the size change event in case it was delivered earlier
|
|
|
|
while the window was still animating into place.
|
|
|
|
*/
|
|
|
|
window->w = 0;
|
|
|
|
window->h = 0;
|
2013-11-11 20:42:59 -08:00
|
|
|
[self windowDidResize:aNotification];
|
|
|
|
}
|
2013-11-11 02:53:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
|
|
|
|
{
|
2013-11-11 21:38:11 -08:00
|
|
|
SDL_Window *window = _data->window;
|
|
|
|
|
2013-11-14 22:26:49 -08:00
|
|
|
SetWindowStyle(window, GetWindowStyle(window));
|
2013-11-11 21:38:11 -08:00
|
|
|
|
2013-11-12 00:32:29 -08:00
|
|
|
isFullscreenSpace = NO;
|
2013-11-11 02:53:00 -08:00
|
|
|
inFullscreenTransition = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidExitFullScreen:(NSNotification *)aNotification
|
|
|
|
{
|
2013-11-11 22:43:05 -08:00
|
|
|
SDL_Window *window = _data->window;
|
2013-11-11 02:53:00 -08:00
|
|
|
NSWindow *nswindow = _data->nswindow;
|
|
|
|
|
|
|
|
inFullscreenTransition = NO;
|
2013-11-11 20:42:59 -08:00
|
|
|
|
2014-03-14 18:06:09 -07:00
|
|
|
[nswindow setLevel:kCGNormalWindowLevel];
|
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
|
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
2013-11-12 00:32:29 -08:00
|
|
|
[self setFullscreenSpace:YES];
|
2013-11-11 21:21:18 -08:00
|
|
|
} else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
|
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
|
|
|
[nswindow miniaturize:nil];
|
2013-11-11 20:42:59 -08:00
|
|
|
} else {
|
2014-03-02 16:36:40 -05:00
|
|
|
/* Adjust the fullscreen toggle button and readd menu now that we're here. */
|
|
|
|
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
|
|
|
/* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
|
|
|
|
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
} else {
|
2014-03-02 12:45:51 -05:00
|
|
|
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
|
|
|
|
}
|
2014-03-02 16:36:40 -05:00
|
|
|
[NSMenu setMenuBarVisible:YES];
|
2014-03-02 12:45:51 -05:00
|
|
|
|
2013-11-11 21:21:18 -08:00
|
|
|
pendingWindowOperation = PENDING_OPERATION_NONE;
|
2013-11-11 22:43:05 -08:00
|
|
|
/* Force the size change event in case it was delivered earlier
|
|
|
|
while the window was still animating into place.
|
|
|
|
*/
|
|
|
|
window->w = 0;
|
|
|
|
window->h = 0;
|
2013-11-11 20:42:59 -08:00
|
|
|
[self windowDidResize:aNotification];
|
2014-03-15 15:35:15 -04:00
|
|
|
|
2014-03-15 16:27:06 -07:00
|
|
|
/* FIXME: Why does the window get hidden? */
|
|
|
|
if (window->flags & SDL_WINDOW_SHOWN) {
|
|
|
|
Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
|
|
|
|
}
|
2013-11-11 20:42:59 -08:00
|
|
|
}
|
2013-11-11 02:53:00 -08:00
|
|
|
}
|
|
|
|
|
2014-03-02 16:36:40 -05:00
|
|
|
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
|
|
|
|
{
|
|
|
|
if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
|
|
|
return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
|
|
|
|
} else {
|
|
|
|
return proposedOptions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* We'll respond to key events by doing nothing so we don't beep.
|
|
|
|
* We could handle key messages here, but we lose some in the NSApp dispatch,
|
|
|
|
* where they get converted to action messages, etc.
|
|
|
|
*/
|
2012-09-29 02:50:42 -07:00
|
|
|
- (void)flagsChanged:(NSEvent *)theEvent
|
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
2012-09-29 02:50:42 -07:00
|
|
|
}
|
|
|
|
- (void)keyDown:(NSEvent *)theEvent
|
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
2012-09-29 02:50:42 -07:00
|
|
|
}
|
|
|
|
- (void)keyUp:(NSEvent *)theEvent
|
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
2012-09-29 02:50:42 -07:00
|
|
|
}
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* We'll respond to selectors by doing nothing so we don't beep.
|
|
|
|
* The escape key gets converted to a "cancel" selector, etc.
|
|
|
|
*/
|
2012-09-29 02:50:42 -07:00
|
|
|
- (void)doCommandBySelector:(SEL)aSelector
|
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
/*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
|
2012-09-29 02:50:42 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
- (BOOL)processHitTest:(NSEvent *)theEvent
|
2014-05-27 01:27:42 -04:00
|
|
|
{
|
|
|
|
SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
|
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
if (_data->window->hit_test) { /* if no hit-test, skip this. */
|
2014-05-27 01:27:42 -04:00
|
|
|
const NSPoint location = [theEvent locationInWindow];
|
|
|
|
const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
|
2014-05-28 01:22:47 -04:00
|
|
|
const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
|
|
|
|
if (rc == SDL_HITTEST_DRAGGABLE) {
|
|
|
|
if (!isDragAreaRunning) {
|
|
|
|
isDragAreaRunning = YES;
|
|
|
|
[_data->nswindow setMovableByWindowBackground:YES];
|
2014-05-27 01:27:42 -04:00
|
|
|
}
|
2014-05-28 01:22:47 -04:00
|
|
|
return YES; /* dragging! */
|
2014-05-27 01:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDragAreaRunning) {
|
|
|
|
isDragAreaRunning = NO;
|
|
|
|
[_data->nswindow setMovableByWindowBackground:NO];
|
|
|
|
return YES; /* was dragging, drop event. */
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
return NO; /* not a special area, carry on. */
|
2014-05-27 01:27:42 -04:00
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
int button;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
if ([self processHitTest:theEvent]) {
|
2014-05-27 01:27:42 -04:00
|
|
|
return; /* dragging, drop event. */
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:18:33 +00:00
|
|
|
switch ([theEvent buttonNumber]) {
|
|
|
|
case 0:
|
2013-11-08 14:04:51 -08:00
|
|
|
if (([theEvent modifierFlags] & NSControlKeyMask) &&
|
|
|
|
GetHintCtrlClickEmulateRightClick()) {
|
2013-09-13 17:42:31 -07:00
|
|
|
wasCtrlLeft = YES;
|
|
|
|
button = SDL_BUTTON_RIGHT;
|
|
|
|
} else {
|
|
|
|
wasCtrlLeft = NO;
|
|
|
|
button = SDL_BUTTON_LEFT;
|
|
|
|
}
|
2006-07-30 05:18:33 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
button = SDL_BUTTON_RIGHT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
button = SDL_BUTTON_MIDDLE;
|
|
|
|
break;
|
|
|
|
default:
|
2011-01-20 17:33:06 -08:00
|
|
|
button = [theEvent buttonNumber] + 1;
|
2006-07-30 05:18:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-02 20:44:16 -08:00
|
|
|
SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
[self mouseDown:theEvent];
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
[self mouseDown:theEvent];
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
int button;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
if ([self processHitTest:theEvent]) {
|
2014-05-27 01:27:42 -04:00
|
|
|
return; /* stopped dragging, drop event. */
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:18:33 +00:00
|
|
|
switch ([theEvent buttonNumber]) {
|
|
|
|
case 0:
|
2013-09-13 17:42:31 -07:00
|
|
|
if (wasCtrlLeft) {
|
|
|
|
button = SDL_BUTTON_RIGHT;
|
|
|
|
wasCtrlLeft = NO;
|
|
|
|
} else {
|
|
|
|
button = SDL_BUTTON_LEFT;
|
|
|
|
}
|
2006-07-30 05:18:33 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
button = SDL_BUTTON_RIGHT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
button = SDL_BUTTON_MIDDLE;
|
|
|
|
break;
|
|
|
|
default:
|
2011-01-20 17:33:06 -08:00
|
|
|
button = [theEvent buttonNumber] + 1;
|
2006-07-30 05:18:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-02 20:44:16 -08:00
|
|
|
SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
[self mouseUp:theEvent];
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2006-07-30 05:18:33 +00:00
|
|
|
[self mouseUp:theEvent];
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)theEvent
|
|
|
|
{
|
2011-02-27 22:06:46 -08:00
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
2010-01-21 06:21:52 +00:00
|
|
|
SDL_Window *window = _data->window;
|
2011-02-24 18:11:29 -08:00
|
|
|
NSPoint point;
|
|
|
|
int x, y;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2014-05-28 01:22:47 -04:00
|
|
|
if ([self processHitTest:theEvent]) {
|
2014-05-27 01:27:42 -04:00
|
|
|
return; /* dragging, drop event. */
|
|
|
|
}
|
|
|
|
|
2011-02-27 22:06:46 -08:00
|
|
|
if (mouse->relative_mode) {
|
2011-01-21 00:25:08 +01:00
|
|
|
return;
|
2011-02-21 10:50:53 -08:00
|
|
|
}
|
|
|
|
|
2011-02-24 18:11:29 -08:00
|
|
|
point = [theEvent locationInWindow];
|
|
|
|
x = (int)point.x;
|
|
|
|
y = (int)(window->h - point.y);
|
2011-01-21 00:25:08 +01:00
|
|
|
|
2014-05-24 18:23:56 -04:00
|
|
|
if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
|
|
|
|
if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
|
2012-11-08 02:26:40 -08:00
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
} else if (x >= window->w) {
|
|
|
|
x = window->w - 1;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
} else if (y >= window->h) {
|
|
|
|
y = window->h - 1;
|
|
|
|
}
|
|
|
|
|
2013-08-07 16:29:15 -07:00
|
|
|
#if !SDL_MAC_NO_SANDBOX
|
2014-02-25 17:27:41 -08:00
|
|
|
CGPoint cgpoint;
|
|
|
|
|
2013-08-07 16:29:15 -07:00
|
|
|
/* When SDL_MAC_NO_SANDBOX is set, this is handled by
|
|
|
|
* SDL_cocoamousetap.m.
|
|
|
|
*/
|
|
|
|
|
2012-11-08 02:26:40 -08:00
|
|
|
cgpoint.x = window->x + x;
|
|
|
|
cgpoint.y = window->y + y;
|
2013-04-23 18:47:38 -07:00
|
|
|
|
2013-04-25 18:40:22 -07:00
|
|
|
/* According to the docs, this was deprecated in 10.6, but it's still
|
|
|
|
* around. The substitute requires a CGEventSource, but I'm not entirely
|
|
|
|
* sure how we'd procure the right one for this event.
|
2013-04-23 18:47:38 -07:00
|
|
|
*/
|
2013-04-25 18:40:22 -07:00
|
|
|
CGSetLocalEventsSuppressionInterval(0.0);
|
2012-11-08 02:26:40 -08:00
|
|
|
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
|
2013-04-25 18:40:22 -07:00
|
|
|
CGSetLocalEventsSuppressionInterval(0.25);
|
2014-02-26 11:35:02 -08:00
|
|
|
|
|
|
|
Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
|
2013-08-07 16:29:15 -07:00
|
|
|
#endif
|
2011-02-24 18:11:29 -08:00
|
|
|
}
|
2006-10-28 16:41:54 +00:00
|
|
|
}
|
2013-03-02 20:44:16 -08:00
|
|
|
SDL_SendMouseMotion(window, 0, 0, x, y);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2006-07-29 22:42:48 +00:00
|
|
|
- (void)mouseDragged:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
[self mouseMoved:theEvent];
|
|
|
|
}
|
|
|
|
|
2006-07-29 23:00:15 +00:00
|
|
|
- (void)rightMouseDragged:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
[self mouseMoved:theEvent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
[self mouseMoved:theEvent];
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent
|
|
|
|
{
|
2011-01-21 00:15:18 +01:00
|
|
|
Cocoa_HandleMouseWheel(_data->window, theEvent);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 23:32:13 -07:00
|
|
|
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
|
|
|
|
{
|
2014-11-23 15:48:52 -05:00
|
|
|
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
|
|
|
|
int existingTouchCount = 0;
|
|
|
|
|
|
|
|
for (NSTouch* touch in touches) {
|
|
|
|
if ([touch phase] != NSTouchPhaseBegan) {
|
|
|
|
existingTouchCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (existingTouchCount == 0) {
|
|
|
|
SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
|
|
|
int numFingers = SDL_GetNumTouchFingers(touchID);
|
|
|
|
DLog("Reset Lost Fingers: %d", numFingers);
|
|
|
|
for (--numFingers; numFingers >= 0; --numFingers) {
|
|
|
|
SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
|
|
|
|
SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
|
2014-07-07 12:48:25 -07:00
|
|
|
[self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
|
|
|
|
{
|
2014-07-07 12:48:25 -07:00
|
|
|
[self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
|
|
|
|
{
|
2014-07-07 12:48:25 -07:00
|
|
|
[self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
|
|
|
|
{
|
2014-07-07 12:48:25 -07:00
|
|
|
[self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
|
|
|
|
2014-07-07 12:48:25 -07:00
|
|
|
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
|
2010-07-28 23:32:13 -07:00
|
|
|
{
|
2014-07-07 12:48:25 -07:00
|
|
|
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
2010-07-31 20:55:33 -07:00
|
|
|
|
2014-07-07 12:48:25 -07:00
|
|
|
for (NSTouch *touch in touches) {
|
2013-03-03 08:41:50 -08:00
|
|
|
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
2010-07-28 23:32:13 -07:00
|
|
|
if (!SDL_GetTouch(touchId)) {
|
2013-03-03 01:01:33 -08:00
|
|
|
if (SDL_AddTouch(touchId, "") < 0) {
|
2010-07-31 20:55:33 -07:00
|
|
|
return;
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2010-08-13 17:05:06 -07:00
|
|
|
|
2013-03-03 08:41:50 -08:00
|
|
|
const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
|
2010-07-28 23:32:13 -07:00
|
|
|
float x = [touch normalizedPosition].x;
|
|
|
|
float y = [touch normalizedPosition].y;
|
2011-02-11 20:49:13 -08:00
|
|
|
/* Make the origin the upper left instead of the lower left */
|
|
|
|
y = 1.0f - y;
|
2010-08-13 17:05:06 -07:00
|
|
|
|
2014-07-07 12:48:25 -07:00
|
|
|
switch (phase) {
|
|
|
|
case NSTouchPhaseBegan:
|
2013-03-03 01:01:33 -08:00
|
|
|
SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
|
2010-07-28 23:32:13 -07:00
|
|
|
break;
|
2014-07-07 12:48:25 -07:00
|
|
|
case NSTouchPhaseEnded:
|
|
|
|
case NSTouchPhaseCancelled:
|
2013-03-03 01:01:33 -08:00
|
|
|
SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
|
2010-07-28 23:32:13 -07:00
|
|
|
break;
|
2014-07-07 12:48:25 -07:00
|
|
|
case NSTouchPhaseMoved:
|
2013-03-03 01:01:33 -08:00
|
|
|
SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
|
2010-07-28 23:32:13 -07:00
|
|
|
break;
|
2014-07-07 12:48:25 -07:00
|
|
|
default:
|
|
|
|
break;
|
2010-07-28 23:32:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
@end
|
|
|
|
|
2015-05-26 11:01:19 -04:00
|
|
|
@interface SDLView : NSView {
|
|
|
|
SDL_Window *_sdlWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSDLWindow:(SDL_Window*)window;
|
2013-05-07 16:52:39 -07:00
|
|
|
|
2011-02-21 21:32:11 -08:00
|
|
|
/* The default implementation doesn't pass rightMouseDown to responder chain */
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent;
|
2014-05-27 01:27:42 -04:00
|
|
|
- (BOOL)mouseDownCanMoveWindow;
|
2015-05-26 11:01:19 -04:00
|
|
|
- (void)drawRect:(NSRect)dirtyRect;
|
2010-05-09 12:58:58 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SDLView
|
2015-05-26 11:01:19 -04:00
|
|
|
- (void)setSDLWindow:(SDL_Window*)window
|
|
|
|
{
|
|
|
|
_sdlWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)dirtyRect
|
|
|
|
{
|
|
|
|
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
|
|
|
}
|
|
|
|
|
2010-05-09 12:58:58 +08:00
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
2011-02-21 10:50:53 -08:00
|
|
|
[[self nextResponder] rightMouseDown:theEvent];
|
2010-05-09 12:58:58 +08:00
|
|
|
}
|
2013-05-07 16:52:39 -07:00
|
|
|
|
2014-05-27 01:27:42 -04:00
|
|
|
- (BOOL)mouseDownCanMoveWindow
|
|
|
|
{
|
|
|
|
/* Always say YES, but this doesn't do anything until we call
|
|
|
|
-[NSWindow setMovableByWindowBackground:YES], which we ninja-toggle
|
|
|
|
during mouse events when we're using a drag area. */
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:52:39 -07:00
|
|
|
- (void)resetCursorRects
|
|
|
|
{
|
|
|
|
[super resetCursorRects];
|
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
|
|
|
|
2013-06-04 13:53:55 -07:00
|
|
|
if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
|
2013-05-07 16:52:39 -07:00
|
|
|
[self addCursorRect:[self bounds]
|
|
|
|
cursor:mouse->cur_cursor->driverdata];
|
|
|
|
} else {
|
|
|
|
[self addCursorRect:[self bounds]
|
|
|
|
cursor:[NSCursor invisibleCursor]];
|
|
|
|
}
|
|
|
|
}
|
2010-05-09 12:58:58 +08:00
|
|
|
@end
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
static int
|
2006-07-27 06:53:23 +00:00
|
|
|
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2006-07-27 06:53:23 +00:00
|
|
|
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
2006-07-24 05:03:02 +00:00
|
|
|
SDL_WindowData *data;
|
|
|
|
|
|
|
|
/* Allocate the window data */
|
2014-06-25 02:08:37 -07:00
|
|
|
window->driverdata = data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
|
2006-07-24 05:03:02 +00:00
|
|
|
if (!data) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_OutOfMemory();
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
2010-01-21 06:21:52 +00:00
|
|
|
data->window = window;
|
2010-01-21 07:28:01 +00:00
|
|
|
data->nswindow = nswindow;
|
2006-07-24 05:03:02 +00:00
|
|
|
data->created = created;
|
2006-07-27 06:53:23 +00:00
|
|
|
data->videodata = videodata;
|
2013-08-07 16:29:25 -07:00
|
|
|
data->nscontexts = [[NSMutableArray alloc] init];
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* Create an event listener for the window */
|
|
|
|
data->listener = [[Cocoa_WindowListener alloc] init];
|
2011-02-21 10:50:53 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* Fill in the SDL window with the window data */
|
|
|
|
{
|
|
|
|
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
2013-02-11 17:39:52 -08:00
|
|
|
window->x = (int)rect.origin.x;
|
|
|
|
window->y = (int)rect.origin.y;
|
|
|
|
window->w = (int)rect.size.width;
|
|
|
|
window->h = (int)rect.size.height;
|
|
|
|
}
|
2011-02-21 10:50:53 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* Set up the listener after we create the view */
|
|
|
|
[data->listener listen:data];
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow isVisible]) {
|
|
|
|
window->flags |= SDL_WINDOW_SHOWN;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_SHOWN;
|
|
|
|
}
|
2013-04-22 12:07:13 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
{
|
|
|
|
unsigned int style = [nswindow styleMask];
|
|
|
|
|
|
|
|
if (style == NSBorderlessWindowMask) {
|
|
|
|
window->flags |= SDL_WINDOW_BORDERLESS;
|
2006-07-24 05:03:02 +00:00
|
|
|
} else {
|
2013-02-11 17:39:52 -08:00
|
|
|
window->flags &= ~SDL_WINDOW_BORDERLESS;
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
if (style & NSResizableWindowMask) {
|
|
|
|
window->flags |= SDL_WINDOW_RESIZABLE;
|
2006-07-24 05:03:02 +00:00
|
|
|
} else {
|
2013-02-11 17:39:52 -08:00
|
|
|
window->flags &= ~SDL_WINDOW_RESIZABLE;
|
2013-01-06 19:04:53 +03:00
|
|
|
}
|
|
|
|
}
|
2013-04-22 12:07:13 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* isZoomed always returns true if the window is not resizable */
|
|
|
|
if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
|
|
|
window->flags |= SDL_WINDOW_MAXIMIZED;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_MAXIMIZED;
|
|
|
|
}
|
2013-04-22 12:07:13 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow isMiniaturized]) {
|
|
|
|
window->flags |= SDL_WINDOW_MINIMIZED;
|
|
|
|
} else {
|
|
|
|
window->flags &= ~SDL_WINDOW_MINIMIZED;
|
|
|
|
}
|
2013-04-22 12:07:13 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow isKeyWindow]) {
|
|
|
|
window->flags |= SDL_WINDOW_INPUT_FOCUS;
|
|
|
|
SDL_SetKeyboardFocus(data->window);
|
|
|
|
}
|
|
|
|
|
2013-04-22 12:07:16 -07:00
|
|
|
/* Prevents the window's "window device" from being destroyed when it is
|
|
|
|
* hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
|
|
|
|
*/
|
|
|
|
[nswindow setOneShot:NO];
|
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* All done! */
|
|
|
|
window->driverdata = data;
|
|
|
|
return 0;
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2014-03-03 21:25:16 -05:00
|
|
|
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
2013-02-11 17:39:52 -08:00
|
|
|
NSWindow *nswindow;
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
NSRect rect;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
unsigned int style;
|
2014-07-07 12:48:25 -07:00
|
|
|
NSArray *screens = [NSScreen screens];
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
|
|
|
rect.origin.x = window->x;
|
|
|
|
rect.origin.y = window->y;
|
|
|
|
rect.size.width = window->w;
|
|
|
|
rect.size.height = window->h;
|
2014-07-07 12:48:25 -07:00
|
|
|
ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
style = GetWindowStyle(window);
|
|
|
|
|
|
|
|
/* Figure out which screen to place this window */
|
|
|
|
NSScreen *screen = nil;
|
2014-07-07 12:48:25 -07:00
|
|
|
for (NSScreen *candidate in screens) {
|
2013-02-11 17:39:52 -08:00
|
|
|
NSRect screenRect = [candidate frame];
|
|
|
|
if (rect.origin.x >= screenRect.origin.x &&
|
|
|
|
rect.origin.x < screenRect.origin.x + screenRect.size.width &&
|
|
|
|
rect.origin.y >= screenRect.origin.y &&
|
|
|
|
rect.origin.y < screenRect.origin.y + screenRect.size.height) {
|
|
|
|
screen = candidate;
|
|
|
|
rect.origin.x -= screenRect.origin.x;
|
|
|
|
rect.origin.y -= screenRect.origin.y;
|
2009-12-01 11:50:00 +00:00
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
}
|
2013-11-10 17:40:35 -08:00
|
|
|
|
|
|
|
@try {
|
|
|
|
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
|
|
|
}
|
|
|
|
@catch (NSException *e) {
|
2015-05-05 19:01:55 -03:00
|
|
|
return SDL_SetError("%s", [[e reason] UTF8String]);
|
2013-11-10 17:40:35 -08:00
|
|
|
}
|
2013-05-21 23:02:16 -04:00
|
|
|
[nswindow setBackgroundColor:[NSColor blackColor]];
|
2014-03-02 12:45:51 -05:00
|
|
|
|
2014-03-03 21:25:16 -05:00
|
|
|
if (videodata->allow_spaces) {
|
2014-07-07 12:48:25 -07:00
|
|
|
SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
|
2014-03-03 21:25:16 -05:00
|
|
|
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
|
2014-03-02 12:45:51 -05:00
|
|
|
/* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
|
|
|
|
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
|
|
|
/* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
|
2013-11-12 01:52:54 -08:00
|
|
|
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
}
|
2013-11-11 03:29:11 -08:00
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* Create a default view for this window */
|
2013-02-11 17:39:52 -08:00
|
|
|
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
2015-05-26 11:01:19 -04:00
|
|
|
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
|
|
|
|
[contentView setSDLWindow:window];
|
2013-09-20 13:43:00 -04:00
|
|
|
|
2013-11-11 03:29:11 -08:00
|
|
|
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
2013-09-20 13:43:00 -04:00
|
|
|
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
|
|
|
[contentView setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
[nswindow setContentView: contentView];
|
|
|
|
[contentView release];
|
2012-09-28 02:33:42 -07:00
|
|
|
|
2014-11-24 11:46:20 -08:00
|
|
|
/* Allow files and folders to be dragged onto the window by users */
|
|
|
|
[nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
|
|
|
|
[nswindow release];
|
|
|
|
return -1;
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
return 0;
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
|
|
|
NSWindow *nswindow = (NSWindow *) data;
|
|
|
|
NSString *title;
|
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* Query the title from the existing window */
|
|
|
|
title = [nswindow title];
|
|
|
|
if (title) {
|
|
|
|
window->title = SDL_strdup([title UTF8String]);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
2006-07-27 06:53:23 +00:00
|
|
|
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
2015-04-08 02:00:14 -04:00
|
|
|
NSString *string = [[NSString alloc] initWithUTF8String:window->title];
|
2013-02-11 17:39:52 -08:00
|
|
|
[nswindow setTitle:string];
|
|
|
|
[string release];
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-02-21 16:45:23 -08:00
|
|
|
void
|
|
|
|
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2011-02-21 16:45:23 -08:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
NSImage *nsimage = Cocoa_CreateImage(icon);
|
2011-02-21 16:45:23 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if (nsimage) {
|
|
|
|
[NSApp setApplicationIconImage:nsimage];
|
2011-02-21 16:45:23 -08:00
|
|
|
}
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2011-02-21 16:45:23 -08:00
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
void
|
|
|
|
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-08-07 16:29:21 -07:00
|
|
|
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = windata->nswindow;
|
2013-02-11 17:39:52 -08:00
|
|
|
NSRect rect;
|
|
|
|
Uint32 moveHack;
|
2011-03-11 16:54:43 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
rect.origin.x = window->x;
|
|
|
|
rect.origin.y = window->y;
|
|
|
|
rect.size.width = window->w;
|
|
|
|
rect.size.height = window->h;
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
2011-03-11 16:54:43 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
moveHack = s_moveHack;
|
|
|
|
s_moveHack = 0;
|
|
|
|
[nswindow setFrameOrigin:rect.origin];
|
|
|
|
s_moveHack = moveHack;
|
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(windata);
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = windata->nswindow;
|
|
|
|
NSSize size;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
size.width = window->w;
|
|
|
|
size.height = window->h;
|
|
|
|
[nswindow setContentSize:size];
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(windata);
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2012-11-18 15:45:12 +03:00
|
|
|
void
|
|
|
|
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2012-11-18 15:45:12 +03:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
NSSize minSize;
|
|
|
|
minSize.width = window->min_w;
|
|
|
|
minSize.height = window->min_h;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
[windata->nswindow setContentMinSize:minSize];
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2012-12-31 12:15:25 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2012-12-31 12:15:25 -08:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
NSSize maxSize;
|
|
|
|
maxSize.width = window->max_w;
|
|
|
|
maxSize.height = window->max_h;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
[windata->nswindow setContentMaxSize:maxSize];
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2012-11-18 15:45:12 +03:00
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
void
|
|
|
|
Cocoa_ShowWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-04-22 18:14:26 -07:00
|
|
|
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
|
|
|
NSWindow *nswindow = windowData->nswindow;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if (![nswindow isMiniaturized]) {
|
2013-04-22 18:14:26 -07:00
|
|
|
[windowData->listener pauseVisibleObservation];
|
2013-02-11 17:39:52 -08:00
|
|
|
[nswindow makeKeyAndOrderFront:nil];
|
2013-04-22 18:14:26 -07:00
|
|
|
[windowData->listener resumeVisibleObservation];
|
2006-07-29 21:51:00 +00:00
|
|
|
}
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_HideWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
|
|
|
|
|
|
|
[nswindow orderOut:nil];
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-04-22 18:14:26 -07:00
|
|
|
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
|
|
|
NSWindow *nswindow = windowData->nswindow;
|
2013-02-11 17:39:52 -08:00
|
|
|
|
2013-09-30 22:35:32 -07:00
|
|
|
/* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
|
|
|
|
a minimized or hidden window, so check for that before showing it.
|
|
|
|
*/
|
2013-04-22 18:14:26 -07:00
|
|
|
[windowData->listener pauseVisibleObservation];
|
2013-07-16 01:02:51 -07:00
|
|
|
if (![nswindow isMiniaturized] && [nswindow isVisible]) {
|
2014-07-31 12:46:23 -07:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2013-07-16 01:02:51 -07:00
|
|
|
[nswindow makeKeyAndOrderFront:nil];
|
|
|
|
}
|
2013-04-22 18:14:26 -07:00
|
|
|
[windowData->listener resumeVisibleObservation];
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-08-07 16:29:21 -07:00
|
|
|
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = windata->nswindow;
|
2011-07-16 11:52:09 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
[nswindow zoom:nil];
|
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(windata);
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-11-11 21:21:18 -08:00
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = data->nswindow;
|
2013-02-11 17:39:52 -08:00
|
|
|
|
2013-11-12 01:52:54 -08:00
|
|
|
if ([data->listener isInFullscreenSpaceTransition]) {
|
2013-11-11 21:21:18 -08:00
|
|
|
[data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
|
|
|
|
} else {
|
|
|
|
[nswindow miniaturize:nil];
|
|
|
|
}
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow isMiniaturized]) {
|
|
|
|
[nswindow deminiaturize:nil];
|
|
|
|
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
|
|
|
[nswindow zoom:nil];
|
2006-07-29 21:51:00 +00:00
|
|
|
}
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
2011-02-26 11:29:23 -08:00
|
|
|
static NSWindow *
|
|
|
|
Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
|
|
|
|
{
|
|
|
|
if (!data->created) {
|
|
|
|
/* Don't mess with other people's windows... */
|
|
|
|
return nswindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data->listener close];
|
2013-04-22 12:07:16 -07:00
|
|
|
data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
|
2011-02-26 11:29:23 -08:00
|
|
|
[data->nswindow setContentView:[nswindow contentView]];
|
2014-11-24 11:46:20 -08:00
|
|
|
[data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
2013-04-22 12:07:16 -07:00
|
|
|
/* See comment in SetupWindowData. */
|
|
|
|
[data->nswindow setOneShot:NO];
|
2011-02-26 11:29:23 -08:00
|
|
|
[data->listener listen:data];
|
|
|
|
|
|
|
|
[nswindow close];
|
|
|
|
|
|
|
|
return data->nswindow;
|
|
|
|
}
|
|
|
|
|
2012-09-13 01:43:53 -04:00
|
|
|
void
|
|
|
|
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2012-09-13 01:43:53 -04:00
|
|
|
{
|
2013-11-14 22:26:49 -08:00
|
|
|
if (SetWindowStyle(window, GetWindowStyle(window))) {
|
2013-02-11 17:39:52 -08:00
|
|
|
if (bordered) {
|
2013-05-18 14:17:52 -07:00
|
|
|
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
|
2012-09-14 11:36:36 -04:00
|
|
|
}
|
2012-09-13 01:43:53 -04:00
|
|
|
}
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2012-09-13 01:43:53 -04:00
|
|
|
|
2013-11-11 02:53:00 -08:00
|
|
|
|
2013-11-12 01:52:54 -08:00
|
|
|
void
|
|
|
|
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2011-02-11 00:25:44 -08:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
NSWindow *nswindow = data->nswindow;
|
|
|
|
NSRect rect;
|
|
|
|
|
|
|
|
/* The view responder chain gets messed with during setStyleMask */
|
|
|
|
if ([[nswindow contentView] nextResponder] == data->listener) {
|
|
|
|
[[nswindow contentView] setNextResponder:nil];
|
|
|
|
}
|
2011-03-21 16:36:17 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if (fullscreen) {
|
|
|
|
SDL_Rect bounds;
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
|
|
|
rect.origin.x = bounds.x;
|
|
|
|
rect.origin.y = bounds.y;
|
|
|
|
rect.size.width = bounds.w;
|
|
|
|
rect.size.height = bounds.h;
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* Hack to fix origin on Mac OS X 10.4 */
|
|
|
|
NSRect screenRect = [[nswindow screen] frame];
|
|
|
|
if (screenRect.size.height >= 1.0f) {
|
|
|
|
rect.origin.y += (screenRect.size.height - rect.size.height);
|
|
|
|
}
|
2011-02-26 11:59:33 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
|
|
|
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
|
2011-02-26 11:29:23 -08:00
|
|
|
} else {
|
2013-02-11 17:39:52 -08:00
|
|
|
nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
|
2011-02-20 12:39:59 -08:00
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
} else {
|
|
|
|
rect.origin.x = window->windowed.x;
|
|
|
|
rect.origin.y = window->windowed.y;
|
|
|
|
rect.size.width = window->windowed.w;
|
|
|
|
rect.size.height = window->windowed.h;
|
2014-06-02 09:09:40 -07:00
|
|
|
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
|
|
|
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
|
|
|
|
} else {
|
|
|
|
nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
|
2013-01-06 19:04:53 +03:00
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
}
|
2011-03-21 16:36:17 -07:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* The view responder chain gets messed with during setStyleMask */
|
|
|
|
if ([[nswindow contentView] nextResponder] != data->listener) {
|
|
|
|
[[nswindow contentView] setNextResponder:data->listener];
|
|
|
|
}
|
2011-02-26 10:11:09 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
s_moveHack = 0;
|
|
|
|
[nswindow setContentSize:rect.size];
|
2013-10-21 02:37:03 -07:00
|
|
|
[nswindow setFrameOrigin:rect.origin];
|
2013-02-11 17:39:52 -08:00
|
|
|
s_moveHack = SDL_GetTicks();
|
2011-02-26 10:15:13 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
/* When the window style changes the title is cleared */
|
|
|
|
if (!fullscreen) {
|
|
|
|
Cocoa_SetWindowTitle(_this, window);
|
|
|
|
}
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
if (SDL_ShouldAllowTopmost() && fullscreen) {
|
|
|
|
/* OpenGL is rendering to the window, so make it visible! */
|
|
|
|
[nswindow setLevel:CGShieldingWindowLevel()];
|
|
|
|
} else {
|
|
|
|
[nswindow setLevel:kCGNormalWindowLevel];
|
2011-07-16 11:52:09 -07:00
|
|
|
}
|
2013-04-22 18:14:26 -07:00
|
|
|
|
2013-08-12 11:09:13 -07:00
|
|
|
if ([nswindow isVisible] || fullscreen) {
|
|
|
|
[data->listener pauseVisibleObservation];
|
|
|
|
[nswindow makeKeyAndOrderFront:nil];
|
|
|
|
[data->listener resumeVisibleObservation];
|
|
|
|
}
|
2013-02-11 17:39:52 -08:00
|
|
|
|
2013-08-07 16:29:25 -07:00
|
|
|
ScheduleContextUpdates(data);
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2011-02-11 00:25:44 -08:00
|
|
|
|
2011-03-11 08:49:20 -08:00
|
|
|
int
|
|
|
|
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
|
|
|
|
{
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
|
|
|
|
const uint32_t tableSize = 256;
|
|
|
|
CGGammaValue redTable[tableSize];
|
|
|
|
CGGammaValue greenTable[tableSize];
|
|
|
|
CGGammaValue blueTable[tableSize];
|
|
|
|
uint32_t i;
|
|
|
|
float inv65535 = 1.0f / 65535.0f;
|
|
|
|
|
|
|
|
/* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
redTable[i] = ramp[0*256+i] * inv65535;
|
|
|
|
greenTable[i] = ramp[1*256+i] * inv65535;
|
|
|
|
blueTable[i] = ramp[2*256+i] * inv65535;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CGSetDisplayTransferByTable(display_id, tableSize,
|
|
|
|
redTable, greenTable, blueTable) != CGDisplayNoErr) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("CGSetDisplayTransferByTable()");
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
|
|
|
|
{
|
|
|
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
|
|
|
CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
|
|
|
|
const uint32_t tableSize = 256;
|
|
|
|
CGGammaValue redTable[tableSize];
|
|
|
|
CGGammaValue greenTable[tableSize];
|
|
|
|
CGGammaValue blueTable[tableSize];
|
|
|
|
uint32_t i, tableCopied;
|
|
|
|
|
|
|
|
if (CGGetDisplayTransferByTable(display_id, tableSize,
|
|
|
|
redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("CGGetDisplayTransferByTable()");
|
2011-03-11 08:49:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < tableCopied; i++) {
|
|
|
|
ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
|
|
|
|
ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
|
|
|
|
ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
void
|
2012-11-07 15:55:43 -08:00
|
|
|
Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2011-02-21 10:50:53 -08:00
|
|
|
/* Move the cursor to the nearest point in the window */
|
2014-02-25 17:27:41 -08:00
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
if (grabbed && data && ![data->listener isMoving]) {
|
2011-02-21 10:50:53 -08:00
|
|
|
int x, y;
|
|
|
|
CGPoint cgpoint;
|
|
|
|
|
|
|
|
SDL_GetMouseState(&x, &y);
|
|
|
|
cgpoint.x = window->x + x;
|
|
|
|
cgpoint.y = window->y + y;
|
2014-02-26 11:35:02 -08:00
|
|
|
|
|
|
|
Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
|
|
|
|
|
|
|
|
DLog("Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
|
2011-02-21 10:50:53 -08:00
|
|
|
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-03-20 11:22:57 -04:00
|
|
|
if ( data && (window->flags & SDL_WINDOW_FULLSCREEN) ) {
|
2013-05-18 14:17:52 -07:00
|
|
|
if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
|
|
|
/* OpenGL is rendering to the window, so make it visible! */
|
|
|
|
[data->nswindow setLevel:CGShieldingWindowLevel()];
|
|
|
|
} else {
|
|
|
|
[data->nswindow setLevel:kCGNormalWindowLevel];
|
|
|
|
}
|
|
|
|
}
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2006-07-24 05:03:02 +00:00
|
|
|
{
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
[data->listener close];
|
|
|
|
[data->listener release];
|
|
|
|
if (data->created) {
|
|
|
|
[data->nswindow close];
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
2013-08-07 16:29:25 -07:00
|
|
|
|
|
|
|
NSArray *contexts = [[data->nscontexts copy] autorelease];
|
|
|
|
for (SDLOpenGLContext *context in contexts) {
|
|
|
|
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
|
|
|
|
[context setWindow:NULL];
|
|
|
|
}
|
|
|
|
[data->nscontexts release];
|
|
|
|
|
2013-02-11 17:39:52 -08:00
|
|
|
SDL_free(data);
|
2006-07-24 05:03:02 +00:00
|
|
|
}
|
2014-07-07 10:33:32 -07:00
|
|
|
window->driverdata = NULL;
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
SDL_bool
|
|
|
|
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
|
|
|
{
|
2010-09-27 01:24:05 -07:00
|
|
|
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
2006-07-24 05:03:02 +00:00
|
|
|
|
|
|
|
if (info->version.major <= SDL_MAJOR_VERSION) {
|
2010-09-27 01:24:05 -07:00
|
|
|
info->subsystem = SDL_SYSWM_COCOA;
|
2011-01-20 16:05:59 -08:00
|
|
|
info->info.cocoa.window = nswindow;
|
2006-07-24 05:03:02 +00:00
|
|
|
return SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
SDL_SetError("Application not compiled with SDL %d.%d\n",
|
|
|
|
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 02:02:12 -08:00
|
|
|
SDL_bool
|
|
|
|
Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
|
|
|
|
{
|
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
|
|
|
|
if ([data->listener isInFullscreenSpace]) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
} else {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 01:52:54 -08:00
|
|
|
SDL_bool
|
|
|
|
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
2015-05-05 19:01:55 -03:00
|
|
|
{ @autoreleasepool
|
2013-11-12 01:52:54 -08:00
|
|
|
{
|
|
|
|
SDL_bool succeeded = SDL_FALSE;
|
|
|
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
|
|
|
|
|
|
|
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
|
|
|
|
succeeded = SDL_TRUE;
|
2014-06-04 09:39:08 -07:00
|
|
|
|
|
|
|
/* Wait for the transition to complete, so application changes
|
|
|
|
take effect properly (e.g. setting the window size, etc.)
|
|
|
|
*/
|
|
|
|
const int limit = 10000;
|
|
|
|
int count = 0;
|
|
|
|
while ([data->listener isInFullscreenSpaceTransition]) {
|
|
|
|
if ( ++count == limit ) {
|
|
|
|
/* Uh oh, transition isn't completing. Should we assert? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDL_Delay(1);
|
|
|
|
SDL_PumpEvents();
|
|
|
|
}
|
2013-11-12 01:52:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return succeeded;
|
2015-05-05 19:01:55 -03:00
|
|
|
}}
|
2013-11-12 01:52:54 -08:00
|
|
|
|
2014-05-27 01:27:42 -04:00
|
|
|
int
|
2014-05-28 01:22:47 -04:00
|
|
|
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
|
2014-05-27 01:27:42 -04:00
|
|
|
{
|
|
|
|
return 0; /* just succeed, the real work is done elsewhere. */
|
|
|
|
}
|
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
|
|
|
|
2006-07-24 05:03:02 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|