From 5c054407508d90811f2498522d4511c520b10c4c Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sat, 06 Jun 2026 23:05:23 +0800
Subject: [PATCH] fix: 仅实时 hover Space Lane 时才对对应窗口应用 spaceFocused 高亮 (v0.0.31)

---
 C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift b/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
index 773abed..799c87d 100644
--- a/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
+++ b/C1.source/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift
@@ -395,6 +395,7 @@
                 isGhost: isGhost(
                     rawWindow: rawWindow,
                     axWindow: axWindow,
+                    app: app,
                     spaceIDs: spaceIDs,
                     hasAXBackedTitleDuplicate: hasAXBackedTitleDuplicate
                 ),
@@ -583,6 +584,7 @@
     private func isGhost(
         rawWindow: [String: Any],
         axWindow: AXWindowMetadata?,
+        app: AlignerApp,
         spaceIDs: [UInt64],
         hasAXBackedTitleDuplicate: Bool = false
     ) -> Bool {
@@ -596,10 +598,20 @@
             return false
         }
         if axWindow != nil {
-            return layer != 0 || alpha <= 0
+            if alpha <= 0 {
+                return true
+            }
+            if layer == 0 {
+                return false
+            }
+
+            return !isOnscreen
         }
         if hasAXBackedTitleDuplicate {
             return true
+        }
+        if isKnownCGOnlyMainWindow(rawWindow: rawWindow, app: app) {
+            return false
         }
         if !spaceIDs.isEmpty, isLikelyFullscreenAuxiliaryCGWindow(bounds: rawBounds) {
             return true
@@ -618,6 +630,39 @@
         bounds.width < 500 || bounds.height < 160
     }
 
+    private func isKnownCGOnlyMainWindow(rawWindow: [String: Any], app: AlignerApp) -> Bool {
+        let layer = intValue(rawWindow[kCGWindowLayer as String]) ?? 0
+        let alpha = doubleValue(rawWindow[kCGWindowAlpha as String]) ?? 1
+        let isOnscreen = boolValue(rawWindow[kCGWindowIsOnscreen as String])
+        let title = stringValue(rawWindow[kCGWindowName as String]) ?? ""
+        let rawBounds = bounds(rawWindow[kCGWindowBounds as String])
+        let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
+
+        if app.bundleIdentifier == "cc.ffitch.shottr" {
+            return alpha > 0
+                && trimmedTitle == "Shottr"
+                && rawBounds.width > WindowEnumerationPolicy.minimumVisibleWidth
+                && 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
+            && alpha > 0
+            && !isOnscreen
+            && !trimmedTitle.isEmpty
+            && rawBounds.width > WindowEnumerationPolicy.minimumVisibleWidth
+            && rawBounds.height > WindowEnumerationPolicy.minimumVisibleHeight
+    }
+
     private func isDesktopElement(rawWindow: [String: Any], app: AlignerApp) -> Bool {
         guard app.bundleIdentifier == "com.apple.finder" else { return false }
         let title = stringValue(rawWindow[kCGWindowName as String]) ?? ""

--
Gitblit v1.9.3