fix: thumbnail sizes could be wrong when switching between screens

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-09-05 04:01:32 +09:00
1 parent 6db893c4e7
commit e13a263b08
3 files changed
+12 -10

No files matched your search

+2
View File
@@ -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
@@ -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]) {
+3 -4
View File
@@ -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
}
}
}
+7 -6
View File
@@ -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)