fix: detect safari fullscreen windows better (closes #3384)

This commit is contained in:
lwouis
2024-05-29 23:49:23 +02:00
parent 523bcbb6e3
commit c3006c69a6
3 changed files with 20 additions and 27 deletions
+14 -12
View File
@@ -78,10 +78,15 @@ class Application: NSObject {
let position = try axWindow.position()
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if let window = self.addWindow(axWindow, wid, title, isFullscreen, isMinimized, position, size) {
if let window = (Windows.list.first { $0.isEqualRobust(axWindow, wid) }) {
window.title = title
window.size = size
window.isFullscreen = isFullscreen
window.isMinimized = isMinimized
window.position = position
} else {
let window = self.addWindow(axWindow, wid, title, isFullscreen, isMinimized, position, size)
App.app.refreshOpenUi([window])
} else if let window = self.addWindowslessAppsIfNeeded() {
App.app.refreshOpenUi(window)
}
}
}
@@ -143,16 +148,13 @@ class Application: NSObject {
}
}
private func addWindow(_ axUiElement: AXUIElement, _ wid: CGWindowID, _ axTitle: String?, _ isFullscreen: Bool, _ isMinimized: Bool, _ position: CGPoint?, _ size: CGSize?) -> Window? {
if (Windows.list.firstIndex { $0.isEqualRobust(axUiElement, wid) }) == nil {
let window = Window(axUiElement, self, wid, axTitle, isFullscreen, isMinimized, position, size)
Windows.appendAndUpdateFocus(window)
if App.app.appIsBeingUsed {
Windows.cycleFocusedWindowIndex(1)
}
return window
private func addWindow(_ axUiElement: AXUIElement, _ wid: CGWindowID, _ axTitle: String?, _ isFullscreen: Bool, _ isMinimized: Bool, _ position: CGPoint?, _ size: CGSize?) -> Window {
let window = Window(axUiElement, self, wid, axTitle, isFullscreen, isMinimized, position, size)
Windows.appendAndUpdateFocus(window)
if App.app.appIsBeingUsed {
Windows.cycleFocusedWindowIndex(1)
}
return nil
return window
}
private func observeEvents() {
+3
View File
@@ -15,6 +15,9 @@ class Spaces {
// if UI was kept open during Space transition, the Spaces may be obsolete; we refresh them
Windows.list.forEachAsync { $0.updatesWindowSpace() }
// from macos 12.2 beta onwards, we can't get other-space windows; grabbing windows when switching spaces mitigates the issue
// also, updating windows on Space transition works around an issue with Safari where its fullscreen windows spawn not in fullscreen.
// resize/move events happen and the window is still not fullscreen. AltTab doesn't get informed that the window is later fullscreen.
// updating on Space change helps correct the window to being fullscreen
Applications.manuallyUpdateWindows()
})
NSWorkspace.shared.notificationCenter.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil, using: { _ in
+3 -15
View File
@@ -23,8 +23,8 @@ fileprivate func handleEvent(_ type: String, _ element: AXUIElement) throws {
case kAXWindowMiniaturizedNotification,
kAXWindowDeminiaturizedNotification: try windowMiniaturizedOrDeminiaturized(element, type)
case kAXTitleChangedNotification: try windowTitleChanged(element, pid)
case kAXWindowResizedNotification: try windowResized(element)
case kAXWindowMovedNotification: try windowMoved(element)
case kAXWindowResizedNotification,
kAXWindowMovedNotification: try windowResizedOrMoved(element)
default: return
}
}
@@ -174,7 +174,7 @@ fileprivate func windowTitleChanged(_ element: AXUIElement, _ pid: pid_t) throws
}
}
fileprivate func windowResized(_ element: AXUIElement) throws {
fileprivate func windowResizedOrMoved(_ element: AXUIElement) throws {
// TODO: only trigger this at the end of the resize, not on every tick
// currently resizing a window will lag AltTab as it triggers too much UI work
if let wid = try element.cgWindowId() {
@@ -194,15 +194,3 @@ fileprivate func windowResized(_ element: AXUIElement) throws {
}
}
}
fileprivate func windowMoved(_ element: AXUIElement) throws {
if let wid = try element.cgWindowId() {
let position = try element.position()
DispatchQueue.main.async {
if let window = (Windows.list.first { $0.isEqualRobust(element, wid) }) {
window.position = position
App.app.refreshOpenUi([window])
}
}
}
}