Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Tue, 16 Jul 2013 01:02:51 -0700
changeset 7469 4310d5aee6fe
parent 7468 e92571f09ce9
child 7470 e2c81eca0326
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.
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoaevents.m	Mon Jul 15 20:30:04 2013 -0400
+++ b/src/video/cocoa/SDL_cocoaevents.m	Tue Jul 16 01:02:51 2013 -0700
@@ -41,12 +41,27 @@
 - (void)setAppleMenu:(NSMenu *)menu;
 @end
 
-@interface SDLAppDelegate : NSObject
+@interface SDLAppDelegate : NSObject {
+    BOOL seenFirstActivate;
+}
+
+- (id)init;
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
 - (void)applicationDidBecomeActive:(NSNotification *)aNotification;
 @end
 
 @implementation SDLAppDelegate : NSObject
+- (id)init
+{
+    self = [super init];
+
+    if (self) {
+        seenFirstActivate = NO;
+    }
+
+    return self;
+}
+
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
 {
     SDL_SendQuit();
@@ -55,6 +70,16 @@
 
 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
 {
+    /* HACK: Ignore the first call. The application gets a
+     * applicationDidBecomeActive: a little bit after the first window is
+     * created, and if we don't ignore it, a window that has been created with
+     * SDL_WINDOW_MINIZED will ~immediately be restored.
+     */
+    if (!seenFirstActivate) {
+        seenFirstActivate = YES;
+        return;
+    }
+
     SDL_VideoDevice *device = SDL_GetVideoDevice();
     if (device && device->windows)
     {
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 15 20:30:04 2013 -0400
+++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Jul 16 01:02:51 2013 -0700
@@ -866,8 +866,12 @@
     SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
     NSWindow *nswindow = windowData->nswindow;
 
+    // makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
+    // a minimized or hidden window, so check for that before showing it.
     [windowData->listener pauseVisibleObservation];
-    [nswindow makeKeyAndOrderFront:nil];
+    if (![nswindow isMiniaturized] && [nswindow isVisible]) {
+        [nswindow makeKeyAndOrderFront:nil];
+    }
     [windowData->listener resumeVisibleObservation];
 
     [pool release];