Skip to content

Commit

Permalink
fix: tabs would sometimes show as separate windows (closes #383)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jul 8, 2020
1 parent 4ff5d89 commit c03d48f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 6 additions & 8 deletions src/logic/events/AccessibilityEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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]])
Expand Down

0 comments on commit c03d48f

Please sign in to comment.