WebPanel: raise over the foreground game via topmost and back
While the game is the foreground window, SetWindowPos(HWND_TOP) puts no window over it, not even a new window of another process (probed in game). The panel then stayed behind the game after every click on the game. HWND_TOPMOST then HWND_NOTOPMOST (both NOACTIVATE) does put it over the game, and the game keeps the foreground. Use that only at the top of the normal band (no other program's window above the game), so it never covers another program; skip a topmost game; back off if it keeps failing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d6d6bd39f9
commit
d4e9525b2d
2 changed files with 26 additions and 1 deletions
|
|
@ -1041,10 +1041,34 @@ internal sealed unsafe class WebPanelHost
|
|||
bool inPlace = IsAbove(_staHwnd, game) && (bandTop
|
||||
? NextAbove(_staHwnd, IntPtr.Zero, skipTopmost: true) == IntPtr.Zero
|
||||
: NextAbove(_staHwnd, IntPtr.Zero, skipTopmost: false) == target);
|
||||
if (inPlace) return;
|
||||
if (inPlace) { ResetRaise(); return; }
|
||||
SetWindowPos(_staHwnd, bandTop ? HWND_TOP : target, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
if (!bandTop || AtBandTop(game)) { ResetRaise(); return; }
|
||||
// A topmost game: nothing in the normal band can go over it; leave it.
|
||||
if (IsTopmost(game)) return;
|
||||
if (_raiseBackoff > 0) { _raiseBackoff--; return; }
|
||||
// While the game is the foreground window, HWND_TOP does not put ANY window over it, not even a new
|
||||
// window of another process (probed in game 2026-11-13). Going topmost and straight back does: the
|
||||
// panel lands at the top of the normal band, over the game, and the game keeps the foreground.
|
||||
// NOACTIVATE on both, so focus never moves.
|
||||
if (!_raiseLogged) { _raiseLogged = true; SafeLog("HWND_TOP did not raise the panel over the foreground game; raising via topmost and back"); }
|
||||
SetWindowPos(_staHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
SetWindowPos(_staHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
if (AtBandTop(game)) { ResetRaise(); return; }
|
||||
// If that keeps not working, say so once and back off to about once a second.
|
||||
if (++_raiseMisses == 10) SafeLog("raising via topmost and back did not put the panel over the game");
|
||||
if (_raiseMisses > 10) _raiseBackoff = 20;
|
||||
}
|
||||
|
||||
/// <summary>Over the game with nothing but topmost windows (and its own dialogs) above it.</summary>
|
||||
private bool AtBandTop(IntPtr game) => IsAbove(_staHwnd, game) && NextAbove(_staHwnd, IntPtr.Zero, skipTopmost: true) == IntPtr.Zero;
|
||||
|
||||
private void ResetRaise() { _raiseMisses = 0; _raiseBackoff = 0; }
|
||||
|
||||
private bool _raiseLogged; // panel thread only: log the topmost raise once per engine generation
|
||||
private int _raiseMisses; // panel thread only: consecutive ticks the panel stayed under the game
|
||||
private int _raiseBackoff; // panel thread only: ticks to skip before the next topmost attempt
|
||||
|
||||
/// <summary>
|
||||
/// The first window above <paramref name="from"/> that is not the panel or in its owner tree, not in
|
||||
/// <paramref name="skipTree"/>'s owner tree (the game, or none), and (with <paramref name="skipTopmost"/>)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ internal static unsafe class WebPanelNative
|
|||
public const int SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_SHOWNA = 8;
|
||||
public const uint GW_HWNDPREV = 3, GA_ROOT = 2, GA_ROOTOWNER = 3;
|
||||
public static readonly IntPtr HWND_TOP = IntPtr.Zero;
|
||||
public static readonly IntPtr HWND_TOPMOST = new(-1), HWND_NOTOPMOST = new(-2);
|
||||
|
||||
public const uint EVENT_SYSTEM_FOREGROUND = 0x0003, WINEVENT_OUTOFCONTEXT = 0x0000;
|
||||
public const int TRANSPARENT = 1, DEFAULT_GUI_FONT = 17, IDC_ARROW = 32512;
|
||||
|
|
|
|||
Loading…
Reference in a new issue