resolve #240, detect user alt-tab activation during auto-restore

This commit is contained in:
Kang Yu 2023-07-16 16:55:44 -07:00
parent 660ec9241e
commit d50ad3ad4a

View file

@ -110,6 +110,7 @@ namespace PersistentWindows.Common
public int haltRestore = 3000; //milliseconds to wait to finish current halted restore and restart next one public int haltRestore = 3000; //milliseconds to wait to finish current halted restore and restart next one
private HashSet<IntPtr> restoredWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> restoredWindows = new HashSet<IntPtr>();
private HashSet<IntPtr> topmostWindowsFixed = new HashSet<IntPtr>(); private HashSet<IntPtr> topmostWindowsFixed = new HashSet<IntPtr>();
private bool altTabPressed = false; //user switched window during auto-restore
private Dictionary<string, string> realProcessFileName = new Dictionary<string, string>() private Dictionary<string, string> realProcessFileName = new Dictionary<string, string>()
{ {
@ -328,6 +329,7 @@ namespace PersistentWindows.Common
restoringFromDB = false; restoringFromDB = false;
restoringFromMem = false; restoringFromMem = false;
altTabPressed = false;
bool wasRestoringSnapshot = restoringSnapshot; bool wasRestoringSnapshot = restoringSnapshot;
restoringSnapshot = false; restoringSnapshot = false;
ResetState(); ResetState();
@ -1291,6 +1293,10 @@ namespace PersistentWindows.Common
{ {
switch (eventType) switch (eventType)
{ {
case User32Events.EVENT_SYSTEM_FOREGROUND:
if (title.Contains("Task Switching"))
altTabPressed = true;
break;
case User32Events.EVENT_OBJECT_LOCATIONCHANGE: case User32Events.EVENT_OBJECT_LOCATIONCHANGE:
if (restoringSnapshot) if (restoringSnapshot)
return; return;
@ -1298,12 +1304,13 @@ namespace PersistentWindows.Common
break; break;
case User32Events.EVENT_SYSTEM_MINIMIZEEND: case User32Events.EVENT_SYSTEM_MINIMIZEEND:
/*
if (User32.GetForegroundWindow() != hwnd) if (User32.GetForegroundWindow() != hwnd)
//the unminimization action is not by user //the unminimization action is not by user
break; break;
if (!IsCursorOnTaskbar()) */
if (!IsCursorOnTaskbar() && !altTabPressed)
//the unminimization action might be caused by Windows OS //the unminimization action might be caused by Windows OS
//TODO: exclude alt-tab
break; break;
goto case User32Events.EVENT_SYSTEM_MOVESIZESTART; goto case User32Events.EVENT_SYSTEM_MOVESIZESTART;
case User32Events.EVENT_SYSTEM_MOVESIZESTART: case User32Events.EVENT_SYSTEM_MOVESIZESTART:
@ -1898,7 +1905,6 @@ namespace PersistentWindows.Common
//CancelRestoreTimer(); //CancelRestoreTimer();
restoreTimes = 0; restoreTimes = 0;
restoredWindows.Clear(); restoredWindows.Clear();
} }
} }