Skip to content

Commit

Permalink
Cropped tab previews fixed (#2192)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1177771139624306/1206569585467178/f
CC: @mallexxx 

**Description**:
This PR fixes an issue with tab previews being presented outside of the
screen bounds.
  • Loading branch information
tomasstrba authored Feb 12, 2024
1 parent 3ca76c2 commit c28ab75
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion DuckDuckGo/TabPreview/TabPreviewWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class TabPreviewWindowController: NSWindowController {

static let width: CGFloat = 280
static let padding: CGFloat = 2
static let bottomPadding: CGFloat = 40
static let delay: CGFloat = 1

private var previewTimer: Timer?
Expand Down Expand Up @@ -124,8 +125,18 @@ final class TabPreviewWindowController: NSWindowController {
guard let window = window else {
return
}
var topLeftPoint = topLeftPoint

// Make sure preview is presented within screen
if let screenVisibleFrame = window.screen?.visibleFrame {
topLeftPoint.x = min(topLeftPoint.x, screenVisibleFrame.width - window.frame.width)

let windowHeight = window.frame.size.height
if topLeftPoint.y <= windowHeight + screenVisibleFrame.origin.y {
topLeftPoint.y = topLeftPoint.y + windowHeight + Self.bottomPadding
}
}

window.setFrame(NSRect(x: 0, y: 0, width: 250, height: 58), display: true)
window.setFrameTopLeftPoint(topLeftPoint)
}

Expand Down

0 comments on commit c28ab75

Please sign in to comment.