Skip to content

Commit

Permalink
[SharedPreviewWindowCoordinator] add fall back (#186)
Browse files Browse the repository at this point in the history
restore fallback to mouse position behavior if getting the icon's frame fails (e.g., returns zero, is not found)
  • Loading branch information
chrisharper22 authored Jul 15, 2024
1 parent 02693b9 commit ef3ec02
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ final class SharedPreviewWindowCoordinator: NSWindow {
// Calculate window position based on the given dock icon frame and dock position
private func calculateWindowPosition(mouseLocation: CGPoint?, windowSize: CGSize, screen: NSScreen) -> CGPoint {
guard let mouseLocation = mouseLocation else { return .zero }
guard let dockIconFrame = DockObserver.shared.getDockIconFrameAtLocation(mouseLocation) else { return .zero }

let dockIconFrame = DockObserver.shared.getDockIconFrameAtLocation(mouseLocation) ?? .zero

var xPosition = dockIconFrame.isEmpty ? mouseLocation.x : dockIconFrame.midX
var yPosition = dockIconFrame.isEmpty ? mouseLocation.y : dockIconFrame.midY

let screenFrame = screen.frame
let dockPosition = DockUtils.shared.getDockPosition()
let dockHeight = DockUtils.shared.calculateDockHeight(screen)

var xPosition = dockIconFrame.midX
var yPosition = dockIconFrame.midY

// Adjust position based on dock position
switch dockPosition {
case .bottom:
Expand Down

0 comments on commit ef3ec02

Please sign in to comment.