Skip to content

Commit 9ce7992

Browse files
authored
Regenerate id cache on deminimize (#1765)
1 parent c5ed3f0 commit 9ce7992

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

Amethyst/Managers/WindowManager.swift

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,6 @@ extension WindowManager {
277277

278278
fileprivate func remove(window: Window) {
279279
markAllScreensForReflow(withChange: .remove(window: window))
280-
281-
let application = applicationWithPID(window.pid())
282-
application?.unobserve(notification: kAXUIElementDestroyedNotification, window: window)
283-
application?.unobserve(notification: kAXWindowMiniaturizedNotification, window: window)
284-
application?.unobserve(notification: kAXWindowDeminiaturizedNotification, window: window)
285-
286280
windows.regenerateActiveIDCache()
287281
windows.remove(window: window)
288282
}
@@ -381,11 +375,6 @@ extension WindowManager {
381375
}
382376

383377
private func add(window: Window, retries: Int = 5) {
384-
guard !windows.isWindowTracked(window) else {
385-
log.warning("skipping window")
386-
return
387-
}
388-
389378
guard window.shouldBeManaged() else {
390379
return
391380
}
@@ -395,6 +384,14 @@ extension WindowManager {
395384
return
396385
}
397386

387+
defer {
388+
windows.regenerateActiveIDCache()
389+
}
390+
391+
guard !windows.isWindowTracked(window) else {
392+
return
393+
}
394+
398395
switch application.defaultFloatForWindow(window) {
399396
case .unreliable where retries > 0:
400397
return DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
@@ -406,21 +403,8 @@ extension WindowManager {
406403
windows.setFloating(false, forWindow: window)
407404
}
408405

409-
windows.regenerateActiveIDCache()
410406
windows.add(window: window, atFront: userConfiguration.sendNewWindowsToMainPane())
411407

412-
application.observe(notification: kAXUIElementDestroyedNotification, window: window) { _ in
413-
self.remove(window: window)
414-
}
415-
application.observe(notification: kAXWindowMiniaturizedNotification, window: window) { _ in
416-
self.remove(window: window)
417-
418-
guard let screen = window.screen() else {
419-
return
420-
}
421-
self.markScreen(screen, forReflowWithChange: .remove(window: window))
422-
}
423-
424408
guard let screen = window.screen() else {
425409
return
426410
}

Amethyst/Model/ApplicationObservation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ struct ApplicationObservation<Delegate: ApplicationObservationDelegate> {
106106
/// A window is deminiaturized
107107
case windowDeminiaturized
108108

109+
/// A window is miniaturized
110+
case windowMiniaturized
111+
109112
/// The application has changed its focused window
110113
case focusedWindowChanged
111114

@@ -128,6 +131,8 @@ struct ApplicationObservation<Delegate: ApplicationObservationDelegate> {
128131
return kAXCreatedNotification
129132
case .windowDeminiaturized:
130133
return kAXWindowDeminiaturizedNotification
134+
case .windowMiniaturized:
135+
return kAXWindowMiniaturizedNotification
131136
case .focusedWindowChanged:
132137
return kAXFocusedWindowChangedNotification
133138
case .applicationActivated:
@@ -178,6 +183,7 @@ struct ApplicationObservation<Delegate: ApplicationObservationDelegate> {
178183
let notifications: [Notification] = [
179184
.created,
180185
.windowDeminiaturized,
186+
.windowMiniaturized,
181187
.focusedWindowChanged,
182188
.applicationActivated,
183189
.windowMoved,
@@ -244,6 +250,8 @@ struct ApplicationObservation<Delegate: ApplicationObservationDelegate> {
244250
delegate?.application(application, didFindPotentiallyNewWindow: window)
245251
case .windowDeminiaturized:
246252
delegate?.application(application, didAddWindow: window)
253+
case .windowMiniaturized:
254+
delegate?.application(application, didRemoveWindow: window)
247255
case .focusedWindowChanged:
248256
guard let focusedWindow = Window.currentlyFocused() else {
249257
return

0 commit comments

Comments
 (0)