diff --git a/src/SKIV.cpp b/src/SKIV.cpp index 412d411..b4438ff 100644 --- a/src/SKIV.cpp +++ b/src/SKIV.cpp @@ -1887,28 +1887,57 @@ wWinMain ( _In_ HINSTANCE hInstance, _registry._SnippingMode = false; _registry._SnippingModeExit = false; - SKIF_ImGui_SetFullscreen (SKIF_ImGui_hWnd, false); - extern HWND hwndBeforeSnip; extern HWND hwndTopBeforeSnip; extern bool iconicBeforeSnip; extern bool trayedBeforeSnip; + SetForegroundWindow (hwndBeforeSnip); + + // Clear the SwapChain backbuffer to black before restoring, otherwise + // old garbage from a previous snip will briefly appear on screen... + if (ImGuiViewport *vp = ImGui::FindViewportByPlatformHandle ((void *)SKIF_ImGui_hWnd)) + { + if (ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)vp->RendererUserData) + { + CComPtr pDev; + if (SUCCEEDED (vd->SwapChain->GetDevice (IID_ID3D11Device, (void **)&pDev.p))) + { + CComPtr pDevCtx; + pDev->GetImmediateContext (&pDevCtx.p); + + FLOAT fClearColor [4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pDevCtx->ClearRenderTargetView (vd->RTView, fClearColor); + vd->SwapChain->Present (0,0); + } + } + } + + if (iconicBeforeSnip || trayedBeforeSnip) + { + // Hide the window while we do this so that it doesn't + // briefly appear in the wrong place... + ShowWindow (SKIF_ImGui_hWnd, SW_HIDE); + } + + SKIF_ImGui_SetFullscreen (SKIF_ImGui_hWnd, false); + + // Put SKIV back in the correct Z-order + SetWindowPos (SKIF_ImGui_hWnd, hwndTopBeforeSnip, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); + if (iconicBeforeSnip) ShowWindow (SKIF_ImGui_hWnd, SW_MINIMIZE); if (trayedBeforeSnip) { - ShowWindow (SKIF_ImGui_hWnd, SW_MINIMIZE); - ShowWindow (SKIF_ImGui_hWnd, SW_HIDE); - UpdateWindow (SKIF_ImGui_hWnd); + ShowWindow (SKIF_ImGui_hWnd, SW_MINIMIZE); SKIF_isTrayed = true; } - SetForegroundWindow (hwndBeforeSnip); - - // Put SKIV back in the correct Z-order - SetWindowPos (SKIF_ImGui_hWnd, hwndTopBeforeSnip, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); + else + { + ShowWindow (SKIF_ImGui_hWnd, SW_SHOWNA); + } ImGui::GetIO ().MouseDown [0] = false; ImGui::GetIO ().MouseDownDuration [0] = -1.0f; diff --git a/src/imgui/imgui_impl_win32.cpp b/src/imgui/imgui_impl_win32.cpp index 8eaf441..bcc84cf 100644 --- a/src/imgui/imgui_impl_win32.cpp +++ b/src/imgui/imgui_impl_win32.cpp @@ -2278,6 +2278,10 @@ SKIF_ImGui_ImplWin32_WantUpdateMonitors (void) bool SKIF_ImGui_ImplWin32_SetFullscreen (HWND hWnd, int fullscreen, HMONITOR monitor) { + // Disable minimize/restore animations, they're obnoxious when snipping. + BOOL bDisableAnimation = TRUE; + DwmSetWindowAttribute (hWnd, DWMWA_TRANSITIONS_FORCEDISABLED, &bDisableAnimation, sizeof (BOOL)); + // Cached data structure to support tracking multiple windows struct fullscreen_s { HWND hWnd; // Used to tracking @@ -2373,8 +2377,18 @@ SKIF_ImGui_ImplWin32_SetFullscreen (HWND hWnd, int fullscreen, HMONITOR monitor) float width = static_cast (rect.right) - left; float height = static_cast (rect.bottom) - top; - SetWindowPos (hWnd, 0, rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, 0); + static SKIF_RegistrySettings& _registry = SKIF_RegistrySettings::GetInstance ( ); + + if (_registry._SnippingMode || _registry._SnippingModeExit) + { + // Required during snipping to place the window correctly after + // restoring it from the system tray or taskbar... + SetWindowPos ( + hWnd, 0, rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_NOSENDCHANGING | SWP_NOACTIVATE | SWP_NOZORDER | SWP_ASYNCWINDOWPOS + ); + } ImGui::SetWindowSize (window, ImVec2 (width, height)); ImGui::SetWindowPos (window, ImVec2 (left, top));