Center window consistently

This commit is contained in:
Beingpax 2025-03-18 11:03:12 +05:45
parent 2a5c687aa4
commit 36167a8519
2 changed files with 12 additions and 3 deletions

View File

@ -81,7 +81,7 @@ class MenuBarManager: ObservableObject {
// Make the window key and order front
window.makeKeyAndOrderFront(nil)
window.center() // Center the window on screen
window.center() // Always center the window for consistent positioning
// Post a notification to navigate to the desired destination
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {

View File

@ -16,7 +16,6 @@ class WindowManager {
// Add additional window configuration for better state management
window.collectionBehavior = [.fullScreenPrimary]
window.setFrameAutosaveName("MainWindow") // Save window position and size
// Ensure proper window level and ordering
window.level = .normal
@ -24,8 +23,18 @@ class WindowManager {
}
func createMainWindow(contentView: NSView) -> NSWindow {
// Use a standard size that fits well on most displays
let defaultSize = NSSize(width: 1200, height: 800)
// Get the main screen frame to help with centering
let screenFrame = NSScreen.main?.visibleFrame ?? NSRect(x: 0, y: 0, width: 1200, height: 800)
// Create window with centered position
let xPosition = (screenFrame.width - defaultSize.width) / 2 + screenFrame.minX
let yPosition = (screenFrame.height - defaultSize.height) / 2 + screenFrame.minY
let window = NSWindow(
contentRect: NSRect(x: 100, y: 100, width: 1200, height: 800),
contentRect: NSRect(x: xPosition, y: yPosition, width: defaultSize.width, height: defaultSize.height),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false