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) 58 @interface SDLWindow : NSWindow <NSDraggingDestination>
60 - (BOOL)canBecomeKeyWindow;
61 - (BOOL)canBecomeMainWindow;
62 - (
void)sendEvent:(NSEvent *)event;
63 - (
void)doCommandBySelector:(
SEL)aSelector;
66 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender;
67 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender;
68 - (BOOL)wantsPeriodicDraggingUpdates;
69 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
74 @implementation SDLWindow
76 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
81 if ([menuItem action] ==
@selector(toggleFullScreen:)) {
91 return [
super validateMenuItem:menuItem];
94 - (BOOL)canBecomeKeyWindow
99 - (BOOL)canBecomeMainWindow
104 - (
void)sendEvent:(NSEvent *)event
106 [
super sendEvent:event];
108 if ([event
type] != NSEventTypeLeftMouseUp) {
112 id delegate = [
self delegate];
117 if ([delegate isMoving]) {
118 [delegate windowDidFinishMoving];
125 - (
void)doCommandBySelector:(
SEL)aSelector
130 - (NSDragOperation)draggingEntered:(
id <NSDraggingInfo>)sender
132 if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
133 return NSDragOperationGeneric;
136 return NSDragOperationNone;
139 - (BOOL)performDragOperation:(
id <NSDraggingInfo>)sender
142 NSPasteboard *pasteboard = [sender draggingPasteboard];
143 NSArray *
types = [NSArray arrayWithObject:NSFilenamesPboardType];
144 NSString *desiredType = [pasteboard availableTypeFromArray:types];
147 if (desiredType == nil) {
151 NSData *
data = [pasteboard dataForType:desiredType];
156 SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
157 NSArray *
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
159 for (NSString *
path in array) {
160 NSURL *fileURL = [NSURL fileURLWithPath:path];
161 NSNumber *isAlias = nil;
163 [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
166 if ([isAlias boolValue]) {
167 NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
168 NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
169 if (bookmark != nil) {
170 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
173 bookmarkDataIsStale:nil
176 if (resolvedURL != nil) {
177 fileURL = resolvedURL;
191 - (BOOL)wantsPeriodicDraggingUpdates
203 for (sdlwindow = _this->
windows; sdlwindow; sdlwindow = sdlwindow->
next) {
205 if (nswindow ==
self) {
219 static void ConvertNSRect(NSScreen *
screen, BOOL fullscreen, NSRect *
r)
221 r->origin.
y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.
y - r->
size.
height;
227 NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
229 @
synchronized (contexts) {
230 for (SDLOpenGLContext *
context in contexts) {
231 if (
context == currentContext) {
234 [context scheduleUpdate];
242 GetHintCtrlClickEmulateRightClick()
250 NSUInteger style = 0;
253 style = NSWindowStyleMaskBorderless;
256 style = NSWindowStyleMaskBorderless;
258 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
261 style |= NSWindowStyleMaskResizable;
268 SetWindowStyle(
SDL_Window * window, NSUInteger style)
271 NSWindow *nswindow = data->
nswindow;
274 if ([[nswindow contentView] nextResponder] == data->
listener) {
275 [[nswindow contentView] setNextResponder:nil];
278 [nswindow setStyleMask:style];
281 if ([[nswindow contentView] nextResponder] != data->
listener) {
282 [[nswindow contentView] setNextResponder:data->listener];
293 NSNotificationCenter *center;
295 NSView *view = [window contentView];
307 center = [NSNotificationCenter defaultCenter];
309 if ([window delegate] != nil) {
310 [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
311 [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
312 [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
313 [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
314 [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
315 [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
316 [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
317 [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
318 [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
319 [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
320 [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
321 [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
322 [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
323 [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
325 [window setDelegate:self];
332 [window addObserver:self
333 forKeyPath:@"visible"
334 options:NSKeyValueObservingOptionNew
337 [window setNextResponder:self];
338 [window setAcceptsMouseMovedEvents:YES];
340 [view setNextResponder:self];
342 [view setAcceptsTouchEvents:YES];
345 - (
void)observeValueForKeyPath:(NSString *)keyPath
347 change:(NSDictionary *)change
348 context:(
void *)context
354 if (
object ==
_data->
nswindow && [keyPath isEqualToString:
@"visible"]) {
355 int newVisibility = [[change objectForKey:@"new"] intValue];
372 BOOL isVisible = [_data->nswindow isVisible];
385 -(BOOL) setFullscreenSpace:(BOOL) state
403 [
self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
405 [
self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
412 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
413 [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
434 NSNotificationCenter *center;
436 NSView *view = [window contentView];
438 center = [NSNotificationCenter defaultCenter];
440 if ([window delegate] !=
self) {
441 [center removeObserver:self name:NSWindowDidExposeNotification object:window];
442 [center removeObserver:self name:NSWindowDidMoveNotification object:window];
443 [center removeObserver:self name:NSWindowDidResizeNotification object:window];
444 [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
445 [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
446 [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
447 [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
448 [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
449 [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
450 [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
451 [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
452 [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
453 [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
454 [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
456 [window setDelegate:nil];
459 [window removeObserver:self forKeyPath:@"visible"];
461 if ([window nextResponder] ==
self) {
462 [window setNextResponder:nil];
464 if ([view nextResponder] ==
self) {
465 [view setNextResponder:nil];
474 -(
void) setPendingMoveX:(
int)x Y:(
int)y
496 - (BOOL)windowShouldClose:(
id)sender
502 - (
void)windowDidExpose:(NSNotification *)aNotification
507 - (
void)windowWillMove:(NSNotification *)aNotification
515 - (
void)windowDidMove:(NSNotification *)aNotification
521 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
522 ConvertNSRect([nswindow
screen], fullscreen, &rect);
536 rect.origin.x = window->
x;
537 rect.origin.y = window->
y;
538 ConvertNSRect([nswindow
screen], fullscreen, &rect);
539 [nswindow setFrameOrigin:rect.origin];
544 x = (int)rect.origin.x;
545 y = (
int)rect.origin.y;
547 ScheduleContextUpdates(
_data);
552 - (
void)windowDidResize:(NSNotification *)aNotification
562 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
564 x = (int)rect.origin.x;
565 y = (
int)rect.origin.y;
566 w = (int)rect.size.width;
567 h = (
int)rect.size.height;
573 ScheduleContextUpdates(
_data);
580 const BOOL zoomed = [nswindow isZoomed];
588 - (
void)windowDidMiniaturize:(NSNotification *)aNotification
593 - (
void)windowDidDeminiaturize:(NSNotification *)aNotification
598 - (
void)windowDidBecomeKey:(NSNotification *)aNotification
616 point = [_data->nswindow mouseLocationOutsideOfEventStream];
618 y = (
int)(window->
h - point.y);
629 [NSMenu setMenuBarVisible:NO];
637 - (
void)windowDidResignKey:(NSNotification *)aNotification
655 [NSMenu setMenuBarVisible:YES];
659 - (
void)windowDidChangeBackingProperties:(NSNotification *)aNotification
661 NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
667 if ([oldscale doubleValue] != [
_data->
nswindow backingScaleFactor]) {
671 [
self windowDidResize:aNotification];
675 - (
void)windowWillEnterFullScreen:(NSNotification *)aNotification
679 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
685 - (
void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
693 SetWindowStyle(window, GetWindowStyle(window));
698 [
self windowDidExitFullScreen:nil];
701 - (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
705 NSWindow *nswindow = data->
nswindow;
711 [
self setFullscreenSpace:NO];
716 SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
719 [NSMenu setMenuBarVisible:NO];
728 [
self windowDidMove:aNotification];
729 [
self windowDidResize:aNotification];
733 - (
void)windowWillExitFullScreen:(NSNotification *)aNotification
743 SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
746 - (
void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
754 SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
759 [
self windowDidEnterFullScreen:nil];
762 - (
void)windowDidExitFullScreen:(NSNotification *)aNotification
769 SetWindowStyle(window, GetWindowStyle(window));
771 [nswindow setLevel:kCGNormalWindowLevel];
775 [
self setFullscreenSpace:YES];
778 [nswindow miniaturize:nil];
783 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
785 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
787 [NSMenu setMenuBarVisible:YES];
805 ConvertNSRect([nswindow screen], NO, &rect);
808 [nswindow setContentSize:rect.size];
809 [nswindow setFrameOrigin:rect.origin];
819 [
self windowDidMove:aNotification];
820 [
self windowDidResize:aNotification];
829 -(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
832 return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
834 return proposedOptions;
843 - (
void)flagsChanged:(NSEvent *)theEvent
847 - (
void)keyDown:(NSEvent *)theEvent
851 - (
void)keyUp:(NSEvent *)theEvent
859 - (
void)doCommandBySelector:(
SEL)aSelector
864 - (BOOL)processHitTest:(NSEvent *)theEvent
869 const NSPoint
location = [theEvent locationInWindow];
875 [_data->nswindow setMovableByWindowBackground:YES];
883 [_data->nswindow setMovableByWindowBackground:NO];
890 - (
void)mouseDown:(NSEvent *)theEvent
896 if ([theEvent window]) {
897 NSRect windowRect = [[[theEvent window] contentView] frame];
898 if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
903 if ([
self processHitTest:theEvent]) {
908 switch ([theEvent buttonNumber]) {
910 if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
911 GetHintCtrlClickEmulateRightClick()) {
926 button = (int) [theEvent buttonNumber] + 1;
930 clicks = (int) [theEvent clickCount];
934 - (
void)rightMouseDown:(NSEvent *)theEvent
936 [
self mouseDown:theEvent];
939 - (
void)otherMouseDown:(NSEvent *)theEvent
941 [
self mouseDown:theEvent];
944 - (
void)mouseUp:(NSEvent *)theEvent
949 if ([
self processHitTest:theEvent]) {
954 switch ([theEvent buttonNumber]) {
970 button = (int) [theEvent buttonNumber] + 1;
974 clicks = (int) [theEvent clickCount];
978 - (
void)rightMouseUp:(NSEvent *)theEvent
980 [
self mouseUp:theEvent];
983 - (
void)otherMouseUp:(NSEvent *)theEvent
985 [
self mouseUp:theEvent];
988 - (
void)mouseMoved:(NSEvent *)theEvent
995 if ([
self processHitTest:theEvent]) {
1004 point = [theEvent locationInWindow];
1006 y = (
int)(window->
h - point.y);
1012 }
else if (x >= window->
w) {
1017 }
else if (y >= window->
h) {
1021 #if !SDL_MAC_NO_SANDBOX 1028 cgpoint.x = window->
x + x;
1029 cgpoint.y = window->
y + y;
1031 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1032 CGAssociateMouseAndMouseCursorPosition(YES);
1041 - (
void)mouseDragged:(NSEvent *)theEvent
1043 [
self mouseMoved:theEvent];
1046 - (
void)rightMouseDragged:(NSEvent *)theEvent
1048 [
self mouseMoved:theEvent];
1051 - (
void)otherMouseDragged:(NSEvent *)theEvent
1053 [
self mouseMoved:theEvent];
1056 - (
void)scrollWheel:(NSEvent *)theEvent
1061 - (
void)touchesBeganWithEvent:(NSEvent *) theEvent
1063 NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
1064 int existingTouchCount = 0;
1066 for (NSTouch* touch
in touches) {
1067 if ([touch phase] != NSTouchPhaseBegan) {
1068 existingTouchCount++;
1071 if (existingTouchCount == 0) {
1074 DLog(
"Reset Lost Fingers: %d", numFingers);
1075 for (--numFingers; numFingers >= 0; --numFingers) {
1081 DLog(
"Began Fingers: %lu .. existing: %d", (
unsigned long)[touches
count], existingTouchCount);
1082 [
self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
1085 - (
void)touchesMovedWithEvent:(NSEvent *) theEvent
1087 [
self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
1090 - (
void)touchesEndedWithEvent:(NSEvent *) theEvent
1092 [
self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
1095 - (
void)touchesCancelledWithEvent:(NSEvent *) theEvent
1097 [
self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
1100 - (
void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
1102 NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
1104 for (NSTouch *touch
in touches) {
1111 float x = [touch normalizedPosition].x;
1112 float y = [touch normalizedPosition].y;
1117 case NSTouchPhaseBegan:
1120 case NSTouchPhaseEnded:
1121 case NSTouchPhaseCancelled:
1124 case NSTouchPhaseMoved:
1135 @interface SDLView : NSView {
1142 - (
void)rightMouseDown:(NSEvent *)theEvent;
1143 - (BOOL)mouseDownCanMoveWindow;
1144 - (
void)drawRect:(NSRect)dirtyRect;
1145 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
1148 @implementation SDLView
1154 - (
void)drawRect:(NSRect)dirtyRect
1159 [[NSColor blackColor] setFill];
1160 NSRectFill(dirtyRect);
1164 - (
void)rightMouseDown:(NSEvent *)theEvent
1166 [[
self nextResponder] rightMouseDown:theEvent];
1169 - (BOOL)mouseDownCanMoveWindow
1177 - (
void)resetCursorRects
1179 [
super resetCursorRects];
1183 [
self addCursorRect:[
self bounds]
1184 cursor:mouse->cur_cursor->driverdata];
1186 [
self addCursorRect:[
self bounds]
1187 cursor:[NSCursor invisibleCursor]];
1191 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1217 data->
nscontexts = [[NSMutableArray alloc] init];
1224 NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1226 window->
x = (int)rect.origin.x;
1227 window->
y = (
int)rect.origin.y;
1228 window->
w = (int)rect.size.width;
1229 window->
h = (
int)rect.size.height;
1233 [data->listener listen:data];
1235 if ([nswindow isVisible]) {
1242 unsigned long style = [nswindow styleMask];
1244 if (style == NSWindowStyleMaskBorderless) {
1249 if (style & NSWindowStyleMaskResizable) {
1263 if ([nswindow isMiniaturized]) {
1269 if ([nswindow isKeyWindow]) {
1277 [nswindow setOneShot:NO];
1294 NSArray *screens = [NSScreen screens];
1297 rect.origin.x = window->
x;
1298 rect.origin.y = window->
y;
1299 rect.size.width = window->
w;
1300 rect.size.height = window->
h;
1303 style = GetWindowStyle(window);
1306 NSScreen *screen = nil;
1307 for (NSScreen *candidate
in screens) {
1308 NSRect screenRect = [candidate frame];
1309 if (rect.origin.x >= screenRect.origin.x &&
1310 rect.origin.x < screenRect.origin.x + screenRect.size.width &&
1311 rect.origin.y >= screenRect.origin.y &&
1312 rect.origin.y < screenRect.origin.y + screenRect.size.height) {
1314 rect.origin.x -= screenRect.origin.x;
1315 rect.origin.y -= screenRect.origin.y;
1320 nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
1322 @catch (NSException *
e) {
1328 SDL_assert([nswindow respondsToSelector:
@selector(toggleFullScreen:)]);
1332 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1337 rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1338 SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
1339 [contentView setSDLWindow:window];
1342 if ([contentView respondsToSelector:
@selector(setWantsBestResolutionOpenGLSurface:)]) {
1343 [contentView setWantsBestResolutionOpenGLSurface:YES];
1346 #if SDL_VIDEO_OPENGL_ES2 1347 #if SDL_VIDEO_OPENGL_EGL 1350 [contentView setWantsLayer:TRUE];
1354 [nswindow setContentView:contentView];
1355 [contentView release];
1358 [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
1360 if (SetupWindowData(_this, window, nswindow,
SDL_TRUE) < 0) {
1370 #if SDL_VIDEO_OPENGL_ES2 1372 #if SDL_VIDEO_OPENGL_EGL 1373 if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
1379 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
1390 NSWindow *nswindow = (NSWindow *) data;
1394 title = [nswindow title];
1399 return SetupWindowData(_this, window, nswindow,
SDL_FALSE);
1406 const char *title = window->
title ? window->
title :
"";
1408 NSString *
string = [[NSString alloc] initWithUTF8String:title];
1409 [nswindow setTitle:string];
1420 [NSApp setApplicationIconImage:nsimage];
1429 NSWindow *nswindow = windata->
nswindow;
1433 rect.origin.x = window->
x;
1434 rect.origin.y = window->
y;
1435 rect.size.width = window->
w;
1436 rect.size.height = window->
h;
1439 moveHack = s_moveHack;
1441 [nswindow setFrameOrigin:rect.origin];
1442 s_moveHack = moveHack;
1444 ScheduleContextUpdates(windata);
1452 NSWindow *nswindow = windata->
nswindow;
1460 rect.origin.x = window->
x;
1461 rect.origin.y = window->
y;
1462 rect.size.width = window->
w;
1463 rect.size.height = window->
h;
1466 moveHack = s_moveHack;
1468 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1469 s_moveHack = moveHack;
1471 ScheduleContextUpdates(windata);
1481 minSize.width = window->
min_w;
1482 minSize.height = window->
min_h;
1484 [windata->
nswindow setContentMinSize:minSize];
1494 maxSize.width = window->
max_w;
1495 maxSize.height = window->
max_h;
1497 [windata->
nswindow setContentMaxSize:maxSize];
1505 NSWindow *nswindow = windowData->
nswindow;
1507 if (![nswindow isMiniaturized]) {
1508 [windowData->listener pauseVisibleObservation];
1509 [nswindow makeKeyAndOrderFront:nil];
1510 [windowData->listener resumeVisibleObservation];
1520 [nswindow orderOut:nil];
1528 NSWindow *nswindow = windowData->
nswindow;
1533 [windowData->listener pauseVisibleObservation];
1534 if (![nswindow isMiniaturized] && [nswindow isVisible]) {
1535 [NSApp activateIgnoringOtherApps:YES];
1536 [nswindow makeKeyAndOrderFront:nil];
1538 [windowData->listener resumeVisibleObservation];
1546 NSWindow *nswindow = windata->
nswindow;
1548 [nswindow zoom:nil];
1550 ScheduleContextUpdates(windata);
1558 NSWindow *nswindow = data->
nswindow;
1560 if ([data->
listener isInFullscreenSpaceTransition]) {
1561 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1563 [nswindow miniaturize:nil];
1573 if ([nswindow isMiniaturized]) {
1574 [nswindow deminiaturize:nil];
1576 [nswindow zoom:nil];
1584 if (SetWindowStyle(window, GetWindowStyle(window))) {
1601 if (![listener isInFullscreenSpace]) {
1602 SetWindowStyle(window, GetWindowStyle(window));
1611 NSWindow *nswindow = data->
nswindow;
1615 if ([[nswindow contentView] nextResponder] == data->
listener) {
1616 [[nswindow contentView] setNextResponder:nil];
1623 rect.origin.x = bounds.
x;
1624 rect.origin.y = bounds.
y;
1625 rect.size.width = bounds.
w;
1626 rect.size.height = bounds.
h;
1627 ConvertNSRect([nswindow screen], fullscreen, &rect);
1630 NSRect screenRect = [[nswindow screen] frame];
1631 if (screenRect.size.height >= 1.0f) {
1635 [nswindow setStyleMask:NSWindowStyleMaskBorderless];
1641 ConvertNSRect([nswindow screen], fullscreen, &rect);
1643 [nswindow setStyleMask:GetWindowStyle(window)];
1646 NSRect frameRect = [nswindow frame];
1647 [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
1648 [nswindow setFrame:frameRect display:NO];
1652 if ([[nswindow contentView] nextResponder] != data->
listener) {
1653 [[nswindow contentView] setNextResponder:data->listener];
1657 [nswindow setContentSize:rect.size];
1658 [nswindow setFrameOrigin:rect.origin];
1668 [nswindow setLevel:CGShieldingWindowLevel()];
1670 [nswindow setLevel:kCGNormalWindowLevel];
1673 if ([nswindow isVisible] || fullscreen) {
1674 [data->listener pauseVisibleObservation];
1675 [nswindow makeKeyAndOrderFront:nil];
1676 [data->listener resumeVisibleObservation];
1679 ScheduleContextUpdates(data);
1688 CGGammaValue redTable[tableSize];
1689 CGGammaValue greenTable[tableSize];
1690 CGGammaValue blueTable[tableSize];
1692 float inv65535 = 1.0f / 65535.0f;
1695 for (i = 0; i < 256; i++) {
1696 redTable[i] = ramp[0*256+i] * inv65535;
1697 greenTable[i] = ramp[1*256+i] * inv65535;
1698 blueTable[i] = ramp[2*256+i] * inv65535;
1701 if (CGSetDisplayTransferByTable(display_id, tableSize,
1702 redTable, greenTable, blueTable) != CGDisplayNoErr) {
1714 CGGammaValue redTable[tableSize];
1715 CGGammaValue greenTable[tableSize];
1716 CGGammaValue blueTable[tableSize];
1719 if (CGGetDisplayTransferByTable(display_id, tableSize,
1720 redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
1724 for (i = 0; i < tableCopied; i++) {
1725 ramp[0*256+i] = (
Uint16)(redTable[i] * 65535.0
f);
1726 ramp[1*256+i] = (
Uint16)(greenTable[i] * 65535.0f);
1727 ramp[2*256+i] = (
Uint16)(blueTable[i] * 65535.0f);
1742 if (grabbed && data && ![data->
listener isMoving]) {
1747 cgpoint.x = window->
x + x;
1748 cgpoint.y = window->
y + y;
1752 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1753 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1758 && ![data->
listener isInFullscreenSpace]) {
1761 [data->nswindow setLevel:CGShieldingWindowLevel()];
1763 [data->nswindow setLevel:kCGNormalWindowLevel];
1775 if ([data->
listener isInFullscreenSpace]) {
1776 [NSMenu setMenuBarVisible:YES];
1778 [data->listener close];
1779 [data->listener release];
1781 [data->nswindow close];
1784 NSArray *contexts = [[data->nscontexts copy] autorelease];
1785 for (SDLOpenGLContext *context
in contexts) {
1787 [context setWindow:NULL];
1789 [data->nscontexts release];
1806 SDL_SetError(
"Application not compiled with SDL %d.%d",
1813 Cocoa_IsWindowInFullscreenSpace(
SDL_Window * window)
1817 if ([data->
listener isInFullscreenSpace]) {
1831 if ([data->
listener setFullscreenSpace:(state ? YES : NO)]) {
1832 const int maxattempts = 3;
1834 while (++attempt <= maxattempts) {
1838 const int limit = 10000;
1840 while ([data->
listener isInFullscreenSpaceTransition]) {
1841 if ( ++count == limit ) {
1848 if ([data->
listener isInFullscreenSpace] == (state ? YES : NO))
1851 if (![data->
listener setFullscreenSpace:(state ? YES : NO)])
1871 [data->
nswindow setAlphaValue:opacity];
int Cocoa_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
EGLNativeDisplayType * display_id
#define SDL_MINOR_VERSION
BOOL isInFullscreenSpace()
GLdouble GLdouble GLdouble r
SDL_Mouse * SDL_GetMouse(void)
NSMutableArray * nscontexts
#define SDL_IsShapedWindow
void SDL_SetKeyboardFocus(SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
GLint GLint GLint GLint GLint x
void Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
#define SDL_MAJOR_VERSION
SDL_bool relative_mode_warp
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
GLuint GLuint GLsizei count
int(* SetRelativeMouseMode)(SDL_bool enabled)
int SDL_SendDropFile(SDL_Window *window, const char *file)
void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
void Cocoa_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
GLfloat GLfloat GLfloat GLfloat h
void Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
#define SDL_GetTouchFinger
The structure that defines a point.
A collection of pixels used in software blitting.
static screen_context_t context
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK
A variable that determines whether ctrl+click should generate a right-click event on Mac...
void Cocoa_SetWindowTitle(_THIS, SDL_Window *window)
GLsizei GLenum GLenum * types
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
#define SDL_GetKeyboardFocus
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
unsigned int modifierFlags
void windowDidFinishMoving()
int SDL_SendDropComplete(SDL_Window *window)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
#define SDL_GetHintBoolean
static SDL_VideoDevice * _this
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
BOOL isInFullscreenSpaceTransition()
void Cocoa_ShowWindow(_THIS, SDL_Window *window)
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Cocoa_WindowListener * listener
struct SDL_VideoData * videodata
void resumeVisibleObservation()
int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
GLubyte GLubyte GLubyte GLubyte w
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
#define SDL_GetNumTouchFingers
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
static const NSUInteger NSEventModifierFlagCapsLock
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
#define SDL_assert(condition)
PendingWindowOperation pendingWindowOperation
SDL_bool SDL_ShouldAllowTopmost(void)
#define SDL_OutOfMemory()
#define SDL_GetMouseFocus
Uint32 last_fullscreen_flags
int Cocoa_CreateWindow(_THIS, SDL_Window *window)
int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
GLint GLint GLsizei GLsizei height
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
The type used to identify a window.
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
int Cocoa_ResizeWindowShape(SDL_Window *window)
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
union SDL_SysWMinfo::@18 info
BOOL inFullscreenTransition
GLsizei const GLchar *const * path
void pauseVisibleObservation()
void Cocoa_HideWindow(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@34 gl_config
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
void Cocoa_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
#define SDL_GetMouseState
void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
A rectangle, with the origin at the upper left.
int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)