From 657c9e5e8bf218307e0f6c8cd73413a0d3e9a0ad Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Thu, 3 Sep 2020 16:37:59 +0900 Subject: [PATCH] fix: issue when selecting windowless app from fullscreen window --- src/logic/Window.swift | 15 -------------- src/logic/events/AccessibilityEvents.swift | 24 ++++++++++------------ 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/logic/Window.swift b/src/logic/Window.swift index acf0f3699..0644d56d7 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -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() } @@ -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 diff --git a/src/logic/events/AccessibilityEvents.swift b/src/logic/events/AccessibilityEvents.swift index f8b9a305f..69f8b6c77 100644 --- a/src/logic/events/AccessibilityEvents.swift +++ b/src/logic/events/AccessibilityEvents.swift @@ -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) } }