Skip to content

Commit

Permalink
fix: show windows from steam app (closes #236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Apr 18, 2020
1 parent 935d556 commit d17c9d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Cocoa

extension AXUIElement {
static let normalLevel = CGWindowLevelForKey(.normalWindow)

func cgWindowId() -> CGWindowID {
var id = CGWindowID(0)
_AXUIElementGetWindow(self, &id)
Expand All @@ -15,14 +15,19 @@ extension AXUIElement {
return pid
}

func isActualWindow() -> Bool {
// TODO: TotalFinder and XtraFinder double-window hacks (see #84)
func isActualWindow(_ bundleIdentifier: String?) -> Bool {
// Some non-windows have title: nil (e.g. some OS elements)
// Some non-windows have subrole: nil (e.g. some OS elements), "AXUnknown" (e.g. Bartender), "AXSystemDialog" (e.g. Intellij tooltips)
// Minimized windows or windows of a hidden app have subrole "AXDialog"
// Activity Monitor main window subrole is "AXDialog" for a brief moment at launch; it then becomes "AXStandardWindow"
// CGWindowLevel == .normalWindow helps filter out iStats Pro and other top-level pop-overs
return ["AXStandardWindow", "AXDialog"].contains(subrole()) && isOnNormalLevel()
let subrole_ = subrole()
return subrole_ != nil &&
(["AXStandardWindow", "AXDialog"].contains(subrole_) ||
// All Steam windows have subrole = AXUnknown
// some dropdown menus are not desirable; they have title == "", or sometimes role == nil when switching between menus quickly
(bundleIdentifier == "com.valvesoftware.steam" && title() != "" && role() != nil)) &&
isOnNormalLevel()
}

func isOnNormalLevel() -> Bool {
Expand Down Expand Up @@ -54,6 +59,10 @@ extension AXUIElement {
return attribute(kAXFocusedWindowAttribute, AXUIElement.self)
}

func role() -> String? {
return attribute(kAXRoleAttribute, String.self)
}

func subrole() -> String? {
return attribute(kAXSubroleAttribute, String.self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Application: NSObject {
func observeNewWindows() {
if let windows = axUiElement!.windows() {
let actualWindows = windows.filter {
$0.isActualWindow() && Windows.list.firstIndexThatMatches($0) == nil
$0.isActualWindow(runningApplication.bundleIdentifier) && Windows.list.firstIndexThatMatches($0) == nil
}
if actualWindows.count > 0 {
addWindows(actualWindows)
Expand Down Expand Up @@ -124,7 +124,7 @@ private func eventApplicationHiddenOrShown(_ app: App, _ element: AXUIElement, _
}

private func eventWindowCreated(_ app: App, _ element: AXUIElement, _ application: Application) {
guard element.isActualWindow() else { return }
guard element.isActualWindow(application.runningApplication.bundleIdentifier) else { return }
// a window being un-minimized can trigger kAXWindowCreatedNotification
guard Windows.list.firstIndexThatMatches(element) == nil else { return }
let window = Window(element, application)
Expand Down

0 comments on commit d17c9d5

Please sign in to comment.