21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_COCOA 25 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 26 # error SDL for Mac OS X must be built with a 10.7 SDK or above. 32 #include "../SDL_sysvideo.h" 33 #include "../../events/SDL_keyboard_c.h" 34 #include "../../events/SDL_mouse_c.h" 35 #include "../../events/SDL_touch_c.h" 36 #include "../../events/SDL_windowevents_c.h" 37 #include "../../events/SDL_dropevents_c.h" 48 #ifdef DEBUG_COCOAWINDOW 49 #define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__) 51 #define DLog(...) do { } while (0) 55 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN) 57 #ifndef MAC_OS_X_VERSION_10_12 58 #define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask 61 @interface SDLWindow : NSWindow <NSDraggingDestination>
63 - (BOOL)canBecomeKeyWindow;
64 - (BOOL)canBecomeMainWindow;
65 - (
void)sendEvent:(NSEvent *)event;
66 - (
void)doCommandBySelector:(
SEL)aSelector;
69 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender;
70 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender;
71 - (BOOL)wantsPeriodicDraggingUpdates;
72 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
77 @implementation SDLWindow
79 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
84 if ([menuItem action] ==
@selector(toggleFullScreen:)) {
94 return [
super validateMenuItem:menuItem];
97 - (BOOL)canBecomeKeyWindow
102 - (BOOL)canBecomeMainWindow
107 - (
void)sendEvent:(NSEvent *)event
109 [
super sendEvent:event];
111 if ([event
type] != NSEventTypeLeftMouseUp) {
115 id delegate = [
self delegate];
120 if ([delegate isMoving]) {
121 [delegate windowDidFinishMoving];
128 - (
void)doCommandBySelector:(
SEL)aSelector
133 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender
135 if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
136 return NSDragOperationGeneric;
139 return NSDragOperationNone;
142 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender
145 NSPasteboard *pasteboard = [sender draggingPasteboard];
146 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
147 NSString *desiredType = [pasteboard availableTypeFromArray:types];
150 if (desiredType == nil) {
154 NSData *
data = [pasteboard dataForType:desiredType];
159 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
160 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
162 for (NSString *
path in array) {
163 NSURL *fileURL = [NSURL fileURLWithPath:path];
164 NSNumber *isAlias = nil;
166 [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
169 if ([isAlias boolValue]) {
170 NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
171 NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
172 if (bookmark != nil) {
173 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
176 bookmarkDataIsStale:nil
179 if (resolvedURL != nil) {
180 fileURL = resolvedURL;
194 - (BOOL)wantsPeriodicDraggingUpdates
206 for (sdlwindow = _this->
windows; sdlwindow; sdlwindow = sdlwindow->
next) {
208 if (nswindow ==
self) {
222 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
224 r->origin.
y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
236 #pragma clang diagnostic push 237 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 240 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
242 @
synchronized (contexts) {
243 for (SDLOpenGLContext *
context in contexts) {
244 if (
context == currentContext) {
247 [context scheduleUpdate];
253 #pragma clang diagnostic pop 259 GetHintCtrlClickEmulateRightClick()
267 NSUInteger style = 0;
270 style = NSWindowStyleMaskBorderless;
273 style = NSWindowStyleMaskBorderless;
275 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
278 style |= NSWindowStyleMaskResizable;
285 SetWindowStyle(
SDL_Window * window, NSUInteger style)
288 NSWindow *nswindow = data->
nswindow;
291 if ([[nswindow contentView] nextResponder] == data->
listener) {
292 [[nswindow contentView] setNextResponder:nil];
295 [nswindow setStyleMask:style];
298 if ([[nswindow contentView] nextResponder] != data->
listener) {
299 [[nswindow contentView] setNextResponder:data->listener];
310 NSNotificationCenter *center;
312 NSView *view = [window contentView];
324 center = [NSNotificationCenter defaultCenter];
326 if ([window delegate] != nil) {
327 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
328 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
329 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
330 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
331 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
332 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
333 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
334 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
335 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
336 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
337 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
338 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
339 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
340 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
342 [window setDelegate:self];
349 [window addObserver:self
350 forKeyPath:@"visible"
351 options:NSKeyValueObservingOptionNew
354 [window setNextResponder:self];
355 [window setAcceptsMouseMovedEvents:YES];
357 [view setNextResponder:self];
359 [view setAcceptsTouchEvents:YES];
362 - (
void)observeValueForKeyPath:(NSString *)keyPath
364 change:(NSDictionary *)change
365 context:(
void *)context
371 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
372 int newVisibility = [[change objectForKey:@"new"] intValue];
389 BOOL isVisible = [_data->nswindow isVisible];
402 -(BOOL) setFullscreenSpace:(BOOL) state
420 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
422 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
429 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
430 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
451 NSNotificationCenter *center;
453 NSView *view = [window contentView];
455 center = [NSNotificationCenter defaultCenter];
457 if ([window delegate] !=
self) {
458 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
459 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
460 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
461 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
462 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
463 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
464 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
465 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
466 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
467 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
468 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
469 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
470 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
471 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
473 [window setDelegate:nil];
476 [window removeObserver:self forKeyPath:@"visible"];
478 if ([window nextResponder] ==
self) {
479 [window setNextResponder:nil];
481 if ([view nextResponder] ==
self) {
482 [view setNextResponder:nil];
491 -(
void) setPendingMoveX:(
int)x Y:(
int)y
513 - (BOOL)windowShouldClose:(
id)sender
519 - (
void)windowDidExpose:(NSNotification *)aNotification
524 - (
void)windowWillMove:(NSNotification *)aNotification
532 - (
void)windowDidMove:(NSNotification *)aNotification
538 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
539 ConvertNSRect([nswindow
screen], fullscreen, &rect);
553 rect.origin.x = window->
x;
554 rect.origin.y = window->
y;
555 ConvertNSRect([nswindow
screen], fullscreen, &rect);
556 [nswindow setFrameOrigin:rect.origin];
561 x = (int)rect.origin.x;
562 y = (
int)rect.origin.y;
564 ScheduleContextUpdates(
_data);
569 - (
void)windowDidResize:(NSNotification *)aNotification
579 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
581 x = (int)rect.origin.x;
582 y = (
int)rect.origin.y;
583 w = (int)rect.size.width;
584 h = (
int)rect.size.height;
590 ScheduleContextUpdates(
_data);
597 const BOOL zoomed = [nswindow isZoomed];
605 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
610 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
615 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
633 point = [_data->nswindow mouseLocationOutsideOfEventStream];
635 y = (
int)(window->
h - point.y);
646 [NSMenu setMenuBarVisible:NO];
654 - (
void)windowDidResignKey:(NSNotification *)aNotification
672 [NSMenu setMenuBarVisible:YES];
676 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
678 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
684 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
688 [
self windowDidResize:aNotification];
692 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
696 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
702 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
710 SetWindowStyle(window, GetWindowStyle(window));
715 [
self windowDidExitFullScreen:nil];
718 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
722 NSWindow *nswindow = data->
nswindow;
728 [
self setFullscreenSpace:NO];
733 SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
736 [NSMenu setMenuBarVisible:NO];
745 [
self windowDidMove:aNotification];
746 [
self windowDidResize:aNotification];
750 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
760 SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
763 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
771 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
776 [
self windowDidEnterFullScreen:nil];
779 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
786 SetWindowStyle(window, GetWindowStyle(window));
788 [nswindow setLevel:kCGNormalWindowLevel];
792 [
self setFullscreenSpace:YES];
795 [nswindow miniaturize:nil];
800 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
802 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
804 [NSMenu setMenuBarVisible:YES];
822 ConvertNSRect([nswindow screen], NO, &rect);
825 [nswindow setContentSize:rect.size];
826 [nswindow setFrameOrigin:rect.origin];
836 [
self windowDidMove:aNotification];
837 [
self windowDidResize:aNotification];
846 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
849 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
851 return proposedOptions;
859 - (
void)flagsChanged:(NSEvent *)theEvent
874 if (!osenabled && sdlenabled) {
877 }
else if (osenabled && !sdlenabled) {
881 - (
void)keyDown:(NSEvent *)theEvent
885 - (
void)keyUp:(NSEvent *)theEvent
893 - (
void)doCommandBySelector:(
SEL)aSelector
898 - (BOOL)processHitTest:(NSEvent *)theEvent
903 const NSPoint
location = [theEvent locationInWindow];
909 [_data->nswindow setMovableByWindowBackground:YES];
917 [_data->nswindow setMovableByWindowBackground:NO];
924 - (
void)mouseDown:(NSEvent *)theEvent
936 if ([theEvent window]) {
937 NSRect windowRect = [[[theEvent window] contentView] frame];
938 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
943 if ([
self processHitTest:theEvent]) {
948 switch ([theEvent buttonNumber]) {
950 if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
951 GetHintCtrlClickEmulateRightClick()) {
966 button = (int) [theEvent buttonNumber] + 1;
970 clicks = (int) [theEvent clickCount];
975 - (
void)rightMouseDown:(NSEvent *)theEvent
977 [
self mouseDown:theEvent];
980 - (
void)otherMouseDown:(NSEvent *)theEvent
982 [
self mouseDown:theEvent];
985 - (
void)mouseUp:(NSEvent *)theEvent
996 if ([
self processHitTest:theEvent]) {
1001 switch ([theEvent buttonNumber]) {
1017 button = (int) [theEvent buttonNumber] + 1;
1021 clicks = (int) [theEvent clickCount];
1026 - (
void)rightMouseUp:(NSEvent *)theEvent
1028 [
self mouseUp:theEvent];
1031 - (
void)otherMouseUp:(NSEvent *)theEvent
1033 [
self mouseUp:theEvent];
1036 - (
void)mouseMoved:(NSEvent *)theEvent
1048 if ([
self processHitTest:theEvent]) {
1057 point = [theEvent locationInWindow];
1059 y = (
int)(window->
h - point.y);
1065 }
else if (x >= window->
w) {
1070 }
else if (y >= window->
h) {
1074 #if !SDL_MAC_NO_SANDBOX 1081 cgpoint.x = window->
x + x;
1082 cgpoint.y = window->
y + y;
1084 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1085 CGAssociateMouseAndMouseCursorPosition(YES);
1095 - (
void)mouseDragged:(NSEvent *)theEvent
1097 [
self mouseMoved:theEvent];
1100 - (
void)rightMouseDragged:(NSEvent *)theEvent
1102 [
self mouseMoved:theEvent];
1105 - (
void)otherMouseDragged:(NSEvent *)theEvent
1107 [
self mouseMoved:theEvent];
1110 - (
void)scrollWheel:(NSEvent *)theEvent
1115 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
1121 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
1123 int existingTouchCount = 0;
1125 for (NSTouch* touch
in touches) {
1126 if ([touch phase] != NSTouchPhaseBegan) {
1127 existingTouchCount++;
1130 if (existingTouchCount == 0) {
1132 DLog(
"Reset Lost Fingers: %d", numFingers);
1133 for (--numFingers; numFingers >= 0; --numFingers) {
1139 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1140 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1143 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1145 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1148 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1150 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1153 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1155 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1158 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1160 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1166 for (NSTouch *touch
in touches) {
1170 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 1171 if ([touch respondsToSelector:
@selector(
type)]) {
1172 if ([touch
type] == NSTouchTypeDirect) {
1183 float x = [touch normalizedPosition].x;
1184 float y = [touch normalizedPosition].y;
1189 case NSTouchPhaseBegan:
1192 case NSTouchPhaseEnded:
1193 case NSTouchPhaseCancelled:
1196 case NSTouchPhaseMoved:
1207 @interface SDLView : NSView {
1214 - (
void)rightMouseDown:(NSEvent *)theEvent;
1215 - (BOOL)mouseDownCanMoveWindow;
1216 - (
void)drawRect:(NSRect)dirtyRect;
1217 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
1218 - (BOOL)wantsUpdateLayer;
1219 - (
void)updateLayer;
1222 @implementation SDLView
1230 - (
void)drawRect:(NSRect)dirtyRect
1235 [[NSColor blackColor] setFill];
1236 NSRectFill(dirtyRect);
1240 -(BOOL) wantsUpdateLayer
1250 self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
1251 ScheduleContextUpdates((
SDL_WindowData *) _sdlWindow->driverdata);
1255 - (
void)rightMouseDown:(NSEvent *)theEvent
1257 [[
self nextResponder] rightMouseDown:theEvent];
1260 - (BOOL)mouseDownCanMoveWindow
1268 - (
void)resetCursorRects
1270 [
super resetCursorRects];
1274 [
self addCursorRect:[
self bounds]
1275 cursor:mouse->cur_cursor->driverdata];
1277 [
self addCursorRect:[
self bounds]
1278 cursor:[NSCursor invisibleCursor]];
1282 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1308 data->
nscontexts = [[NSMutableArray alloc] init];
1320 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1322 window->
x = (int)rect.origin.x;
1323 window->
y = (
int)rect.origin.y;
1324 window->
w = (int)rect.size.width;
1325 window->
h = (
int)rect.size.height;
1329 [data->listener listen:data];
1331 if ([nswindow isVisible]) {
1338 unsigned long style = [nswindow styleMask];
1340 if (style == NSWindowStyleMaskBorderless) {
1345 if (style & NSWindowStyleMaskResizable) {
1359 if ([nswindow isMiniaturized]) {
1365 if ([nswindow isKeyWindow]) {
1373 [nswindow setOneShot:NO];
1390 NSArray *screens = [NSScreen screens];
1393 rect.origin.x = window->
x;
1394 rect.origin.y = window->
y;
1395 rect.size.width = window->
w;
1396 rect.size.height = window->
h;
1399 style = GetWindowStyle(window);
1402 NSScreen *screen = nil;
1403 for (NSScreen *candidate
in screens) {
1404 NSRect screenRect = [candidate frame];
1405 if (rect.origin.x >= screenRect.origin.x &&
1406 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1407 rect.origin.y >= screenRect.origin.y &&
1408 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1410 rect.origin.x -= screenRect.origin.x;
1411 rect.origin.y -= screenRect.origin.y;
1416 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1418 @catch (NSException *
e) {
1422 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 1424 if ([nswindow respondsToSelector:
@selector(setTabbingMode:)]) {
1425 [nswindow setTabbingMode:NSWindowTabbingModeDisallowed];
1431 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1435 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1440 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1441 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1442 [contentView setSDLWindow:window];
1446 #pragma clang diagnostic push 1447 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 1450 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1451 [contentView setWantsBestResolutionOpenGLSurface:YES];
1455 #pragma clang diagnostic pop 1458 #if SDL_VIDEO_OPENGL_ES2 1459 #if SDL_VIDEO_OPENGL_EGL 1462 [contentView setWantsLayer:TRUE];
1466 [nswindow setContentView:contentView];
1467 [contentView release];
1469 if (SetupWindowData(_this, window, nswindow,
SDL_TRUE) < 0) {
1479 #if SDL_VIDEO_OPENGL_ES2 1481 #if SDL_VIDEO_OPENGL_EGL 1482 if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
1488 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
1499 NSWindow *nswindow = (NSWindow *) data;
1503 title = [nswindow title];
1508 return SetupWindowData(_this, window, nswindow,
SDL_FALSE);
1515 const char *title = window->
title ? window->
title :
"";
1517 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1518 [nswindow setTitle:string];
1529 [NSApp setApplicationIconImage:nsimage];
1538 NSWindow *nswindow = windata->
nswindow;
1542 rect.origin.x = window->
x;
1543 rect.origin.y = window->
y;
1544 rect.size.width = window->
w;
1545 rect.size.height = window->
h;
1548 moveHack = s_moveHack;
1550 [nswindow setFrameOrigin:rect.origin];
1551 s_moveHack = moveHack;
1553 ScheduleContextUpdates(windata);
1561 NSWindow *nswindow = windata->
nswindow;
1569 rect.origin.x = window->
x;
1570 rect.origin.y = window->
y;
1571 rect.size.width = window->
w;
1572 rect.size.height = window->
h;
1575 moveHack = s_moveHack;
1577 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1578 s_moveHack = moveHack;
1580 ScheduleContextUpdates(windata);
1590 minSize.width = window->
min_w;
1591 minSize.height = window->
min_h;
1593 [windata->
nswindow setContentMinSize:minSize];
1603 maxSize.width = window->
max_w;
1604 maxSize.height = window->
max_h;
1606 [windata->
nswindow setContentMaxSize:maxSize];
1614 NSWindow *nswindow = windowData->
nswindow;
1616 if (![nswindow isMiniaturized]) {
1617 [windowData->listener pauseVisibleObservation];
1618 [nswindow makeKeyAndOrderFront:nil];
1619 [windowData->listener resumeVisibleObservation];
1629 [nswindow orderOut:nil];
1637 NSWindow *nswindow = windowData->
nswindow;
1642 [windowData->listener pauseVisibleObservation];
1643 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1644 [NSApp activateIgnoringOtherApps:YES];
1645 [nswindow makeKeyAndOrderFront:nil];
1647 [windowData->listener resumeVisibleObservation];
1655 NSWindow *nswindow = windata->
nswindow;
1657 [nswindow zoom:nil];
1659 ScheduleContextUpdates(windata);
1667 NSWindow *nswindow = data->
nswindow;
1669 if ([data->
listener isInFullscreenSpaceTransition]) {
1670 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1672 [nswindow miniaturize:nil];
1682 if ([nswindow isMiniaturized]) {
1683 [nswindow deminiaturize:nil];
1685 [nswindow zoom:nil];
1693 if (SetWindowStyle(window, GetWindowStyle(window))) {
1710 if (![listener isInFullscreenSpace]) {
1711 SetWindowStyle(window, GetWindowStyle(window));
1720 NSWindow *nswindow = data->
nswindow;
1724 if ([[nswindow contentView] nextResponder] == data->
listener) {
1725 [[nswindow contentView] setNextResponder:nil];
1732 rect.origin.x = bounds.
x;
1733 rect.origin.y = bounds.
y;
1734 rect.size.width = bounds.
w;
1735 rect.size.height = bounds.
h;
1736 ConvertNSRect([nswindow screen], fullscreen, &rect);
1739 NSRect screenRect = [[nswindow screen] frame];
1740 if (screenRect.size.height >= 1.0f) {
1744 [nswindow setStyleMask:NSWindowStyleMaskBorderless];
1750 ConvertNSRect([nswindow screen], fullscreen, &rect);
1752 [nswindow setStyleMask:GetWindowStyle(window)];
1755 NSRect frameRect = [nswindow frame];
1756 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1757 [nswindow setFrame:frameRect display:NO];
1761 if ([[nswindow contentView] nextResponder] != data->
listener) {
1762 [[nswindow contentView] setNextResponder:data->listener];
1766 [nswindow setContentSize:rect.size];
1767 [nswindow setFrameOrigin:rect.origin];
1777 [nswindow setLevel:CGShieldingWindowLevel()];
1779 [nswindow setLevel:kCGNormalWindowLevel];
1782 if ([nswindow isVisible] || fullscreen) {
1783 [data->listener pauseVisibleObservation];
1784 [nswindow makeKeyAndOrderFront:nil];
1785 [data->listener resumeVisibleObservation];
1788 ScheduleContextUpdates(data);
1797 CGGammaValue redTable[tableSize];
1798 CGGammaValue greenTable[tableSize];
1799 CGGammaValue blueTable[tableSize];
1801 float inv65535 = 1.0f / 65535.0f;
1804 for (i = 0; i < 256; i++) {
1805 redTable[i] = ramp[0*256+i] * inv65535;
1806 greenTable[i] = ramp[1*256+i] * inv65535;
1807 blueTable[i] = ramp[2*256+i] * inv65535;
1810 if (CGSetDisplayTransferByTable(display_id, tableSize,
1811 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1823 CGGammaValue redTable[tableSize];
1824 CGGammaValue greenTable[tableSize];
1825 CGGammaValue blueTable[tableSize];
1828 if (CGGetDisplayTransferByTable(display_id, tableSize,
1829 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1833 for (i = 0; i < tableCopied; i++) {
1834 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1835 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1836 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1851 if (grabbed && data && ![data->
listener isMoving]) {
1856 cgpoint.x = window->
x + x;
1857 cgpoint.y = window->
y + y;
1861 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1862 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1867 && ![data->
listener isInFullscreenSpace]) {
1870 [data->nswindow setLevel:CGShieldingWindowLevel()];
1872 [data->nswindow setLevel:kCGNormalWindowLevel];
1884 if ([data->
listener isInFullscreenSpace]) {
1885 [NSMenu setMenuBarVisible:YES];
1887 [data->listener close];
1888 [data->listener release];
1891 [data->nswindow setContentView:nil];
1892 [data->nswindow close];
1895 NSArray *contexts = [[data->nscontexts copy] autorelease];
1896 for (SDLOpenGLContext *context
in contexts) {
1898 [context setWindow:NULL];
1900 [data->nscontexts release];
1917 SDL_SetError(
"Application not compiled with SDL %d.%d",
1924 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1928 if ([data->
listener isInFullscreenSpace]) {
1942 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1943 const int maxattempts = 3;
1945 while (++attempt <= maxattempts) {
1949 const int limit = 10000;
1951 while ([data->
listener isInFullscreenSpaceTransition]) {
1952 if ( ++count == limit ) {
1959 if ([data->
listener isInFullscreenSpace] == (state ? YES : NO))
1962 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
1983 [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1985 [data->nswindow unregisterDraggedTypes];
1993 [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 (integer)
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_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
#define SDL_GetHintBoolean
static SDL_VideoDevice * _this
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
BOOL isInFullscreenSpaceTransition()
void Cocoa_ShowWindow(_THIS, SDL_Window *window)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Cocoa_WindowListener * listener
struct SDL_VideoData * videodata
void resumeVisibleObservation()
int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
GLubyte GLubyte GLubyte GLubyte w
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
#define NSEventSubtypeMouseEvent
#define SDL_GetNumTouchFingers
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
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
#define SDL_MOUSE_TOUCHID
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)
union SDL_SysWMinfo::@17 info
int Cocoa_ResizeWindowShape(SDL_Window *window)
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
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 (integer).
int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@262 gl_config