Mac: Bring back FS windows when appropriate
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 15 Jul 2013 11:58:49 -0700
changeset 7466 3416e8cfbaf0
parent 7465 1bcf7aac5623
child 7467 998579383ced
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
--- a/src/video/cocoa/SDL_cocoaevents.m	Mon Jul 15 11:58:45 2013 -0700
+++ b/src/video/cocoa/SDL_cocoaevents.m	Mon Jul 15 11:58:49 2013 -0700
@@ -43,6 +43,7 @@
 
 @interface SDLAppDelegate : NSObject
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
+- (void)applicationDidBecomeActive:(NSNotification *)aNotification;
 @end
 
 @implementation SDLAppDelegate : NSObject
@@ -52,6 +53,33 @@
     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]);