From 2717b095eca94254599ceb50e9908caf71fae41e Mon Sep 17 00:00:00 2001 From: narzoul Date: Tue, 10 May 2016 00:04:21 +0200 Subject: [PATCH] Restore main window, last active popup and GDI on WM_ACTIVATEAPP Fixes an issue with Fallout's window disappearing from the taskbar every other time it's minimized. Also fixes StarCraft's Save Screen Capture dialog being hidden after the main window is restored. --- DDrawCompat/CompatActivateAppHandler.cpp | 38 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/DDrawCompat/CompatActivateAppHandler.cpp b/DDrawCompat/CompatActivateAppHandler.cpp index dca2c3c..898a863 100644 --- a/DDrawCompat/CompatActivateAppHandler.cpp +++ b/DDrawCompat/CompatActivateAppHandler.cpp @@ -19,6 +19,16 @@ namespace void activateApp(IDirectDraw7& dd) { + if (!(g_fullScreenCooperativeFlags & DDSCL_NOWINDOWCHANGES)) + { + ShowWindow(g_fullScreenCooperativeWindow, SW_RESTORE); + HWND lastActivePopup = GetLastActivePopup(g_fullScreenCooperativeWindow); + if (lastActivePopup && lastActivePopup != g_fullScreenCooperativeWindow) + { + BringWindowToTop(lastActivePopup); + } + } + CompatDirectDraw::s_origVtable.SetCooperativeLevel( &dd, g_fullScreenCooperativeWindow, g_fullScreenCooperativeFlags); if (CompatPrimarySurface::isDisplayModeChanged) @@ -27,12 +37,19 @@ namespace CompatDirectDraw::s_origVtable.SetDisplayMode( &dd, dm.width, dm.height, 32, dm.refreshRate, 0); } - CompatGdi::enableEmulation(); + + if (CompatPrimarySurface::surface) + { + CompatDirectDrawSurface::s_origVtable.Restore( + CompatPrimarySurface::surface); + CompatDirectDrawSurface::fixSurfacePtrs( + *CompatPrimarySurface::surface); + CompatGdi::invalidate(nullptr); + } } void deactivateApp(IDirectDraw7& dd) { - CompatGdi::disableEmulation(); if (CompatPrimarySurface::isDisplayModeChanged) { CompatDirectDraw::s_origVtable.RestoreDisplayMode(&dd); @@ -66,10 +83,18 @@ namespace { Compat::LogEnter("handleActivateApp", isActivated); - const bool isActiveChanged = g_isActive != isActivated; + if (isActivated == g_isActive) + { + return; + } g_isActive = isActivated; - if (isActiveChanged && g_fullScreenDirectDraw) + if (!isActivated) + { + CompatGdi::disableEmulation(); + } + + if (g_fullScreenDirectDraw) { IDirectDraw7* dd = nullptr; g_fullScreenDirectDraw->lpVtbl->QueryInterface( @@ -87,6 +112,11 @@ namespace CompatDirectDraw::s_origVtable.Release(dd); } + if (isActivated) + { + CompatGdi::enableEmulation(); + } + Compat::LogLeave("handleActivateApp", isActivated); } }