diff --git a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs index e42dc67..c2b05c0 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs @@ -34,7 +34,7 @@ namespace PersistentWindows.Common private const int UserMoveLatency = 1000; // delay in milliseconds from user move/minimize/unminimize/maximize to capture, must < CaptureLatency private const int MaxUserMoves = 4; // max user window moves per capture cycle private const int MinWindowOsMoveEvents = 12; // threshold of window move events initiated by OS per capture cycle - private const int MaxSnapshots = 37; // 0-9, a-z, and final one for undo + private const int MaxSnapshots = 38; // 0-9, a-z, ` and final one for undo private const int MaxHistoryQueueLength = 40; // must be bigger than MaxSnapshots + 1 private const int PauseRestoreTaskbar = 3500; //cursor idle time before dragging taskbar @@ -510,6 +510,13 @@ namespace PersistentWindows.Common Log.Event("Restore finished in pass {0} with {1} windows recovered for display setting {2}", restorePass, numWindowRestored, curDisplayKey); sessionActive = true; + if (!wasRestoringSnapshot) + { + if (!snapshotTakenTime.ContainsKey(curDisplayKey)) + snapshotTakenTime[curDisplayKey] = new Dictionary(); + snapshotTakenTime[curDisplayKey][MaxSnapshots - 2] = lastUserActionTime[curDisplayKey]; + } + if (wasRestoringSnapshot || noRestoreWindowsTmp.Count > 0) CaptureApplicationsOnCurrentDisplays(curDisplayKey, immediateCapture: true); else diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs index f17ec94..635825f 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/Program.cs @@ -25,6 +25,8 @@ namespace PersistentWindows.SystrayShell public static bool Gui = true; public static bool hotkey_window = true; + private const int MaxSnapshots = 38; // 0-9, a-z, ` and final one for undo + static PersistentWindowProcessor pwp = null; static SystrayForm systrayForm = null; static bool silent = false; //suppress all balloon tip & sound prompt @@ -514,6 +516,8 @@ namespace PersistentWindows.SystrayShell c = '0'; c += (char)id; } + else if (id == MaxSnapshots - 2) + c = '`'; else { c = 'a'; @@ -525,6 +529,8 @@ namespace PersistentWindows.SystrayShell static public int SnapshotCharToId(char c) { + if (c == '`') + return MaxSnapshots - 2; if (c < '0') return -1; if (c > 'z') diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs index a1d3c2d..bdb1c73 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs @@ -15,6 +15,8 @@ namespace PersistentWindows.SystrayShell { public partial class SystrayForm : Form { + private const int MaxSnapshots = 38; // 0-9, a-z, ` and final one for undo + public bool restoreToolStripMenuItemEnabled; public bool restoreSnapshotMenuItemEnabled; @@ -70,11 +72,11 @@ namespace PersistentWindows.SystrayShell pauseUpgradeCounter = true; - int keyPressed = -1; + Keys keyPressed = Keys.None; //check 0-9 key pressed - for (int i = 0x30; i < 0x3a; ++i) + for (Keys i = Keys.D0; i <= Keys.D9; ++i) { - if (User32.GetAsyncKeyState(i) != 0) + if (User32.GetAsyncKeyState((int)i) != 0) { keyPressed = i; break; @@ -82,16 +84,24 @@ namespace PersistentWindows.SystrayShell } //check a-z pressed - if (keyPressed < 0) - for (int i = 0x41; i < 0x5b; ++i) + if (keyPressed == Keys.None) + for (Keys i = Keys.A; i <= Keys.Z; ++i) { - if (User32.GetAsyncKeyState(i) != 0) + if (User32.GetAsyncKeyState((int)i) != 0) { keyPressed = i; break; } } + if (keyPressed == Keys.None) + { + if (User32.GetAsyncKeyState((int)Keys.Oem3) != 0) + { + keyPressed = Keys.Oem3; + } + } + int totalSpecialKeyPressed = shiftKeyPressed + altKeyPressed; if (clickCount > 2) @@ -104,7 +114,7 @@ namespace PersistentWindows.SystrayShell else if (altKeyPressed == clickCount && altKeyPressed != 0 && ctrlKeyPressed == 0) { //restore previous workspace (not necessarily a snapshot) - Program.RestoreSnapshot(36); //MaxSnapShot - 1 + Program.RestoreSnapshot(MaxSnapshots - 1); } else { @@ -128,12 +138,14 @@ namespace PersistentWindows.SystrayShell else { int snapshot; - if (keyPressed < 0x3a) - snapshot = keyPressed - 0x30; + if (keyPressed == Keys.Oem3) + snapshot = MaxSnapshots - 2; + else if (keyPressed <= Keys.D9) + snapshot = keyPressed - Keys.D0; else - snapshot = keyPressed - 0x41 + 10; + snapshot = keyPressed - Keys.A + 10; - if (snapshot < 0 || snapshot > 35) + if (snapshot < 0 || snapshot > MaxSnapshots - 2) { //invalid key pressed } @@ -407,15 +419,17 @@ namespace PersistentWindows.SystrayShell Console.WriteLine("MouseClick"); // clear memory of keyboard input - for (int i = 0x30; i < 0x3a; ++i) + for (Keys i = Keys.D0; i <= Keys.D9; ++i) { - User32.GetAsyncKeyState(i); + User32.GetAsyncKeyState((int)i); } - for (int i = 0x41; i < 0x5b; ++i) + for (Keys i = Keys.A; i <= Keys.Z; ++i) { - User32.GetAsyncKeyState(i); + User32.GetAsyncKeyState((int)i); } + + User32.GetAsyncKeyState((int)Keys.Oem3); } }