fix: app icons could sometimes be at the wrong size
This commit is contained in:
1 parent
0f2c0e794c
commit
d5d131185e
4 files changed
+16
-20
No files matched your search
@@ -195,12 +195,8 @@ extension DispatchQoS {
|
||||
|
||||
extension NSImageView {
|
||||
func setSize(_ size: NSSize) {
|
||||
image?.size = size
|
||||
frame.size = size
|
||||
// TODO: NSImageView does some internal magic, and ends up with constraints. We need to add our own to force its size
|
||||
// We can't update .image.size because we share the image between multiple NSImageViews
|
||||
// I wish there was a better way to only set the frame.size
|
||||
addOrUpdateConstraint(widthAnchor, size.width)
|
||||
addOrUpdateConstraint(heightAnchor, size.height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +210,12 @@ extension NSTextField {
|
||||
}
|
||||
|
||||
extension NSImage {
|
||||
/// if an image can be used in different contexts (e.g. multiple NSTextViews), it's safer to copy it
|
||||
/// see https://www.noodlesoft.com/blog/2011/04/15/the-proper-care-and-feeding-of-nsimage/
|
||||
func copyToSeparateContexts() -> NSImage {
|
||||
return copy() as! NSImage
|
||||
}
|
||||
|
||||
// NSImage(named) caches/reuses NSImage objects; we force separate instances of images by using copy()
|
||||
static func initCopy(_ name: String) -> NSImage {
|
||||
return NSImage(named: name)!.copy() as! NSImage
|
||||
|
||||
@@ -104,10 +104,9 @@ class Window {
|
||||
if let index = (Windows.list.firstIndex { $0.cgWindowId == cgWindowId }) {
|
||||
let view = ThumbnailsView.recycledViews[index]
|
||||
if !view.thumbnail.isHidden {
|
||||
view.thumbnail.image = thumbnail
|
||||
view.thumbnail.image = thumbnail?.copyToSeparateContexts()
|
||||
let thumbnailSize = ThumbnailView.thumbnailSize(thumbnail, false)
|
||||
view.thumbnail.image?.size = thumbnailSize
|
||||
view.thumbnail.frame.size = thumbnailSize
|
||||
view.thumbnail.setSize(thumbnailSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class PreviewPanel: NSPanel {
|
||||
|
||||
func show(_ id: CGWindowID, _ preview: NSImage, _ position: CGPoint, _ size: CGSize) {
|
||||
if id != currentId {
|
||||
previewView.image = preview
|
||||
previewView.image = preview.copyToSeparateContexts()
|
||||
previewView.image!.size = size
|
||||
var frame = NSRect(origin: position, size: size)
|
||||
// Flip Y coordinate from Quartz (0,0 at bottom-left) to Cocoa coordinates (0,0 at top-left)
|
||||
|
||||
@@ -299,19 +299,14 @@ class ThumbnailView: FlippedView {
|
||||
}
|
||||
|
||||
private func updateThumbnail(_ element: Window) {
|
||||
// we need to reset the original size, otherwise it may be too small and not get resized
|
||||
// this can happen when switching from one screen to another for example
|
||||
if let screenshot = element.thumbnail, let thumbnailFullSize = element.thumbnailFullSize {
|
||||
screenshot.size = thumbnailFullSize
|
||||
}
|
||||
if !thumbnail.isHidden && thumbnail != element.thumbnail {
|
||||
if let screenshot = element.thumbnail {
|
||||
thumbnail.image = screenshot
|
||||
} else if let appIconFallback = element.icon {
|
||||
thumbnail.image = screenshot.copyToSeparateContexts()
|
||||
} else {
|
||||
thumbnail.image = element.icon?.copyToSeparateContexts()
|
||||
// if no thumbnail, show appIcon instead
|
||||
// .icon is always 32x32 by default. We scale it so it can be "thumbnail-ed" down
|
||||
appIconFallback.size = NSSize(width: 1024, height: 1024)
|
||||
thumbnail.image = appIconFallback
|
||||
thumbnail.setSize(NSSize(width: 1024, height: 1024))
|
||||
}
|
||||
// for Accessibility > "speak items under the pointer"
|
||||
thumbnail.setAccessibilityLabel(element.title)
|
||||
@@ -321,7 +316,7 @@ class ThumbnailView: FlippedView {
|
||||
private func updateAppIcon(_ element: Window, _ title: String) -> Bool {
|
||||
let appIconChanged = appIcon.image != element.icon
|
||||
if appIconChanged {
|
||||
appIcon.image = element.icon
|
||||
appIcon.image = element.icon?.copyToSeparateContexts()
|
||||
appIcon.setAccessibilityLabel(title)
|
||||
}
|
||||
return appIconChanged
|
||||
@@ -362,7 +357,7 @@ class ThumbnailView: FlippedView {
|
||||
setAccessibilityHelp(getAccessibilityHelp(element.application.runningApplication.localizedName, element.dockLabel))
|
||||
}
|
||||
if element.isWindowlessApp && windowlessIcon.image != element.icon {
|
||||
windowlessIcon.image = element.icon
|
||||
windowlessIcon.image = element.icon?.copyToSeparateContexts()
|
||||
}
|
||||
windowControlIcons.forEach { $0.window_ = element }
|
||||
showOrHideWindowControls(false)
|
||||
|
||||
Reference in new issue
Block a user