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" 46 #ifdef DEBUG_COCOAWINDOW 47 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) 49 #define DLog(...) do { } while (0) 53 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN) 56 @interface SDLWindow : NSWindow <NSDraggingDestination>
58 - (BOOL)canBecomeKeyWindow;
59 - (BOOL)canBecomeMainWindow;
60 - (
void)sendEvent:(NSEvent *)event;
61 - (
void)doCommandBySelector:(
SEL)aSelector;
64 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender;
65 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender;
66 - (BOOL)wantsPeriodicDraggingUpdates;
69 @implementation SDLWindow
71 - (BOOL)canBecomeKeyWindow
76 - (BOOL)canBecomeMainWindow
81 - (
void)sendEvent:(NSEvent *)event
83 [
super sendEvent:event];
89 id delegate = [
self delegate];
94 if ([delegate isMoving]) {
95 [delegate windowDidFinishMoving];
102 - (
void)doCommandBySelector:(
SEL)aSelector
107 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender
109 if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
110 return NSDragOperationGeneric;
113 return NSDragOperationNone;
116 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender
119 NSPasteboard *pasteboard = [sender draggingPasteboard];
120 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
121 NSString *desiredType = [pasteboard availableTypeFromArray:types];
122 if (desiredType == nil) {
126 NSData *
data = [pasteboard dataForType:desiredType];
131 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
132 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
134 for (NSString *
path in array) {
135 NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
136 NSNumber *isAlias = nil;
139 if ([fileURL respondsToSelector:
@selector(getResourceValue:forKey:error:)]) {
140 [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
144 if ([isAlias boolValue]) {
145 NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
146 NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
147 if (bookmark != nil) {
148 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
151 bookmarkDataIsStale:nil
154 if (resolvedURL != nil) {
155 fileURL = resolvedURL;
168 - (BOOL)wantsPeriodicDraggingUpdates
178 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
180 r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
186 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
188 @
synchronized (contexts) {
189 for (SDLOpenGLContext *context
in contexts) {
190 if (context == currentContext) {
193 [context scheduleUpdate];
200 GetHintCtrlClickEmulateRightClick()
203 return hint !=
NULL && *hint !=
'0';
212 style = NSBorderlessWindowMask;
215 style = NSBorderlessWindowMask;
217 style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
220 style |= NSResizableWindowMask;
227 SetWindowStyle(
SDL_Window * window,
unsigned int style)
230 NSWindow *nswindow = data->
nswindow;
232 if (![nswindow respondsToSelector:
@selector(setStyleMask:)]) {
237 if ([[nswindow contentView] nextResponder] == data->
listener) {
238 [[nswindow contentView] setNextResponder:nil];
241 [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
244 if ([[nswindow contentView] nextResponder] != data->
listener) {
245 [[nswindow contentView] setNextResponder:data->listener];
256 NSNotificationCenter *center;
258 NSView *view = [window contentView];
270 center = [NSNotificationCenter defaultCenter];
272 if ([window delegate] != nil) {
273 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
274 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
275 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
276 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
277 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
278 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
279 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
280 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
281 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
282 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
283 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
284 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
285 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
286 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
288 [window setDelegate:self];
295 [window addObserver:self
296 forKeyPath:@"visible"
297 options:NSKeyValueObservingOptionNew
300 [window setNextResponder:self];
301 [window setAcceptsMouseMovedEvents:YES];
303 [view setNextResponder:self];
305 if ([view respondsToSelector:
@selector(setAcceptsTouchEvents:)]) {
306 [view setAcceptsTouchEvents:YES];
310 - (
void)observeValueForKeyPath:(NSString *)keyPath
312 change:(NSDictionary *)change
313 context:(
void *)context
319 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
320 int newVisibility = [[change objectForKey:@"new"] intValue];
337 BOOL isVisible = [_data->nswindow isVisible];
350 -(BOOL) setFullscreenSpace:(BOOL) state
368 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
370 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
377 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
378 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
399 NSNotificationCenter *center;
401 NSView *view = [window contentView];
403 center = [NSNotificationCenter defaultCenter];
405 if ([window delegate] !=
self) {
406 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
407 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
408 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
409 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
410 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
411 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
412 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
413 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
414 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
415 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
416 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
417 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
418 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
419 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
421 [window setDelegate:nil];
424 [window removeObserver:self forKeyPath:@"visible"];
426 if ([window nextResponder] ==
self) {
427 [window setNextResponder:nil];
429 if ([view nextResponder] ==
self) {
430 [view setNextResponder:nil];
439 -(
void) setPendingMoveX:(
int)x Y:(
int)y
461 - (BOOL)windowShouldClose:(
id)sender
467 - (
void)windowDidExpose:(NSNotification *)aNotification
472 - (
void)windowWillMove:(NSNotification *)aNotification
480 - (
void)windowDidMove:(NSNotification *)aNotification
486 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
487 ConvertNSRect([nswindow
screen], fullscreen, &rect);
496 rect.origin.x = window->
x;
497 rect.origin.y = window->
y;
498 ConvertNSRect([nswindow
screen], fullscreen, &rect);
499 [nswindow setFrameOrigin:rect.origin];
504 x = (int)rect.origin.x;
505 y = (
int)rect.origin.y;
507 ScheduleContextUpdates(
_data);
512 - (
void)windowDidResize:(NSNotification *)aNotification
522 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
524 x = (int)rect.origin.x;
525 y = (
int)rect.origin.y;
526 w = (int)rect.size.width;
527 h = (
int)rect.size.height;
533 ScheduleContextUpdates(
_data);
540 const BOOL zoomed = [nswindow isZoomed];
548 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
553 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
558 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
576 point = [_data->nswindow mouseLocationOutsideOfEventStream];
578 y = (
int)(window->
h - point.y);
589 [NSMenu setMenuBarVisible:NO];
593 if (
floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) {
594 const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
600 - (
void)windowDidResignKey:(NSNotification *)aNotification
618 [NSMenu setMenuBarVisible:YES];
622 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
624 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
630 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
634 [
self windowDidResize:aNotification];
638 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
642 SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
648 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
656 SetWindowStyle(window, GetWindowStyle(window));
661 [
self windowDidExitFullScreen:nil];
664 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
672 [
self setFullscreenSpace:NO];
675 [NSMenu setMenuBarVisible:NO];
684 [
self windowDidResize:aNotification];
688 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
695 SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask);
701 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
709 SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
714 [
self windowDidEnterFullScreen:nil];
717 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
724 SetWindowStyle(window, GetWindowStyle(window));
726 [nswindow setLevel:kCGNormalWindowLevel];
730 [
self setFullscreenSpace:YES];
733 [nswindow miniaturize:nil];
738 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
740 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
742 [NSMenu setMenuBarVisible:YES];
750 [
self windowDidResize:aNotification];
759 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
762 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
764 return proposedOptions;
773 - (
void)flagsChanged:(NSEvent *)theEvent
777 - (
void)keyDown:(NSEvent *)theEvent
781 - (
void)keyUp:(NSEvent *)theEvent
789 - (
void)doCommandBySelector:(
SEL)aSelector
794 - (BOOL)processHitTest:(NSEvent *)theEvent
799 const NSPoint
location = [theEvent locationInWindow];
805 [_data->nswindow setMovableByWindowBackground:YES];
813 [_data->nswindow setMovableByWindowBackground:NO];
820 - (
void)mouseDown:(NSEvent *)theEvent
825 if ([theEvent window]) {
826 NSRect windowRect = [[[theEvent window] contentView] frame];
831 windowRect.size.width += 1;
832 windowRect.size.height += 1;
834 if (!NSPointInRect([theEvent locationInWindow], windowRect)) {
839 if ([
self processHitTest:theEvent]) {
843 switch ([theEvent buttonNumber]) {
845 if (([theEvent modifierFlags] & NSControlKeyMask) &&
846 GetHintCtrlClickEmulateRightClick()) {
861 button = [theEvent buttonNumber] + 1;
867 - (
void)rightMouseDown:(NSEvent *)theEvent
869 [
self mouseDown:theEvent];
872 - (
void)otherMouseDown:(NSEvent *)theEvent
874 [
self mouseDown:theEvent];
877 - (
void)mouseUp:(NSEvent *)theEvent
881 if ([
self processHitTest:theEvent]) {
885 switch ([theEvent buttonNumber]) {
901 button = [theEvent buttonNumber] + 1;
907 - (
void)rightMouseUp:(NSEvent *)theEvent
909 [
self mouseUp:theEvent];
912 - (
void)otherMouseUp:(NSEvent *)theEvent
914 [
self mouseUp:theEvent];
917 - (
void)mouseMoved:(NSEvent *)theEvent
924 if ([
self processHitTest:theEvent]) {
932 point = [theEvent locationInWindow];
934 y = (
int)(window->
h - point.y);
940 }
else if (x >= window->
w) {
945 }
else if (y >= window->
h) {
949 #if !SDL_MAC_NO_SANDBOX 956 cgpoint.x = window->
x + x;
957 cgpoint.y = window->
y + y;
963 CGSetLocalEventsSuppressionInterval(0.0);
964 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
965 CGSetLocalEventsSuppressionInterval(0.25);
974 - (
void)mouseDragged:(NSEvent *)theEvent
976 [
self mouseMoved:theEvent];
979 - (
void)rightMouseDragged:(NSEvent *)theEvent
981 [
self mouseMoved:theEvent];
984 - (
void)otherMouseDragged:(NSEvent *)theEvent
986 [
self mouseMoved:theEvent];
989 - (
void)scrollWheel:(NSEvent *)theEvent
994 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
996 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
997 int existingTouchCount = 0;
999 for (NSTouch* touch
in touches) {
1000 if ([touch phase] != NSTouchPhaseBegan) {
1001 existingTouchCount++;
1004 if (existingTouchCount == 0) {
1007 DLog(
"Reset Lost Fingers: %d", numFingers);
1008 for (--numFingers; numFingers >= 0; --numFingers) {
1014 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1015 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1018 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1020 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1023 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1025 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1028 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1030 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1033 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1035 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1037 for (NSTouch *touch
in touches) {
1044 float x = [touch normalizedPosition].x;
1045 float y = [touch normalizedPosition].y;
1050 case NSTouchPhaseBegan:
1053 case NSTouchPhaseEnded:
1054 case NSTouchPhaseCancelled:
1057 case NSTouchPhaseMoved:
1068 @interface SDLView : NSView {
1075 - (
void)rightMouseDown:(NSEvent *)theEvent;
1076 - (BOOL)mouseDownCanMoveWindow;
1077 - (
void)drawRect:(NSRect)dirtyRect;
1080 @implementation SDLView
1086 - (
void)drawRect:(NSRect)dirtyRect
1091 - (
void)rightMouseDown:(NSEvent *)theEvent
1093 [[
self nextResponder] rightMouseDown:theEvent];
1096 - (BOOL)mouseDownCanMoveWindow
1104 - (
void)resetCursorRects
1106 [
super resetCursorRects];
1110 [
self addCursorRect:[
self bounds]
1111 cursor:mouse->cur_cursor->driverdata];
1113 [
self addCursorRect:[
self bounds]
1114 cursor:[NSCursor invisibleCursor]];
1135 data->
nscontexts = [[NSMutableArray alloc] init];
1142 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1144 window->
x = (int)rect.origin.x;
1145 window->
y = (
int)rect.origin.y;
1146 window->
w = (int)rect.size.width;
1147 window->
h = (
int)rect.size.height;
1151 [data->listener listen:data];
1153 if ([nswindow isVisible]) {
1160 unsigned int style = [nswindow styleMask];
1162 if (style == NSBorderlessWindowMask) {
1167 if (style & NSResizableWindowMask) {
1181 if ([nswindow isMiniaturized]) {
1187 if ([nswindow isKeyWindow]) {
1195 [nswindow setOneShot:NO];
1212 NSArray *screens = [NSScreen screens];
1215 rect.origin.x = window->
x;
1216 rect.origin.y = window->
y;
1217 rect.size.width = window->
w;
1218 rect.size.height = window->
h;
1221 style = GetWindowStyle(window);
1224 NSScreen *screen = nil;
1225 for (NSScreen *candidate
in screens) {
1226 NSRect screenRect = [candidate frame];
1227 if (rect.origin.x >= screenRect.origin.x &&
1228 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1229 rect.origin.y >= screenRect.origin.y &&
1230 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1232 rect.origin.x -= screenRect.origin.x;
1233 rect.origin.y -= screenRect.origin.y;
1238 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1240 @catch (NSException *
e) {
1243 [nswindow setBackgroundColor:[NSColor blackColor]];
1247 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1251 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1256 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1257 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1258 [contentView setSDLWindow:window];
1261 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1262 [contentView setWantsBestResolutionOpenGLSurface:YES];
1266 [nswindow setContentView: contentView];
1267 [contentView release];
1270 [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1272 if (SetupWindowData(
_this, window, nswindow,
SDL_TRUE) < 0) {
1283 NSWindow *nswindow = (NSWindow *) data;
1287 title = [nswindow title];
1299 const char *title = window->
title ? window->
title :
"";
1301 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1302 [nswindow setTitle:string];
1313 [NSApp setApplicationIconImage:nsimage];
1322 NSWindow *nswindow = windata->
nswindow;
1326 rect.origin.x = window->
x;
1327 rect.origin.y = window->
y;
1328 rect.size.width = window->
w;
1329 rect.size.height = window->
h;
1332 moveHack = s_moveHack;
1334 [nswindow setFrameOrigin:rect.origin];
1335 s_moveHack = moveHack;
1337 ScheduleContextUpdates(windata);
1345 NSWindow *nswindow = windata->
nswindow;
1353 rect.origin.x = window->
x;
1354 rect.origin.y = window->
y;
1355 rect.size.width = window->
w;
1356 rect.size.height = window->
h;
1359 moveHack = s_moveHack;
1361 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1362 s_moveHack = moveHack;
1364 ScheduleContextUpdates(windata);
1374 minSize.width = window->
min_w;
1375 minSize.height = window->
min_h;
1377 [windata->
nswindow setContentMinSize:minSize];
1387 maxSize.width = window->
max_w;
1388 maxSize.height = window->
max_h;
1390 [windata->
nswindow setContentMaxSize:maxSize];
1398 NSWindow *nswindow = windowData->
nswindow;
1400 if (![nswindow isMiniaturized]) {
1401 [windowData->listener pauseVisibleObservation];
1402 [nswindow makeKeyAndOrderFront:nil];
1403 [windowData->listener resumeVisibleObservation];
1413 [nswindow orderOut:nil];
1421 NSWindow *nswindow = windowData->
nswindow;
1426 [windowData->listener pauseVisibleObservation];
1427 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1428 [NSApp activateIgnoringOtherApps:YES];
1429 [nswindow makeKeyAndOrderFront:nil];
1431 [windowData->listener resumeVisibleObservation];
1439 NSWindow *nswindow = windata->
nswindow;
1441 [nswindow zoom:nil];
1443 ScheduleContextUpdates(windata);
1451 NSWindow *nswindow = data->
nswindow;
1453 if ([data->
listener isInFullscreenSpaceTransition]) {
1454 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1456 [nswindow miniaturize:nil];
1466 if ([nswindow isMiniaturized]) {
1467 [nswindow deminiaturize:nil];
1469 [nswindow zoom:nil];
1474 Cocoa_RebuildWindow(
SDL_WindowData * data, NSWindow * nswindow,
unsigned style)
1481 [data->listener close];
1482 data->
nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
1483 [data->nswindow setContentView:[nswindow contentView]];
1484 [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1486 [data->nswindow setOneShot:NO];
1487 [data->listener listen:data];
1498 if (SetWindowStyle(window, GetWindowStyle(window))) {
1511 NSWindow *nswindow = data->
nswindow;
1515 if ([[nswindow contentView] nextResponder] == data->
listener) {
1516 [[nswindow contentView] setNextResponder:nil];
1523 rect.origin.x = bounds.
x;
1524 rect.origin.y = bounds.
y;
1525 rect.size.width = bounds.
w;
1526 rect.size.height = bounds.
h;
1527 ConvertNSRect([nswindow screen], fullscreen, &rect);
1530 NSRect screenRect = [[nswindow screen] frame];
1531 if (screenRect.size.height >= 1.0f) {
1535 if ([nswindow respondsToSelector:
@selector(setStyleMask:)]) {
1536 [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
1538 nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
1545 ConvertNSRect([nswindow screen], fullscreen, &rect);
1547 if ([nswindow respondsToSelector:
@selector(setStyleMask:)]) {
1548 [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
1551 NSRect frameRect = [nswindow frame];
1552 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1553 [nswindow setFrame:frameRect display:NO];
1555 nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
1560 if ([[nswindow contentView] nextResponder] != data->
listener) {
1561 [[nswindow contentView] setNextResponder:data->listener];
1565 [nswindow setContentSize:rect.size];
1566 [nswindow setFrameOrigin:rect.origin];
1576 [nswindow setLevel:CGShieldingWindowLevel()];
1578 [nswindow setLevel:kCGNormalWindowLevel];
1581 if ([nswindow isVisible] || fullscreen) {
1582 [data->listener pauseVisibleObservation];
1583 [nswindow makeKeyAndOrderFront:nil];
1584 [data->listener resumeVisibleObservation];
1587 ScheduleContextUpdates(data);
1596 CGGammaValue redTable[tableSize];
1597 CGGammaValue greenTable[tableSize];
1598 CGGammaValue blueTable[tableSize];
1600 float inv65535 = 1.0f / 65535.0f;
1603 for (i = 0; i < 256; i++) {
1604 redTable[i] = ramp[0*256+i] * inv65535;
1605 greenTable[i] = ramp[1*256+i] * inv65535;
1606 blueTable[i] = ramp[2*256+i] * inv65535;
1609 if (CGSetDisplayTransferByTable(display_id, tableSize,
1610 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1622 CGGammaValue redTable[tableSize];
1623 CGGammaValue greenTable[tableSize];
1624 CGGammaValue blueTable[tableSize];
1627 if (CGGetDisplayTransferByTable(display_id, tableSize,
1628 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1632 for (i = 0; i < tableCopied; i++) {
1633 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1634 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1635 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1645 if (grabbed && data && ![data->
listener isMoving]) {
1650 cgpoint.x = window->
x + x;
1651 cgpoint.y = window->
y + y;
1655 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1656 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1661 && ![data->
listener isInFullscreenSpace]) {
1664 [data->nswindow setLevel:CGShieldingWindowLevel()];
1666 [data->nswindow setLevel:kCGNormalWindowLevel];
1678 if ([data->
listener isInFullscreenSpace]) {
1679 [NSMenu setMenuBarVisible:YES];
1681 [data->listener close];
1682 [data->listener release];
1684 [data->nswindow close];
1687 NSArray *contexts = [[data->nscontexts copy] autorelease];
1688 for (SDLOpenGLContext *context
in contexts) {
1690 [context setWindow:NULL];
1692 [data->nscontexts release];
1709 SDL_SetError(
"Application not compiled with SDL %d.%d\n",
1716 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1720 if ([data->
listener isInFullscreenSpace]) {
1734 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1735 const int maxattempts = 3;
1737 while (++attempt <= maxattempts) {
1741 const int limit = 10000;
1743 while ([data->
listener isInFullscreenSpaceTransition]) {
1744 if ( ++count == limit ) {
1751 if ([data->
listener isInFullscreenSpace] == (state ? YES : NO))
1754 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
int Cocoa_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
#define SDL_MINOR_VERSION
BOOL isInFullscreenSpace()
SDL_Mouse * SDL_GetMouse(void)
NSMutableArray * nscontexts
GLdouble GLdouble GLdouble r
#define SDL_IsShapedWindow
void SDL_SetKeyboardFocus(SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
uint32_t Uint32
An unsigned 32-bit integer type.
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
void Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
GLint GLint GLint GLint GLint x
#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)
void Cocoa_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
#define SDL_GetTouchFinger
The structure that defines a point.
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
#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
GLint GLint GLsizei GLsizei height
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
unsigned int modifierFlags
void windowDidFinishMoving()
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
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)
GLuint GLuint GLsizei GLenum type
void * SDL_calloc(size_t nmemb, size_t size)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
GLint GLint GLint GLint GLint GLint y
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)
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
#define SDL_BUTTON_MIDDLE
#define SDL_GetNumTouchFingers
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
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)
#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)
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
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
int SDL_SendDropFile(const char *file)
The type used to identify a window.
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
int Cocoa_ResizeWindowShape(SDL_Window *window)
uint16_t Uint16
An unsigned 16-bit integer type.
SDL_VideoDevice * SDL_GetVideoDevice(void)
union SDL_SysWMinfo::@18 info
BOOL inFullscreenTransition
GLsizei const GLchar *const * path
void pauseVisibleObservation()
GLubyte GLubyte GLubyte GLubyte w
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)
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
#define SDL_GetMouseState
GLfloat GLfloat GLfloat GLfloat h
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)