21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_COCOA 27 #include "../../events/SDL_events_c.h" 32 #ifndef kIOPMAssertPreventUserIdleDisplaySleep 33 #define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep 36 @interface SDLApplication : NSApplication
39 - (
void)sendEvent:(NSEvent *)theEvent;
43 @implementation SDLApplication
53 static void Cocoa_DispatchEvent(NSEvent *theEvent)
57 switch ([theEvent
type]) {
59 case NSOtherMouseDown:
60 case NSRightMouseDown:
64 case NSLeftMouseDragged:
65 case NSRightMouseDragged:
66 case NSOtherMouseDragged:
84 - (
void)sendEvent:(NSEvent *)theEvent
86 if (s_bShouldHandleEventsInSDLApplication) {
87 Cocoa_DispatchEvent(theEvent);
90 [
super sendEvent:theEvent];
96 @interface NSApplication(NSAppleMenu)
97 - (
void)setAppleMenu:(NSMenu *)menu;
100 @interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
102 BOOL seenFirstActivate;
108 @implementation SDLAppDelegate : NSObject
113 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
115 seenFirstActivate = NO;
117 [center addObserver:self
118 selector:@selector(windowWillClose:)
119 name:NSWindowWillCloseNotification
122 [center addObserver:self
123 selector:@selector(focusSomeWindow:)
124 name:NSApplicationDidBecomeActiveNotification
133 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
135 [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
136 [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
141 - (
void)windowWillClose:(NSNotification *)notification;
143 NSWindow *win = (NSWindow*)[notification
object];
145 if (![win isKeyWindow]) {
158 for (NSWindow *
window in [NSApp orderedWindows]) {
160 if (![
window isOnActiveSpace]) {
163 [window makeKeyAndOrderFront:self];
172 for (NSNumber *
num in [NSWindow windowNumbersWithOptions:0]) {
174 if (window && window != win && [window canBecomeKeyWindow]) {
175 [window makeKeyAndOrderFront:self];
181 - (
void)focusSomeWindow:(NSNotification *)aNotification
188 if (!seenFirstActivate) {
189 seenFirstActivate = YES;
194 if (device && device->
windows) {
199 if (fullscreen_window) {
201 SDL_RestoreWindow(fullscreen_window);
208 SDL_RestoreWindow(window);
210 SDL_RaiseWindow(window);
215 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
221 static SDLAppDelegate *appDelegate = nil;
224 GetApplicationName(
void)
229 appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
231 appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
235 appName = [[NSProcessInfo processInfo] processName];
242 CreateApplicationMenus(
void)
250 NSMenuItem *menuItem;
257 mainMenu = [[NSMenu alloc] init];
260 [NSApp setMainMenu:mainMenu];
266 appName = GetApplicationName();
267 appleMenu = [[NSMenu alloc] initWithTitle:@""];
270 title = [@"About " stringByAppendingString:appName];
271 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
273 [appleMenu addItem:[NSMenuItem separatorItem]];
275 [appleMenu addItemWithTitle:@"Preferencesâ „€¦" action:nil keyEquivalent:@","];
277 [appleMenu addItem:[NSMenuItem separatorItem]];
279 serviceMenu = [[NSMenu alloc] initWithTitle:@""];
280 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Services" action:nil keyEquivalent:
@""];
281 [menuItem setSubmenu:serviceMenu];
283 [NSApp setServicesMenu:serviceMenu];
284 [serviceMenu release];
286 [appleMenu addItem:[NSMenuItem separatorItem]];
288 title = [@"Hide " stringByAppendingString:appName];
289 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
291 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Hide Others" action:
@selector(hideOtherApplications:) keyEquivalent:
@"h"];
292 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
294 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
296 [appleMenu addItem:[NSMenuItem separatorItem]];
298 title = [@"Quit " stringByAppendingString:appName];
299 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
302 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
303 [menuItem setSubmenu:appleMenu];
304 [[NSApp mainMenu] addItem:menuItem];
308 [NSApp setAppleMenu:appleMenu];
313 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
316 [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
318 [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
321 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
322 [menuItem setSubmenu:windowMenu];
323 [[NSApp mainMenu] addItem:menuItem];
327 [NSApp setWindowsMenu:windowMenu];
328 [windowMenu release];
332 if (
floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
334 viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
337 menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
338 [menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
341 menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
342 [menuItem setSubmenu:viewMenu];
343 [[NSApp mainMenu] addItem:menuItem];
357 [SDLApplication sharedApplication];
360 s_bShouldHandleEventsInSDLApplication =
SDL_TRUE;
363 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
364 [NSApp activateIgnoringOtherApps:YES];
367 if ([NSApp mainMenu] == nil) {
368 CreateApplicationMenus();
370 [NSApp finishLaunching];
371 NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
372 [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
373 [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
374 [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
376 [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
377 [appDefaults release];
379 if (NSApp && !appDelegate) {
380 appDelegate = [[SDLAppDelegate alloc] init];
385 if (![NSApp delegate]) {
386 [(NSApplication *)NSApp setDelegate:appDelegate];
388 appDelegate->seenFirstActivate = YES;
403 UpdateSystemActivity(UsrActivity);
409 NSEvent *
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
410 if (
event == nil ) {
414 if (!s_bShouldHandleEventsInSDLApplication) {
415 Cocoa_DispatchEvent(
event);
419 [NSApp sendEvent:event];
444 NSString *
name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
445 IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
void Cocoa_RegisterApp(void)
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
int SDL_SendDropFile(SDL_Window *window, const char *file)
static SDL_Window * window
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void Cocoa_SuspendScreenSaver(_THIS)
GLuint const GLchar * name
IOPMAssertionID screensaver_assertion
uint32_t Uint32
An unsigned 32-bit integer type.
int SDL_SendDropComplete(SDL_Window *window)
#define SDL_GetHintBoolean
static SDL_VideoDevice * _this
#define SDL_HINT_MAC_BACKGROUND_APP
When set don't force the SDL app to become a foreground process.
GLuint GLuint GLsizei GLenum type
Uint32 screensaver_activity
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
void Cocoa_PumpEvents(_THIS)
BOOL screensaver_use_iopm
SDL_VideoDisplay * displays
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
SDL_Window * fullscreen_window
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)
#define SDL_assert(condition)
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.
SDL_VideoDevice * SDL_GetVideoDevice(void)
SDL_bool suspend_screensaver
GLuint GLsizei GLsizei * length
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.