From ae0f48a9d9543d43b120674f0e58164d7cce95ad Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sun, 14 Jun 2026 21:06:22 +0800
Subject: [PATCH] Refine Quick Switch UI states
---
C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift b/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
index 75bc119..16c3e0c 100644
--- a/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
+++ b/C1.source/Sources/AlignerCore/Windows/WindowEnumerationPolicy.swift
@@ -22,6 +22,7 @@
public let activationPolicy: AlignerActivationPolicy
public let title: String
public let size: CGSize
+ public let frame: CGRect?
public let subrole: AlignerWindowSubrole
public let isMinimized: Bool
public let isFullscreen: Bool
@@ -40,6 +41,7 @@
title: String,
identifierSource: AlignerWindow.IdentifierSource = .cgWindow,
size: CGSize,
+ frame: CGRect? = nil,
subrole: AlignerWindowSubrole,
isMinimized: Bool = false,
isFullscreen: Bool = false,
@@ -57,6 +59,7 @@
self.activationPolicy = activationPolicy
self.title = title
self.size = size
+ self.frame = frame
self.subrole = subrole
self.isMinimized = isMinimized
self.isFullscreen = isFullscreen
@@ -76,17 +79,23 @@
public static func shouldInclude(_ record: WindowEnumerationRecord) -> Bool {
guard record.id != 0 else { return false }
- guard record.activationPolicy == .regular else { return false }
+ guard hasSupportedActivationPolicy(record) else { return false }
guard isSupportedSubrole(record.subrole) else { return false }
guard !record.app.isHidden || record.isFullscreen else { return false }
guard !record.isGhost else { return false }
guard !record.isDesktopElement else { return false }
guard !record.isSystemCritical else { return false }
guard record.isInteractable else { return false }
+ guard !isKnownClosedShottrCGPlaceholder(record) else { return false }
guard !isCGOnlyOffscreenGhost(record) else { return false }
guard !isKnownClosedDocumentPlaceholder(record) else { return false }
return record.isMinimized || record.isFullscreen || isLargeEnough(record.size)
+ }
+
+ private static func hasSupportedActivationPolicy(_ record: WindowEnumerationRecord) -> Bool {
+ record.activationPolicy == .regular
+ || (record.activationPolicy == .accessory && isKnownAccessoryMainWindow(record))
}
public static func window(from record: WindowEnumerationRecord) -> AlignerWindow? {
@@ -100,6 +109,7 @@
isMinimized: record.isMinimized,
isFullscreen: record.isFullscreen,
isGhost: record.isGhost,
+ frame: record.frame,
spaceIDs: record.spaceIDs
)
}
@@ -118,7 +128,50 @@
}
private static func isCGOnlyOffscreenGhost(_ record: WindowEnumerationRecord) -> Bool {
- record.identifierSource == .cgWindow
+ guard record.identifierSource == .cgWindow,
+ !record.hasAXBacking,
+ !record.isOnscreen,
+ !record.isMinimized,
+ !record.isFullscreen
+ else {
+ return false
+ }
+
+ if !record.spaceIDs.isEmpty {
+ return false
+ }
+
+ return !isKnownCGOnlyOffscreenMainWindow(record)
+ }
+
+ private static func isKnownCGOnlyOffscreenMainWindow(_ record: WindowEnumerationRecord) -> Bool {
+ let trimmedTitle = record.title.trimmingCharacters(in: .whitespacesAndNewlines)
+
+ switch record.app.bundleIdentifier {
+ case "com.apple.finder":
+ return !trimmedTitle.isEmpty && isLargeEnough(record.size)
+ case "io.dcloud.HBuilderX":
+ return !trimmedTitle.isEmpty && isLargeEnough(record.size)
+ default:
+ return false
+ }
+ }
+
+ private static func isKnownAccessoryMainWindow(_ record: WindowEnumerationRecord) -> Bool {
+ let trimmedTitle = record.title.trimmingCharacters(in: .whitespacesAndNewlines)
+
+ return record.app.bundleIdentifier == "cc.ffitch.shottr"
+ && trimmedTitle == "Shottr"
+ && record.isOnscreen
+ && isLargeEnough(record.size)
+ }
+
+ private static func isKnownClosedShottrCGPlaceholder(_ record: WindowEnumerationRecord) -> Bool {
+ let trimmedTitle = record.title.trimmingCharacters(in: .whitespacesAndNewlines)
+
+ return record.app.bundleIdentifier == "cc.ffitch.shottr"
+ && trimmedTitle == "Shottr"
+ && record.identifierSource == .cgWindow
&& !record.hasAXBacking
&& !record.isOnscreen
&& !record.isMinimized
--
Gitblit v1.9.3