new feature: shift click PW icon to center foreground window

This commit is contained in:
Kang Yu 2024-03-02 20:24:43 -08:00
parent 83e3ef4cc8
commit 984c89e099
3 changed files with 16 additions and 3 deletions

View file

@ -947,6 +947,14 @@ namespace PersistentWindows.Common
return offscreen;
}
public void CenterWindow(IntPtr hwnd)
{
IntPtr desktopWindow = User32.GetDesktopWindow();
RECT target_rect = new RECT();
User32.GetWindowRect(desktopWindow, ref target_rect);
User32.MoveWindow(hwnd, target_rect.Left + target_rect.Width / 4, target_rect.Top + target_rect.Height / 4, target_rect.Width / 2, target_rect.Height / 2, true);
}
public bool RecallLastKilledPosition(IntPtr hwnd)
{
if (deadApps.ContainsKey(curDisplayKey))
@ -1202,9 +1210,7 @@ namespace PersistentWindows.Common
if (IsOffScreen(hwnd))
{
IntPtr desktopWindow = User32.GetDesktopWindow();
User32.GetWindowRect(desktopWindow, ref target_rect);
User32.MoveWindow(hwnd, target_rect.Left + 50, target_rect.Top + 50, target_rect.Width * 3 / 4, target_rect.Height * 3 / 4, true);
CenterWindow(hwnd);
Log.Error("fix invisible window \"{0}\"", GetWindowTitle(hwnd));
}
}

View file

@ -622,6 +622,11 @@ namespace PersistentWindows.SystrayShell
pwp.RecallLastKilledPosition(pwp.GetForegroundWindow());
}
static public void CenterWindow()
{
pwp.CenterWindow(pwp.GetForegroundWindow());
}
static public void PauseAutoRestore()
{
pwp.pauseAutoRestore = true;

View file

@ -116,6 +116,8 @@ namespace PersistentWindows.SystrayShell
Program.FgWindowToBottom();
else if (ctrlKeyPressed > 0 && altKeyPressed == 0 && shiftKeyPressed == 0)
Program.RecallLastKilledPosition();
else if (ctrlKeyPressed == 0 && altKeyPressed == 0 && shiftKeyPressed > 0)
Program.CenterWindow();
else if (ctrlKeyPressed == 0 && altKeyPressed == 0 && shiftKeyPressed == 0)
//restore unnamed(default) snapshot
Program.RestoreSnapshot(0);