Skip to content

Commit

Permalink
fix: show windows which are opened in fullscreen (closes #335)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed May 21, 2020
1 parent 408b800 commit 2674c8f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ extension AXUIElement {
return attribute(kAXWindowsAttribute, [AXUIElement].self)
}

func isTabbed(_ window: AXUIElement) -> Bool {
return windows()?.first { $0 == window } == nil
func isTabbed(_ app: AXUIElement, _ spaceId: CGSSpaceID) -> Bool {
// 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() &&
app.windows()?.first { $0 == self } == nil
}

func isMinimized() -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions src/logic/DebugProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class DebugProfile {
("isMinimized", String(window.isMinimized)),
("isHidden", String(window.isHidden)),
("isOnAllSpaces", String(window.isOnAllSpaces)),
("spaceId", window.spaceId.flatMap { String($0) } ?? "nil"),
("spaceIndex", window.spaceIndex.flatMap { String($0) } ?? "nil"),
("spaceId", String(window.spaceId)),
("spaceIndex", String(window.spaceIndex)),
])
}

Expand Down
10 changes: 5 additions & 5 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Window {
var isHidden: Bool
var isMinimized: Bool
var isOnAllSpaces: Bool
var spaceId: CGSSpaceID?
var spaceIndex: SpaceIndex?
var spaceId: CGSSpaceID
var spaceIndex: SpaceIndex
var axUiElement: AXUIElement
var application: Application
var axObserver: AXObserver?
Expand All @@ -30,12 +30,12 @@ class Window {
self.axUiElement = axUiElement
self.application = application
self.cgWindowId = axUiElement.cgWindowId()
self.spaceId = Spaces.currentSpaceId
self.spaceIndex = Spaces.currentSpaceIndex
self.icon = application.runningApplication.icon
self.isTabbed = application.axUiElement!.isTabbed(axUiElement)
self.isTabbed = axUiElement.isTabbed(application.axUiElement!, spaceId)
self.isHidden = application.runningApplication.isHidden
self.isMinimized = axUiElement.isMinimized()
self.spaceId = Spaces.currentSpaceId
self.spaceIndex = Spaces.currentSpaceIndex
self.isOnAllSpaces = false
self.title = Window.bestEffortTitle(axUiElement, cgWindowId, application)
debugPrint("Adding window", cgWindowId, title, application.runningApplication.bundleIdentifier ?? "nil", Spaces.currentSpaceId, Spaces.currentSpaceIndex)
Expand Down
5 changes: 2 additions & 3 deletions src/logic/events/AccessibilityEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ func axObserverCallback(observer: AXObserver, element: AXUIElement, notification

private func focusedUiElementChanged(_ element: AXUIElement, _ applicationPointer: UnsafeMutableRawPointer?) {
// this event is the only opportunity we have to check if a window became a tab, or a tab became a window
// we can only detect tabs for windows on the current space, as AXUIElement.windows() only reports current space windows
let application = Unmanaged<Application>.fromOpaque(applicationPointer!).takeUnretainedValue()
Windows.list.forEach {
if $0.spaceId == Spaces.currentSpaceId && $0.application == application {
$0.isTabbed = application.axUiElement!.isTabbed($0.axUiElement)
if $0.application == application {
$0.isTabbed = $0.axUiElement.isTabbed(application.axUiElement!, $0.spaceId)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ class App: NSApplication, NSApplicationDelegate {
debugPrint("showUiOrCycleSelection: isFirstSummon")
isFirstSummon = false
if Windows.list.count == 0 || CGWindow.isMissionControlActive() { hideUi(); return }
// TODO: find a way to update isSingleSpace by listening to space creation, instead of on every trigger
// TODO: find a way to update space info when spaces are changed, instead of on every trigger
Spaces.idsAndIndexes = Spaces.allIdsAndIndexes()
// TODO: find a way to update space index when windows are moved to another space, instead of on every trigger
Windows.updateSpaces()
let screen = Screen.preferred()
Windows.refreshWhichWindowsToShowTheUser(screen)
Expand Down
4 changes: 2 additions & 2 deletions src/ui/main-window/ThumbnailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class ThumbnailView: NSStackView {
}
assignIfDifferent(&hiddenIcon.isHidden, !element.isHidden)
assignIfDifferent(&minimizedIcon.isHidden, !element.isMinimized)
assignIfDifferent(&spaceIcon.isHidden, element.spaceIndex == nil || Spaces.isSingleSpace || Preferences.hideSpaceNumberLabels)
assignIfDifferent(&spaceIcon.isHidden, Spaces.isSingleSpace || Preferences.hideSpaceNumberLabels)
if !spaceIcon.isHidden {
if element.isOnAllSpaces {
spaceIcon.setStar()
} else {
spaceIcon.setNumber(UInt32(element.spaceIndex!))
spaceIcon.setNumber(UInt32(element.spaceIndex))
}
}
assignIfDifferent(&frame.size.width, max(thumbnail.frame.size.width + Preferences.intraCellPadding * 2, ThumbnailView.widthMin(screen)))
Expand Down

0 comments on commit 2674c8f

Please sign in to comment.