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" 47 #ifdef DEBUG_COCOAWINDOW 48 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) 50 #define DLog(...) do { } while (0) 54 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN) 57 @interface SDLWindow : NSWindow <NSDraggingDestination>
59 - (BOOL)canBecomeKeyWindow;
60 - (BOOL)canBecomeMainWindow;
61 - (
void)sendEvent:(NSEvent *)event;
62 - (
void)doCommandBySelector:(
SEL)aSelector;
65 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender;
66 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender;
67 - (BOOL)wantsPeriodicDraggingUpdates;
68 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
73 @implementation SDLWindow
75 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
80 if ([menuItem action] ==
@selector(toggleFullScreen:)) {
90 return [
super validateMenuItem:menuItem];
93 - (BOOL)canBecomeKeyWindow
98 - (BOOL)canBecomeMainWindow
103 - (
void)sendEvent:(NSEvent *)event
105 [
super sendEvent:event];
107 if ([event
type] != NSEventTypeLeftMouseUp) {
111 id delegate = [
self delegate];
116 if ([delegate isMoving]) {
117 [delegate windowDidFinishMoving];
124 - (
void)doCommandBySelector:(
SEL)aSelector
129 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender
131 if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
132 return NSDragOperationGeneric;
135 return NSDragOperationNone;
138 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender
141 NSPasteboard *pasteboard = [sender draggingPasteboard];
142 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
143 NSString *desiredType = [pasteboard availableTypeFromArray:types];
146 if (desiredType == nil) {
150 NSData *
data = [pasteboard dataForType:desiredType];
155 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
156 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
158 for (NSString *
path in array) {
159 NSURL *fileURL = [NSURL fileURLWithPath:path];
160 NSNumber *isAlias = nil;
162 [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
165 if ([isAlias boolValue]) {
166 NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
167 NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
168 if (bookmark != nil) {
169 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
172 bookmarkDataIsStale:nil
175 if (resolvedURL != nil) {
176 fileURL = resolvedURL;
190 - (BOOL)wantsPeriodicDraggingUpdates
202 for (sdlwindow = _this->
windows; sdlwindow; sdlwindow = sdlwindow->
next) {
204 if (nswindow ==
self) {
218 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
220 r->origin.
y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
226 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
228 @
synchronized (contexts) {
229 for (SDLOpenGLContext *
context in contexts) {
230 if (
context == currentContext) {
233 [context scheduleUpdate];
241 GetHintCtrlClickEmulateRightClick()
249 NSUInteger style = 0;
252 style = NSWindowStyleMaskBorderless;
255 style = NSWindowStyleMaskBorderless;
257 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
260 style |= NSWindowStyleMaskResizable;
267 SetWindowStyle(
SDL_Window * window, NSUInteger style)
270 NSWindow *nswindow = data->
nswindow;
273 if ([[nswindow contentView] nextResponder] == data->
listener) {
274 [[nswindow contentView] setNextResponder:nil];
277 [nswindow setStyleMask:style];
280 if ([[nswindow contentView] nextResponder] != data->
listener) {
281 [[nswindow contentView] setNextResponder:data->listener];
292 NSNotificationCenter *center;
294 NSView *view = [window contentView];
306 center = [NSNotificationCenter defaultCenter];
308 if ([window delegate] != nil) {
309 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
310 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
311 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
312 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
313 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
314 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
315 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
316 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
317 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
318 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
319 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
320 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
321 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
322 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
324 [window setDelegate:self];
331 [window addObserver:self
332 forKeyPath:@"visible"
333 options:NSKeyValueObservingOptionNew
336 [window setNextResponder:self];
337 [window setAcceptsMouseMovedEvents:YES];
339 [view setNextResponder:self];
341 [view setAcceptsTouchEvents:YES];
344 - (
void)observeValueForKeyPath:(NSString *)keyPath
346 change:(NSDictionary *)change
347 context:(
void *)context
353 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
354 int newVisibility = [[change objectForKey:@"new"] intValue];
371 BOOL isVisible = [_data->nswindow isVisible];
384 -(BOOL) setFullscreenSpace:(BOOL) state
402 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
404 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
411 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
412 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
433 NSNotificationCenter *center;
435 NSView *view = [window contentView];
437 center = [NSNotificationCenter defaultCenter];
439 if ([window delegate] !=
self) {
440 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
441 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
442 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
443 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
444 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
445 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
446 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
447 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
448 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
449 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
450 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
451 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
452 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
453 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
455 [window setDelegate:nil];
458 [window removeObserver:self forKeyPath:@"visible"];
460 if ([window nextResponder] ==
self) {
461 [window setNextResponder:nil];
463 if ([view nextResponder] ==
self) {
464 [view setNextResponder:nil];
473 -(
void) setPendingMoveX:(
int)x Y:(
int)y
495 - (BOOL)windowShouldClose:(
id)sender
501 - (
void)windowDidExpose:(NSNotification *)aNotification
506 - (
void)windowWillMove:(NSNotification *)aNotification
514 - (
void)windowDidMove:(NSNotification *)aNotification
520 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
521 ConvertNSRect([nswindow
screen], fullscreen, &rect);
535 rect.origin.x = window->
x;
536 rect.origin.y = window->
y;
537 ConvertNSRect([nswindow
screen], fullscreen, &rect);
538 [nswindow setFrameOrigin:rect.origin];
543 x = (int)rect.origin.x;
544 y = (
int)rect.origin.y;
546 ScheduleContextUpdates(
_data);
551 - (
void)windowDidResize:(NSNotification *)aNotification
561 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
563 x = (int)rect.origin.x;
564 y = (
int)rect.origin.y;
565 w = (int)rect.size.width;
566 h = (
int)rect.size.height;
572 ScheduleContextUpdates(
_data);
579 const BOOL zoomed = [nswindow isZoomed];
587 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
592 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
597 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
615 point = [_data->nswindow mouseLocationOutsideOfEventStream];
617 y = (
int)(window->
h - point.y);
628 [NSMenu setMenuBarVisible:NO];
636 - (
void)windowDidResignKey:(NSNotification *)aNotification
654 [NSMenu setMenuBarVisible:YES];
658 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
660 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
666 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
670 [
self windowDidResize:aNotification];
674 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
678 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
684 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
692 SetWindowStyle(window, GetWindowStyle(window));
697 [
self windowDidExitFullScreen:nil];
700 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
704 NSWindow *nswindow = data->
nswindow;
710 [
self setFullscreenSpace:NO];
715 SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
718 [NSMenu setMenuBarVisible:NO];
727 [
self windowDidMove:aNotification];
728 [
self windowDidResize:aNotification];
732 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
742 SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
745 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
753 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
758 [
self windowDidEnterFullScreen:nil];
761 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
768 SetWindowStyle(window, GetWindowStyle(window));
770 [nswindow setLevel:kCGNormalWindowLevel];
774 [
self setFullscreenSpace:YES];
777 [nswindow miniaturize:nil];
782 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
784 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
786 [NSMenu setMenuBarVisible:YES];
804 ConvertNSRect([nswindow screen], NO, &rect);
807 [nswindow setContentSize:rect.size];
808 [nswindow setFrameOrigin:rect.origin];
818 [
self windowDidMove:aNotification];
819 [
self windowDidResize:aNotification];
828 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
831 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
833 return proposedOptions;
842 - (
void)flagsChanged:(NSEvent *)theEvent
846 - (
void)keyDown:(NSEvent *)theEvent
850 - (
void)keyUp:(NSEvent *)theEvent
858 - (
void)doCommandBySelector:(
SEL)aSelector
863 - (BOOL)processHitTest:(NSEvent *)theEvent
868 const NSPoint
location = [theEvent locationInWindow];
874 [_data->nswindow setMovableByWindowBackground:YES];
882 [_data->nswindow setMovableByWindowBackground:NO];
889 - (
void)mouseDown:(NSEvent *)theEvent
895 if ([theEvent window]) {
896 NSRect windowRect = [[[theEvent window] contentView] frame];
897 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
902 if ([
self processHitTest:theEvent]) {
907 switch ([theEvent buttonNumber]) {
909 if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
910 GetHintCtrlClickEmulateRightClick()) {
925 button = (int) [theEvent buttonNumber] + 1;
929 clicks = (int) [theEvent clickCount];
933 - (
void)rightMouseDown:(NSEvent *)theEvent
935 [
self mouseDown:theEvent];
938 - (
void)otherMouseDown:(NSEvent *)theEvent
940 [
self mouseDown:theEvent];
943 - (
void)mouseUp:(NSEvent *)theEvent
948 if ([
self processHitTest:theEvent]) {
953 switch ([theEvent buttonNumber]) {
969 button = (int) [theEvent buttonNumber] + 1;
973 clicks = (int) [theEvent clickCount];
977 - (
void)rightMouseUp:(NSEvent *)theEvent
979 [
self mouseUp:theEvent];
982 - (
void)otherMouseUp:(NSEvent *)theEvent
984 [
self mouseUp:theEvent];
987 - (
void)mouseMoved:(NSEvent *)theEvent
994 if ([
self processHitTest:theEvent]) {
1003 point = [theEvent locationInWindow];
1005 y = (
int)(window->
h - point.y);
1011 }
else if (x >= window->
w) {
1016 }
else if (y >= window->
h) {
1020 #if !SDL_MAC_NO_SANDBOX 1027 cgpoint.x = window->
x + x;
1028 cgpoint.y = window->
y + y;
1030 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1031 CGAssociateMouseAndMouseCursorPosition(YES);
1040 - (
void)mouseDragged:(NSEvent *)theEvent
1042 [
self mouseMoved:theEvent];
1045 - (
void)rightMouseDragged:(NSEvent *)theEvent
1047 [
self mouseMoved:theEvent];
1050 - (
void)otherMouseDragged:(NSEvent *)theEvent
1052 [
self mouseMoved:theEvent];
1055 - (
void)scrollWheel:(NSEvent *)theEvent
1060 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
1062 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
1063 int existingTouchCount = 0;
1065 for (NSTouch* touch
in touches) {
1066 if ([touch phase] != NSTouchPhaseBegan) {
1067 existingTouchCount++;
1070 if (existingTouchCount == 0) {
1073 DLog(
"Reset Lost Fingers: %d", numFingers);
1074 for (--numFingers; numFingers >= 0; --numFingers) {
1080 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1081 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1084 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1086 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1089 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1091 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1094 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1096 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1099 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1101 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1103 for (NSTouch *touch
in touches) {
1110 float x = [touch normalizedPosition].x;
1111 float y = [touch normalizedPosition].y;
1116 case NSTouchPhaseBegan:
1119 case NSTouchPhaseEnded:
1120 case NSTouchPhaseCancelled:
1123 case NSTouchPhaseMoved:
1134 @interface SDLView : NSView {
1141 - (
void)rightMouseDown:(NSEvent *)theEvent;
1142 - (BOOL)mouseDownCanMoveWindow;
1143 - (
void)drawRect:(NSRect)dirtyRect;
1144 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
1147 @implementation SDLView
1153 - (
void)drawRect:(NSRect)dirtyRect
1158 - (
void)rightMouseDown:(NSEvent *)theEvent
1160 [[
self nextResponder] rightMouseDown:theEvent];
1163 - (BOOL)mouseDownCanMoveWindow
1171 - (
void)resetCursorRects
1173 [
super resetCursorRects];
1177 [
self addCursorRect:[
self bounds]
1178 cursor:mouse->cur_cursor->driverdata];
1180 [
self addCursorRect:[
self bounds]
1181 cursor:[NSCursor invisibleCursor]];
1185 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1211 data->
nscontexts = [[NSMutableArray alloc] init];
1218 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1220 window->
x = (int)rect.origin.x;
1221 window->
y = (
int)rect.origin.y;
1222 window->
w = (int)rect.size.width;
1223 window->
h = (
int)rect.size.height;
1227 [data->listener listen:data];
1229 if ([nswindow isVisible]) {
1236 unsigned long style = [nswindow styleMask];
1238 if (style == NSWindowStyleMaskBorderless) {
1243 if (style & NSWindowStyleMaskResizable) {
1257 if ([nswindow isMiniaturized]) {
1263 if ([nswindow isKeyWindow]) {
1271 [nswindow setOneShot:NO];
1288 NSArray *screens = [NSScreen screens];
1291 rect.origin.x = window->
x;
1292 rect.origin.y = window->
y;
1293 rect.size.width = window->
w;
1294 rect.size.height = window->
h;
1297 style = GetWindowStyle(window);
1300 NSScreen *screen = nil;
1301 for (NSScreen *candidate
in screens) {
1302 NSRect screenRect = [candidate frame];
1303 if (rect.origin.x >= screenRect.origin.x &&
1304 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1305 rect.origin.y >= screenRect.origin.y &&
1306 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1308 rect.origin.x -= screenRect.origin.x;
1309 rect.origin.y -= screenRect.origin.y;
1314 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1316 @catch (NSException *
e) {
1319 [nswindow setBackgroundColor:[NSColor blackColor]];
1323 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1327 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1332 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1333 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1334 [contentView setSDLWindow:window];
1337 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1338 [contentView setWantsBestResolutionOpenGLSurface:YES];
1342 [nswindow setContentView:contentView];
1343 [contentView release];
1346 [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1348 if (SetupWindowData(_this, window, nswindow,
SDL_TRUE) < 0) {
1359 NSWindow *nswindow = (NSWindow *) data;
1363 title = [nswindow title];
1368 return SetupWindowData(_this, window, nswindow,
SDL_FALSE);
1375 const char *title = window->
title ? window->
title :
"";
1377 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1378 [nswindow setTitle:string];
1389 [NSApp setApplicationIconImage:nsimage];
1398 NSWindow *nswindow = windata->
nswindow;
1402 rect.origin.x = window->
x;
1403 rect.origin.y = window->
y;
1404 rect.size.width = window->
w;
1405 rect.size.height = window->
h;
1408 moveHack = s_moveHack;
1410 [nswindow setFrameOrigin:rect.origin];
1411 s_moveHack = moveHack;
1413 ScheduleContextUpdates(windata);
1421 NSWindow *nswindow = windata->
nswindow;
1429 rect.origin.x = window->
x;
1430 rect.origin.y = window->
y;
1431 rect.size.width = window->
w;
1432 rect.size.height = window->
h;
1435 moveHack = s_moveHack;
1437 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1438 s_moveHack = moveHack;
1440 ScheduleContextUpdates(windata);
1450 minSize.width = window->
min_w;
1451 minSize.height = window->
min_h;
1453 [windata->
nswindow setContentMinSize:minSize];
1463 maxSize.width = window->
max_w;
1464 maxSize.height = window->
max_h;
1466 [windata->
nswindow setContentMaxSize:maxSize];
1474 NSWindow *nswindow = windowData->
nswindow;
1476 if (![nswindow isMiniaturized]) {
1477 [windowData->listener pauseVisibleObservation];
1478 [nswindow makeKeyAndOrderFront:nil];
1479 [windowData->listener resumeVisibleObservation];
1489 [nswindow orderOut:nil];
1497 NSWindow *nswindow = windowData->
nswindow;
1502 [windowData->listener pauseVisibleObservation];
1503 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1504 [NSApp activateIgnoringOtherApps:YES];
1505 [nswindow makeKeyAndOrderFront:nil];
1507 [windowData->listener resumeVisibleObservation];
1515 NSWindow *nswindow = windata->
nswindow;
1517 [nswindow zoom:nil];
1519 ScheduleContextUpdates(windata);
1527 NSWindow *nswindow = data->
nswindow;
1529 if ([data->
listener isInFullscreenSpaceTransition]) {
1530 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1532 [nswindow miniaturize:nil];
1542 if ([nswindow isMiniaturized]) {
1543 [nswindow deminiaturize:nil];
1545 [nswindow zoom:nil];
1553 if (SetWindowStyle(window, GetWindowStyle(window))) {
1570 if (![listener isInFullscreenSpace]) {
1571 SetWindowStyle(window, GetWindowStyle(window));
1580 NSWindow *nswindow = data->
nswindow;
1584 if ([[nswindow contentView] nextResponder] == data->
listener) {
1585 [[nswindow contentView] setNextResponder:nil];
1592 rect.origin.x = bounds.
x;
1593 rect.origin.y = bounds.
y;
1594 rect.size.width = bounds.
w;
1595 rect.size.height = bounds.
h;
1596 ConvertNSRect([nswindow screen], fullscreen, &rect);
1599 NSRect screenRect = [[nswindow screen] frame];
1600 if (screenRect.size.height >= 1.0f) {
1604 [nswindow setStyleMask:NSWindowStyleMaskBorderless];
1610 ConvertNSRect([nswindow screen], fullscreen, &rect);
1612 [nswindow setStyleMask:GetWindowStyle(window)];
1615 NSRect frameRect = [nswindow frame];
1616 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1617 [nswindow setFrame:frameRect display:NO];
1621 if ([[nswindow contentView] nextResponder] != data->
listener) {
1622 [[nswindow contentView] setNextResponder:data->listener];
1626 [nswindow setContentSize:rect.size];
1627 [nswindow setFrameOrigin:rect.origin];
1637 [nswindow setLevel:CGShieldingWindowLevel()];
1639 [nswindow setLevel:kCGNormalWindowLevel];
1642 if ([nswindow isVisible] || fullscreen) {
1643 [data->listener pauseVisibleObservation];
1644 [nswindow makeKeyAndOrderFront:nil];
1645 [data->listener resumeVisibleObservation];
1648 ScheduleContextUpdates(data);
1657 CGGammaValue redTable[tableSize];
1658 CGGammaValue greenTable[tableSize];
1659 CGGammaValue blueTable[tableSize];
1661 float inv65535 = 1.0f / 65535.0f;
1664 for (i = 0; i < 256; i++) {
1665 redTable[i] = ramp[0*256+i] * inv65535;
1666 greenTable[i] = ramp[1*256+i] * inv65535;
1667 blueTable[i] = ramp[2*256+i] * inv65535;
1670 if (CGSetDisplayTransferByTable(display_id, tableSize,
1671 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1683 CGGammaValue redTable[tableSize];
1684 CGGammaValue greenTable[tableSize];
1685 CGGammaValue blueTable[tableSize];
1688 if (CGGetDisplayTransferByTable(display_id, tableSize,
1689 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1693 for (i = 0; i < tableCopied; i++) {
1694 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1695 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1696 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1711 if (grabbed && data && ![data->
listener isMoving]) {
1716 cgpoint.x = window->
x + x;
1717 cgpoint.y = window->
y + y;
1721 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1722 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1727 && ![data->
listener isInFullscreenSpace]) {
1730 [data->nswindow setLevel:CGShieldingWindowLevel()];
1732 [data->nswindow setLevel:kCGNormalWindowLevel];
1744 if ([data->
listener isInFullscreenSpace]) {
1745 [NSMenu setMenuBarVisible:YES];
1747 [data->listener close];
1748 [data->listener release];
1750 [data->nswindow close];
1753 NSArray *contexts = [[data->nscontexts copy] autorelease];
1754 for (SDLOpenGLContext *context
in contexts) {
1756 [context setWindow:NULL];
1758 [data->nscontexts release];
1775 SDL_SetError(
"Application not compiled with SDL %d.%d",
1782 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1786 if ([data->
listener isInFullscreenSpace]) {
1800 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1801 const int maxattempts = 3;
1803 while (++attempt <= maxattempts) {
1807 const int limit = 10000;
1809 while ([data->
listener isInFullscreenSpaceTransition]) {
1810 if ( ++count == limit ) {
1817 if ([data->
listener isInFullscreenSpace] == (state ? YES : NO))
1820 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
1840 [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(* SetRelativeMouseMode)(SDL_bool enabled)
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 SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
#define SDL_GetHintBoolean
static SDL_VideoDevice * _this
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
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
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
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
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 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)