mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 13:05:38 +02:00
new feature: ctrl click pw icon to bring the current foreground window back to where it was before activated
This commit is contained in:
parent
92e9fcdc69
commit
94bcf761d6
3 changed files with 64 additions and 16 deletions
|
@ -81,6 +81,7 @@ namespace PersistentWindows.Common
|
|||
private DateTime lastUnminimizeTime = DateTime.Now;
|
||||
private IntPtr lastUnminimizeWindow = IntPtr.Zero;
|
||||
private Dictionary<string, IntPtr> foreGroundWindow = new Dictionary<string, IntPtr>();
|
||||
private IntPtr prevForegroundWindow = IntPtr.Zero;
|
||||
public Dictionary<uint, string> processCmd = new Dictionary<uint, string>();
|
||||
public bool fullScreenGamingMode = false;
|
||||
|
||||
|
@ -1360,6 +1361,8 @@ namespace PersistentWindows.Common
|
|||
}
|
||||
else
|
||||
{
|
||||
if (foreGroundWindow.ContainsKey(curDisplayKey))
|
||||
prevForegroundWindow = foreGroundWindow[curDisplayKey];
|
||||
foreGroundWindow[curDisplayKey] = hwnd;
|
||||
foregroundTimer.Change(100, Timeout.Infinite);
|
||||
|
||||
|
@ -1703,6 +1706,34 @@ namespace PersistentWindows.Common
|
|||
return fixZorder == 2 || (restoringSnapshot && fixZorder > 0);
|
||||
}
|
||||
|
||||
public void BringForegroundToBackground()
|
||||
{
|
||||
//IntPtr hwnd = foreGroundWindow[curDisplayKey];
|
||||
IntPtr hwnd = prevForegroundWindow;
|
||||
SwitchForeBackground(hwnd);
|
||||
}
|
||||
|
||||
public void SwitchForeBackground(IntPtr hwnd)
|
||||
{
|
||||
int prevIndex = monitorApplications[curDisplayKey][hwnd].Count - 1;
|
||||
var cur_metrics = monitorApplications[curDisplayKey][hwnd][prevIndex];
|
||||
IntPtr front_hwnd = cur_metrics.PrevZorderWindow;
|
||||
for (; prevIndex >= 0; --prevIndex)
|
||||
{
|
||||
var metrics = monitorApplications[curDisplayKey][hwnd][prevIndex];
|
||||
if (!metrics.IsValid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (metrics.PrevZorderWindow != front_hwnd)
|
||||
{
|
||||
RestoreZorder(hwnd, metrics.PrevZorderWindow);
|
||||
RestoreApplicationsOnCurrentDisplays(curDisplayKey, hwnd, metrics.CaptureTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int RestoreZorder(IntPtr hWnd, IntPtr prev)
|
||||
{
|
||||
if (prev == IntPtr.Zero)
|
||||
|
@ -2461,7 +2492,7 @@ namespace PersistentWindows.Common
|
|||
try
|
||||
{
|
||||
RemoveInvalidCapture();
|
||||
zorderFixed = RestoreApplicationsOnCurrentDisplays(displayKey, IntPtr.Zero);
|
||||
zorderFixed = RestoreApplicationsOnCurrentDisplays(displayKey, IntPtr.Zero, DateTime.Now);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -2848,7 +2879,7 @@ namespace PersistentWindows.Common
|
|||
return hTaskBar;
|
||||
}
|
||||
|
||||
private bool RestoreApplicationsOnCurrentDisplays(string displayKey, IntPtr sWindow)
|
||||
private bool RestoreApplicationsOnCurrentDisplays(string displayKey, IntPtr sWindow, DateTime time)
|
||||
{
|
||||
bool zorderFixed = false;
|
||||
|
||||
|
@ -2864,6 +2895,8 @@ namespace PersistentWindows.Common
|
|||
Log.Info("");
|
||||
Log.Info("Restoring windows pass {0} for {1}", restoreTimes, displayKey);
|
||||
|
||||
DateTime lastCaptureTime = time;
|
||||
|
||||
IEnumerable<IntPtr> sWindows;
|
||||
var arr = new IntPtr[1];
|
||||
if (sWindow != IntPtr.Zero)
|
||||
|
@ -2874,26 +2907,26 @@ namespace PersistentWindows.Common
|
|||
else
|
||||
{
|
||||
sWindows = CaptureWindowsOfInterest();
|
||||
}
|
||||
|
||||
// determine the time to be restored
|
||||
DateTime lastCaptureTime = DateTime.Now;
|
||||
if (lastUserActionTime.ContainsKey(displayKey))
|
||||
{
|
||||
if (restoringSnapshot)
|
||||
// determine the time to be restored
|
||||
if (lastUserActionTime.ContainsKey(displayKey))
|
||||
{
|
||||
if (!snapshotTakenTime.ContainsKey(curDisplayKey)
|
||||
|| !snapshotTakenTime[curDisplayKey].ContainsKey(snapshotId))
|
||||
return false;
|
||||
if (restoringSnapshot)
|
||||
{
|
||||
if (!snapshotTakenTime.ContainsKey(curDisplayKey)
|
||||
|| !snapshotTakenTime[curDisplayKey].ContainsKey(snapshotId))
|
||||
return false;
|
||||
|
||||
lastCaptureTime = snapshotTakenTime[curDisplayKey][snapshotId];
|
||||
}
|
||||
else
|
||||
{
|
||||
lastCaptureTime = lastUserActionTime[displayKey];
|
||||
lastCaptureTime = snapshotTakenTime[curDisplayKey][snapshotId];
|
||||
}
|
||||
else
|
||||
{
|
||||
lastCaptureTime = lastUserActionTime[displayKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HashSet<int> dbMatchWindow = new HashSet<int>(); // db entry (id) matches existing window
|
||||
HashSet<IntPtr> windowMatchDb = new HashSet<IntPtr>(); //existing window matches db
|
||||
|
||||
|
@ -3046,6 +3079,7 @@ namespace PersistentWindows.Common
|
|||
}
|
||||
|
||||
Log.Trace("Restore time {0}", printRestoreTime);
|
||||
if (sWindow == IntPtr.Zero)
|
||||
if (restoreTimes == 0)
|
||||
{
|
||||
Log.Event("Start restoring window layout back to {0} for display setting {1}", printRestoreTime, curDisplayKey);
|
||||
|
@ -3172,6 +3206,7 @@ namespace PersistentWindows.Common
|
|||
topmostWindowsFixed.Add(hWnd);
|
||||
}
|
||||
|
||||
if (sWindow == IntPtr.Zero) //z-order for batch restore
|
||||
if (AllowRestoreZorder() && curDisplayMetrics.NeedRestoreZorder)
|
||||
{
|
||||
zorderFixed = true; //force next pass for topmost flag fix and zorder check
|
||||
|
|
|
@ -538,6 +538,11 @@ namespace PersistentWindows.SystrayShell
|
|||
pwp.RestoreSnapshot(id);
|
||||
}
|
||||
|
||||
static public void BringForegroundToBackground()
|
||||
{
|
||||
pwp.BringForegroundToBackground();
|
||||
}
|
||||
|
||||
static public void PauseAutoRestore()
|
||||
{
|
||||
pwp.pauseAutoRestore = true;
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace PersistentWindows.SystrayShell
|
|||
|
||||
public bool autoUpgrade = false;
|
||||
|
||||
private int ctrlKeyPressed = 0;
|
||||
private int shiftKeyPressed = 0;
|
||||
private int altKeyPressed = 0;
|
||||
private int clickCount = 0;
|
||||
|
@ -140,6 +141,7 @@ namespace PersistentWindows.SystrayShell
|
|||
clickCount = 0;
|
||||
doubleClick = false;
|
||||
firstClick = false;
|
||||
ctrlKeyPressed = 0;
|
||||
shiftKeyPressed = 0;
|
||||
altKeyPressed = 0;
|
||||
|
||||
|
@ -386,6 +388,12 @@ namespace PersistentWindows.SystrayShell
|
|||
{
|
||||
Console.WriteLine("Down");
|
||||
|
||||
if ((User32.GetKeyState(0x11) & 0x8000) != 0)
|
||||
{
|
||||
ctrlKeyPressed++;
|
||||
Program.BringForegroundToBackground();
|
||||
}
|
||||
|
||||
if ((User32.GetKeyState(0x10) & 0x8000) != 0)
|
||||
shiftKeyPressed++;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue