unify maximize/minimize procedure, remove dry run test code

This commit is contained in:
Kang Yu 2023-04-29 12:29:27 -07:00
parent 4bceca33e6
commit 6619f7c205
2 changed files with 13 additions and 29 deletions

View file

@ -90,7 +90,6 @@ namespace PersistentWindows.Common
public bool restoringFromMem = false; // automatic restore from memory or snapshot public bool restoringFromMem = false; // automatic restore from memory or snapshot
public bool restoringFromDB = false; // manual restore from DB public bool restoringFromDB = false; // manual restore from DB
public bool restoringSnapshot = false; // implies restoringFromMem public bool restoringSnapshot = false; // implies restoringFromMem
public bool dryRun = false; // only capturre, no actual restore
public bool showDesktop = false; // show desktop when display changes public bool showDesktop = false; // show desktop when display changes
public int fixZorder = 1; // 1 means restore z-order only for snapshot; 2 means restore z-order for all; 0 means no z-order restore at all public int fixZorder = 1; // 1 means restore z-order only for snapshot; 2 means restore z-order for all; 0 means no z-order restore at all
public int fixZorderMethod = 5; // bit i represent restore method for pass i public int fixZorderMethod = 5; // bit i represent restore method for pass i
@ -3022,9 +3021,6 @@ namespace PersistentWindows.Common
if (IsTaskBar(hWnd)) if (IsTaskBar(hWnd))
{ {
if (dryRun)
continue;
bool changed_edge = MoveTaskBar(hWnd, rect); bool changed_edge = MoveTaskBar(hWnd, rect);
bool changed_width = false; bool changed_width = false;
if (!remoteSession || restoringFromDB || restoringSnapshot) if (!remoteSession || restoringFromDB || restoringSnapshot)
@ -3037,7 +3033,6 @@ namespace PersistentWindows.Common
changeIconText($"Restore {GetWindowTitle(hWnd)}"); changeIconText($"Restore {GetWindowTitle(hWnd)}");
if (!dryRun)
{ {
if (prevDisplayMetrics.IsMinimized) if (prevDisplayMetrics.IsMinimized)
{ {
@ -3079,7 +3074,7 @@ namespace PersistentWindows.Common
bool need_move_window = true; bool need_move_window = true;
bool restore_fullscreen = false; bool restore_fullscreen = false;
if (prevDisplayMetrics.IsFullScreen && !prevDisplayMetrics.IsMinimized && !dryRun) if (prevDisplayMetrics.IsFullScreen && !prevDisplayMetrics.IsMinimized)
{ {
if (curDisplayMetrics.IsMinimized) if (curDisplayMetrics.IsMinimized)
{ {
@ -3096,16 +3091,21 @@ namespace PersistentWindows.Common
if (curDisplayMetrics.NeedUpdateWindowPlacement) if (curDisplayMetrics.NeedUpdateWindowPlacement)
{ {
// recover NormalPosition (the workspace position prior to snap) // recover NormalPosition (the workspace position prior to snap)
if (windowPlacement.ShowCmd == ShowWindowCommands.Maximize && !dryRun) if (windowPlacement.ShowCmd == ShowWindowCommands.Maximize)
{ {
// When restoring maximized windows, it occasionally switches res and when the maximized setting is restored //restore maximized window to correct monitor
// 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; windowPlacement.ShowCmd = ShowWindowCommands.Normal;
User32.SetWindowPlacement(hWnd, ref windowPlacement); User32.SetWindowPlacement(hWnd, ref windowPlacement);
windowPlacement.ShowCmd = ShowWindowCommands.Maximize; windowPlacement.ShowCmd = ShowWindowCommands.Maximize;
} }
else if (prevDisplayMetrics.IsFullScreen && !prevDisplayMetrics.IsMinimized && !dryRun) else if (prevDisplayMetrics.IsMinimized)
{
//restore minimized window button to correct taskbar
windowPlacement.ShowCmd = ShowWindowCommands.Normal;
User32.SetWindowPlacement(hWnd, ref windowPlacement);
windowPlacement.ShowCmd = ShowWindowCommands.ShowMinimized;
}
else if (prevDisplayMetrics.IsFullScreen)
{ {
Log.Error("recover full screen window {0}", GetWindowTitle(hWnd)); Log.Error("recover full screen window {0}", GetWindowTitle(hWnd));
long style = User32.GetWindowLong(hWnd, User32.GWL_STYLE); long style = User32.GetWindowLong(hWnd, User32.GWL_STYLE);
@ -3132,24 +3132,14 @@ namespace PersistentWindows.Common
} }
} }
if (!dryRun && need_move_window) if (need_move_window)
{ {
if (prevDisplayMetrics.IsMinimized)
{
windowPlacement.ShowCmd = ShowWindowCommands.Normal;
}
success &= User32.SetWindowPlacement(hWnd, ref windowPlacement); success &= User32.SetWindowPlacement(hWnd, ref windowPlacement);
if (prevDisplayMetrics.IsMinimized)
{
windowPlacement.ShowCmd = ShowWindowCommands.ShowMinimized;
success &= User32.SetWindowPlacement(hWnd, ref windowPlacement);
}
} }
} }
// recover previous screen position // recover previous screen position
if (!dryRun && !prevDisplayMetrics.IsMinimized) if (!prevDisplayMetrics.IsMinimized)
{ {
if (need_move_window) if (need_move_window)
{ {
@ -3348,7 +3338,6 @@ namespace PersistentWindows.Common
if (!String.IsNullOrEmpty(curDisplayMetrics.ProcessExePath)) if (!String.IsNullOrEmpty(curDisplayMetrics.ProcessExePath))
{ {
if (!dryRun)
{ {
try try
{ {

View file

@ -47,7 +47,6 @@ namespace PersistentWindows.SystrayShell
int halt_restore = 0; //seconds to wait before trying restore again, due to frequent monitor config changes int halt_restore = 0; //seconds to wait before trying restore again, due to frequent monitor config changes
string ignore_process = ""; string ignore_process = "";
int debug_process = 0; int debug_process = 0;
bool dry_run = false; //dry run mode without real restore, for debug purpose only
bool fix_zorder = false; bool fix_zorder = false;
bool fix_zorder_specified = false; bool fix_zorder_specified = false;
bool show_desktop = false; //show desktop when display changes bool show_desktop = false; //show desktop when display changes
@ -181,9 +180,6 @@ namespace PersistentWindows.SystrayShell
case "-notification=1": case "-notification=1":
notification = true; notification = true;
break; break;
case "-dry_run":
dry_run = true;
break;
case "-fix_zorder=0": case "-fix_zorder=0":
fix_zorder = false; fix_zorder = false;
fix_zorder_specified = true; fix_zorder_specified = true;
@ -262,7 +258,6 @@ namespace PersistentWindows.SystrayShell
systrayForm.upgradeNoticeMenuItem.Text = "Enable upgrade notice"; systrayForm.upgradeNoticeMenuItem.Text = "Enable upgrade notice";
pwp.icon = IdleIcon; pwp.icon = IdleIcon;
pwp.dryRun = dry_run;
if (fix_zorder_specified) if (fix_zorder_specified)
{ {
if (fix_zorder) if (fix_zorder)