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) {
222static 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
259GetHintCtrlClickEmulateRightClick()
267 NSUInteger style = 0;
270 style = NSWindowStyleMaskBorderless;
273 style = NSWindowStyleMaskBorderless;
275 style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
278 style |= NSWindowStyleMaskResizable;
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);
555 ConvertNSRect([nswindow
screen], fullscreen, &
rect);
556 [nswindow setFrameOrigin:rect.origin];
564 ScheduleContextUpdates(
_data);
569- (
void)windowDidResize:(NSNotification *)aNotification
579 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
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];
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
706 if (
window->is_destroying) {
715 [
self windowDidExitFullScreen:nil];
718- (
void)windowDidEnterFullScreen:(NSNotification *)aNotification
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
767 if (
window->is_destroying) {
771 SetWindowStyle(
window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
776 [
self windowDidEnterFullScreen:nil];
779- (
void)windowDidExitFullScreen:(NSNotification *)aNotification
788 [nswindow setLevel:kCGNormalWindowLevel];
792 [
self setFullscreenSpace:YES];
795 [nswindow miniaturize:nil];
800 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
802 [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
804 [NSMenu setMenuBarVisible:YES];
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
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];
1074#if !SDL_MAC_NO_SANDBOX
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;
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
1305 data->nswindow = nswindow;
1306 data->created = created;
1307 data->videodata = videodata;
1308 data->nscontexts = [[NSMutableArray alloc] init];
1313 data->sdlContentView = created ? [nswindow contentView] : nil;
1320 NSRect
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
1329 [data->listener listen:data];
1331 if ([nswindow isVisible]) {
1334 window->flags &= ~SDL_WINDOW_SHOWN;
1338 unsigned long style = [nswindow styleMask];
1340 if (style == NSWindowStyleMaskBorderless) {
1343 window->flags &= ~SDL_WINDOW_BORDERLESS;
1345 if (style & NSWindowStyleMaskResizable) {
1348 window->flags &= ~SDL_WINDOW_RESIZABLE;
1356 window->flags &= ~SDL_WINDOW_MAXIMIZED;
1359 if ([nswindow isMiniaturized]) {
1362 window->flags &= ~SDL_WINDOW_MINIMIZED;
1365 if ([nswindow isKeyWindow]) {
1373 [nswindow setOneShot:NO];
1390 NSArray *screens = [NSScreen screens];
1399 style = GetWindowStyle(
window);
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];
1479#if SDL_VIDEO_OPENGL_ES2
1481#if SDL_VIDEO_OPENGL_EGL
1488 return SDL_SetError(
"Could not create GLES window surface (EGL support not configured)");
1499 NSWindow *nswindow = (NSWindow *)
data;
1503 title = [nswindow title];
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;
1548 moveHack = s_moveHack;
1550 [nswindow setFrameOrigin:rect.origin];
1551 s_moveHack = moveHack;
1553 ScheduleContextUpdates(windata);
1561 NSWindow *nswindow = windata->
nswindow;
1575 moveHack = s_moveHack;
1577 [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
1578 s_moveHack = moveHack;
1580 ScheduleContextUpdates(windata);
1591 minSize.height =
window->min_h;
1593 [windata->
nswindow setContentMinSize:minSize];
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);
1670 [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
1672 [nswindow miniaturize:nil];
1682 if ([nswindow isMiniaturized]) {
1683 [nswindow deminiaturize:nil];
1685 [nswindow zoom:nil];
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.0
f);
1836 ramp[2*256+i] = (
Uint16)(blueTable[
i] * 65535.0
f);
1861 DLog(
"Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
1862 CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
1870 [data->nswindow setLevel:CGShieldingWindowLevel()];
1872 [data->nswindow setLevel:kCGNormalWindowLevel];
1885 [NSMenu setMenuBarVisible:YES];
1887 [data->listener close];
1888 [data->listener release];
1889 if (
data->created) {
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",
1942 if ([
data->listener setFullscreenSpace:(
state ? YES : NO)]) {
1943 const int maxattempts = 3;
1945 while (++attempt <= maxattempts) {
1949 const int limit = 10000;
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];
#define SDL_assert(condition)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
void Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
int Cocoa_ResizeWindowShape(SDL_Window *window)
#define NSEventSubtypeMouseEvent
static const NSUInteger NSEventModifierFlagCapsLock
NSImage * Cocoa_CreateImage(SDL_Surface *surface)
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
void Cocoa_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void Cocoa_ShowWindow(_THIS, SDL_Window *window)
void Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
int Cocoa_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
@ PENDING_OPERATION_LEAVE_FULLSCREEN
@ PENDING_OPERATION_MINIMIZE
@ PENDING_OPERATION_ENTER_FULLSCREEN
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
void Cocoa_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
void Cocoa_HideWindow(_THIS, SDL_Window *window)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
int Cocoa_CreateWindow(_THIS, SDL_Window *window)
void Cocoa_SetWindowTitle(_THIS, SDL_Window *window)
int SDL_SendDropFile(SDL_Window *window, const char *file)
int SDL_SendDropComplete(SDL_Window *window)
#define SDL_GetMouseState
#define SDL_GetNumTouchFingers
#define SDL_GetKeyboardFocus
#define SDL_GetTouchFinger
#define SDL_GetMouseFocus
#define SDL_GetHintBoolean
#define SDL_IsShapedWindow
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_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
#define SDL_OutOfMemory()
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
#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 SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
void SDL_SetKeyboardFocus(SDL_Window *window)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
void SDL_SetMouseFocus(SDL_Window *window)
SDL_Mouse * SDL_GetMouse(void)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
GLint GLint GLsizei GLsizei height
GLuint GLuint GLsizei GLenum type
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei GLenum GLenum * types
GLsizei const GLchar *const * path
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
SDL_bool SDL_ShouldAllowTopmost(void)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
SDL_VideoDevice * SDL_GetVideoDevice(void)
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
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_MOUSE_TOUCHID
@ SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE
@ SDL_TOUCH_DEVICE_DIRECT
#define SDL_MINOR_VERSION
#define SDL_MAJOR_VERSION
static SDL_VideoDevice * _this
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
@ SDL_WINDOW_ALLOW_HIGHDPI
@ SDL_WINDOW_INPUT_GRABBED
@ SDL_WINDOW_FULLSCREEN_DESKTOP
@ SDL_WINDOWEVENT_RESIZED
@ SDL_WINDOWEVENT_HIT_TEST
@ SDL_WINDOWEVENT_MINIMIZED
@ SDL_WINDOWEVENT_MAXIMIZED
@ SDL_WINDOWEVENT_RESTORED
@ SDL_WINDOWEVENT_EXPOSED
@ SDL_GL_CONTEXT_PROFILE_ES
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
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)
EGLSurface EGLNativeWindowType * window
EGLNativeDisplayType * display_id
BOOL isInFullscreenSpace()
BOOL inFullscreenTransition
void windowDidFinishMoving()
PendingWindowOperation pendingWindowOperation
void pauseVisibleObservation()
BOOL isInFullscreenSpaceTransition()
void resumeVisibleObservation()
int(* SetRelativeMouseMode)(SDL_bool enabled)
SDL_bool relative_mode_warp
int(* WarpMouseGlobal)(int x, int y)
The structure that defines a point (integer)
A rectangle, with the origin at the upper left (integer).
A collection of pixels used in software blitting.
union SDL_SysWMinfo::@17 info
unsigned int modifierFlags
struct SDL_VideoDevice::@262 gl_config
struct SDL_VideoData * videodata
The type used to identify a window.
static screen_context_t context