Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
This fixes bug #1446. You can now create a window with SDL_CreateWindow(...,
SDL_WINDOW_MINIMIZED), and not have it immediately restore itself.
It also changes SDL_RaiseWindow() to be a no-op on minimized or hidden windows,
which is how it behaves on Windows.
1.1 --- a/src/video/cocoa/SDL_cocoaevents.m Mon Jul 15 20:30:04 2013 -0400
1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m Tue Jul 16 01:02:51 2013 -0700
1.3 @@ -41,12 +41,27 @@
1.4 - (void)setAppleMenu:(NSMenu *)menu;
1.5 @end
1.6
1.7 -@interface SDLAppDelegate : NSObject
1.8 +@interface SDLAppDelegate : NSObject {
1.9 + BOOL seenFirstActivate;
1.10 +}
1.11 +
1.12 +- (id)init;
1.13 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
1.14 - (void)applicationDidBecomeActive:(NSNotification *)aNotification;
1.15 @end
1.16
1.17 @implementation SDLAppDelegate : NSObject
1.18 +- (id)init
1.19 +{
1.20 + self = [super init];
1.21 +
1.22 + if (self) {
1.23 + seenFirstActivate = NO;
1.24 + }
1.25 +
1.26 + return self;
1.27 +}
1.28 +
1.29 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
1.30 {
1.31 SDL_SendQuit();
1.32 @@ -55,6 +70,16 @@
1.33
1.34 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
1.35 {
1.36 + /* HACK: Ignore the first call. The application gets a
1.37 + * applicationDidBecomeActive: a little bit after the first window is
1.38 + * created, and if we don't ignore it, a window that has been created with
1.39 + * SDL_WINDOW_MINIZED will ~immediately be restored.
1.40 + */
1.41 + if (!seenFirstActivate) {
1.42 + seenFirstActivate = YES;
1.43 + return;
1.44 + }
1.45 +
1.46 SDL_VideoDevice *device = SDL_GetVideoDevice();
1.47 if (device && device->windows)
1.48 {
2.1 --- a/src/video/cocoa/SDL_cocoawindow.m Mon Jul 15 20:30:04 2013 -0400
2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m Tue Jul 16 01:02:51 2013 -0700
2.3 @@ -866,8 +866,12 @@
2.4 SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
2.5 NSWindow *nswindow = windowData->nswindow;
2.6
2.7 + // makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
2.8 + // a minimized or hidden window, so check for that before showing it.
2.9 [windowData->listener pauseVisibleObservation];
2.10 - [nswindow makeKeyAndOrderFront:nil];
2.11 + if (![nswindow isMiniaturized] && [nswindow isVisible]) {
2.12 + [nswindow makeKeyAndOrderFront:nil];
2.13 + }
2.14 [windowData->listener resumeVisibleObservation];
2.15
2.16 [pool release];