factor ResetState()

This commit is contained in:
Kang Yu 2020-02-23 20:09:39 -08:00
parent aecc9f6e29
commit e3a3cc1706

View file

@ -34,14 +34,16 @@ namespace Ninjacrab.PersistentWindows.Common
// capture control: window move/resize activity // capture control: window move/resize activity
private int userMoves = 0; // user initiated window move/resize events private int userMoves = 0; // user initiated window move/resize events
private bool osMove = false; // window move/resize is initiated by OS
private DateTime firstEventTime; private DateTime firstEventTime;
private HashSet<IntPtr> pendingCaptureWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> pendingCaptureWindows = new HashSet<IntPtr>();
// restore control // restore control
private bool restoringWindowPos = false; // about to restore private bool restoringWindowPos = false; // about to restore
private bool osMove = false; // window move/resize is initiated by OS
private int restoreTimes = 0; private int restoreTimes = 0;
private int restoreNestLevel = 0; // nested call level private int restoreNestLevel = 0; // nested call level
// session control
private bool remoteSession = false; private bool remoteSession = false;
// callbacks // callbacks
@ -120,7 +122,7 @@ namespace Ninjacrab.PersistentWindows.Common
{ {
DateTime date = DateTime.Now; DateTime date = DateTime.Now;
Log.Info("Display settings changing {0}", date); Log.Info("Display settings changing {0}", date);
CancelCaptureTimer(); ResetState();
}; };
SystemEvents.DisplaySettingsChanging += this.displaySettingsChangingHandler; SystemEvents.DisplaySettingsChanging += this.displaySettingsChangingHandler;
@ -131,7 +133,7 @@ namespace Ninjacrab.PersistentWindows.Common
DateTime date = DateTime.Now; DateTime date = DateTime.Now;
Log.Info("Display settings changed {0}", date); Log.Info("Display settings changed {0}", date);
CancelCaptureTimer(); ResetState();
restoringWindowPos = true; restoringWindowPos = true;
BeginRestoreApplicationsOnCurrentDisplays(); BeginRestoreApplicationsOnCurrentDisplays();
@ -146,13 +148,12 @@ namespace Ninjacrab.PersistentWindows.Common
{ {
case PowerModes.Suspend: case PowerModes.Suspend:
Log.Info("System suspending"); Log.Info("System suspending");
CancelCaptureTimer(); ResetState();
break; break;
case PowerModes.Resume: case PowerModes.Resume:
Log.Info("System Resuming"); Log.Info("System Resuming");
CancelCaptureTimer(); ResetState();
break; break;
} }
}; };
@ -164,12 +165,10 @@ namespace Ninjacrab.PersistentWindows.Common
switch (args.Reason) switch (args.Reason)
{ {
case SessionSwitchReason.RemoteDisconnect: case SessionSwitchReason.RemoteDisconnect:
remoteSession = false;
goto case SessionSwitchReason.SessionLock;
case SessionSwitchReason.SessionLock: case SessionSwitchReason.SessionLock:
case SessionSwitchReason.ConsoleDisconnect: case SessionSwitchReason.ConsoleDisconnect:
Log.Trace("Session closing: reason {0}", args.Reason); Log.Trace("Session closing: reason {0}", args.Reason);
CancelCaptureTimer(); ResetState();
break; break;
case SessionSwitchReason.RemoteConnect: case SessionSwitchReason.RemoteConnect:
@ -428,19 +427,27 @@ namespace Ninjacrab.PersistentWindows.Common
thread.Start(); thread.Start();
} }
private void StartCaptureApplicationsOnCurrentDisplays() private void ResetState()
{ {
// end of restore period // end of restore period
CancelRestoreTimer(); CancelRestoreTimer();
restoringWindowPos = false;
restoreTimes = 0; restoreTimes = 0;
restoreNestLevel = 0;
// reset capture statistics for next capture period // reset capture statistics for next capture period
CancelCaptureTimer(); CancelCaptureTimer();
pendingCaptureWindows.Clear(); pendingCaptureWindows.Clear();
userMoves = 0; userMoves = 0;
osMove = false;
// session control
remoteSession = false;
}
private void StartCaptureApplicationsOnCurrentDisplays()
{
restoringWindowPos = false;
osMove = false;
ResetState();
CaptureApplicationsOnCurrentDisplays(); CaptureApplicationsOnCurrentDisplays();
} }