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.
This commit is contained in:
Jørgen P. Tjernø 2013-07-16 01:02:51 -07:00
parent 5256d2e392
commit 3f15d37da2
2 changed files with 31 additions and 2 deletions

View file

@ -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)
{

View file

@ -866,8 +866,12 @@ Cocoa_RaiseWindow(_THIS, SDL_Window * window)
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];