21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_COCOA
25 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
26 # error SDL for Mac OS X must be built with a 10.7 SDK or above.
32 #include "../SDL_sysvideo.h"
33 #include "../../events/SDL_keyboard_c.h"
34 #include "../../events/SDL_mouse_c.h"
35 #include "../../events/SDL_touch_c.h"
36 #include "../../events/SDL_windowevents_c.h"
37 #include "../../events/SDL_dropevents_c.h"
48 #ifdef DEBUG_COCOAWINDOW
49 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
51 #define DLog(...) do { } while (0)
55 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
58 @interface SDLWindow : NSWindow <NSDraggingDestination>
60 - (BOOL)canBecomeKeyWindow;
61 - (BOOL)canBecomeMainWindow;
62 - (
void)sendEvent:(NSEvent *)event;
63 - (
void)doCommandBySelector:(
SEL)aSelector;
66 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender;
67 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender;
68 - (BOOL)wantsPeriodicDraggingUpdates;
69 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
74 @implementation SDLWindow
76 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
81 if ([menuItem action] ==
@selector(toggleFullScreen:)) {
91 return [
super validateMenuItem:menuItem];
94 - (BOOL)canBecomeKeyWindow
99 - (BOOL)canBecomeMainWindow
104 - (
void)sendEvent:(NSEvent *)event
106 [
super sendEvent:event];
108 if ([event
type] != NSEventTypeLeftMouseUp) {
112 id delegate = [
self delegate];
117 if ([delegate isMoving]) {
118 [delegate windowDidFinishMoving];
125 - (
void)doCommandBySelector:(
SEL)aSelector
130 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender
132 if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
133 return NSDragOperationGeneric;
136 return NSDragOperationNone;
139 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender
142 NSPasteboard *pasteboard = [sender draggingPasteboard];
143 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
144 NSString *desiredType = [pasteboard availableTypeFromArray:types];
147 if (desiredType == nil) {
151 NSData *
data = [pasteboard dataForType:desiredType];
156 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
157 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
159 for (NSString *
path in array) {
160 NSURL *fileURL = [NSURL fileURLWithPath:path];
161 NSNumber *isAlias = nil;
163 [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
166 if ([isAlias boolValue]) {
167 NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
168 NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
169 if (bookmark != nil) {
170 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
173 bookmarkDataIsStale:nil
176 if (resolvedURL != nil) {
177 fileURL = resolvedURL;
191 - (BOOL)wantsPeriodicDraggingUpdates
203 for (sdlwindow = _this->
windows; sdlwindow; sdlwindow = sdlwindow->
next) {
205 if (nswindow ==
self) {
219 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
221 r->origin.
y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
227 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
229 @
synchronized (contexts) {
230 for (SDLOpenGLContext *
context in contexts) {
231 if (
context == currentContext) {
234 [context scheduleUpdate];
242 GetHintCtrlClickEmulateRightClick()
250 NSUInteger style = 0;
253 style = NSWindowStyleMaskBorderless;
256 style = NSWindowStyleMaskBorderless;
258 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
261 style |= NSWindowStyleMaskResizable;
268 SetWindowStyle(
SDL_Window * window, NSUInteger style)
271 NSWindow *nswindow = data->
nswindow;
274 if ([[nswindow contentView] nextResponder] == data->
listener) {
275 [[nswindow contentView] setNextResponder:nil];
278 [nswindow setStyleMask:style];
281 if ([[nswindow contentView] nextResponder] != data->
listener) {
282 [[nswindow contentView] setNextResponder:data->listener];
293 NSNotificationCenter *center;
295 NSView *view = [window contentView];
307 center = [NSNotificationCenter defaultCenter];
309 if ([window delegate] != nil) {
310 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
311 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
312 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
313 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
314 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
315 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
316 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
317 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
318 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
319 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
320 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
321 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
322 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
323 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
325 [window setDelegate:self];
332 [window addObserver:self
333 forKeyPath:@"visible"
334 options:NSKeyValueObservingOptionNew
337 [window setNextResponder:self];
338 [window setAcceptsMouseMovedEvents:YES];
340 [view setNextResponder:self];
342 [view setAcceptsTouchEvents:YES];
345 - (
void)observeValueForKeyPath:(NSString *)keyPath
347 change:(NSDictionary *)change
348 context:(
void *)context
354 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
355 int newVisibility = [[change objectForKey:@"new"] intValue];
372 BOOL isVisible = [_data->nswindow isVisible];
385 -(BOOL) setFullscreenSpace:(BOOL) state
403 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
405 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
412 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
413 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
434 NSNotificationCenter *center;
436 NSView *view = [window contentView];
438 center = [NSNotificationCenter defaultCenter];
440 if ([window delegate] !=
self) {
441 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
442 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
443 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
444 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
445 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
446 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
447 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
448 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
449 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
450 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
451 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
452 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
453 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
454 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
456 [window setDelegate:nil];
459 [window removeObserver:self forKeyPath:@"visible"];
461 if ([window nextResponder] ==
self) {
462 [window setNextResponder:nil];
464 if ([view nextResponder] ==
self) {
465 [view setNextResponder:nil];
474 -(
void) setPendingMoveX:(
int)x Y:(
int)y
496 - (BOOL)windowShouldClose:(
id)sender
502 - (
void)windowDidExpose:(NSNotification *)aNotification
507 - (
void)windowWillMove:(NSNotification *)aNotification
515 - (
void)windowDidMove:(NSNotification *)aNotification
521 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
522 ConvertNSRect([nswindow
screen], fullscreen, &rect);
536 rect.origin.x = window->
x;
537 rect.origin.y = window->
y;
538 ConvertNSRect([nswindow
screen], fullscreen, &rect);
539 [nswindow setFrameOrigin:rect.origin];
544 x = (int)rect.origin.x;
545 y = (
int)rect.origin.y;
547 ScheduleContextUpdates(
_data);
552 - (
void)windowDidResize:(NSNotification *)aNotification
562 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
564 x = (int)rect.origin.x;
565 y = (
int)rect.origin.y;
566 w = (int)rect.size.width;
567 h = (
int)rect.size.height;
573 ScheduleContextUpdates(
_data);
580 const BOOL zoomed = [nswindow isZoomed];
588 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
593 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
598 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
616 point = [_data->nswindow mouseLocationOutsideOfEventStream];
618 y = (
int)(window->
h - point.y);
629 [NSMenu setMenuBarVisible:NO];
637 - (
void)windowDidResignKey:(NSNotification *)aNotification
655 [NSMenu setMenuBarVisible:YES];
659 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
661 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
667 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
671 [
self windowDidResize:aNotification];
675 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
679 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
685 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
693 SetWindowStyle(window, GetWindowStyle(window));
698 [
self windowDidExitFullScreen:nil];
701 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
705 NSWindow *nswindow = data->
nswindow;
711 [
self setFullscreenSpace:NO];
716 SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
719 [NSMenu setMenuBarVisible:NO];
728 [
self windowDidMove:aNotification];
729 [
self windowDidResize:aNotification];
733 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
743 SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
746 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
754 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
759 [
self windowDidEnterFullScreen:nil];
762 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
769 SetWindowStyle(window, GetWindowStyle(window));
771 [nswindow setLevel:kCGNormalWindowLevel];
775 [
self setFullscreenSpace:YES];
778 [nswindow miniaturize:nil];
783 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
785 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
787 [NSMenu setMenuBarVisible:YES];
805 ConvertNSRect([nswindow screen], NO, &rect);
808 [nswindow setContentSize:rect.size];
809 [nswindow setFrameOrigin:rect.origin];
819 [
self windowDidMove:aNotification];
820 [
self windowDidResize:aNotification];
829 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
832 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
834 return proposedOptions;
843 - (
void)flagsChanged:(NSEvent *)theEvent
847 - (
void)keyDown:(NSEvent *)theEvent
851 - (
void)keyUp:(NSEvent *)theEvent
859 - (
void)doCommandBySelector:(
SEL)aSelector
864 - (BOOL)processHitTest:(NSEvent *)theEvent
869 const NSPoint
location = [theEvent locationInWindow];
875 [_data->nswindow setMovableByWindowBackground:YES];
883 [_data->nswindow setMovableByWindowBackground:NO];
890 - (
void)mouseDown:(NSEvent *)theEvent
896 if ([theEvent window]) {
897 NSRect windowRect = [[[theEvent window] contentView] frame];
898 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
903 if ([
self processHitTest:theEvent]) {
908 switch ([theEvent buttonNumber]) {
910 if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
911 GetHintCtrlClickEmulateRightClick()) {
926 button = (int) [theEvent buttonNumber] + 1;
930 clicks = (int) [theEvent clickCount];
934 - (
void)rightMouseDown:(NSEvent *)theEvent
936 [
self mouseDown:theEvent];
939 - (
void)otherMouseDown:(NSEvent *)theEvent
941 [
self mouseDown:theEvent];
944 - (
void)mouseUp:(NSEvent *)theEvent
949 if ([
self processHitTest:theEvent]) {
954 switch ([theEvent buttonNumber]) {
970 button = (int) [theEvent buttonNumber] + 1;
974 clicks = (int) [theEvent clickCount];
978 - (
void)rightMouseUp:(NSEvent *)theEvent
980 [
self mouseUp:theEvent];
983 - (
void)otherMouseUp:(NSEvent *)theEvent
985 [
self mouseUp:theEvent];
988 - (
void)mouseMoved:(NSEvent *)theEvent
995 if ([
self processHitTest:theEvent]) {
1004 point = [theEvent locationInWindow];
1006 y = (
int)(window->
h - point.y);
1012 }
else if (x >= window->
w) {
1017 }
else if (y >= window->
h) {
1021 #if !SDL_MAC_NO_SANDBOX
1028 cgpoint.x = window->
x + x;
1029 cgpoint.y = window->
y + y;
1031 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1032 CGAssociateMouseAndMouseCursorPosition(YES);
1041 - (
void)mouseDragged:(NSEvent *)theEvent
1043 [
self mouseMoved:theEvent];
1046 - (
void)rightMouseDragged:(NSEvent *)theEvent
1048 [
self mouseMoved:theEvent];
1051 - (
void)otherMouseDragged:(NSEvent *)theEvent
1053 [
self mouseMoved:theEvent];
1056 - (
void)scrollWheel:(NSEvent *)theEvent
1061 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
1063 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
1064 int existingTouchCount = 0;
1066 for (NSTouch* touch
in touches) {
1067 if ([touch phase] != NSTouchPhaseBegan) {
1068 existingTouchCount++;
1071 if (existingTouchCount == 0) {
1074 DLog(
"Reset Lost Fingers: %d", numFingers);
1075 for (--numFingers; numFingers >= 0; --numFingers) {
1081 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1082 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1085 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1087 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1090 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1092 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1095 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1097 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1100 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1102 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1104 for (NSTouch *touch
in touches) {
1111 float x = [touch normalizedPosition].x;
1112 float y = [touch normalizedPosition].y;
1117 case NSTouchPhaseBegan:
1120 case NSTouchPhaseEnded:
1121 case NSTouchPhaseCancelled:
1124 case NSTouchPhaseMoved:
1135 @interface SDLView : NSView {
1142 - (
void)rightMouseDown:(NSEvent *)theEvent;
1143 - (BOOL)mouseDownCanMoveWindow;
1144 - (
void)drawRect:(NSRect)dirtyRect;
1145 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
1146 - (BOOL)wantsUpdateLayer;
1147 - (
void)updateLayer;
1150 @implementation SDLView
1158 - (
void)drawRect:(NSRect)dirtyRect
1163 [[NSColor blackColor] setFill];
1164 NSRectFill(dirtyRect);
1168 -(BOOL) wantsUpdateLayer
1178 self.layer.backgroundColor = NSColor.blackColor.CGColor;
1179 ScheduleContextUpdates((
SDL_WindowData *) _sdlWindow->driverdata);
1183 - (
void)rightMouseDown:(NSEvent *)theEvent
1185 [[
self nextResponder] rightMouseDown:theEvent];
1188 - (BOOL)mouseDownCanMoveWindow
1196 - (
void)resetCursorRects
1198 [
super resetCursorRects];
1202 [
self addCursorRect:[
self bounds]
1203 cursor:mouse->cur_cursor->driverdata];
1205 [
self addCursorRect:[
self bounds]
1206 cursor:[NSCursor invisibleCursor]];
1210 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1236 data->
nscontexts = [[NSMutableArray alloc] init];
1243 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1245 window->
x = (int)rect.origin.x;
1246 window->
y = (
int)rect.origin.y;
1247 window->
w = (int)rect.size.width;
1248 window->
h = (
int)rect.size.height;
1252 [data->listener listen:data];
1254 if ([nswindow isVisible]) {
1261 unsigned long style = [nswindow styleMask];
1263 if (style == NSWindowStyleMaskBorderless) {
1268 if (style & NSWindowStyleMaskResizable) {
1282 if ([nswindow isMiniaturized]) {
1288 if ([nswindow isKeyWindow]) {
1296 [nswindow setOneShot:NO];
1313 NSArray *screens = [NSScreen screens];
1316 rect.origin.x = window->
x;
1317 rect.origin.y = window->
y;
1318 rect.size.width = window->
w;
1319 rect.size.height = window->
h;
1322 style = GetWindowStyle(window);
1325 NSScreen *screen = nil;
1326 for (NSScreen *candidate
in screens) {
1327 NSRect screenRect = [candidate frame];
1328 if (rect.origin.x >= screenRect.origin.x &&
1329 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1330 rect.origin.y >= screenRect.origin.y &&
1331 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1333 rect.origin.x -= screenRect.origin.x;
1334 rect.origin.y -= screenRect.origin.y;
1339 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1341 @catch (NSException *
e) {
1347 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1351 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1356 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1357 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1358 [contentView setSDLWindow:window];
1361 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1362 [contentView setWantsBestResolutionOpenGLSurface:YES];
1366 #if SDL_VIDEO_OPENGL_ES2
1367 #if SDL_VIDEO_OPENGL_EGL
1370 [contentView setWantsLayer:TRUE];
1374 [nswindow setContentView:contentView];
1375 [contentView release];
1377 if (SetupWindowData(_this, window, nswindow,
SDL_TRUE) < 0) {
1387 #if SDL_VIDEO_OPENGL_ES2
1389 #if SDL_VIDEO_OPENGL_EGL
1390 if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
1396 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
1407 NSWindow *nswindow = (NSWindow *) data;
1411 title = [nswindow title];
1416 return SetupWindowData(_this, window, nswindow,
SDL_FALSE);
1423 const char *title = window->
title ? window->
title :
"";
1425 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1426 [nswindow setTitle:string];
1437 [NSApp setApplicationIconImage:nsimage];
1446 NSWindow *nswindow = windata->
nswindow;
1450 rect.origin.x = window->
x;
1451 rect.origin.y = window->
y;
1452 rect.size.width = window->
w;
1453 rect.size.height = window->
h;
1456 moveHack = s_moveHack;
1458 [nswindow setFrameOrigin:rect.origin];
1459 s_moveHack = moveHack;
1461 ScheduleContextUpdates(windata);
1469 NSWindow *nswindow = windata->
nswindow;
1477 rect.origin.x = window->
x;
1478 rect.origin.y = window->
y;
1479 rect.size.width = window->
w;
1480 rect.size.height = window->
h;
1483 moveHack = s_moveHack;
1485 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1486 s_moveHack = moveHack;
1488 ScheduleContextUpdates(windata);
1498 minSize.width = window->
min_w;
1499 minSize.height = window->
min_h;
1501 [windata->
nswindow setContentMinSize:minSize];
1511 maxSize.width = window->
max_w;
1512 maxSize.height = window->
max_h;
1514 [windata->
nswindow setContentMaxSize:maxSize];
1522 NSWindow *nswindow = windowData->
nswindow;
1524 if (![nswindow isMiniaturized]) {
1525 [windowData->listener pauseVisibleObservation];
1526 [nswindow makeKeyAndOrderFront:nil];
1527 [windowData->listener resumeVisibleObservation];
1537 [nswindow orderOut:nil];
1545 NSWindow *nswindow = windowData->
nswindow;
1550 [windowData->listener pauseVisibleObservation];
1551 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1552 [NSApp activateIgnoringOtherApps:YES];
1553 [nswindow makeKeyAndOrderFront:nil];
1555 [windowData->listener resumeVisibleObservation];
1563 NSWindow *nswindow = windata->
nswindow;
1565 [nswindow zoom:nil];
1567 ScheduleContextUpdates(windata);
1575 NSWindow *nswindow = data->
nswindow;
1578 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1580 [nswindow miniaturize:nil];
1590 if ([nswindow isMiniaturized]) {
1591 [nswindow deminiaturize:nil];
1593 [nswindow zoom:nil];
1601 if (SetWindowStyle(window, GetWindowStyle(window))) {
1619 SetWindowStyle(window, GetWindowStyle(window));
1628 NSWindow *nswindow = data->
nswindow;
1632 if ([[nswindow contentView] nextResponder] == data->
listener) {
1633 [[nswindow contentView] setNextResponder:nil];
1640 rect.origin.x = bounds.
x;
1641 rect.origin.y = bounds.
y;
1642 rect.size.width = bounds.
w;
1643 rect.size.height = bounds.
h;
1644 ConvertNSRect([nswindow screen], fullscreen, &rect);
1647 NSRect screenRect = [[nswindow screen] frame];
1648 if (screenRect.size.height >= 1.0f) {
1652 [nswindow setStyleMask:NSWindowStyleMaskBorderless];
1658 ConvertNSRect([nswindow screen], fullscreen, &rect);
1660 [nswindow setStyleMask:GetWindowStyle(window)];
1663 NSRect frameRect = [nswindow frame];
1664 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1665 [nswindow setFrame:frameRect display:NO];
1669 if ([[nswindow contentView] nextResponder] != data->
listener) {
1670 [[nswindow contentView] setNextResponder:data->listener];
1674 [nswindow setContentSize:rect.size];
1675 [nswindow setFrameOrigin:rect.origin];
1685 [nswindow setLevel:CGShieldingWindowLevel()];
1687 [nswindow setLevel:kCGNormalWindowLevel];
1690 if ([nswindow isVisible] || fullscreen) {
1691 [data->listener pauseVisibleObservation];
1692 [nswindow makeKeyAndOrderFront:nil];
1693 [data->listener resumeVisibleObservation];
1696 ScheduleContextUpdates(data);
1705 CGGammaValue redTable[tableSize];
1706 CGGammaValue greenTable[tableSize];
1707 CGGammaValue blueTable[tableSize];
1709 float inv65535 = 1.0f / 65535.0f;
1712 for (i = 0; i < 256; i++) {
1713 redTable[i] = ramp[0*256+i] * inv65535;
1714 greenTable[i] = ramp[1*256+i] * inv65535;
1715 blueTable[i] = ramp[2*256+i] * inv65535;
1718 if (CGSetDisplayTransferByTable(display_id, tableSize,
1719 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1731 CGGammaValue redTable[tableSize];
1732 CGGammaValue greenTable[tableSize];
1733 CGGammaValue blueTable[tableSize];
1736 if (CGGetDisplayTransferByTable(display_id, tableSize,
1737 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1741 for (i = 0; i < tableCopied; i++) {
1742 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1743 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1744 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1764 cgpoint.x = window->
x + x;
1765 cgpoint.y = window->
y + y;
1769 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1770 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1778 [data->nswindow setLevel:CGShieldingWindowLevel()];
1780 [data->nswindow setLevel:kCGNormalWindowLevel];
1793 [NSMenu setMenuBarVisible:YES];
1795 [data->listener close];
1796 [data->listener release];
1798 [data->nswindow close];
1801 NSArray *contexts = [[data->nscontexts copy] autorelease];
1802 for (SDLOpenGLContext *context
in contexts) {
1804 [context setWindow:NULL];
1806 [data->nscontexts release];
1823 SDL_SetError(
"Application not compiled with SDL %d.%d",
1830 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1848 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1849 const int maxattempts = 3;
1851 while (++attempt <= maxattempts) {
1855 const int limit = 10000;
1858 if ( ++count == limit ) {
1868 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
1889 [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1891 [data->nswindow unregisterDraggedTypes];
1899 [data->
nswindow setAlphaValue:opacity];
int Cocoa_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
EGLNativeDisplayType * display_id
#define SDL_MINOR_VERSION
BOOL isInFullscreenSpace()
GLdouble GLdouble GLdouble r
SDL_Mouse * SDL_GetMouse(void)
NSMutableArray * nscontexts
#define SDL_IsShapedWindow
void SDL_SetKeyboardFocus(SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
GLint GLint GLint GLint GLint x
void Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
#define SDL_MAJOR_VERSION
SDL_bool relative_mode_warp
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
GLuint GLuint GLsizei count
int SDL_SendDropFile(SDL_Window *window, const char *file)
void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
void Cocoa_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
GLfloat GLfloat GLfloat GLfloat h
void Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
#define SDL_GetTouchFinger
The structure that defines a point.
A collection of pixels used in software blitting.
static screen_context_t context
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK
A variable that determines whether ctrl+click should generate a right-click event on Mac...
void Cocoa_SetWindowTitle(_THIS, SDL_Window *window)
GLsizei GLenum GLenum * types
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
#define SDL_GetKeyboardFocus
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
unsigned int modifierFlags
void windowDidFinishMoving()
int SDL_SendDropComplete(SDL_Window *window)
int(* WarpMouseGlobal)(int x, int y)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
#define SDL_GetHintBoolean
struct SDL_VideoDevice::@32 gl_config
static SDL_VideoDevice * _this
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
BOOL isInFullscreenSpaceTransition()
void Cocoa_ShowWindow(_THIS, SDL_Window *window)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Cocoa_WindowListener * listener
struct SDL_VideoData * videodata
void resumeVisibleObservation()
int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
GLubyte GLubyte GLubyte GLubyte w
int(* SetRelativeMouseMode)(SDL_bool enabled)
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
#define SDL_GetNumTouchFingers
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
static const NSUInteger NSEventModifierFlagCapsLock
GLenum GLenum GLsizei const GLuint GLboolean enabled
void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
#define SDL_assert(condition)
PendingWindowOperation pendingWindowOperation
SDL_bool SDL_ShouldAllowTopmost(void)
#define SDL_OutOfMemory()
#define SDL_GetMouseFocus
Uint32 last_fullscreen_flags
int Cocoa_CreateWindow(_THIS, SDL_Window *window)
int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
GLint GLint GLsizei GLsizei height
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
The type used to identify a window.
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
int Cocoa_ResizeWindowShape(SDL_Window *window)
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
union SDL_SysWMinfo::@18 info
BOOL inFullscreenTransition
GLsizei const GLchar *const * path
void pauseVisibleObservation()
void Cocoa_HideWindow(_THIS, SDL_Window *window)
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
void Cocoa_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
#define SDL_GetMouseState
void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
A rectangle, with the origin at the upper left.
int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)