diff --git a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/Models/ApplicationDisplayMetrics.cs b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/Models/ApplicationDisplayMetrics.cs index 5d68a75..f0fa14f 100644 --- a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/Models/ApplicationDisplayMetrics.cs +++ b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/Models/ApplicationDisplayMetrics.cs @@ -11,6 +11,7 @@ namespace Ninjacrab.PersistentWindows.Common.Models public string ApplicationName { get; set; } public RECT ScreenPosition { get; set; } public WindowPlacement WindowPlacement { get; set; } + public bool NeedUpdateWindowPlacement { get; set; } public static string GetKey(IntPtr hWnd, string applicationName) { diff --git a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs index aca70c4..7aa91cd 100644 --- a/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Ninjacrab.PersistentWindows.Common/PersistentWindowProcessor.cs @@ -460,6 +460,7 @@ namespace Ninjacrab.PersistentWindows.Common ProcessId = processId, WindowPlacement = windowPlacement, + NeedUpdateWindowPlacement = false, ScreenPosition = screenPosition }; @@ -477,10 +478,6 @@ namespace Ninjacrab.PersistentWindows.Common monitorApplications[displayKey].Remove(curDisplayMetrics.Key); needUpdate = true; } - else if (!prevDisplayMetrics.ScreenPosition.Equals(curDisplayMetrics.ScreenPosition)) - { - needUpdate = true; - } else if (!prevDisplayMetrics.EqualPlacement(curDisplayMetrics)) { Log.Trace("Unexpected WindowPlacement.NormalPosition change if ScreenPosition keep same {0} {1} {2}", @@ -524,6 +521,11 @@ namespace Ninjacrab.PersistentWindows.Common } */ //monitorApplications[displayKey][curDisplayMetrics.Key].WindowPlacement = curDisplayMetrics.WindowPlacement; + curDisplayMetrics.NeedUpdateWindowPlacement = true; + needUpdate = true; + } + else if (!prevDisplayMetrics.ScreenPosition.Equals(curDisplayMetrics.ScreenPosition)) + { needUpdate = true; } else @@ -617,7 +619,7 @@ namespace Ninjacrab.PersistentWindows.Common // block capture for current hwnd this.curRestoreHwnd = hwnd; - bool success; + bool success = true; // recover NormalPosition (the workspace position prior to snap) if (windowPlacement.ShowCmd == ShowWindowCommands.Maximize) { @@ -628,18 +630,22 @@ namespace Ninjacrab.PersistentWindows.Common 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, - windowPlacement.NormalPosition.Left, - windowPlacement.NormalPosition.Top, - windowPlacement.NormalPosition.Width, - windowPlacement.NormalPosition.Height, - success); + if (curDisplayMetrics.NeedUpdateWindowPlacement) + { + success &= User32.SetWindowPlacement(hwnd, ref windowPlacement); + Log.Info("SetWindowPlacement({0} [{1}x{2}]-[{3}x{4}]) - {5}", + window.Process.ProcessName, + windowPlacement.NormalPosition.Left, + windowPlacement.NormalPosition.Top, + windowPlacement.NormalPosition.Width, + windowPlacement.NormalPosition.Height, + success); + } // recover previous screen position RECT rect = prevDisplayMetrics.ScreenPosition; - //success &= User32.MoveWindow(hwnd, rect.Left, rect.Top, rect.Width, rect.Height, true); + success &= User32.MoveWindow(hwnd, rect.Left, rect.Top, rect.Width, rect.Height, true); + /* success &= User32.SetWindowPos( window.HWnd, IntPtr.Zero, @@ -660,6 +666,7 @@ namespace Ninjacrab.PersistentWindows.Common rect.Height, SetWindowPosFlags.DoNotActivate | SetWindowPosFlags.DoNotChangeOwnerZOrder); + */ Log.Info("MoveWindow({0} [{1}x{2}]-[{3}x{4}]) - {5}", window.Process.ProcessName,