Skip to content

Commit

Permalink
Reduce visual artifacts when engaging / disengaging snipping, and dis…
Browse files Browse the repository at this point in the history
…able minimize/maximize animation
  • Loading branch information
Kaldaien committed Jul 21, 2024
1 parent eaf4b64 commit fc07dbc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
47 changes: 38 additions & 9 deletions src/SKIV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ID3D11Device> pDev;
if (SUCCEEDED (vd->SwapChain->GetDevice (IID_ID3D11Device, (void **)&pDev.p)))
{
CComPtr <ID3D11DeviceContext> 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;
Expand Down
18 changes: 16 additions & 2 deletions src/imgui/imgui_impl_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2373,8 +2377,18 @@ SKIF_ImGui_ImplWin32_SetFullscreen (HWND hWnd, int fullscreen, HMONITOR monitor)
float width = static_cast<float> (rect.right) - left;
float height = static_cast<float> (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));
Expand Down

0 comments on commit fc07dbc

Please sign in to comment.