Skip to content

Commit

Permalink
move windowsFilter in its own variable and update the filtering itself
Browse files Browse the repository at this point in the history
  • Loading branch information
godbout committed Jan 30, 2025
1 parent db78ee0 commit 58ddb00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Binary file not shown.
29 changes: 19 additions & 10 deletions Sources/WooshyWindowToTheForeground/Menus/Entrance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,25 @@ struct Window {

class Entrance {
static let shared = Entrance()

static var screenRecordingGranted = false
// filtering out:
// 1. Menu Bar Icons
// 2. Windows that are not transparent
// 3. a bunch of Window Server Windows (Cursor, StatusIndicator, Menubar, etc.)
// 4. Notification Center when it shows up (like receiving a Notification)
// 5. a Screenshot Window that doesn't go away after you used Screenshot
// 6. Alfred itself
static let windowsFilter: String = {
"""
kCGWindowLayer != 25
&& kCGWindowAlpha > 0
&& kCGWindowOwnerName != "Window Server"
&& kCGWindowOwnerName != "Notification Center"
&& kCGWindowOwnerName != "Screenshot"
&& kCGWindowOwnerName != "Alfred"
"""
}()

private init() {}

Expand Down Expand Up @@ -100,16 +118,7 @@ extension Entrance {

private static func cgVisibleWindows() -> [Window]? {
guard let tooManyWindows = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as NSArray? else { return nil }
guard let visibleWindows = tooManyWindows.filtered(using: NSPredicate(format: """
(kCGWindowBounds.Width > 37 && kCGWindowBounds.Height > 37)
&& kCGWindowOwnerName != "Alfred"
&& kCGWindowOwnerName != "Notification Center"
&& kCGWindowOwnerName != "Wallpaper"
&& kCGWindowOwnerName != "Screenshot"
&& (kCGWindowOwnerName != "HazeOver" || kCGWindowAlpha = 1)
&& (kCGWindowOwnerName != "Magnet" || kCGWindowLayer != 25)
&& kCGWindowAlpha > 0
""")) as NSArray? else { return nil }
let visibleWindows = tooManyWindows.filtered(using: NSPredicate(format: windowsFilter))

var windows: [Window] = []

Expand Down

0 comments on commit 58ddb00

Please sign in to comment.