new macOS version
This commit is contained in:
@@ -32,6 +32,11 @@ final class FloatingPanel: NSPanel {
|
||||
// Don't activate the app when clicked (user keeps focus on their work)
|
||||
becomesKeyOnlyIfNeeded = true
|
||||
}
|
||||
|
||||
// Allow the panel to become key so buttons inside it can receive clicks.
|
||||
// Combined with .nonactivatingPanel, this lets buttons work without
|
||||
// stealing focus from the user's active app.
|
||||
override var canBecomeKey: Bool { true }
|
||||
}
|
||||
|
||||
// MARK: - Controller
|
||||
@@ -49,14 +54,20 @@ final class FloatingPanelController {
|
||||
let p = FloatingPanel()
|
||||
let hud = FloatingHUDView()
|
||||
.environment(session)
|
||||
p.contentView = NSHostingView(rootView: hud)
|
||||
|
||||
// Position: top-right of the main screen, just below the menu bar
|
||||
// NSHostingController gives proper preferredContentSize tracking so the
|
||||
// panel auto-resizes as SwiftUI content grows or shrinks.
|
||||
let controller = NSHostingController(rootView: hud)
|
||||
p.contentViewController = controller
|
||||
|
||||
// Position: top-right of the main screen, just below the menu bar.
|
||||
// Anchor the top edge so the panel grows downward as content expands.
|
||||
if let screen = NSScreen.main {
|
||||
let margin: CGFloat = 16
|
||||
let x = screen.visibleFrame.maxX - 320 - margin
|
||||
let y = screen.visibleFrame.maxY - 160 - margin
|
||||
p.setFrameOrigin(NSPoint(x: x, y: y))
|
||||
// Place top edge just below the menu bar
|
||||
let topY = screen.visibleFrame.maxY - margin
|
||||
p.setFrameTopLeftPoint(NSPoint(x: x, y: topY))
|
||||
} else {
|
||||
p.center()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user