I am programmatically creating a window that needs to span across 2 screens. the size of the window being created is correct but the window is starting about halfway across the first screen. I can drag it back to the beginning of the first screen and the NSWindow fits perfectly.
I just need to know where I'm going wrong in terms of the starting point for the window.
func createNewWindow() {
let bannerWidth = NSScreen.screens[0].frame.width * 2
let bannerHeight = NSScreen.screens[0].frame.height
let rect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: bannerWidth, height: bannerHeight))
let newWindow = NSWindow(contentRect: rect, styleMask: [.closable], backing: .buffered, defer: false)
let storyboard = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "ExternalScreen") as? NSViewController
let window = storyboard?.view
newWindow.styleMask.update(with: .resizable)
NSMenu.setMenuBarVisible(false)
newWindow.title = "New Window"
newWindow.isOpaque = false
newWindow.isMovableByWindowBackground = true
newWindow.backgroundColor = NSColor(calibratedHue: 0, saturation: 1.0, brightness: 0, alpha: 0.7)
newWindow.toggleFullScreen(true)
newWindow.makeKeyAndOrderFront(nil)
newWindow.toolbar?.isVisible = false
newWindow.contentView?.addSubview(window!)
}
You're setting the content rectangle, but not setting the frame. The frame is the rectangle that the window occupies in screen coordinates. To move the window, you can setFrameOrigin() or setFrameTopLeftPoint().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With