From b285c5706efd0678376fcc11619f4aa8536d4370 Mon Sep 17 00:00:00 2001
From: Ken Thomases <ken@codeweavers.com>
Date: Tue, 4 Jun 2013 04:59:42 -0500
Subject: [PATCH] winemac: Defer minimizing hidden windows until they are
 shown.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Minimizing invisible windows causes weird phantoms to appear in
Exposé, the Window menu, and the Dock.
---
 dlls/winemac.drv/cocoa_window.h |  1 +
 dlls/winemac.drv/cocoa_window.m | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_window.h b/dlls/winemac.drv/cocoa_window.h
index e1af247bcde..0f7e084fc3e 100644
--- a/dlls/winemac.drv/cocoa_window.h
+++ b/dlls/winemac.drv/cocoa_window.h
@@ -29,6 +29,7 @@ @interface WineWindow : NSPanel <NSWindowDelegate>
     BOOL disabled;
     BOOL noActivate;
     BOOL floating;
+    BOOL pendingMinimize;
     WineWindow* latentParentWindow;
 
     void* hwnd;
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index 2da8a088740..035576e5567 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -636,10 +636,16 @@ - (void) setMacDrvState:(const struct macdrv_window_state*)state
         }
         [self setCollectionBehavior:behavior];
 
+        pendingMinimize = FALSE;
         if (state->minimized && ![self isMiniaturized])
         {
-            ignore_windowMiniaturize = TRUE;
-            [self miniaturize:nil];
+            if ([self isVisible])
+            {
+                ignore_windowMiniaturize = TRUE;
+                [self miniaturize:nil];
+            }
+            else
+                pendingMinimize = TRUE;
         }
         else if (!state->minimized && [self isMiniaturized])
         {
@@ -754,6 +760,13 @@ - (BOOL) orderBelow:(WineWindow*)prev orAbove:(WineWindow*)next
             if (needAdjustWindowLevels)
                 [controller adjustWindowLevels];
 
+            if (pendingMinimize)
+            {
+                ignore_windowMiniaturize = TRUE;
+                [self miniaturize:nil];
+                pendingMinimize = FALSE;
+            }
+
             NSEnableScreenUpdates();
 
             /* Cocoa may adjust the frame when the window is ordered onto the screen.
@@ -770,6 +783,8 @@ - (BOOL) orderBelow:(WineWindow*)prev orAbove:(WineWindow*)next
 
     - (void) doOrderOut
     {
+        if ([self isMiniaturized])
+            pendingMinimize = TRUE;
         self.latentParentWindow = [self parentWindow];
         [latentParentWindow removeChildWindow:self];
         [self orderOut:nil];
@@ -948,6 +963,13 @@ - (void) makeFocused:(BOOL)activate
         [self orderFront:nil];
         [controller adjustWindowLevels];
 
+        if (pendingMinimize)
+        {
+            ignore_windowMiniaturize = TRUE;
+            [self miniaturize:nil];
+            pendingMinimize = FALSE;
+        }
+
         NSEnableScreenUpdates();
 
         causing_becomeKeyWindow = TRUE;
@@ -1057,6 +1079,13 @@ - (void) makeKeyAndOrderFront:(id)sender
             [self setLevel:[front level]];
         [self orderFront:nil];
         [controller adjustWindowLevels];
+
+        if (pendingMinimize)
+        {
+            ignore_windowMiniaturize = TRUE;
+            [self miniaturize:nil];
+            pendingMinimize = FALSE;
+        }
     }
 
     - (void) sendEvent:(NSEvent*)event
-- 
GitLab