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
120 NSPasteboard *pasteboard = [sender draggingPasteboard];
121 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
122 NSString *desiredType = [pasteboard availableTypeFromArray:types];
125 if (desiredType == nil) {
129 NSData *
data = [pasteboard dataForType:desiredType];
134 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
135 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
137 for (NSString *
path in array) {
138 NSURL *fileURL = [NSURL fileURLWithPath:path];
139 NSNumber *isAlias = nil;
141 [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;
162 for (sdlwindow = _this->
windows; sdlwindow; sdlwindow = sdlwindow->
next) {
164 if (nswindow ==
self) {
179 - (BOOL)wantsPeriodicDraggingUpdates
189 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
191 r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
197 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
199 @
synchronized (contexts) {
200 for (SDLOpenGLContext *context
in contexts) {
201 if (context == currentContext) {
204 [context scheduleUpdate];
212 GetHintCtrlClickEmulateRightClick()
220 NSUInteger style = 0;
223 style = NSBorderlessWindowMask;
226 style = NSBorderlessWindowMask;
228 style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
231 style |= NSResizableWindowMask;
238 SetWindowStyle(
SDL_Window * window, NSUInteger style)
241 NSWindow *nswindow = data->
nswindow;
244 if ([[nswindow contentView] nextResponder] == data->
listener) {
245 [[nswindow contentView] setNextResponder:nil];
248 [nswindow setStyleMask:style];
251 if ([[nswindow contentView] nextResponder] != data->
listener) {
252 [[nswindow contentView] setNextResponder:data->listener];
263 NSNotificationCenter *center;
265 NSView *view = [window contentView];
277 center = [NSNotificationCenter defaultCenter];
279 if ([window delegate] != nil) {
280 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
281 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
282 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
283 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
284 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
285 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
286 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
287 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
288 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
289 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
290 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
291 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
292 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
293 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
295 [window setDelegate:self];
302 [window addObserver:self
303 forKeyPath:@"visible"
304 options:NSKeyValueObservingOptionNew
307 [window setNextResponder:self];
308 [window setAcceptsMouseMovedEvents:YES];
310 [view setNextResponder:self];
312 [view setAcceptsTouchEvents:YES];
315 - (
void)observeValueForKeyPath:(NSString *)keyPath
317 change:(NSDictionary *)change
318 context:(
void *)context
324 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
325 int newVisibility = [[change objectForKey:@"new"] intValue];
342 BOOL isVisible = [_data->nswindow isVisible];
355 -(BOOL) setFullscreenSpace:(BOOL) state
373 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
375 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
382 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
383 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
404 NSNotificationCenter *center;
406 NSView *view = [window contentView];
408 center = [NSNotificationCenter defaultCenter];
410 if ([window delegate] !=
self) {
411 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
412 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
413 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
414 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
415 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
416 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
417 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
418 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
419 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
420 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
421 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
422 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
423 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
424 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
426 [window setDelegate:nil];
429 [window removeObserver:self forKeyPath:@"visible"];
431 if ([window nextResponder] ==
self) {
432 [window setNextResponder:nil];
434 if ([view nextResponder] ==
self) {
435 [view setNextResponder:nil];
444 -(
void) setPendingMoveX:(
int)x Y:(
int)y
466 - (BOOL)windowShouldClose:(
id)sender
472 - (
void)windowDidExpose:(NSNotification *)aNotification
477 - (
void)windowWillMove:(NSNotification *)aNotification
485 - (
void)windowDidMove:(NSNotification *)aNotification
491 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
492 ConvertNSRect([nswindow
screen], fullscreen, &rect);
501 rect.origin.x = window->
x;
502 rect.origin.y = window->
y;
503 ConvertNSRect([nswindow
screen], fullscreen, &rect);
504 [nswindow setFrameOrigin:rect.origin];
509 x = (int)rect.origin.x;
510 y = (
int)rect.origin.y;
512 ScheduleContextUpdates(
_data);
517 - (
void)windowDidResize:(NSNotification *)aNotification
527 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
529 x = (int)rect.origin.x;
530 y = (
int)rect.origin.y;
531 w = (int)rect.size.width;
532 h = (
int)rect.size.height;
538 ScheduleContextUpdates(
_data);
545 const BOOL zoomed = [nswindow isZoomed];
553 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
558 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
563 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
581 point = [_data->nswindow mouseLocationOutsideOfEventStream];
583 y = (
int)(window->
h - point.y);
594 [NSMenu setMenuBarVisible:NO];
597 const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
602 - (
void)windowDidResignKey:(NSNotification *)aNotification
620 [NSMenu setMenuBarVisible:YES];
624 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
626 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
632 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
636 [
self windowDidResize:aNotification];
640 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
644 SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
650 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
658 SetWindowStyle(window, GetWindowStyle(window));
663 [
self windowDidExitFullScreen:nil];
666 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
674 [
self setFullscreenSpace:NO];
677 [NSMenu setMenuBarVisible:NO];
686 [
self windowDidResize:aNotification];
690 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
697 SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask);
703 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
711 SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
716 [
self windowDidEnterFullScreen:nil];
719 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
726 SetWindowStyle(window, GetWindowStyle(window));
728 [nswindow setLevel:kCGNormalWindowLevel];
732 [
self setFullscreenSpace:YES];
735 [nswindow miniaturize:nil];
740 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
742 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
744 [NSMenu setMenuBarVisible:YES];
752 [
self windowDidResize:aNotification];
761 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
764 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
766 return proposedOptions;
775 - (
void)flagsChanged:(NSEvent *)theEvent
779 - (
void)keyDown:(NSEvent *)theEvent
783 - (
void)keyUp:(NSEvent *)theEvent
791 - (
void)doCommandBySelector:(
SEL)aSelector
796 - (BOOL)processHitTest:(NSEvent *)theEvent
801 const NSPoint
location = [theEvent locationInWindow];
807 [_data->nswindow setMovableByWindowBackground:YES];
815 [_data->nswindow setMovableByWindowBackground:NO];
822 - (
void)mouseDown:(NSEvent *)theEvent
828 if ([theEvent window]) {
829 NSRect windowRect = [[[theEvent window] contentView] frame];
830 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
835 if ([
self processHitTest:theEvent]) {
840 switch ([theEvent buttonNumber]) {
842 if (([theEvent modifierFlags] & NSControlKeyMask) &&
843 GetHintCtrlClickEmulateRightClick()) {
858 button = (int) [theEvent buttonNumber] + 1;
862 clicks = (int) [theEvent clickCount];
866 - (
void)rightMouseDown:(NSEvent *)theEvent
868 [
self mouseDown:theEvent];
871 - (
void)otherMouseDown:(NSEvent *)theEvent
873 [
self mouseDown:theEvent];
876 - (
void)mouseUp:(NSEvent *)theEvent
881 if ([
self processHitTest:theEvent]) {
886 switch ([theEvent buttonNumber]) {
902 button = (int) [theEvent buttonNumber] + 1;
906 clicks = (int) [theEvent clickCount];
910 - (
void)rightMouseUp:(NSEvent *)theEvent
912 [
self mouseUp:theEvent];
915 - (
void)otherMouseUp:(NSEvent *)theEvent
917 [
self mouseUp:theEvent];
920 - (
void)mouseMoved:(NSEvent *)theEvent
927 if ([
self processHitTest:theEvent]) {
936 point = [theEvent locationInWindow];
938 y = (
int)(window->
h - point.y);
944 }
else if (x >= window->
w) {
949 }
else if (y >= window->
h) {
953 #if !SDL_MAC_NO_SANDBOX 960 cgpoint.x = window->
x + x;
961 cgpoint.y = window->
y + y;
963 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
964 CGAssociateMouseAndMouseCursorPosition(YES);
973 - (
void)mouseDragged:(NSEvent *)theEvent
975 [
self mouseMoved:theEvent];
978 - (
void)rightMouseDragged:(NSEvent *)theEvent
980 [
self mouseMoved:theEvent];
983 - (
void)otherMouseDragged:(NSEvent *)theEvent
985 [
self mouseMoved:theEvent];
988 - (
void)scrollWheel:(NSEvent *)theEvent
993 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
995 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
996 int existingTouchCount = 0;
998 for (NSTouch* touch
in touches) {
999 if ([touch phase] != NSTouchPhaseBegan) {
1000 existingTouchCount++;
1003 if (existingTouchCount == 0) {
1006 DLog(
"Reset Lost Fingers: %d", numFingers);
1007 for (--numFingers; numFingers >= 0; --numFingers) {
1013 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1014 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1017 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1019 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1022 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1024 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1027 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1029 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1032 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1034 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1036 for (NSTouch *touch
in touches) {
1043 float x = [touch normalizedPosition].x;
1044 float y = [touch normalizedPosition].y;
1049 case NSTouchPhaseBegan:
1052 case NSTouchPhaseEnded:
1053 case NSTouchPhaseCancelled:
1056 case NSTouchPhaseMoved:
1067 @interface SDLView : NSView {
1074 - (
void)rightMouseDown:(NSEvent *)theEvent;
1075 - (BOOL)mouseDownCanMoveWindow;
1076 - (
void)drawRect:(NSRect)dirtyRect;
1077 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
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]];
1118 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1144 data->
nscontexts = [[NSMutableArray alloc] init];
1151 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1153 window->
x = (int)rect.origin.x;
1154 window->
y = (
int)rect.origin.y;
1155 window->
w = (int)rect.size.width;
1156 window->
h = (
int)rect.size.height;
1160 [data->listener listen:data];
1162 if ([nswindow isVisible]) {
1169 unsigned long style = [nswindow styleMask];
1171 if (style == NSBorderlessWindowMask) {
1176 if (style & NSResizableWindowMask) {
1190 if ([nswindow isMiniaturized]) {
1196 if ([nswindow isKeyWindow]) {
1204 [nswindow setOneShot:NO];
1221 NSArray *screens = [NSScreen screens];
1224 rect.origin.x = window->
x;
1225 rect.origin.y = window->
y;
1226 rect.size.width = window->
w;
1227 rect.size.height = window->
h;
1230 style = GetWindowStyle(window);
1233 NSScreen *screen = nil;
1234 for (NSScreen *candidate
in screens) {
1235 NSRect screenRect = [candidate frame];
1236 if (rect.origin.x >= screenRect.origin.x &&
1237 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1238 rect.origin.y >= screenRect.origin.y &&
1239 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1241 rect.origin.x -= screenRect.origin.x;
1242 rect.origin.y -= screenRect.origin.y;
1247 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1249 @catch (NSException *
e) {
1252 [nswindow setBackgroundColor:[NSColor blackColor]];
1256 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1260 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1265 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1266 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1267 [contentView setSDLWindow:window];
1270 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1271 [contentView setWantsBestResolutionOpenGLSurface:YES];
1275 [nswindow setContentView:contentView];
1276 [contentView release];
1279 [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1281 if (SetupWindowData(_this, window, nswindow,
SDL_TRUE) < 0) {
1292 NSWindow *nswindow = (NSWindow *) data;
1296 title = [nswindow title];
1301 return SetupWindowData(_this, window, nswindow,
SDL_FALSE);
1308 const char *title = window->
title ? window->
title :
"";
1310 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1311 [nswindow setTitle:string];
1322 [NSApp setApplicationIconImage:nsimage];
1331 NSWindow *nswindow = windata->
nswindow;
1335 rect.origin.x = window->
x;
1336 rect.origin.y = window->
y;
1337 rect.size.width = window->
w;
1338 rect.size.height = window->
h;
1341 moveHack = s_moveHack;
1343 [nswindow setFrameOrigin:rect.origin];
1344 s_moveHack = moveHack;
1346 ScheduleContextUpdates(windata);
1354 NSWindow *nswindow = windata->
nswindow;
1362 rect.origin.x = window->
x;
1363 rect.origin.y = window->
y;
1364 rect.size.width = window->
w;
1365 rect.size.height = window->
h;
1368 moveHack = s_moveHack;
1370 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1371 s_moveHack = moveHack;
1373 ScheduleContextUpdates(windata);
1383 minSize.width = window->
min_w;
1384 minSize.height = window->
min_h;
1386 [windata->
nswindow setContentMinSize:minSize];
1396 maxSize.width = window->
max_w;
1397 maxSize.height = window->
max_h;
1399 [windata->
nswindow setContentMaxSize:maxSize];
1407 NSWindow *nswindow = windowData->
nswindow;
1409 if (![nswindow isMiniaturized]) {
1410 [windowData->listener pauseVisibleObservation];
1411 [nswindow makeKeyAndOrderFront:nil];
1412 [windowData->listener resumeVisibleObservation];
1422 [nswindow orderOut:nil];
1430 NSWindow *nswindow = windowData->
nswindow;
1435 [windowData->listener pauseVisibleObservation];
1436 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1437 [NSApp activateIgnoringOtherApps:YES];
1438 [nswindow makeKeyAndOrderFront:nil];
1440 [windowData->listener resumeVisibleObservation];
1448 NSWindow *nswindow = windata->
nswindow;
1450 [nswindow zoom:nil];
1452 ScheduleContextUpdates(windata);
1460 NSWindow *nswindow = data->
nswindow;
1462 if ([data->
listener isInFullscreenSpaceTransition]) {
1463 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1465 [nswindow miniaturize:nil];
1475 if ([nswindow isMiniaturized]) {
1476 [nswindow deminiaturize:nil];
1478 [nswindow zoom:nil];
1486 if (SetWindowStyle(window, GetWindowStyle(window))) {
1503 if (![listener isInFullscreenSpace]) {
1504 SetWindowStyle(window, GetWindowStyle(window));
1513 NSWindow *nswindow = data->
nswindow;
1517 if ([[nswindow contentView] nextResponder] == data->
listener) {
1518 [[nswindow contentView] setNextResponder:nil];
1525 rect.origin.x = bounds.
x;
1526 rect.origin.y = bounds.
y;
1527 rect.size.width = bounds.
w;
1528 rect.size.height = bounds.
h;
1529 ConvertNSRect([nswindow screen], fullscreen, &rect);
1532 NSRect screenRect = [[nswindow screen] frame];
1533 if (screenRect.size.height >= 1.0f) {
1537 [nswindow setStyleMask:NSBorderlessWindowMask];
1543 ConvertNSRect([nswindow screen], fullscreen, &rect);
1545 [nswindow setStyleMask:GetWindowStyle(window)];
1548 NSRect frameRect = [nswindow frame];
1549 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1550 [nswindow setFrame:frameRect display:NO];
1554 if ([[nswindow contentView] nextResponder] != data->
listener) {
1555 [[nswindow contentView] setNextResponder:data->listener];
1559 [nswindow setContentSize:rect.size];
1560 [nswindow setFrameOrigin:rect.origin];
1570 [nswindow setLevel:CGShieldingWindowLevel()];
1572 [nswindow setLevel:kCGNormalWindowLevel];
1575 if ([nswindow isVisible] || fullscreen) {
1576 [data->listener pauseVisibleObservation];
1577 [nswindow makeKeyAndOrderFront:nil];
1578 [data->listener resumeVisibleObservation];
1581 ScheduleContextUpdates(data);
1590 CGGammaValue redTable[tableSize];
1591 CGGammaValue greenTable[tableSize];
1592 CGGammaValue blueTable[tableSize];
1594 float inv65535 = 1.0f / 65535.0f;
1597 for (i = 0; i < 256; i++) {
1598 redTable[i] = ramp[0*256+i] * inv65535;
1599 greenTable[i] = ramp[1*256+i] * inv65535;
1600 blueTable[i] = ramp[2*256+i] * inv65535;
1603 if (CGSetDisplayTransferByTable(display_id, tableSize,
1604 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1616 CGGammaValue redTable[tableSize];
1617 CGGammaValue greenTable[tableSize];
1618 CGGammaValue blueTable[tableSize];
1621 if (CGGetDisplayTransferByTable(display_id, tableSize,
1622 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1626 for (i = 0; i < tableCopied; i++) {
1627 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1628 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1629 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1639 if (grabbed && data && ![data->
listener isMoving]) {
1644 cgpoint.x = window->
x + x;
1645 cgpoint.y = window->
y + y;
1649 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1650 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1655 && ![data->
listener isInFullscreenSpace]) {
1658 [data->nswindow setLevel:CGShieldingWindowLevel()];
1660 [data->nswindow setLevel:kCGNormalWindowLevel];
1672 if ([data->
listener isInFullscreenSpace]) {
1673 [NSMenu setMenuBarVisible:YES];
1675 [data->listener close];
1676 [data->listener release];
1678 [data->nswindow close];
1681 NSArray *contexts = [[data->nscontexts copy] autorelease];
1682 for (SDLOpenGLContext *context
in contexts) {
1684 [context setWindow:NULL];
1686 [data->nscontexts release];
1703 SDL_SetError(
"Application not compiled with SDL %d.%d\n",
1710 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1728 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1729 const int maxattempts = 3;
1731 while (++attempt <= maxattempts) {
1735 const int limit = 10000;
1737 while ([data->
listener isInFullscreenSpaceTransition]) {
1738 if ( ++count == limit ) {
1745 if ([data->
listener isInFullscreenSpace] == (state ? YES : NO))
1748 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
1768 [data->
nswindow setAlphaValue:opacity];
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)
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)
int SDL_SendDropFile(SDL_Window *window, const char *file)
void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
static SDL_Window * window
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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
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)
#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
uint32_t Uint32
An unsigned 32-bit integer type.
GLint GLint GLsizei GLsizei height
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)
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 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)
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)
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)
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)
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
#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)