CodexBloom - Programming Q&A Platform

implementing Custom NSWindow in Full-Screen Mode on macOS 13.6 - Window Resizing Incorrectly

👀 Views: 35 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
macos nswindow fullscreen swiftui swift

After trying multiple solutions online, I still can't figure this out. I've spent hours debugging this and I'm stuck on something that should probably be simple. I'm experiencing a peculiar scenario with my custom `NSWindow` in full-screen mode on macOS 13.6. When I enter full-screen, the window is expected to occupy the entire screen area without any margins or inconsistencies. However, upon entering full-screen, the window seems to resize incorrectly, leaving a small margin on the bottom and right sides. This doesn't happen when the window is not in full-screen mode. I have set up the window as follows: ```swift class CustomWindow: NSWindow { override func awakeFromNib() { self.styleMask.insert(.fullSizeContentView) self.collectionBehavior = [.fullScreenPrimary, .transient] } } ``` I am also calling `toggleFullScreen(nil)` from a button action: ```swift @IBAction func fullScreenButtonClicked(_ sender: Any) { self.toggleFullScreen(nil) } ``` Additionally, I have ensured that the window's content view is set to use auto layout. I've also tried adjusting the `contentView`'s constraints, but the scenario continues. The window's frame seems to be off by a few pixels, resulting in a clipped appearance of the content. I've checked the logs for any relevant warnings or errors and noticed the following message during the transition to full-screen: ``` NSWindow warning: Full-screen window size adjustment is not valid. ``` I would appreciate any insights into why this might be happening or additional steps I can take to troubleshoot or resolve this scenario. This is part of a larger web app I'm building. Is there a simpler solution I'm overlooking? Thanks for your help in advance!