yield foreground window when drifting out of browser window

This commit is contained in:
Kang Yu 2024-03-23 21:50:56 -07:00
parent 873bec0b32
commit 55e2ff2356
3 changed files with 16 additions and 5 deletions

View file

@ -489,7 +489,7 @@ namespace PersistentWindows.Common
{
if (stay)
{
if (tiny)
if (tiny && Visible)
{
POINT cursorPos;
User32.GetCursorPos(out cursorPos);
@ -498,7 +498,17 @@ namespace PersistentWindows.Common
StartAliveTimer();
return;
}
IntPtr fgwnd = GetForegroundWindow();
IntPtr cursorWnd = User32.WindowFromPoint(cursorPos);
if (cursorWnd != Handle && cursorWnd != fgwnd && User32.GetAncestor(cursorWnd, User32.GetAncestorRoot) != fgwnd)
{
//yield focus
User32.SetForegroundWindow(fgwnd);
StartAliveTimer();
return;
}
if (PersistentWindowProcessor.IsBrowserWindow(fgwnd))
{
IntPtr hCursor = GetCursor();

View file

@ -1264,7 +1264,7 @@ namespace PersistentWindows.Common
if (IsTaskBar(hwnd))
return true;
if (User32.GetAncestor(hwnd, 1) != desktopWindow)
if (User32.GetAncestor(hwnd, User32.GetAncestorParent) != desktopWindow)
return false;
long style = User32.GetWindowLong(hwnd, User32.GWL_STYLE);
@ -3963,7 +3963,7 @@ namespace PersistentWindows.Common
public static bool IsDesktopWindow(IntPtr hwnd)
{
IntPtr root = User32.GetAncestor(hwnd, 2);
IntPtr root = User32.GetAncestor(hwnd, User32.GetAncestorRoot);
return root == vacantDeskWindow;
}

View file

@ -483,8 +483,9 @@ namespace PersistentWindows.Common.WinApiBridge
[DllImport("user32.dll")]
public static extern IntPtr GetAncestor(IntPtr hWnd, uint gaFlags); // I'm too lazy to write an enum for them
public const int GetRoot = 2;
public const int GetRootOwner = 3;
public const int GetAncestorParent = 1;
public const int GetAncestorRoot = 2;
public const int GetAncestorRootOwner = 3;
public const int ICON_SMALL = 0;
public const int ICON_BIG = 1;