diff --git a/src/logic/Window.swift b/src/logic/Window.swift index 2d775490..2da564cf 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -7,7 +7,6 @@ class Window { var creationOrder = Int.zero var title: String! var thumbnail: NSImage? - var thumbnailFullSize: NSSize? var icon: NSImage? { get { application.icon } } var shouldShowTheUser = true var isTabbed: Bool = false @@ -99,7 +98,6 @@ class Window { func refreshThumbnail(_ screenshot: NSImage?) { thumbnail = screenshot - thumbnailFullSize = screenshot?.size if App.app.appIsBeingUsed && shouldShowTheUser { if let index = (Windows.list.firstIndex { $0.cgWindowId == cgWindowId }) { let view = ThumbnailsView.recycledViews[index] @@ -113,13 +111,6 @@ class Window { } } - func getPreview() -> (NSImage, NSSize)? { - if let thumbnail = thumbnail, let thumbnailFullSize = thumbnailFullSize { - return (thumbnail, thumbnailFullSize) - } - return nil - } - func canBeClosed() -> Bool { return !isWindowlessApp } diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index cdce3e1d..9629ab37 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -147,20 +147,17 @@ class Windows { } static func previewFocusedWindowIfNeeded() { - guard - Preferences.previewFocusedWindow, - !Preferences.onlyShowApplications(), - App.app.appIsBeingUsed && App.app.thumbnailsPanel.isKeyWindow, - let window = focusedWindow(), - let id = window.cgWindowId, - let (preview, previewSize) = window.getPreview(), - let position = window.position, - let size = window.size - else { + if Preferences.previewFocusedWindow && !Preferences.onlyShowApplications() + && App.app.appIsBeingUsed && App.app.thumbnailsPanel.isKeyWindow, + let window = focusedWindow(), + let id = window.cgWindowId, + let thumbnail = window.thumbnail, + let position = window.position, + let size = window.size { + App.app.previewPanel.show(id, thumbnail, position, size) + } else { App.app.previewPanel.orderOut(nil) - return } - App.app.previewPanel.show(id, preview, previewSize, position, size) } static func voiceOverWindow(_ windowIndex: Int = focusedWindowIndex) { diff --git a/src/ui/main-window/PreviewPanel.swift b/src/ui/main-window/PreviewPanel.swift index ddd9b30a..4cc96be2 100644 --- a/src/ui/main-window/PreviewPanel.swift +++ b/src/ui/main-window/PreviewPanel.swift @@ -5,6 +5,11 @@ class PreviewPanel: NSPanel { private let borderView = BorderView() private var currentId: CGWindowID? + /// this allows the window to be above the menubar when its origin.y is set to 0 + override func constrainFrameRect(_ frameRect: NSRect, to screen: NSScreen?) -> NSRect { + frameRect + } + convenience init() { self.init(contentRect: .zero, styleMask: [.nonactivatingPanel, .titled, .fullSizeContentView], backing: .buffered, defer: false) isFloatingPanel = true @@ -18,17 +23,14 @@ class PreviewPanel: NSPanel { previewView.addSubview(borderView) // triggering AltTab before or during Space transition animation brings the window on the Space post-transition collectionBehavior = .canJoinAllSpaces - // 2nd highest level possible; this allows the app to go on top of context menus - // highest level is .screenSaver but makes drag and drop on top the main window impossible - level = .popUpMenu // helps filter out this window from the thumbnails setAccessibilitySubrole(.unknown) } - func show(_ id: CGWindowID, _ preview: NSImage, _ previewSize: NSSize, _ position: CGPoint, _ size: CGSize) { + func show(_ id: CGWindowID, _ preview: NSImage, _ position: CGPoint, _ size: CGSize) { if id != currentId { previewView.image = preview - previewView.image!.size = previewSize + 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) // Always use the primary screen as reference since all coordinates are relative to it @@ -48,7 +50,7 @@ class PreviewPanel: NSPanel { // 2. Select a window in the switcher that is on the same monitor as the thumbnails panel, and whose position overlaps with the thumbnails panel // 3. For a single frame, the preview of the newly selected window can appear above the thumbnails panel before going back underneath it // Simply using order(.below) is not sufficient to prevent this brief flicker. We explicitly set the preview panel's window level to be one below the thumbnails panel - App.app.previewPanel.level = NSWindow.Level(rawValue: App.app.previewPanel.level.rawValue - 1) + App.app.previewPanel.level = NSWindow.Level(rawValue: App.app.thumbnailsPanel.level.rawValue - 1) } } }