Skip to content

Commit

Permalink
Create MacWindow only for kAXStandardWindowSubrole and kAXDialogSubrole
Browse files Browse the repository at this point in the history
This commit fixes todo
  • Loading branch information
nikitabobko committed Nov 1, 2023
1 parent 7bd7752 commit 7199373
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/command/FocusCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct FocusCommand: Command {
guard let currentWindow = focusedWindowOrEffectivelyFocused else { return }
let workspace = currentWindow.workspace
// todo floating windows break mru
// todo floating non AXStandardWindow shouldn't be part of the tree
let floatingWindows = makeFloatingWindowsSeenAsTiling(workspace: workspace)
defer {
restoreFloatingWindows(floatingWindows: floatingWindows, workspace: workspace)
Expand Down
10 changes: 8 additions & 2 deletions src/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class MacWindow: Window, CustomStringConvertible {
static var allWindows: [MacWindow] { Array(allWindowsMap.values) }

static func get(app: MacApp, axWindow: AXUIElement) -> MacWindow? {
if !isWindow(axWindow) { return nil }
guard let id = axWindow.windowId() else { return nil }
if let existing = allWindowsMap[id] {
return existing
Expand Down Expand Up @@ -135,13 +136,18 @@ final class MacWindow: Window, CustomStringConvertible {
}
}

func shouldFloat(_ axWindow: AXUIElement) -> Bool {
private func isWindow(_ axWindow: AXUIElement) -> Bool {
let subrole = axWindow.get(Ax.subroleAttr)
return subrole == kAXStandardWindowSubrole || subrole == kAXDialogSubrole
}

func shouldFloat(_ axWindow: AXUIElement) -> Bool { // Note: a lot of windows don't have title on startup
// Don't tile:
// - Chrome cmd+f window ("AXUnknown" value)
// - login screen (Yes fuck, it's also a window from Apple's API perspective) ("AXUnknown" value)
// - XCode "Build succeeded" popup
// - IntelliJ tooltips, context menus, drop downs
// - macOS native file picker ("Open..." menu)
// - macOS native file picker ("Open..." menu) (kAXDialogSubrole value)
//
// Minimized windows or windows of a hidden app have subrole "AXDialog"
axWindow.get(Ax.subroleAttr) != kAXStandardWindowSubrole
Expand Down

0 comments on commit 7199373

Please sign in to comment.