23 #if SDL_VIDEO_DRIVER_COCOA
27 #include "../../events/SDL_events_c.h"
29 #if !defined(UsrActivity) && defined(__LP64__) && !defined(__POWER__)
40 @interface NSApplication(NSAppleMenu)
41 - (
void)setAppleMenu:(NSMenu *)menu;
44 @interface SDLAppDelegate : NSObject {
45 BOOL seenFirstActivate;
49 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
50 - (
void)applicationDidBecomeActive:(NSNotification *)aNotification;
53 @implementation SDLAppDelegate : NSObject
59 seenFirstActivate = NO;
65 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
68 return NSTerminateCancel;
71 - (
void)applicationDidBecomeActive:(NSNotification *)aNotification
78 if (!seenFirstActivate) {
79 seenFirstActivate = YES;
91 if (fullscreen_window)
108 - (
BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
115 GetApplicationName(
void)
118 NSString *appName = 0;
121 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
123 appName = [dict objectForKey: @"CFBundleName"];
126 appName = [[NSProcessInfo processInfo] processName];
132 CreateApplicationMenus(
void)
139 NSMenuItem *menuItem;
146 [NSApp setMainMenu:[[NSMenu alloc] init]];
149 appName = GetApplicationName();
150 appleMenu = [[NSMenu alloc] initWithTitle:@""];
153 title = [@"About " stringByAppendingString:appName];
154 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
156 [appleMenu addItem:[NSMenuItem separatorItem]];
158 [appleMenu addItemWithTitle:@"Preferencesâ € ¦ " action:nil keyEquivalent:@","];
160 [appleMenu addItem:[NSMenuItem separatorItem]];
162 serviceMenu = [[NSMenu alloc] initWithTitle:@""];
163 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Services" action:nil keyEquivalent:
@""];
164 [menuItem setSubmenu:serviceMenu];
166 [NSApp setServicesMenu:serviceMenu];
167 [serviceMenu release];
169 [appleMenu addItem:[NSMenuItem separatorItem]];
171 title = [@"Hide " stringByAppendingString:appName];
172 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
174 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Hide Others" action:
@selector(hideOtherApplications:) keyEquivalent:
@"h"];
175 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
177 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
179 [appleMenu addItem:[NSMenuItem separatorItem]];
181 title = [@"Quit " stringByAppendingString:appName];
182 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
185 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
186 [menuItem setSubmenu:appleMenu];
187 [[NSApp mainMenu] addItem:menuItem];
191 [NSApp setAppleMenu:appleMenu];
196 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
199 [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
201 [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
204 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
205 [menuItem setSubmenu:windowMenu];
206 [[NSApp mainMenu] addItem:menuItem];
210 [NSApp setWindowsMenu:windowMenu];
211 [windowMenu release];
218 ProcessSerialNumber psn;
219 NSAutoreleasePool *pool;
221 if (!GetCurrentProcess(&psn)) {
222 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
223 SetFrontProcess(&psn);
226 pool = [[NSAutoreleasePool alloc] init];
228 [NSApplication sharedApplication];
230 if ([NSApp mainMenu] == nil) {
231 CreateApplicationMenus();
233 [NSApp finishLaunching];
234 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AppleMomentumScrollSupported"];
235 [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
238 if (NSApp && ![NSApp delegate]) {
239 [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
247 NSAutoreleasePool *pool;
254 (
int)(now-data->screensaver_activity) >= 30000) {
255 UpdateSystemActivity(UsrActivity);
260 pool = [[NSAutoreleasePool alloc] init];
262 NSEvent *
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
263 if (
event == nil ) {
268 case NSLeftMouseDown:
269 case NSOtherMouseDown:
270 case NSRightMouseDown:
274 case NSLeftMouseDragged:
275 case NSRightMouseDragged:
276 case NSOtherMouseDragged:
290 [NSApp sendEvent:event];
void Cocoa_RegisterApp(void)
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
static void init(struct bs2b *bs2b)
static SDL_VideoDevice * _this
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Uint32 screensaver_activity
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void Cocoa_PumpEvents(_THIS)
DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window *window)
Restore the size and position of a minimized or maximized window.
SDL_VideoDisplay * displays
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
SDL_Window * fullscreen_window
int SDL_SendDropFile(const char *file)
DECLSPEC void SDLCALL SDL_RaiseWindow(SDL_Window *window)
Raise a window above other windows and set the input focus.
SDL_VideoDevice * SDL_GetVideoDevice(void)
SDL_bool suspend_screensaver
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC