Skip to content

Commit

Permalink
fix: thumbnail sizes could be wrong when switching between screens
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Sep 4, 2020
1 parent 6db893c commit e13a263
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Window {
var cgWindowId: CGWindowID
var title: String!
var thumbnail: NSImage?
var thumbnailFullSize: NSSize?
var icon: NSImage? { get { application.icon } }
var shouldShowTheUser = true
var isTabbed: Bool = false
Expand Down Expand Up @@ -66,6 +67,7 @@ class Window {
func refreshThumbnail() {
guard let cgImage = cgWindowId.screenshot() else { return }
thumbnail = NSImage(cgImage: cgImage, size: NSSize(width: cgImage.width, height: cgImage.height))
thumbnailFullSize = thumbnail!.size
}

func refreshIsTabbed(_ currentWindows: [AXUIElement]) {
Expand Down
7 changes: 3 additions & 4 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ class Windows {
DispatchQueue.main.async {
let view = ThumbnailsView.recycledViews[currentIndex]
if view.thumbnail.image != window.thumbnail {
let oldSize = view.thumbnail.frame.size
view.thumbnail.image = window.thumbnail
let (thumbnailWidth, thumbnailHeight) = ThumbnailView.thumbnailSize(window.thumbnail, screen)
let thumbnailSize = NSSize(width: thumbnailWidth.rounded(), height: thumbnailHeight.rounded())
view.thumbnail.image?.size = thumbnailSize
view.thumbnail.frame.size = thumbnailSize
view.thumbnail.image?.size = oldSize
view.thumbnail.frame.size = oldSize
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/ui/main-window/ThumbnailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ class ThumbnailView: NSStackView {

func updateRecycledCellWithNewContent(_ element: Window, _ index: Int, _ newHeight: CGFloat, _ screen: NSScreen) {
window_ = element
if thumbnail.image != element.thumbnail {
thumbnail.image = element.thumbnail
let (thumbnailWidth, thumbnailHeight) = ThumbnailView.thumbnailSize(element.thumbnail, screen)
let thumbnailSize = NSSize(width: thumbnailWidth.rounded(), height: thumbnailHeight.rounded())
thumbnail.image?.size = thumbnailSize
thumbnail.frame.size = thumbnailSize
thumbnail.image = element.thumbnail
if let image = thumbnail.image {
image.size = element.thumbnailFullSize!
}
let (thumbnailWidth, thumbnailHeight) = ThumbnailView.thumbnailSize(element.thumbnail, screen)
let thumbnailSize = NSSize(width: thumbnailWidth.rounded(), height: thumbnailHeight.rounded())
thumbnail.image?.size = thumbnailSize
thumbnail.frame.size = thumbnailSize
if appIcon.image != element.icon {
appIcon.image = element.icon
let appIconSize = NSSize(width: Preferences.iconSize, height: Preferences.iconSize)
Expand Down

0 comments on commit e13a263

Please sign in to comment.