fix: preview could sometimes be incorrectly positioned

This commit is contained in:
lwouis committed 2026-01-03 19:18:42 +01:00
1 parent bcb130e7eb
commit edc2f00603
2 files changed
+20 -15

No files matched your search

+2 -2
View File
@@ -97,13 +97,13 @@ class Window {
func refreshThumbnail(_ screenshot: CGImage) {
thumbnail = screenshot
if !App.app.appIsBeingUsed || !shouldShowTheUser { return }
if let size,
if let position, let size,
let view = (ThumbnailsView.recycledViews.first { $0.window_?.cgWindowId == cgWindowId }) {
if !view.thumbnail.isHidden {
let thumbnailSize = ThumbnailView.thumbnailSize(screenshot, false)
view.thumbnail.updateWithResizedCopy(screenshot, thumbnailSize)
}
App.app.previewPanel.updateImageIfShowing(cgWindowId, screenshot, size)
App.app.previewPanel.updateIfShowing(cgWindowId, screenshot, position, size)
}
}
+18 -13
View File
@@ -27,20 +27,10 @@ class PreviewPanel: NSPanel {
setAccessibilitySubrole(.unknown)
}
func updateImageIfShowing(_ id: CGWindowID?, _ preview: CGImage, _ size: CGSize) {
if isVisible && id == currentId {
previewView.updateWithResizedCopy(preview, size)
}
}
func show(_ id: CGWindowID, _ preview: CGImage, _ position: CGPoint, _ size: CGSize) {
func show(_ id: CGWindowID, _ image: CGImage, _ position: CGPoint, _ size: CGSize) {
if id != currentId {
previewView.updateWithResizedCopy(preview, 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)
// Always use the primary screen as reference since all coordinates are relative to it
frame.origin.y = NSScreen.screens.first!.frame.maxY - frame.maxY
setFrame(frame, display: false)
repositionAndResize(position, size)
previewView.updateWithResizedCopy(image, size)
}
if id != currentId || !isVisible {
if Preferences.previewFadeInAnimation {
@@ -60,6 +50,21 @@ class PreviewPanel: NSPanel {
level = NSWindow.Level(rawValue: App.app.thumbnailsPanel.level.rawValue - 1)
}
}
func updateIfShowing(_ id: CGWindowID?, _ image: CGImage, _ position: CGPoint, _ size: CGSize) {
if isVisible && id == currentId {
repositionAndResize(position, size)
previewView.updateWithResizedCopy(image, size)
}
}
private func repositionAndResize( _ position: CGPoint, _ size: CGSize) {
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)
// Always use the primary screen as reference since all coordinates are relative to it
frame.origin.y = NSScreen.screens.first!.frame.maxY - frame.maxY
setFrame(frame, display: false)
}
}
private class BorderView: NSView {