Hopefully fixed the Positioning

This commit is contained in:
Hariharan Mudaliar 2026-02-07 23:42:06 +05:30
commit 40e805a785
No known key found for this signature in database
GPG key ID: 025583EB0BE5640E
3 changed files with 145 additions and 9 deletions

View file

@ -31,6 +31,7 @@ final class LockScreenWeatherPanelManager {
private(set) var latestFrame: NSRect?
private var lastSnapshot: LockScreenWeatherSnapshot?
private var lastContentSize: CGSize?
private var lastInlineBaselineHeight: CGFloat = 0
private var screenChangeObserver: NSObjectProtocol?
private var workspaceObservers: [NSObjectProtocol] = []
@ -64,6 +65,9 @@ final class LockScreenWeatherPanelManager {
let view = LockScreenWeatherWidget(snapshot: snapshot)
let hostingView = NSHostingView(rootView: view)
let fittingSize = hostingView.fittingSize
if snapshot.widgetStyle == .inline {
lastInlineBaselineHeight = max(lastInlineBaselineHeight, fittingSize.height)
}
hostingView.frame = NSRect(origin: .zero, size: fittingSize)
let targetFrame = frame(for: fittingSize, snapshot: snapshot, on: screen)
@ -116,13 +120,18 @@ final class LockScreenWeatherPanelManager {
let verticalOffset = screenFrame.height * 0.15
let isCircular = snapshot.widgetStyle == .circular
let topMargin: CGFloat = isCircular ? 120 : 48
let maxY = screenFrame.maxY - size.height - topMargin
let inlineBaselineHeight: CGFloat = max(lastInlineBaselineHeight, 80)
let positionHeight = snapshot.widgetStyle == .inline
? max(size.height, inlineBaselineHeight)
: size.height
let maxY = screenFrame.maxY - positionHeight - topMargin
let baseY = min(maxY, screenFrame.midY + verticalOffset)
let loweredY = baseY - 36
let inlineLift: CGFloat = snapshot.widgetStyle == .inline ? 44 : 0
let circularDrop: CGFloat = isCircular ? 28 : 0
let sizeDrop = max(0, size.height - 80) * 0.35
let sizeDropHeight = positionHeight
let sizeDrop = max(0, sizeDropHeight - 80) * 0.35
let userOffset = CGFloat(Defaults[.lockScreenWeatherVerticalOffset])
let clampedOffset = min(max(userOffset, -160), 160)
let adjustedY = loweredY + inlineLift + clampedOffset - circularDrop - sizeDrop