diff --git a/alt-tab-macos/logic/Spaces.swift b/alt-tab-macos/logic/Spaces.swift index 2f472ce9..e502819b 100644 --- a/alt-tab-macos/logic/Spaces.swift +++ b/alt-tab-macos/logic/Spaces.swift @@ -26,7 +26,7 @@ class Spaces { static func updateCurrentSpace() { currentSpaceId = CGSManagedDisplayGetCurrentSpace(cgsMainConnectionId, Screen.mainUuid()) currentSpaceIndex = allIdsAndIndexes().first { $0.0 == currentSpaceId }!.1 - debugPrint("current space", currentSpaceId) + debugPrint("Current space", currentSpaceId) } static func allIdsAndIndexes() -> [(CGSSpaceID, SpaceIndex)] { diff --git a/alt-tab-macos/ui/Cell.swift b/alt-tab-macos/ui/Cell.swift index bc17da2d..b622af07 100644 --- a/alt-tab-macos/ui/Cell.swift +++ b/alt-tab-macos/ui/Cell.swift @@ -42,7 +42,8 @@ class Cell: NSCollectionViewItem { func updateRecycledCellWithNewContent(_ element: Window, _ mouseDownCallback: @escaping MouseDownCallback, _ mouseMovedCallback: @escaping MouseMovedCallback, _ screen: NSScreen) { window = element thumbnail.image = element.thumbnail - let thumbnailSize = Cell.thumbnailSize(element.thumbnail, screen) + let (thumbnailWidth, thumbnailHeight) = Cell.thumbnailSize(element.thumbnail, screen) + let thumbnailSize = NSSize(width: thumbnailWidth.rounded(), height: thumbnailHeight.rounded()) thumbnail.image?.size = thumbnailSize thumbnail.frame.size = thumbnailSize appIcon.image = element.icon @@ -110,27 +111,22 @@ class Cell: NSCollectionViewItem { } static func widthMax(_ screen: NSScreen) -> CGFloat { - return floor((ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.interCellPadding) * Cell.downscaleFactor()) + return (ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.interCellPadding) * Cell.downscaleFactor() } static func widthMin(_ screen: NSScreen) -> CGFloat { - return floor((ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.interCellPadding) * Cell.downscaleFactor()) + return (ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.interCellPadding) * Cell.downscaleFactor() } static func height(_ screen: NSScreen) -> CGFloat { - return floor((ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.interCellPadding) * Cell.downscaleFactor()) + return (ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.interCellPadding) * Cell.downscaleFactor() } static func width(_ image: NSImage?, _ screen: NSScreen) -> CGFloat { - return floor(max(thumbnailSize(image, screen).width + Preferences.intraCellPadding * 2, Cell.widthMin(screen))) + return max(thumbnailSize(image, screen).0 + Preferences.intraCellPadding * 2, Cell.widthMin(screen)) } - static func thumbnailSize(_ image: NSImage?, _ screen: NSScreen) -> NSSize { - let (width, height) = thumbnailSize_(image, screen) - return NSSize(width: floor(width), height: floor(height)) - } - - static func thumbnailSize_(_ image: NSImage?, _ screen: NSScreen) -> (CGFloat, CGFloat) { + static func thumbnailSize(_ image: NSImage?, _ screen: NSScreen) -> (CGFloat, CGFloat) { let thumbnailWidthMin = Cell.widthMin(screen) - Preferences.intraCellPadding * 2 let thumbnailHeightMax = Cell.height(screen) - Preferences.intraCellPadding * 3 - Preferences.iconSize let thumbnailWidthMax = Cell.widthMax(screen) - Preferences.intraCellPadding * 2 diff --git a/alt-tab-macos/ui/CollectionViewCenterFlowLayout.swift b/alt-tab-macos/ui/CollectionViewCenterFlowLayout.swift index 7adc6a32..1e09dfa7 100644 --- a/alt-tab-macos/ui/CollectionViewCenterFlowLayout.swift +++ b/alt-tab-macos/ui/CollectionViewCenterFlowLayout.swift @@ -45,7 +45,7 @@ class CollectionViewCenterFlowLayout: NSCollectionViewFlowLayout { } private func shiftCenteredElementToTheLeft(_ attributes: [NSCollectionViewLayoutAttributes], _ widestRow: CGFloat, _ totalHeight: CGFloat) { - let horizontalMargin = floor((collectionView!.frame.size.width - widestRow) / 2) + let horizontalMargin = ((collectionView!.frame.size.width - widestRow) / 2).rounded() for attribute in attributes { attribute.frame.origin.x -= horizontalMargin } diff --git a/alt-tab-macos/ui/ThumbnailsPanel.swift b/alt-tab-macos/ui/ThumbnailsPanel.swift index 47fa1dec..67028899 100644 --- a/alt-tab-macos/ui/ThumbnailsPanel.swift +++ b/alt-tab-macos/ui/ThumbnailsPanel.swift @@ -75,7 +75,7 @@ class ThumbnailsPanel: NSPanel, NSCollectionViewDataSource, NSCollectionViewDele func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { guard indexPath.item < Windows.list.count else { return .zero } - return NSSize(width: Cell.width(Windows.list[indexPath.item].thumbnail, currentScreen!), height: Cell.height(currentScreen!)) + return NSSize(width: Cell.width(Windows.list[indexPath.item].thumbnail, currentScreen!).rounded(), height: Cell.height(currentScreen!).rounded()) } func highlightCell() { @@ -97,7 +97,7 @@ class ThumbnailsPanel: NSPanel, NSCollectionViewDataSource, NSCollectionViewDele let layout = collectionView.collectionViewLayout as! CollectionViewCenterFlowLayout if uiWorkShouldBeDone { layout.currentScreen = screen } if uiWorkShouldBeDone { layout.invalidateLayout() } - if uiWorkShouldBeDone { collectionView.setFrameSize(NSSize(width: ThumbnailsPanel.widthMax(screen), height: ThumbnailsPanel.heightMax(screen))) } + if uiWorkShouldBeDone { collectionView.setFrameSize(NSSize(width: ThumbnailsPanel.widthMax(screen).rounded(), height: ThumbnailsPanel.heightMax(screen).rounded())) } if uiWorkShouldBeDone { collectionView.reloadData() } if uiWorkShouldBeDone { collectionView.layoutSubtreeIfNeeded() } if uiWorkShouldBeDone { collectionView.setFrameSize(NSSize(width: layout.widestRow!, height: layout.totalHeight!)) } @@ -108,14 +108,10 @@ class ThumbnailsPanel: NSPanel, NSCollectionViewDataSource, NSCollectionViewDele } static func widthMax(_ screen: NSScreen) -> CGFloat { - return floor(screen.frame.width * Preferences.maxScreenUsage - Preferences.windowPadding * 2) + return screen.frame.width * Preferences.maxScreenUsage - Preferences.windowPadding * 2 } static func heightMax(_ screen: NSScreen) -> CGFloat { - return floor(screen.frame.height * Preferences.maxScreenUsage - Preferences.windowPadding * 2) - } - - static func heightMin(_ screen: NSScreen) -> CGFloat { - return floor(Cell.height(screen) - Preferences.windowPadding * 2) + return screen.frame.height * Preferences.maxScreenUsage - Preferences.windowPadding * 2 } }