Search code examples
swiftmacosnswindowuiwindowmac-catalyst

Accessing NSWindow-like properties in Catalyst macOS app


I am thinking about porting my macOS app to Catalyst.

My app shows a transparent window (no title bar, clear background) on top of all other apps windows (dock included). To do that, in the non-catalyst code I use:

window.isOpaque = false
window.hasShadow = false
window.backgroundColor = .clear
window.styleMask = .borderless
window.isMovableByWindowBackground = true
window.level = .statusBar

Using UIKit, I was only able to remove the toolbar so far:

window.titleBar.titleVisibility

...But no clue about the other settings.

I plan to make the app available on the App Store in the future, but if the only way to do so is and hack with a private API, that's fine.

Any ideas?

Thanks in advance


Solution

  • There is no official API for doing that, but you can easily access the NSWindow instance and modify it directly. You can do that manually or using some library like Dynamic (Full disclosure: I'm the author):

    let window = Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(uiWindow)
    
    window.isOpaque = false
    window.hasShadow = false
    window.backgroundColor = Dynamic.NSColor.clearColor
    window.styleMask = 0 /*borderless*/
    window.isMovableByWindowBackground = true
    window.level = 25 /*statusBar*/