From 0dd37cf785df586e9d915b56b8e70a2723bcdad5 Mon Sep 17 00:00:00 2001 From: Kang Yu Date: Tue, 18 Feb 2020 13:33:59 -0800 Subject: [PATCH] Fix flickering window loop issue in V3.0 and V3.1 Restore window z order Restore maximized window indicator --- .../PersistentWindowProcessor.cs | 24 ++++++++++++++++++- .../WinApiBridge/User32.cs | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs index 8581cce..6e62c26 100644 --- a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs @@ -613,6 +613,15 @@ namespace Ninjacrab.PersistentWindows.Common bool success; // recover NormalPosition (the workspace position prior to snap) + if (windowPlacement.ShowCmd == ShowWindowCommands.Maximize) + { + // When restoring maximized windows, it occasionally switches res and when the maximized setting is restored + // the window thinks it's maximized, but does not eat all the real estate. So we'll temporarily unmaximize then + // re-apply that + windowPlacement.ShowCmd = ShowWindowCommands.Normal; + User32.SetWindowPlacement(hwnd, ref windowPlacement); + windowPlacement.ShowCmd = ShowWindowCommands.Maximize; + } success = User32.SetWindowPlacement(hwnd, ref windowPlacement); Log.Info("SetWindowPlacement({0} [{1}x{2}]-[{3}x{4}]) - {5}", window.Process.ProcessName, @@ -632,7 +641,20 @@ namespace Ninjacrab.PersistentWindows.Common rect.Top, rect.Width, rect.Height, - (uint)(SetWindowPosFlags.IgnoreZOrder | SetWindowPosFlags.AsynchronousWindowPosition)); + SetWindowPosFlags.DoNotActivate | + SetWindowPosFlags.DoNotChangeOwnerZOrder | + SetWindowPosFlags.AsynchronousWindowPosition); + + success &= User32.SetWindowPos( + window.HWnd, + IntPtr.Zero, + rect.Left, + rect.Top, + rect.Width, + rect.Height, + SetWindowPosFlags.DoNotActivate | + SetWindowPosFlags.DoNotChangeOwnerZOrder); + Log.Info("MoveWindow({0} [{1}x{2}]-[{3}x{4}]) - {5}", window.Process.ProcessName, rect.Left, diff --git a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/WinApiBridge/User32.cs b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/WinApiBridge/User32.cs index ca0d17f..3a6f70a 100644 --- a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/WinApiBridge/User32.cs +++ b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/WinApiBridge/User32.cs @@ -90,7 +90,7 @@ namespace Ninjacrab.PersistentWindows.Common.WinApiBridge [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, - uint uFlags); + SetWindowPosFlags uFlags); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)]