From 247c82b195be7cb7311ba6c5b9aca358fb91e0dc Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Thu, 04 Jun 2026 17:37:59 +0800
Subject: [PATCH] fix finder cg-only window enumeration
---
C1.source/Resources/Aligner-Info.plist | 4 ++--
C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift | 8 ++++++++
C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift | 2 ++
C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift | 39 +++++++++++++++++++++++++++++++++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/C1.source/Resources/Aligner-Info.plist b/C1.source/Resources/Aligner-Info.plist
index be79823..5c82ff7 100644
--- a/C1.source/Resources/Aligner-Info.plist
+++ b/C1.source/Resources/Aligner-Info.plist
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>0.0.23</string>
+ <string>0.0.24</string>
<key>CFBundleVersion</key>
- <string>20260604.1723</string>
+ <string>20260604.1736</string>
<key>LSMinimumSystemVersion</key>
<string>26.0</string>
<key>NSHighResolutionCapable</key>
diff --git a/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift b/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
index 49a7cf9..799c87d 100644
--- a/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
+++ b/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
@@ -645,6 +645,14 @@
&& rawBounds.height > WindowEnumerationPolicy.minimumVisibleHeight
}
+ if app.bundleIdentifier == "com.apple.finder" {
+ return layer == 0
+ && alpha > 0
+ && !trimmedTitle.isEmpty
+ && rawBounds.width > WindowEnumerationPolicy.minimumVisibleWidth
+ && rawBounds.height > WindowEnumerationPolicy.minimumVisibleHeight
+ }
+
guard app.bundleIdentifier == "io.dcloud.HBuilderX" else { return false }
return layer == 0
diff --git a/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift b/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
index a219abb..6357849 100644
--- a/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
+++ b/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
@@ -139,6 +139,8 @@
let trimmedTitle = record.title.trimmingCharacters(in: .whitespacesAndNewlines)
switch record.app.bundleIdentifier {
+ case "com.apple.finder":
+ return !trimmedTitle.isEmpty && isLargeEnough(record.size)
case "cc.ffitch.shottr":
return trimmedTitle == "Shottr" && isLargeEnough(record.size)
case "io.dcloud.HBuilderX":
diff --git a/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift b/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
index 11c41ed..2dcabd3 100644
--- a/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
+++ b/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
@@ -314,6 +314,45 @@
XCTAssertNil(WindowEnumerationPolicy.window(from: utilityRecord))
}
+ func testWindowEnumerationPolicyKeepsFinderCGOnlyOffscreenMainWindows() {
+ let finderApp = AlignerApp(
+ bundleIdentifier: "com.apple.finder",
+ name: "访达",
+ category: .finder
+ )
+ let record = WindowEnumerationRecord(
+ id: 83_664,
+ app: finderApp,
+ title: "Screencapture",
+ size: CGSize(width: 920, height: 436),
+ subrole: .standard,
+ hasAXBacking: false,
+ isOnscreen: false
+ )
+ let emptyTitleRecord = WindowEnumerationRecord(
+ id: 83_665,
+ app: finderApp,
+ title: "",
+ size: CGSize(width: 920, height: 436),
+ subrole: .standard,
+ hasAXBacking: false,
+ isOnscreen: false
+ )
+ let tinyRecord = WindowEnumerationRecord(
+ id: 83_666,
+ app: finderApp,
+ title: "Finder Utility",
+ size: CGSize(width: 80, height: 40),
+ subrole: .standard,
+ hasAXBacking: false,
+ isOnscreen: false
+ )
+
+ XCTAssertEqual(WindowEnumerationPolicy.window(from: record)?.title, "Screencapture")
+ XCTAssertNil(WindowEnumerationPolicy.window(from: emptyTitleRecord))
+ XCTAssertNil(WindowEnumerationPolicy.window(from: tinyRecord))
+ }
+
func testWindowEnumerationPolicyKeepsMinimizedAndFullscreenCGOnlyOffscreenWindows() {
let minimized = makeWindowRecord(
title: "Minimized Document.md",
--
Gitblit v1.9.3