Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Amethyst/Managers/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,23 @@ extension WindowManager {
LayoutWindow(id: $0.id(), frame: $0.frame(), isFocused: $0.isFocused())
}

let snapshotFloatingMap = floatingMap
let snapshotActiveIDCache = activeIDCache
let snapshotWindowsByID = Dictionary(uniqueKeysWithValues: windows.map { ($0.id(), $0) })

return WindowSet<Window>(
windows: layoutWindows,
isWindowWithIDActive: { [weak self] id -> Bool in
guard let window = self?.window(withID: id) else {
isWindowWithIDActive: { id -> Bool in
guard let window = snapshotWindowsByID[id] else {
return false
}
return self?.isWindowActive(window) ?? false
return window.isActive() && snapshotActiveIDCache.contains(window.cgID())
},
isWindowWithIDFloating: { [weak self] windowID -> Bool in
guard let window = self?.window(withID: windowID) else {
return false
}
return self?.isWindowFloating(window) ?? false
isWindowWithIDFloating: { windowID -> Bool in
return snapshotFloatingMap[windowID] ?? false
},
windowForID: { [weak self] windowID -> Window? in
return self?.window(withID: windowID)
windowForID: { windowID -> Window? in
return snapshotWindowsByID[windowID]
}
)
}
Expand Down
16 changes: 11 additions & 5 deletions Amethyst/Model/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,23 @@ final class AXWindowID: Hashable, Codable {
}

private let window: AXWindow
private let pid: pid_t
private let windowID: CGWindowID

/// Equality for window IDs is based on the underlying CoreGraphics id and the owning pid, which (mostly) uniquely identifies a window.
static func == (lhs: AXWindowID, rhs: AXWindowID) -> Bool {
return lhs.window.pid() == rhs.window.pid() && lhs.window.windowID() == rhs.window.windowID()
return lhs.pid == rhs.pid && lhs.windowID == rhs.windowID
}

func hash(into hasher: inout Hasher) {
hasher.combine(window.pid())
hasher.combine(window.windowID())
hasher.combine(pid)
hasher.combine(windowID)
}

fileprivate init(window: AXWindow) {
self.window = window
self.pid = window.pid()
self.windowID = window.windowID()
}

init(from decoder: Decoder) throws {
Expand All @@ -193,12 +197,14 @@ final class AXWindowID: Hashable, Codable {
}

self.window = AXWindow(axElement: window.axElementRef)
self.pid = pid
self.windowID = windowID
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(window.pid(), forKey: .pid)
try container.encode(window.windowID(), forKey: .windowID)
try container.encode(pid, forKey: .pid)
try container.encode(windowID, forKey: .windowID)
}
}

Expand Down
Loading