| 1234567891011121314151617181920212223242526272829303132333435 |
- import AppKit
- import CoreGraphics
- enum AppWindow {
- static let width: CGFloat = 1140
- static let height: CGFloat = 720
- static let minWidth: CGFloat = width
- static let minHeight: CGFloat = height
- /// Extra top inset for the sidebar when the window is in macOS full screen.
- static let fullScreenTopInset: CGFloat = 16
- /// Small top breathing room for the embedded Reddit panel.
- static let redditTopInset: CGFloat = 30
- @MainActor
- static func centerOnScreen(_ window: NSWindow) {
- guard !window.styleMask.contains(.fullScreen) else { return }
- let screen = NSScreen.main ?? window.screen
- guard let screen else {
- window.center()
- return
- }
- var frame = window.frame
- frame.size = NSSize(width: width, height: height)
- let visible = screen.visibleFrame
- frame.origin.x = visible.origin.x + ((visible.width - frame.width) / 2)
- frame.origin.y = visible.origin.y + ((visible.height - frame.height) / 2)
- window.setFrame(frame, display: true)
- }
- }
|