Skip to content

Commit

Permalink
feat: improve display of very small windows (closes #3902)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Dec 6, 2024
1 parent 57e3a36 commit 9bafd03
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ui/main-window/ThumbnailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ThumbnailView: NSStackView {
thumbnail.image = element.icon?.copy() as? NSImage
thumbnail.image?.size = NSSize(width: 1024, height: 1024)
}
let thumbnailSize = ThumbnailView.thumbnailSize(thumbnail.image, screen)
let thumbnailSize = ThumbnailView.thumbnailSize(thumbnail.image, screen, false)
thumbnail.image?.size = thumbnailSize
thumbnail.frame.size = thumbnailSize
// for Accessibility > "speak items under the pointer"
Expand Down Expand Up @@ -331,7 +331,7 @@ class ThumbnailView: NSStackView {
if element.isWindowlessApp {
windowlessIcon.image = appIcon.image!.copy() as? NSImage
windowlessIcon.image?.size = NSSize(width: 1024, height: 1024)
let windowlessIconSize = ThumbnailView.thumbnailSize(windowlessIcon.image, screen)
let windowlessIconSize = ThumbnailView.thumbnailSize(windowlessIcon.image, screen, true)
windowlessIcon.image!.size = windowlessIconSize
windowlessIcon.frame.size = windowlessIconSize
windowlessIcon.needsDisplay = true
Expand Down Expand Up @@ -548,14 +548,18 @@ class ThumbnailView: NSStackView {
return (ThumbnailsPanel.maxThumbnailsHeight(screen) - Appearance.interCellPadding) / Appearance.rowsCount - Appearance.interCellPadding
}

static func thumbnailSize(_ image: NSImage?, _ screen: NSScreen) -> NSSize {
static func thumbnailSize(_ image: NSImage?, _ screen: NSScreen, _ isWindowlessApp: Bool) -> NSSize {
guard let image = image else { return NSSize(width: 0, height: 0) }
let thumbnailHeightMax = ThumbnailView.maxThumbnailHeight(screen)
- Appearance.edgeInsetsSize * 2
- Appearance.intraCellPadding
- Appearance.iconSize
let thumbnailWidthMax = ThumbnailView.maxThumbnailWidth(screen)
- Appearance.edgeInsetsSize * 2
// don't stretch very small windows; keep them 1:1 in the switcher
if !isWindowlessApp && image.size.width < thumbnailWidthMax && image.size.height < thumbnailHeightMax {
return image.size
}
let thumbnailHeight = min(image.size.height, thumbnailHeightMax)
let thumbnailWidth = min(image.size.width, thumbnailWidthMax)
let imageRatio = image.size.width / image.size.height
Expand Down

0 comments on commit 9bafd03

Please sign in to comment.