fix(desktop-wake): multi-hwnd subclass + no maximize on search popup (1.2.8)
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 37s

SearchResultWindow2 can be warmed after main is already warm; desktop-wake no longer maximizes the popup.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-02 21:10:15 +08:00
parent 84157758e6
commit 17ac1b4e11
11 changed files with 96 additions and 27 deletions

View File

@@ -19,6 +19,7 @@ namespace JiangchangDesktopWake
private const uint OBJID_CLIENT = 0xFFFFFFFC;
private const uint OBJID_WINDOW = 0x00000000;
private const int SW_RESTORE = 9;
private const int SW_SHOW = 5;
private const int SW_MAXIMIZE = 3;
private const int WH_CALLWNDPROC = 4;
private const uint PROCESS_CREATE_THREAD = 0x0002;
@@ -42,6 +43,9 @@ namespace JiangchangDesktopWake
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
@@ -578,12 +582,32 @@ namespace JiangchangDesktopWake
return new IntPtr(Convert.ToInt64(s, 16));
}
/// <summary>
/// 主窗可 Maximize;SearchResultWindow2 等浮层禁止 Maximize(会撑爆/关掉浮层)。
/// </summary>
private static bool ShouldMaximize(IntPtr hwnd)
{
try
{
var sb = new StringBuilder(256);
if (GetClassName(hwnd, sb, sb.Capacity) <= 0) return true;
string cls = sb.ToString();
if (string.Equals(cls, "SearchResultWindow2", StringComparison.Ordinal))
return false;
if (cls.IndexOf("Shadow", StringComparison.OrdinalIgnoreCase) >= 0)
return false;
}
catch { }
return true;
}
private static void Activate(IntPtr hwnd)
{
try
{
if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE);
else ShowWindow(hwnd, SW_MAXIMIZE);
else if (ShouldMaximize(hwnd)) ShowWindow(hwnd, SW_MAXIMIZE);
else ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
Thread.Sleep(250);
}