Skip to content

Commit

Permalink
fix: don't upscale thumbnails of small windows
Browse files Browse the repository at this point in the history
  • Loading branch information
louis.pontoise authored and lwouis committed Mar 10, 2020
1 parent 01e33b0 commit 0bc7472
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions alt-tab-macos/ui/Cell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ class Cell: NSCollectionViewItem {
}

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
guard let image = image else { return (thumbnailWidthMin, thumbnailHeightMax) }
guard let image = image else { return (Cell.widthMin(screen) - Preferences.intraCellPadding * 2, thumbnailHeightMax) }
let thumbnailHeight = min(image.size.height, thumbnailHeightMax)
let thumbnailWidth = min(image.size.width, thumbnailWidthMax)
let imageRatio = image.size.width / image.size.height
let thumbnailRatio = thumbnailWidthMax / thumbnailHeightMax
let thumbnailRatio = thumbnailWidth / thumbnailHeight
if thumbnailRatio > imageRatio {
return (image.size.width * thumbnailHeightMax / image.size.height, thumbnailHeightMax)
return (image.size.width * thumbnailHeight / image.size.height, thumbnailHeight)
}
return (thumbnailWidthMax, image.size.height * thumbnailWidthMax / image.size.width)
return (thumbnailWidth, image.size.height * thumbnailWidth / image.size.width)
}
}

0 comments on commit 0bc7472

Please sign in to comment.