Skip to content

Commit

Permalink
feat: display windows partially on screen correctly (closes #727)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jan 25, 2021
1 parent 2447140 commit 2f92936
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/logic/Spaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Cocoa

class Spaces {
static var currentSpaceId = CGSSpaceID(1)
static var visibleSpaceIds = [CGSSpaceID]()
static var screenToVisibleSpaceMap = [ScreenUuid: CGSSpaceID]()
static var currentSpaceIndex = SpaceIndex(1)
static var isSingleSpace = true
static var idsAndIndexes: [(CGSSpaceID, SpaceIndex)] = allIdsAndIndexes()
Expand All @@ -14,7 +14,7 @@ class Spaces {
updateCurrentSpace()
refreshVisibleSpaces()
})
NSWorkspace.shared.notificationCenter.addObserver(forName: NSApplication.didChangeScreenParametersNotification , object: nil, queue: nil, using: { _ in
NSWorkspace.shared.notificationCenter.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil, using: { _ in
debugPrint("OS event", "didChangeScreenParametersNotification")
refreshVisibleSpaces()
})
Expand All @@ -29,11 +29,11 @@ class Spaces {
}

static func refreshVisibleSpaces() {
visibleSpaceIds = NSScreen.screens.compactMap {
screenToVisibleSpaceMap.removeAll()
NSScreen.screens.forEach {
if let uuid = $0.uuid() {
return CGSManagedDisplayGetCurrentSpace(cgsMainConnectionId, uuid)
screenToVisibleSpaceMap[uuid] = CGSManagedDisplayGetCurrentSpace(cgsMainConnectionId, uuid)
}
return nil
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,18 @@ class Windows {
!(!(Preferences.showFullscreenWindows[App.app.shortcutIndex] != .hide) && window.isFullscreen) &&
!(!(Preferences.showMinimizedWindows[App.app.shortcutIndex] != .hide) && window.isMinimized) &&
!(Preferences.spacesToShow[App.app.shortcutIndex] == .active && window.spaceId != Spaces.currentSpaceId) &&
!(Preferences.spacesToShow[App.app.shortcutIndex] == .visible && !Spaces.visibleSpaceIds.contains(window.spaceId)) &&
!(Preferences.spacesToShow[App.app.shortcutIndex] == .visible && !Spaces.screenToVisibleSpaceMap.values.contains(window.spaceId)) &&
!(Preferences.screensToShow[App.app.shortcutIndex] == .showingAltTab && !isOnScreen(window, screen)) &&
(Preferences.showTabsAsWindows || !window.isTabbed))
}

static func isOnScreen(_ window: Window, _ screen: NSScreen) -> Bool {
if let topLeftCorner = window.position, let size = window.size {
if let topLeftCorner = window.position, let size = window.size, let screenUuid = screen.uuid(), let screenSpaceId = Spaces.screenToVisibleSpaceMap[screenUuid] {
var screenFrameInQuartzCoordinates = screen.frame
screenFrameInQuartzCoordinates.origin.y = NSMaxY(NSScreen.screens[0].frame) - NSMaxY(screen.frame)
let windowRect = CGRect(origin: topLeftCorner, size: size)
return windowRect.intersects(screenFrameInQuartzCoordinates)
debugPrint(windowRect.intersects(screenFrameInQuartzCoordinates), screenSpaceId, window.spaceId)
return windowRect.intersects(screenFrameInQuartzCoordinates) && screenSpaceId == window.spaceId
}
return true
}
Expand Down

0 comments on commit 2f92936

Please sign in to comment.