Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Mac: Handle SDL_CreateWindow with SDL_WINDOW_MINIMZED.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jorgenpt committed Jul 16, 2013
1 parent 6221d73 commit c775889
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -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];
Expand Down

0 comments on commit c775889

Please sign in to comment.