简体   繁体   中英

Enable fullscreen for floating window in macOS app

I set the app windows to floating, to keep them on top:

NSApplication.shared.windows.forEach { window in
    window.level = .floating
}

However, this disables the fullscreen mode:

  • The green window button maximizes the window size but doesn't activate fullscreen mode
  • The "View" menu "Enter Full Screen" item is disabled

Can these two behaviors (floating windows & fullscreen mode) be enabled in parallel? I have checked project settings and developer docs, but didn't find anything.

I got it to work by setting collectionBehavior :

NSApplication.shared.windows.forEach { window in
    window.collectionBehavior = [.fullScreenPrimary]
    window.level = .floating
}

I found a similar SO question , they also set some properties (not the level ) of the window, and fullscreen gets disabled.

So is it that if collectionBehavior is not specified for an NSWindow, then fullscreen is enabled as long as certain NSWindow properties (eg level ) are not explicitly set?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM