complete moving HotKeyWindow module to Common

This commit is contained in:
Kang Yu 2024-03-18 12:12:52 -07:00
parent 47d182fdf8
commit 5c26373d07
5 changed files with 19 additions and 23 deletions

View file

@ -1,5 +1,5 @@
 
namespace PersistentWindows.SystrayShell namespace PersistentWindows.Common
{ {
partial class HotKeyWindow partial class HotKeyWindow
{ {
@ -148,7 +148,7 @@ namespace PersistentWindows.SystrayShell
this.Controls.Add(this.buttonCloseTab); this.Controls.Add(this.buttonCloseTab);
this.Controls.Add(this.buttonNextTab); this.Controls.Add(this.buttonNextTab);
this.Controls.Add(this.buttonPrevTab); this.Controls.Add(this.buttonPrevTab);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.KeyPreview = true; this.KeyPreview = true;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
@ -156,7 +156,6 @@ namespace PersistentWindows.SystrayShell
this.Opacity = 0.5D; this.Opacity = 0.5D;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.TopMost = true; this.TopMost = true;
this.Load += new System.EventHandler(this.HotKeyWindow_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
} }

View file

@ -11,7 +11,7 @@ using System.Windows.Forms;
using PersistentWindows.Common.WinApiBridge; using PersistentWindows.Common.WinApiBridge;
namespace PersistentWindows.SystrayShell namespace PersistentWindows.Common
{ {
public partial class HotKeyWindow : Form public partial class HotKeyWindow : Form
{ {
@ -291,14 +291,10 @@ namespace PersistentWindows.SystrayShell
User32.SetForegroundWindow(Handle); User32.SetForegroundWindow(Handle);
} }
private void HotKeyWindow_Load(object sender, EventArgs e) private static IntPtr GetForegroundWindow()
{ {
Icon = Program.IdleIcon; return PersistentWindowProcessor.GetForegroundWindow();
} }
static IntPtr GetForegroundWindow()
{
return Program.GetForegroundWindow();
}
} }
} }

View file

@ -50,12 +50,12 @@ namespace PersistentWindows.Common
private HashSet<IntPtr> allUserMoveWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> allUserMoveWindows = new HashSet<IntPtr>();
private HashSet<IntPtr> unResponsiveWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> unResponsiveWindows = new HashSet<IntPtr>();
private HashSet<IntPtr> noRecordWindows = new HashSet<IntPtr>(); private HashSet<IntPtr> noRecordWindows = new HashSet<IntPtr>();
private IntPtr desktopWindow = User32.GetDesktopWindow(); private static IntPtr desktopWindow = User32.GetDesktopWindow();
private IntPtr vacantDeskWindow = IntPtr.Zero; private IntPtr vacantDeskWindow = IntPtr.Zero;
// windows that are not to be restored // windows that are not to be restored
private HashSet<IntPtr> noRestoreWindows = new HashSet<IntPtr>(); //windows excluded from auto-restore private static HashSet<IntPtr> noRestoreWindows = new HashSet<IntPtr>(); //windows excluded from auto-restore
private HashSet<IntPtr> noRestoreWindowsTmp = new HashSet<IntPtr>(); //user moved windows during restore private static HashSet<IntPtr> noRestoreWindowsTmp = new HashSet<IntPtr>(); //user moved windows during restore
// realtime fixing window location // realtime fixing window location
private IntPtr curMovingWnd = IntPtr.Zero; private IntPtr curMovingWnd = IntPtr.Zero;
@ -70,7 +70,7 @@ namespace PersistentWindows.Common
private Timer captureTimer; private Timer captureTimer;
private string curDisplayKey; // current display config name private string curDisplayKey; // current display config name
public string dbDisplayKey = null; public string dbDisplayKey = null;
private Dictionary<IntPtr, string> windowTitle = new Dictionary<IntPtr, string>(); // for matching running window with DB record private static Dictionary<IntPtr, string> windowTitle = new Dictionary<IntPtr, string>(); // for matching running window with DB record
private Queue<IntPtr> pendingMoveEvents = new Queue<IntPtr>(); // queue of window with possible position change for capture private Queue<IntPtr> pendingMoveEvents = new Queue<IntPtr>(); // queue of window with possible position change for capture
private HashSet<string> normalSessions = new HashSet<string>(); //normal user sessions, for differentiating full screen game session or other transient session private HashSet<string> normalSessions = new HashSet<string>(); //normal user sessions, for differentiating full screen game session or other transient session
public bool manualNormalSession = false; //user need to manually take snapshot or save/restore from db to flag normal session public bool manualNormalSession = false; //user need to manually take snapshot or save/restore from db to flag normal session
@ -878,7 +878,7 @@ namespace PersistentWindows.Common
return isFullScreen; return isFullScreen;
} }
private string GetWindowTitle(IntPtr hwnd, bool use_cache = true) private static string GetWindowTitle(IntPtr hwnd, bool use_cache = true)
{ {
if (use_cache && windowTitle.ContainsKey(hwnd)) if (use_cache && windowTitle.ContainsKey(hwnd))
return windowTitle[hwnd]; return windowTitle[hwnd];
@ -898,7 +898,7 @@ namespace PersistentWindows.Common
return ""; return "";
} }
private bool IsMinimized(IntPtr hwnd) private static bool IsMinimized(IntPtr hwnd)
{ {
bool result = User32.IsIconic(hwnd) || !User32.IsWindowVisible(hwnd); bool result = User32.IsIconic(hwnd) || !User32.IsWindowVisible(hwnd);
long style = User32.GetWindowLong(hwnd, User32.GWL_STYLE); long style = User32.GetWindowLong(hwnd, User32.GWL_STYLE);
@ -1225,7 +1225,7 @@ namespace PersistentWindows.Common
} }
private bool IsTopLevelWindow(IntPtr hwnd) private static bool IsTopLevelWindow(IntPtr hwnd)
{ {
if (IsTaskBar(hwnd)) if (IsTaskBar(hwnd))
return true; return true;
@ -1847,7 +1847,7 @@ namespace PersistentWindows.Common
return fixZorder == 2 || (restoringSnapshot && fixZorder > 0); return fixZorder == 2 || (restoringSnapshot && fixZorder > 0);
} }
public IntPtr GetForegroundWindow() public static IntPtr GetForegroundWindow()
{ {
IntPtr topMostWindow = User32.GetTopWindow(desktopWindow); IntPtr topMostWindow = User32.GetTopWindow(desktopWindow);
for (IntPtr hwnd = topMostWindow; hwnd != IntPtr.Zero; hwnd = User32.GetWindow(hwnd, 2)) for (IntPtr hwnd = topMostWindow; hwnd != IntPtr.Zero; hwnd = User32.GetWindow(hwnd, 2))
@ -2749,7 +2749,7 @@ namespace PersistentWindows.Common
} }
private string GetWindowClassName(IntPtr hwnd) private static string GetWindowClassName(IntPtr hwnd)
{ {
int nChars = 4096; int nChars = 4096;
StringBuilder buf = new StringBuilder(nChars); StringBuilder buf = new StringBuilder(nChars);
@ -2765,7 +2765,7 @@ namespace PersistentWindows.Common
return true; return true;
} }
private bool IsTaskBar(IntPtr hwnd) private static bool IsTaskBar(IntPtr hwnd)
{ {
if (!User32.IsWindow(hwnd)) if (!User32.IsWindow(hwnd))
return false; return false;

View file

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using PersistentWindows.Common;
using PersistentWindows.Common.WinApiBridge; using PersistentWindows.Common.WinApiBridge;
namespace PersistentWindows.SystrayShell namespace PersistentWindows.SystrayShell

View file

@ -623,12 +623,12 @@ namespace PersistentWindows.SystrayShell
static public void RecallLastKilledPosition() static public void RecallLastKilledPosition()
{ {
pwp.RecallLastKilledPosition(pwp.GetForegroundWindow()); pwp.RecallLastKilledPosition(PersistentWindowProcessor.GetForegroundWindow());
} }
static public void CenterWindow() static public void CenterWindow()
{ {
pwp.CenterWindow(pwp.GetForegroundWindow()); pwp.CenterWindow(PersistentWindowProcessor.GetForegroundWindow());
} }
static public void PauseAutoRestore() static public void PauseAutoRestore()
@ -731,7 +731,7 @@ namespace PersistentWindows.SystrayShell
public static IntPtr GetForegroundWindow() public static IntPtr GetForegroundWindow()
{ {
return pwp.GetForegroundWindow(); return PersistentWindowProcessor.GetForegroundWindow();
} }
} }
} }