Skip to content

Commit

Permalink
fix: add rough downscaling when there are many windows (closes #69)
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 314801c commit ced5ee6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions alt-tab-macos/ui/Cell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,23 @@ class Cell: NSCollectionViewItem {
return vStackView
}

static func downscaleFactor() -> CGFloat {
let nCellsBeforePotentialOverflow = Preferences.nCellsRows * Preferences.minCellsPerRow
guard CGFloat(Windows.list.count) > nCellsBeforePotentialOverflow else { return 1 }
// TODO: replace this buggy heuristic with a correct implementation of downscaling
return nCellsBeforePotentialOverflow / (nCellsBeforePotentialOverflow + (sqrt(CGFloat(Windows.list.count) - nCellsBeforePotentialOverflow) * 2))
}

static func widthMax(_ screen: NSScreen) -> CGFloat {
return ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding
return (ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor()
}

static func widthMin(_ screen: NSScreen) -> CGFloat {
return ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding
return (ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor()
}

static func height(_ screen: NSScreen) -> CGFloat {
return ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding
return (ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding) * Cell.downscaleFactor()
}

static func width(_ image: NSImage?, _ screen: NSScreen) -> CGFloat {
Expand Down

0 comments on commit ced5ee6

Please sign in to comment.