From 9eff3ec410bc48ad751bcbd7445be8f2a16283c9 Mon Sep 17 00:00:00 2001 From: zimoyin <2556608754@qq.com> Date: Tue, 13 Oct 2026 15:12:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=AC=E6=B5=AE=E6=9D=A1=EF=BC=9A=E9=94=9A?= =?UTF-8?q?=E5=AE=9A=E7=AA=97=E5=8F=A3=E5=8F=AA=E9=9C=80=E6=9C=AA=E8=A2=AB?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E9=81=AE=E6=8C=A1=EF=BC=8C=E5=B9=B6=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E6=9C=80=E5=B0=8F=E5=8C=96=E7=9A=84=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两个原因让悬浮条一直不显示: 1) 可见性规则过严——锚定窗口只要被任何外部窗口压住一角就隐藏。现在改为 只要求“未被完全遮住”,部分遮挡不影响显示。 2) UWP 应用会留下最小化的同名框架窗口(矩形在 -32000),窗口匹配可能选中它, 于是报“矩形过小或不在屏幕范围内”。现在优先选可见窗口;只有最小化窗口时 明确说明原因。 实测(真实 Windows 设置窗口 + 本工具窗口压在其上 + 置顶小工具压住一角): canShow=True,悬浮条在锚定窗口左上角显示,3 个按钮正常绘制。 Co-Authored-By: Claude Code --- docs/XPath定位.md | 5 +- .../Services/FloatingBarManager.cs | 107 ++++++++++++++++-- 2 files changed, 100 insertions(+), 12 deletions(-) diff --git a/docs/XPath定位.md b/docs/XPath定位.md index 4b5e775..ad85308 100644 --- a/docs/XPath定位.md +++ b/docs/XPath定位.md @@ -397,7 +397,10 @@ i3/o1 点击“检测显示条件”,按提示处理: -> 本工具自己的窗口(主界面、设置窗口)**不算遮挡**,无论是设置页的检测还是运行时判断:你在设置窗口里配置时,悬浮条照样会按条件显示。只有**别的程序**挡住了锚定窗口,悬浮条才会隐藏,并在检测结果里点名是哪个窗口挡住的。 +> - 本工具自己的窗口(主界面、设置窗口)**永远不算遮挡**:在设置窗口里配置时,悬浮条照样按条件显示。 +> - 别的程序**只是压住锚定窗口的一部分**(例如一个置顶小工具压住一个角)也不影响显示。 +> - 只有锚定窗口**被别的程序完全遮住**、或者它本身最小化/隐藏了,悬浮条才不显示,并在检测结果里点名是哪个窗口挡住的。 +> - 如果匹配到的窗口是**最小化**的(UWP 应用常留下一个最小化的同名框架窗口),检测会明确说明,不会再把它当成正常锚点。 1. 悬浮条是否启用; 2. 是否有至少一个启用按钮; diff --git a/src/pacs_win_uia/Services/FloatingBarManager.cs b/src/pacs_win_uia/Services/FloatingBarManager.cs index 01cf9af..f3eccea 100644 --- a/src/pacs_win_uia/Services/FloatingBarManager.cs +++ b/src/pacs_win_uia/Services/FloatingBarManager.cs @@ -392,7 +392,7 @@ namespace pacs_win_uia.Services var anchor = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top); string reason; if (runtime.Definition.RequireWindowVisible && - !WindowVisibility.IsVisibleOnScreen(runtime.Anchor, anchor, _ownProcessId, true, out reason)) + !IsAnchorVisible(new NativeWindowInfo(runtime.Anchor) { WindowBounds = ToNativeRectangle(anchor) }, out reason)) { Hide(runtime); return; @@ -478,9 +478,7 @@ namespace pacs_win_uia.Services if (window == null) { result.Reason = "锚定窗口:" + error; return result; } result.Anchor = window.Handle; result.Details = "锚定窗口:" + window + ";PID=" + window.ProcessId; - if (bar.RequireWindowVisible && !WindowVisibility.IsVisibleOnScreen(window.Handle, - window.WindowRectangle, System.Diagnostics.Process.GetCurrentProcess().Id, - true, out error)) + if (bar.RequireWindowVisible && !IsAnchorVisible(window, out error)) { result.Reason = "锚定窗口可见性不满足:" + error; return result; @@ -533,8 +531,7 @@ namespace pacs_win_uia.Services return null; } process = NormalizeProcessName(process); - NativeWindowInfo match = null; - int count = 0; + var matches = new List(); foreach (NativeWindowInfo window in windows ?? new List()) { if (window == null || window.IsOwnProcess || !window.IsVisible) continue; @@ -543,15 +540,103 @@ namespace pacs_win_uia.Services if (!string.IsNullOrWhiteSpace(windowClass) && !string.Equals(window.ClassName, windowClass, StringComparison.Ordinal)) continue; if (!string.IsNullOrWhiteSpace(title) && (window.Title == null || window.Title.IndexOf(title, StringComparison.OrdinalIgnoreCase) < 0)) continue; - match = window; - count++; + matches.Add(window); } - if (count == 1) return match; - error = count == 0 ? "没有同时符合已填写条件的窗口(进程=" + process + ";类=" + windowClass + ";标题=" + title + ")。" - : "匹配到 " + count + " 个窗口,不能确定锚点;请补充窗口类/标题条件。"; + + if (matches.Count == 0) + { + error = "没有同时符合已填写条件的窗口(进程=" + process + ";类=" + windowClass + ";标题=" + title + ")。"; + return null; + } + + // UWP/Store apps keep a minimized frame window around, often with the same title as the + // window the operator is actually looking at. Choosing it would anchor the bar to a + // window at (-32000,-32000), which can never be visible — so visible windows win. + var usable = new List(); + foreach (NativeWindowInfo window in matches) + { + if (!window.IsMinimized) usable.Add(window); + } + + if (usable.Count == 1) return usable[0]; + if (usable.Count > 1) + { + error = "匹配到 " + usable.Count + " 个可见窗口,不能确定锚点;请补充窗口类或标题条件。" + + DescribeCandidates(usable); + return null; + } + + if (matches.Count == 1) + { + error = "唯一匹配的窗口是最小化的:" + matches[0] + + "(最小化的窗口不在屏幕上,悬浮条无法显示)。请还原该窗口,或换一个可见的锚定窗口。"; + return null; + } + + error = "匹配到的 " + matches.Count + " 个窗口都已最小化,无法确定锚点:" + DescribeCandidates(matches); return null; } + + /// + /// "Is the anchored window on screen?" — deliberately NOT "is every pixel of it unobstructed". + /// A single always-on-top helper window overlapping a corner used to hide the bar completely, + /// which the operator cannot explain. Requirements now: + /// · the window exists, is visible and not minimized; + /// · it is not completely hidden by other applications. + /// The tool's own windows never count as occluders (see CheckDisplayConditions). + /// + private static bool IsAnchorVisible(NativeWindowInfo window, out string reason) + { + reason = null; + if (window == null || window.Handle == IntPtr.Zero) + { + reason = "没有锚定窗口。"; + return false; + } + + var occluders = new List(); + Region visible; + if (!WindowVisibility.TryGetVisibleRegion(window.Handle, false, null, true, occluders, + out visible, out reason)) + { + reason = reason ?? "锚定窗口不在屏幕上。"; + if (occluders.Count > 0) + { + reason += WindowVisibility.DescribeOccluders(occluders, + System.Diagnostics.Process.GetCurrentProcess().Id, true); + } + return false; + } + + using (visible) + { + if (WindowVisibility.HasArea(visible)) return true; + } + + reason = "锚定窗口被其他程序完全遮住。"; + return false; + } + + private static NativeRectangleInfo ToNativeRectangle(Rectangle rectangle) + { + return new NativeRectangleInfo + { + Left = rectangle.Left, Top = rectangle.Top, Right = rectangle.Right, Bottom = rectangle.Bottom + }; + } + + private static string DescribeCandidates(IList windows) + { + var text = new System.Text.StringBuilder(); + for (int index = 0; index < windows.Count && index < 4; index++) + { + text.Append(Environment.NewLine).Append(" · ").Append(windows[index]); + } + + return text.ToString(); + } + public static string NormalizeProcessName(string process) { process = (process ?? string.Empty).Trim();