fix: tabs would sometimes show as separate windows (closes #383)

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-07-08 20:30:46 +09:00
1 parent 4ff5d89429
commit c03d48f239
2 files changed
+13 -11

No files matched your search

+7 -3
View File
@@ -68,11 +68,15 @@ class Window {
thumbnail = NSImage(cgImage: cgImage, size: NSSize(width: cgImage.width, height: cgImage.height))
}
func getIsTabbed(_ currentWindows: [AXUIElement]?) -> Bool {
func refreshIsTabbed(_ currentWindows: [AXUIElement]) {
if (currentWindows.first { $0 == axUiElement } != nil) {
isTabbed = false
}
// we can only detect tabs for windows on the current space, as AXUIElement.windows() only reports current space windows
// also, windows that start in fullscreen will have the wrong spaceID at that point in time, so we check if they are fullscreen too
return spaceId == Spaces.currentSpaceId && !isFullscreen &&
currentWindows?.first { $0 == axUiElement } == nil
else if spaceId == Spaces.currentSpaceId {
isTabbed = true
}
}
func close() {
+6 -8
View File
@@ -47,16 +47,14 @@ private func focusedUiElementChanged(_ element: AXUIElement, _ pid: pid_t) throw
let appAxUiElement = AXUIElementCreateApplication(pid)
if let currentWindows = try appAxUiElement.windows() {
DispatchQueue.main.async {
let windows = Windows.list.filter {
let windows = Windows.list.filter { w in
// for AXUIElement of apps, CFEqual or == don't work; looks like a Cocoa bug
let isFromApp = $0.application.runningApplication.processIdentifier == pid
let isFromApp = w.application.runningApplication.processIdentifier == pid
if isFromApp {
// this event is the only opportunity we have to check if a window became a tab, or a tab became a window
let isTabbedNew = $0.getIsTabbed(currentWindows)
if $0.isTabbed != isTabbedNew {
$0.isTabbed = isTabbedNew
return true
}
let oldIsTabbed = w.isTabbed
w.refreshIsTabbed(currentWindows)
return oldIsTabbed != w.isTabbed
}
return false
}
@@ -128,7 +126,7 @@ private func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) throws {
Windows.list.insertAndScaleRecycledPool(Windows.list.remove(at: existingIndex), at: 0)
App.app.refreshOpenUi([Windows.list[0], Windows.list[existingIndex]])
} else if let runningApp = NSRunningApplication(processIdentifier: pid),
element.isActualWindow(runningApp, wid, isOnNormalLevel, axTitle, subrole, role),
element.isActualWindow(runningApp, wid, isOnNormalLevel, axTitle, subrole, role),
let app = (Applications.list.first { $0.runningApplication.processIdentifier == pid }) {
Windows.list.insertAndScaleRecycledPool(Window(element, app, wid, axTitle, isFullscreen, isMinimized, position), at: 0)
App.app.refreshOpenUi([Windows.list[0]])