Skip to content

Commit

Permalink
fix: issue when selecting windowless app from fullscreen window
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Sep 4, 2020
1 parent 58e9026 commit 657c9e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
15 changes: 0 additions & 15 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class Window {
self.spaceIndex = Spaces.currentSpaceIndex
self.isFullscreen = isFullscreen
self.isMinimized = isMinimized
self.isOnAllSpaces = false
self.position = position
self.title = bestEffortTitle(axTitle)
self.isTabbed = false
if !Preferences.hideThumbnails {
refreshThumbnail()
}
Expand Down Expand Up @@ -81,19 +79,6 @@ class Window {
thumbnailFullSize = thumbnail!.size
}

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
else if spaceId == Spaces.currentSpaceId &&
// quirk with AltTab listing no windows at first; we force it to false
application.runningApplication.bundleIdentifier != App.id {
isTabbed = true
}
}

func close() {
if isWindowlessApp { return }
BackgroundWork.accessibilityCommandsQueue.asyncWithCap { [weak self] in
Expand Down
24 changes: 11 additions & 13 deletions src/logic/events/AccessibilityEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ func handleEvent(_ type: String, _ element: AXUIElement) throws {
}

private func focusedUiElementChanged(_ element: AXUIElement, _ pid: pid_t) throws {
let appAxUiElement = AXUIElementCreateApplication(pid)
if let currentWindows = try appAxUiElement.windows() {
DispatchQueue.main.async {
let windows = Windows.list.filter { w in
// for AXUIElement of apps, CFEqual or == don't work; looks like a Cocoa bug
let isFromApp = w.application.pid == 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 oldIsTabbed = w.isTabbed
w.refreshIsTabbed(currentWindows)
return oldIsTabbed != w.isTabbed
}
return false
if let app = NSRunningApplication(processIdentifier: pid) {
let currentWindows = try AXUIElementCreateApplication(pid).windows()
let windows = Windows.list.filter { w in
if w.application.pid == pid && pid != ProcessInfo.processInfo.processIdentifier &&
w.spaceId == Spaces.currentSpaceId {
let oldIsTabbed = w.isTabbed
w.isTabbed = (currentWindows?.first { $0 == w.axUiElement } == nil) ?? true
return oldIsTabbed != w.isTabbed
}
return false
}
DispatchQueue.main.async {
App.app.refreshOpenUi(windows)
}
}
Expand Down

0 comments on commit 657c9e5

Please sign in to comment.