Files
zerorigin-toolbox/internal/platform/windows/fullscreen_test.go
T
zerorigin2019 bd6a071c69 fix: 空虚拟桌面(任务栏无程序)时角落/边缘触发全部失效
根因:空桌面时前台窗口是 Shell 桌面窗口(Progman/WorkerW/#32769
/SHELLDLL_DefView/SysListView32),矩形覆盖全屏且无 WS_MAXIMIZE 样式,
被全屏检测(覆盖率≥95%)误判为"全屏",引擎按默认 fullscreen=ignore
抑制了所有规则,导致切桌面/调音量不触发。

修复:foregroundFullscreen 先按窗口类名排除 Shell 桌面窗口(桌面不算
全屏)。新增 isDesktopClass 纯函数单测 + GetDesktopWindow 集成断言。
2026-08-05 00:57:18 +08:00

89 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package windows
import (
"testing"
"time"
)
// TestIsFullscreenRect 验证覆盖判定边界(94%/95%/96%、无交集、跨屏)。
func TestIsFullscreenRect(t *testing.T) {
screen := MonitorRect{Left: 0, Top: 0, Right: 1920, Bottom: 1080}
cases := []struct {
name string
win MonitorRect
want bool
}{
{"完全覆盖", MonitorRect{0, 0, 1920, 1080}, true},
{"无边框全屏", MonitorRect{0, 0, 1920, 1080}, true},
{"任务栏遮挡(94%)", MonitorRect{0, 0, 1920, 1015}, false}, // 1015/1080 ≈ 93.9%
{"任务栏遮挡(96%)", MonitorRect{0, 0, 1920, 1040}, true}, // 1040/1080 ≈ 96.3%
{"普通窗口", MonitorRect{100, 100, 1200, 800}, false},
{"无交集", MonitorRect{3000, 3000, 4000, 4000}, false},
{"覆盖95%临界", MonitorRect{0, 0, 1920, 1026}, true}, // 1026/1080 = 95.0%
}
for _, c := range cases {
if got := IsFullscreenRect(c.win, screen, 0); got != c.want {
t.Errorf("%s: IsFullscreenRect = %v, want %v", c.name, got, c.want)
}
}
}
// TestIsFullscreenRectMultiMonitor 验证跨屏窗口按交集最大屏幕判定。
func TestIsFullscreenRectMultiMonitor(t *testing.T) {
screen := MonitorRect{Left: 1920, Top: 0, Right: 3840, Bottom: 1080}
win := MonitorRect{Left: 1900, Top: 0, Right: 3840, Bottom: 1080} // 几乎全盖副屏
if !IsFullscreenRect(win, screen, 0) {
t.Fatal("near-fullscreen on secondary monitor should be true")
}
}
// TestIsDesktopClass 验证 Shell 桌面窗口类名识别(空桌面场景回归)。
func TestIsDesktopClass(t *testing.T) {
cases := []struct {
cls string
want bool
}{
{"Progman", true}, // Shell 桌面主窗口
{"WorkerW", true}, // 壁纸层(Win11 前台焦点)
{"#32769", true}, // 系统桌面窗口(GetDesktopWindow)
{"SHELLDLL_DefView", true}, // 桌面图标宿主
{"SysListView32", true}, // 桌面图标列表
{"Chrome_WidgetWin_1", false},
{"ConsoleWindowClass", false},
{"CabinetWClass", false}, // 资源管理器(普通窗口,不算桌面)
{"", false},
}
for _, c := range cases {
if got := isDesktopClass(c.cls); got != c.want {
t.Errorf("isDesktopClass(%q) = %v, want %v", c.cls, got, c.want)
}
}
}
// TestIsDesktopWindowReal 集成验证:GetDesktopWindow 返回的系统桌面窗口
// (类名 #32769)必须判定为桌面(防止空桌面被误判全屏导致规则抑制)。
func TestIsDesktopWindowReal(t *testing.T) {
hwnd, _, _ := procGetDesktopWindow.Call()
if hwnd == 0 {
t.Skip("GetDesktopWindow returned 0")
}
if !isDesktopWindow(hwnd) {
t.Fatal("desktop window (#32769) should be detected as desktop")
}
}
// TestFullscreenWatcherLifecycle 验证轮询器 Start/Stop 幂等与状态可读。
func TestFullscreenWatcherLifecycle(t *testing.T) {
w := NewFullscreenWatcher()
w.Start()
w.Start() // 幂等
time.Sleep(100 * time.Millisecond)
_ = w.IsFullscreen() // 可读(值不校验:取决于会话前台窗口)
w.Stop()
w.Stop() // 幂等
// 重启
w.Start()
time.Sleep(50 * time.Millisecond)
w.Stop()
}