#301, postpone taskbar restore to avoid competing with OS

This commit is contained in:
Kang Yu 2024-03-15 11:23:01 -07:00
parent 8cad4d810b
commit 150133cfb1

View file

@ -2715,12 +2715,12 @@ namespace PersistentWindows.Common
} }
else if (restoreTimes < MaxRestoreTimes) else if (restoreTimes < MaxRestoreTimes)
{ {
bool zorderFixed = false; bool extra_restore = false;
try try
{ {
RemoveInvalidCapture(); RemoveInvalidCapture();
zorderFixed = RestoreApplicationsOnCurrentDisplays(displayKey, IntPtr.Zero, DateTime.Now); extra_restore = RestoreApplicationsOnCurrentDisplays(displayKey, IntPtr.Zero, DateTime.Now);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -2730,7 +2730,6 @@ namespace PersistentWindows.Common
restoreTimes++; restoreTimes++;
bool slow_restore = remoteSession && !restoringSnapshot; bool slow_restore = remoteSession && !restoringSnapshot;
bool extra_restore = zorderFixed;
// force next restore, as Windows OS might not send expected message during restore // force next restore, as Windows OS might not send expected message during restore
if (restoreTimes < (extra_restore ? MaxRestoreTimes : restoringSnapshot ? 1 : MinRestoreTimes)) if (restoreTimes < (extra_restore ? MaxRestoreTimes : restoringSnapshot ? 1 : MinRestoreTimes))
StartRestoreTimer(); StartRestoreTimer();
@ -2912,7 +2911,7 @@ namespace PersistentWindows.Common
User32.SetCursorPos(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2); User32.SetCursorPos(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
} }
private bool MoveTaskBar(IntPtr hwnd, RECT targetRect) private bool MoveTaskBar(IntPtr hwnd, RECT targetRect, ref bool extra_restore)
{ {
// simulate mouse drag, assuming taskbar is unlocked // simulate mouse drag, assuming taskbar is unlocked
/* /*
@ -2942,6 +2941,9 @@ namespace PersistentWindows.Common
if (intersect.Equals(sourceRect) || intersect.Equals(targetRect)) if (intersect.Equals(sourceRect) || intersect.Equals(targetRect))
return false; //only taskbar size changes return false; //only taskbar size changes
if (extra_restore)
return false;
Log.Event($"move taskbar to {targetRect}"); Log.Event($"move taskbar to {targetRect}");
//IntPtr hReBar = User32.FindWindowEx(hwnd, IntPtr.Zero, "ReBarWindow32", null); //IntPtr hReBar = User32.FindWindowEx(hwnd, IntPtr.Zero, "ReBarWindow32", null);
@ -2998,7 +3000,7 @@ namespace PersistentWindows.Common
} }
// recover height of horizontal taskbar or width of vertical taskbar // recover height of horizontal taskbar or width of vertical taskbar
private bool RecoverTaskBarArea(IntPtr hwnd, RECT targetRect) private bool RecoverTaskBarArea(IntPtr hwnd, RECT targetRect, ref bool extra_restore)
{ {
RECT sourceRect = new RECT(); RECT sourceRect = new RECT();
User32.GetWindowRect(hwnd, ref sourceRect); User32.GetWindowRect(hwnd, ref sourceRect);
@ -3030,6 +3032,12 @@ namespace PersistentWindows.Common
} }
} }
if (!top_edge && !left_edge && restoreTimes < 2)
{
extra_restore = true;
return false;
}
Log.Error("restore width of taskbar window {0}", GetWindowTitle(hwnd)); Log.Error("restore width of taskbar window {0}", GetWindowTitle(hwnd));
int start_y; int start_y;
@ -3122,7 +3130,7 @@ namespace PersistentWindows.Common
private bool RestoreApplicationsOnCurrentDisplays(string displayKey, IntPtr sWindow, DateTime time) private bool RestoreApplicationsOnCurrentDisplays(string displayKey, IntPtr sWindow, DateTime time)
{ {
bool zorderFixed = false; bool extra_restore = false;
if (!monitorApplications.ContainsKey(displayKey) if (!monitorApplications.ContainsKey(displayKey)
|| monitorApplications[displayKey].Count == 0) || monitorApplications[displayKey].Count == 0)
@ -3395,10 +3403,8 @@ namespace PersistentWindows.Common
{ {
User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, null); User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, null);
} }
bool changed_edge = MoveTaskBar(hWnd, rect); bool changed_edge = MoveTaskBar(hWnd, rect, ref extra_restore);
bool changed_width = false; bool changed_width = RecoverTaskBarArea(hWnd, rect, ref extra_restore);
if (!remoteSession || restoringFromDB || restoringSnapshot)
changed_width = RecoverTaskBarArea(hWnd, rect);
if (changed_edge || changed_width) if (changed_edge || changed_width)
restoredWindows.Add(hWnd); restoredWindows.Add(hWnd);
if (taskbarMovable == 0) if (taskbarMovable == 0)
@ -3451,7 +3457,7 @@ namespace PersistentWindows.Common
if (sWindow == IntPtr.Zero) //z-order for batch restore if (sWindow == IntPtr.Zero) //z-order for batch restore
if (AllowRestoreZorder() && curDisplayMetrics.NeedRestoreZorder) if (AllowRestoreZorder() && curDisplayMetrics.NeedRestoreZorder)
{ {
zorderFixed = true; //force next pass for topmost flag fix and zorder check extra_restore = true; //force next pass for topmost flag fix and zorder check
if (((fixZorderMethod >> restoreTimes) & 1) == 1) if (((fixZorderMethod >> restoreTimes) & 1) == 1)
batchZorderFix = true; batchZorderFix = true;
@ -3657,7 +3663,7 @@ namespace PersistentWindows.Common
{ {
FixTopMostWindow(hWnd); FixTopMostWindow(hWnd);
topmostWindowsFixed.Add(hWnd); topmostWindowsFixed.Add(hWnd);
zorderFixed = true; //force next pass for topmost flag fix and zorder check extra_restore = true; //force next pass for topmost flag fix and zorder check
} }
} }
@ -3832,7 +3838,7 @@ namespace PersistentWindows.Common
} }
} }
return zorderFixed; return extra_restore;
} }