Skip to content

Commit

Permalink
perf: alt-tab appears quicker when summoned
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 27, 2020
1 parent de02e5b commit c2bb896
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/logic/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Application: NSObject {
var axUiElement: AXUIElement?
var axObserver: AXObserver?
var isReallyFinishedLaunching = false
var isHidden: Bool!
var icon: NSImage?
var dockLabel: String?

static func notifications(_ app: NSRunningApplication) -> [String] {
Expand All @@ -30,6 +32,8 @@ class Application: NSObject {
init(_ runningApplication: NSRunningApplication) {
self.runningApplication = runningApplication
super.init()
isHidden = runningApplication.isHidden
icon = runningApplication.icon
addAndObserveWindows()
kvObservers = [
runningApplication.observe(\.isFinishedLaunching, options: [.new]) { [weak self] _, _ in self?.addAndObserveWindows() },
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class Window {
var cgWindowId: CGWindowID
var title: String!
var thumbnail: NSImage?
var icon: NSImage? { get { application.runningApplication.icon } }
var icon: NSImage? { get { application.icon } }
var shouldShowTheUser = true
var isTabbed: Bool = false
var isHidden: Bool { get { application.runningApplication.isHidden } }
var isHidden: Bool { get { application.isHidden } }
var dockLabel: Int? { get { application.dockLabel.flatMap { Int($0) } } }
var isFullscreen: Bool
var isMinimized: Bool
Expand Down
3 changes: 3 additions & 0 deletions src/logic/events/AccessibilityEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private func applicationActivated(_ element: AXUIElement) throws {

private func applicationHiddenOrShown(_ element: AXUIElement, _ pid: pid_t, _ type: String) throws {
DispatchQueue.main.async {
if let app = (Applications.list.first { $0.runningApplication.processIdentifier == pid }) {
app.isHidden = type == kAXApplicationHiddenNotification
}
let windows = Windows.list.filter {
// for AXUIElement of apps, CFEqual or == don't work; looks like a Cocoa bug
return $0.application.runningApplication.processIdentifier == pid
Expand Down

0 comments on commit c2bb896

Please sign in to comment.