From c799c2dac9eff7f3a520d46ec11169284b06cc22 Mon Sep 17 00:00:00 2001 From: "J?rgen P. Tjern?" Date: Mon, 15 Jul 2013 11:58:49 -0700 Subject: [PATCH] Mac: Bring back FS windows when appropriate This automatically restores FS windows when the application is made active (Cmd-Tab, you click the Dock icon, or you launch the .app again). --- src/video/cocoa/SDL_cocoaevents.m | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index e952a9e9f..19bd6f7fc 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -43,6 +43,7 @@ - (void)setAppleMenu:(NSMenu *)menu; @interface SDLAppDelegate : NSObject - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; +- (void)applicationDidBecomeActive:(NSNotification *)aNotification; @end @implementation SDLAppDelegate : NSObject @@ -52,6 +53,33 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende return NSTerminateCancel; } +- (void)applicationDidBecomeActive:(NSNotification *)aNotification +{ + SDL_VideoDevice *device = SDL_GetVideoDevice(); + if (device && device->windows) + { + SDL_Window *window = device->windows; + int i; + for (i = 0; i < device->num_displays; ++i) + { + SDL_Window *fullscreen_window = device->displays[i].fullscreen_window; + if (fullscreen_window) + { + if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) { + SDL_RestoreWindow(fullscreen_window); + } + return; + } + } + + if (window->flags & SDL_WINDOW_MINIMIZED) { + SDL_RestoreWindow(window); + } else { + SDL_RaiseWindow(window); + } + } +} + - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { return (BOOL)SDL_SendDropFile([filename UTF8String]);