From c775889f0267074652f8ef3c47bbc19e32b4548b Mon Sep 17 00:00:00 2001 From: "J?rgen P. Tjern?" Date: Tue, 16 Jul 2013 01:02:51 -0700 Subject: [PATCH] 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 | 27 ++++++++++++++++++++++++++- src/video/cocoa/SDL_cocoawindow.m | 6 +++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 19bd6f7fc..61d6e1596 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -41,12 +41,27 @@ @interface NSApplication(NSAppleMenu) - (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 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende - (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) { diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index df3881407..a48a074ea 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -866,8 +866,12 @@ - (void)resetCursorRects 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];