悬浮条:锚定窗口只需未被完全遮挡,并跳过最小化的同名窗口
两个原因让悬浮条一直不显示: 1) 可见性规则过严——锚定窗口只要被任何外部窗口压住一角就隐藏。现在改为 只要求“未被完全遮住”,部分遮挡不影响显示。 2) UWP 应用会留下最小化的同名框架窗口(矩形在 -32000),窗口匹配可能选中它, 于是报“矩形过小或不在屏幕范围内”。现在优先选可见窗口;只有最小化窗口时 明确说明原因。 实测(真实 Windows 设置窗口 + 本工具窗口压在其上 + 置顶小工具压住一角): canShow=True,悬浮条在锚定窗口左上角显示,3 个按钮正常绘制。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
+4
-1
@@ -397,7 +397,10 @@ i3/o1
|
|||||||
|
|
||||||
点击“检测显示条件”,按提示处理:
|
点击“检测显示条件”,按提示处理:
|
||||||
|
|
||||||
> 本工具自己的窗口(主界面、设置窗口)**不算遮挡**,无论是设置页的检测还是运行时判断:你在设置窗口里配置时,悬浮条照样会按条件显示。只有**别的程序**挡住了锚定窗口,悬浮条才会隐藏,并在检测结果里点名是哪个窗口挡住的。
|
> - 本工具自己的窗口(主界面、设置窗口)**永远不算遮挡**:在设置窗口里配置时,悬浮条照样按条件显示。
|
||||||
|
> - 别的程序**只是压住锚定窗口的一部分**(例如一个置顶小工具压住一个角)也不影响显示。
|
||||||
|
> - 只有锚定窗口**被别的程序完全遮住**、或者它本身最小化/隐藏了,悬浮条才不显示,并在检测结果里点名是哪个窗口挡住的。
|
||||||
|
> - 如果匹配到的窗口是**最小化**的(UWP 应用常留下一个最小化的同名框架窗口),检测会明确说明,不会再把它当成正常锚点。
|
||||||
|
|
||||||
1. 悬浮条是否启用;
|
1. 悬浮条是否启用;
|
||||||
2. 是否有至少一个启用按钮;
|
2. 是否有至少一个启用按钮;
|
||||||
|
|||||||
@@ -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);
|
var anchor = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
|
||||||
string reason;
|
string reason;
|
||||||
if (runtime.Definition.RequireWindowVisible &&
|
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);
|
Hide(runtime);
|
||||||
return;
|
return;
|
||||||
@@ -478,9 +478,7 @@ namespace pacs_win_uia.Services
|
|||||||
if (window == null) { result.Reason = "锚定窗口:" + error; return result; }
|
if (window == null) { result.Reason = "锚定窗口:" + error; return result; }
|
||||||
result.Anchor = window.Handle;
|
result.Anchor = window.Handle;
|
||||||
result.Details = "锚定窗口:" + window + ";PID=" + window.ProcessId;
|
result.Details = "锚定窗口:" + window + ";PID=" + window.ProcessId;
|
||||||
if (bar.RequireWindowVisible && !WindowVisibility.IsVisibleOnScreen(window.Handle,
|
if (bar.RequireWindowVisible && !IsAnchorVisible(window, out error))
|
||||||
window.WindowRectangle, System.Diagnostics.Process.GetCurrentProcess().Id,
|
|
||||||
true, out error))
|
|
||||||
{
|
{
|
||||||
result.Reason = "锚定窗口可见性不满足:" + error;
|
result.Reason = "锚定窗口可见性不满足:" + error;
|
||||||
return result;
|
return result;
|
||||||
@@ -533,8 +531,7 @@ namespace pacs_win_uia.Services
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
process = NormalizeProcessName(process);
|
process = NormalizeProcessName(process);
|
||||||
NativeWindowInfo match = null;
|
var matches = new List<NativeWindowInfo>();
|
||||||
int count = 0;
|
|
||||||
foreach (NativeWindowInfo window in windows ?? new List<NativeWindowInfo>())
|
foreach (NativeWindowInfo window in windows ?? new List<NativeWindowInfo>())
|
||||||
{
|
{
|
||||||
if (window == null || window.IsOwnProcess || !window.IsVisible) continue;
|
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(windowClass) && !string.Equals(window.ClassName, windowClass, StringComparison.Ordinal)) continue;
|
||||||
if (!string.IsNullOrWhiteSpace(title) && (window.Title == null
|
if (!string.IsNullOrWhiteSpace(title) && (window.Title == null
|
||||||
|| window.Title.IndexOf(title, StringComparison.OrdinalIgnoreCase) < 0)) continue;
|
|| window.Title.IndexOf(title, StringComparison.OrdinalIgnoreCase) < 0)) continue;
|
||||||
match = window;
|
matches.Add(window);
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
if (count == 1) return match;
|
|
||||||
error = count == 0 ? "没有同时符合已填写条件的窗口(进程=" + process + ";类=" + windowClass + ";标题=" + title + ")。"
|
if (matches.Count == 0)
|
||||||
: "匹配到 " + count + " 个窗口,不能确定锚点;请补充窗口类/标题条件。";
|
{
|
||||||
|
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<NativeWindowInfo>();
|
||||||
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// "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).
|
||||||
|
/// </summary>
|
||||||
|
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<IntPtr>();
|
||||||
|
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<NativeWindowInfo> 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)
|
public static string NormalizeProcessName(string process)
|
||||||
{
|
{
|
||||||
process = (process ?? string.Empty).Trim();
|
process = (process ?? string.Empty).Trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user