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"];
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
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];
241 NSMutableArray *contexts =
data->nscontexts;
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;
272 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
275 style |= NSWindowStyleMaskResizable;
283 NSUInteger style = 0;
286 style = NSWindowStyleMaskBorderless;
288 style = GetWindowWindowedStyle(
window);
300 if ([[nswindow contentView] nextResponder] ==
data->listener) {
301 [[nswindow contentView] setNextResponder:nil];
304 [nswindow setStyleMask:style];
307 if ([[nswindow contentView] nextResponder] !=
data->listener) {
308 [[nswindow contentView] setNextResponder:data->listener];
319 NSNotificationCenter *center;
321 NSView *view = [window contentView];
333 center = [NSNotificationCenter defaultCenter];
335 if ([
window delegate] != nil) {
336 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
337 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
338 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
339 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
340 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
341 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
342 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
343 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
344 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
345 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
346 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
347 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
348 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
349 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
351 [window setDelegate:self];
358 [window addObserver:self
359 forKeyPath:@"visible"
360 options:NSKeyValueObservingOptionNew
363 [window setNextResponder:self];
364 [window setAcceptsMouseMovedEvents:YES];
366 [view setNextResponder:self];
368 [view setAcceptsTouchEvents:YES];
371 - (
void)observeValueForKeyPath:(NSString *)keyPath
373 change:(NSDictionary *)change
374 context:(
void *)context
380 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
381 int newVisibility = [[change objectForKey:@"new"] intValue];
398 BOOL isVisible = [_data->nswindow isVisible];
411 -(BOOL) setFullscreenSpace:(BOOL) state
429 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
431 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
438 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
439 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
460 NSNotificationCenter *center;
462 NSView *view = [window contentView];
464 center = [NSNotificationCenter defaultCenter];
466 if ([
window delegate] !=
self) {
467 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
468 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
469 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
470 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
471 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
472 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
473 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
474 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
475 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
476 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
477 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
478 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
479 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
480 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
482 [window setDelegate:nil];
485 [window removeObserver:self forKeyPath:@"visible"];
487 if ([
window nextResponder] ==
self) {
488 [window setNextResponder:nil];
490 if ([view nextResponder] ==
self) {
491 [view setNextResponder:nil];
500 -(
void) setPendingMoveX:(
int)x Y:(
int)y
522 - (BOOL)windowShouldClose:(
id)sender
528 - (
void)windowDidExpose:(NSNotification *)aNotification
533 - (
void)windowWillMove:(NSNotification *)aNotification
541 - (
void)windowDidMove:(NSNotification *)aNotification
547 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
548 ConvertNSRect([nswindow
screen], fullscreen, &
rect);
564 ConvertNSRect([nswindow
screen], fullscreen, &
rect);
565 [nswindow setFrameOrigin:rect.origin];
573 ScheduleContextUpdates(
_data);
578 - (
void)windowDidResize:(NSNotification *)aNotification
588 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
592 w = (int)
rect.size.width;
593 h = (
int)
rect.size.height;
599 ScheduleContextUpdates(
_data);
606 const BOOL zoomed = [nswindow isZoomed];
614 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
619 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
624 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
642 point = [_data->nswindow mouseLocationOutsideOfEventStream];
655 [NSMenu setMenuBarVisible:NO];
663 - (
void)windowDidResignKey:(NSNotification *)aNotification
681 [NSMenu setMenuBarVisible:YES];
685 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
687 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
693 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
697 [
self windowDidResize:aNotification];
701 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
705 SetWindowStyle(
window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
711 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
715 if (
window->is_destroying) {
724 [
self windowDidExitFullScreen:nil];
727 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
737 [
self setFullscreenSpace:NO];
742 SetWindowStyle(
window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
745 [NSMenu setMenuBarVisible:NO];
754 [
self windowDidMove:aNotification];
755 [
self windowDidResize:aNotification];
759 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
774 SetWindowStyle(
window, GetWindowWindowedStyle(
window) | NSWindowStyleMaskResizable);
777 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
781 if (
window->is_destroying) {
785 SetWindowStyle(
window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
790 [
self windowDidEnterFullScreen:nil];
793 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
810 [nswindow setLevel:NSFloatingWindowLevel];
812 [nswindow setLevel:kCGNormalWindowLevel];
817 [
self setFullscreenSpace:YES];
820 [nswindow miniaturize:nil];
825 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
827 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
829 [NSMenu setMenuBarVisible:YES];
850 [nswindow setContentSize:rect.size];
851 [nswindow setFrameOrigin:rect.origin];
861 [
self windowDidMove:aNotification];
862 [
self windowDidResize:aNotification];
876 button = [nswindow standardWindowButton:NSWindowMiniaturizeButton];
887 -(NSApplicationPresentationOptions)
window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
890 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
892 return proposedOptions;
900 - (
void)flagsChanged:(NSEvent *)theEvent
915 if (!osenabled && sdlenabled) {
918 }
else if (osenabled && !sdlenabled) {
922 - (
void)keyDown:(NSEvent *)theEvent
926 - (
void)keyUp:(NSEvent *)theEvent
934 - (
void)doCommandBySelector:(
SEL)aSelector
939 - (BOOL)processHitTest:(NSEvent *)theEvent
944 const NSPoint
location = [theEvent locationInWindow];
950 [_data->nswindow setMovableByWindowBackground:YES];
958 [_data->nswindow setMovableByWindowBackground:NO];
965 - (
void)mouseDown:(NSEvent *)theEvent
978 NSRect windowRect = [[[theEvent window] contentView] frame];
979 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
984 if ([
self processHitTest:theEvent]) {
989 switch ([theEvent buttonNumber]) {
991 if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
992 GetHintCtrlClickEmulateRightClick()) {
1007 button = (int) [theEvent buttonNumber] + 1;
1011 clicks = (int) [theEvent clickCount];
1016 - (
void)rightMouseDown:(NSEvent *)theEvent
1018 [
self mouseDown:theEvent];
1021 - (
void)otherMouseDown:(NSEvent *)theEvent
1023 [
self mouseDown:theEvent];
1026 - (
void)mouseUp:(NSEvent *)theEvent
1037 if ([
self processHitTest:theEvent]) {
1042 switch ([theEvent buttonNumber]) {
1058 button = (int) [theEvent buttonNumber] + 1;
1062 clicks = (int) [theEvent clickCount];
1067 - (
void)rightMouseUp:(NSEvent *)theEvent
1069 [
self mouseUp:theEvent];
1072 - (
void)otherMouseUp:(NSEvent *)theEvent
1074 [
self mouseUp:theEvent];
1077 - (
void)mouseMoved:(NSEvent *)theEvent
1089 if ([
self processHitTest:theEvent]) {
1098 point = [theEvent locationInWindow];
1115 #if !SDL_MAC_NO_SANDBOX
1125 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1126 CGAssociateMouseAndMouseCursorPosition(YES);
1136 - (
void)mouseDragged:(NSEvent *)theEvent
1138 [
self mouseMoved:theEvent];
1141 - (
void)rightMouseDragged:(NSEvent *)theEvent
1143 [
self mouseMoved:theEvent];
1146 - (
void)otherMouseDragged:(NSEvent *)theEvent
1148 [
self mouseMoved:theEvent];
1151 - (
void)scrollWheel:(NSEvent *)theEvent
1156 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
1162 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
1164 int existingTouchCount = 0;
1166 for (NSTouch* touch
in touches) {
1167 if ([touch phase] != NSTouchPhaseBegan) {
1168 existingTouchCount++;
1171 if (existingTouchCount == 0) {
1173 DLog(
"Reset Lost Fingers: %d", numFingers);
1174 for (--numFingers; numFingers >= 0; --numFingers) {
1186 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1187 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1190 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1192 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1195 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1197 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1200 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1202 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1205 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1207 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1213 for (NSTouch *touch
in touches) {
1224 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202
1225 if ([touch respondsToSelector:
@selector(
type)]) {
1233 if ([touch
type] == NSTouchTypeDirect) {
1244 float x = [touch normalizedPosition].x;
1245 float y = [touch normalizedPosition].y;
1250 case NSTouchPhaseBegan:
1253 case NSTouchPhaseEnded:
1254 case NSTouchPhaseCancelled:
1257 case NSTouchPhaseMoved:
1268 @interface SDLView : NSView {
1275 - (
void)rightMouseDown:(NSEvent *)theEvent;
1276 - (BOOL)mouseDownCanMoveWindow;
1277 - (
void)drawRect:(NSRect)dirtyRect;
1278 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
1279 - (BOOL)wantsUpdateLayer;
1280 - (
void)updateLayer;
1283 @implementation SDLView
1294 - (
void)drawRect:(NSRect)dirtyRect
1299 if ([NSGraphicsContext currentContext]) {
1300 [[NSColor blackColor] setFill];
1301 NSRectFill(dirtyRect);
1302 }
else if (
self.
layer) {
1303 self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
1309 - (BOOL)wantsUpdateLayer
1320 self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
1321 ScheduleContextUpdates((
SDL_WindowData *) _sdlWindow->driverdata);
1325 - (
void)rightMouseDown:(NSEvent *)theEvent
1327 [[
self nextResponder] rightMouseDown:theEvent];
1330 - (BOOL)mouseDownCanMoveWindow
1338 - (
void)resetCursorRects
1340 [
super resetCursorRects];
1344 [
self addCursorRect:[
self bounds]
1345 cursor:mouse->cur_cursor->driverdata];
1347 [
self addCursorRect:[
self bounds]
1348 cursor:[NSCursor invisibleCursor]];
1352 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1375 data->nswindow = nswindow;
1376 data->created = created;
1377 data->videodata = videodata;
1378 data->nscontexts = [[NSMutableArray alloc] init];
1383 data->sdlContentView = created ? [nswindow contentView] : nil;
1390 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1399 [data->listener listen:data];
1401 if ([nswindow isVisible]) {
1408 unsigned long style = [nswindow styleMask];
1410 if (style == NSWindowStyleMaskBorderless) {
1415 if (style & NSWindowStyleMaskResizable) {
1429 if ([nswindow isMiniaturized]) {
1435 if ([nswindow isKeyWindow]) {
1443 [nswindow setOneShot:NO];
1460 NSArray *screens = [NSScreen screens];
1469 style = GetWindowStyle(
window);
1473 for (NSScreen *candidate
in screens) {
1474 NSRect screenRect = [candidate frame];
1475 if (
rect.origin.
x >= screenRect.origin.x &&
1476 rect.origin.
x < screenRect.origin.x + screenRect.size.width &&
1477 rect.origin.
y >= screenRect.origin.y &&
1478 rect.origin.
y < screenRect.origin.y + screenRect.size.height) {
1480 rect.origin.
x -= screenRect.origin.
x;
1481 rect.origin.
y -= screenRect.origin.
y;
1486 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1488 @catch (NSException *
e) {
1492 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
1494 if ([nswindow respondsToSelector:
@selector(setTabbingMode:)]) {
1495 [nswindow setTabbingMode:NSWindowTabbingModeDisallowed];
1501 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1505 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1510 [nswindow setLevel:NSFloatingWindowLevel];
1514 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1515 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1516 [contentView setSDLWindow:window];
1520 #pragma clang diagnostic push
1521 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
1525 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1527 [contentView setWantsBestResolutionOpenGLSurface:highdpi];
1530 #pragma clang diagnostic pop
1533 #if SDL_VIDEO_OPENGL_ES2
1534 #if SDL_VIDEO_OPENGL_EGL
1537 [contentView setWantsLayer:TRUE];
1541 [nswindow setContentView:contentView];
1542 [contentView release];
1554 #if SDL_VIDEO_OPENGL_ES2
1556 #if SDL_VIDEO_OPENGL_EGL
1563 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
1574 NSWindow *nswindow = (NSWindow *)
data;
1578 title = [nswindow title];
1590 const char *title =
window->title ?
window->title :
"";
1592 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1593 [nswindow setTitle:string];
1604 [NSApp setApplicationIconImage:nsimage];
1613 NSWindow *nswindow = windata->
nswindow;
1623 moveHack = s_moveHack;
1625 [nswindow setFrameOrigin:rect.origin];
1626 s_moveHack = moveHack;
1628 ScheduleContextUpdates(windata);
1636 NSWindow *nswindow = windata->
nswindow;
1650 moveHack = s_moveHack;
1652 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1653 s_moveHack = moveHack;
1655 ScheduleContextUpdates(windata);
1666 minSize.height =
window->min_h;
1668 [windata->
nswindow setContentMinSize:minSize];
1679 maxSize.height =
window->max_h;
1681 [windata->
nswindow setContentMaxSize:maxSize];
1689 NSWindow *nswindow = windowData->
nswindow;
1691 if (![nswindow isMiniaturized]) {
1692 [windowData->listener pauseVisibleObservation];
1693 [nswindow makeKeyAndOrderFront:nil];
1694 [windowData->listener resumeVisibleObservation];
1704 [nswindow orderOut:nil];
1712 NSWindow *nswindow = windowData->
nswindow;
1717 [windowData->listener pauseVisibleObservation];
1718 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1719 [NSApp activateIgnoringOtherApps:YES];
1720 [nswindow makeKeyAndOrderFront:nil];
1722 [windowData->listener resumeVisibleObservation];
1730 NSWindow *nswindow = windata->
nswindow;
1732 [nswindow zoom:nil];
1734 ScheduleContextUpdates(windata);
1744 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1746 [nswindow miniaturize:nil];
1756 if ([nswindow isMiniaturized]) {
1757 [nswindow deminiaturize:nil];
1759 [nswindow zoom:nil];
1798 if ([[nswindow contentView] nextResponder] ==
data->listener) {
1799 [[nswindow contentView] setNextResponder:nil];
1806 rect.origin.
x = bounds.
x;
1807 rect.origin.
y = bounds.
y;
1808 rect.size.width = bounds.
w;
1809 rect.size.height = bounds.
h;
1810 ConvertNSRect([nswindow
screen], fullscreen, &
rect);
1815 NSProcessInfo *processInfo = [NSProcessInfo processInfo];
1816 NSOperatingSystemVersion version = { 10, 15, 0 };
1817 if (![processInfo respondsToSelector:
@selector(isOperatingSystemAtLeastVersion:)] ||
1818 ![processInfo isOperatingSystemAtLeastVersion:version]) {
1819 NSRect screenRect = [[nswindow screen] frame];
1820 if (screenRect.size.height >= 1.0f) {
1825 [nswindow setStyleMask:NSWindowStyleMaskBorderless];
1831 ConvertNSRect([nswindow
screen], fullscreen, &
rect);
1839 [nswindow setStyleMask:GetWindowWindowedStyle(window)];
1842 NSRect frameRect = [nswindow frame];
1843 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1844 [nswindow setFrame:frameRect display:NO];
1848 if ([[nswindow contentView] nextResponder] !=
data->listener) {
1849 [[nswindow contentView] setNextResponder:data->listener];
1853 [nswindow setContentSize:rect.size];
1854 [nswindow setFrameOrigin:rect.origin];
1864 [nswindow setLevel:CGShieldingWindowLevel()];
1866 [nswindow setLevel:NSFloatingWindowLevel];
1868 [nswindow setLevel:kCGNormalWindowLevel];
1871 if ([nswindow isVisible] || fullscreen) {
1872 [data->listener pauseVisibleObservation];
1873 [nswindow makeKeyAndOrderFront:nil];
1874 [data->listener resumeVisibleObservation];
1877 ScheduleContextUpdates(
data);
1886 CGGammaValue redTable[tableSize];
1887 CGGammaValue greenTable[tableSize];
1888 CGGammaValue blueTable[tableSize];
1890 float inv65535 = 1.0f / 65535.0f;
1893 for (
i = 0;
i < 256;
i++) {
1894 redTable[i] = ramp[0*256+i] * inv65535;
1895 greenTable[i] = ramp[1*256+i] * inv65535;
1896 blueTable[i] = ramp[2*256+i] * inv65535;
1899 if (CGSetDisplayTransferByTable(
display_id, tableSize,
1900 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1912 CGGammaValue redTable[tableSize];
1913 CGGammaValue greenTable[tableSize];
1914 CGGammaValue blueTable[tableSize];
1917 if (CGGetDisplayTransferByTable(
display_id, tableSize,
1918 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1922 for (
i = 0;
i < tableCopied;
i++) {
1923 ramp[0*256+i] = (
Uint16)(redTable[
i] * 65535.0
f);
1924 ramp[1*256+i] = (
Uint16)(greenTable[
i] * 65535.0
f);
1925 ramp[2*256+i] = (
Uint16)(blueTable[
i] * 65535.0
f);
1950 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1951 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1959 [data->nswindow setLevel:CGShieldingWindowLevel()];
1961 [data->nswindow setLevel:NSFloatingWindowLevel];
1963 [data->nswindow setLevel:kCGNormalWindowLevel];
1976 [NSMenu setMenuBarVisible:YES];
1978 [data->listener close];
1979 [data->listener release];
1980 if (
data->created) {
1982 [data->nswindow setContentView:nil];
1983 [data->nswindow close];
1986 NSArray *contexts = [[data->nscontexts copy] autorelease];
1987 for (SDLOpenGLContext *
context in contexts) {
1989 [context setWindow:NULL];
1991 [data->nscontexts release];
2008 SDL_SetError(
"Application not compiled with SDL %d.%d",
2033 if (
data->inWindowFullscreenTransition) {
2038 if ([
data->listener setFullscreenSpace:(
state ? YES : NO)]) {
2039 const int maxattempts = 3;
2041 while (++attempt <= maxattempts) {
2045 const int limit = 10000;
2058 if (![
data->listener setFullscreenSpace:(
state ? YES : NO)])
2080 [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
2082 [data->nswindow unregisterDraggedTypes];
2090 [
data->nswindow setAlphaValue:opacity];