feat(macos): hover HUD for activity

This commit is contained in:
Peter Steinberger
2025-12-19 00:03:58 +01:00
parent 0c06276b48
commit 47510e2912
8 changed files with 512 additions and 70 deletions

View File

@@ -42,6 +42,28 @@ enum WindowPlacement {
return NSRect(x: x, y: y, width: clampedWidth, height: clampedHeight)
}
static func anchoredBelowFrame(size: NSSize, anchor: NSRect, padding: CGFloat, in bounds: NSRect) -> NSRect {
if bounds == .zero {
let x = round(anchor.midX - size.width / 2)
let y = round(anchor.minY - size.height - padding)
return NSRect(x: x, y: y, width: size.width, height: size.height)
}
let clampedWidth = min(size.width, bounds.width)
let clampedHeight = min(size.height, bounds.height)
let desiredX = round(anchor.midX - clampedWidth / 2)
let desiredY = round(anchor.minY - clampedHeight - padding)
let maxX = bounds.maxX - clampedWidth
let maxY = bounds.maxY - clampedHeight
let x = maxX >= bounds.minX ? min(max(desiredX, bounds.minX), maxX) : bounds.minX
let y = maxY >= bounds.minY ? min(max(desiredY, bounds.minY), maxY) : bounds.minY
return NSRect(x: x, y: y, width: clampedWidth, height: clampedHeight)
}
static func ensureOnScreen(
window: NSWindow,
defaultSize: NSSize,