The WindowManagement package allows you to control window behaviors of SwiftUI Scenes without doing weird tricks. Views can also access the NSWindow through the Environment.

Scene Modifiers

View Modifiers


Scherm­afbeelding 2023-01-06 om 21 45 28


This package uses and modifies some internals of SwiftUI. As SwiftUI changes frequently, implementations might break.

Note: DocumentGroup is not supported (yet)


  • macOS 12.0 (Untested, but should work)
  • macOS 13.0+

Available Scene modifiers


This modifier enables the modification of the underlying NSWindow for this scene. It should always be called before any of the other modifiers. The identifier must be the same as the one set in the Scene initializer. For the Settings Scene, use registerSettingsWindow.

func register(_ identifier: String)

func registerSettingsWindow()


Indicates whether the window can be moved by clicking and dragging its background.

func movableByBackground(_ value: Bool)


Indicates whether the view can be moved.

func movable(_ value: Bool)


Apply a certain stylemask to the window. Note that NSWindow.StyleMask.titled is always included, otherwise SwiftUI will crash.

func styleMask(_ styleMask: NSWindow.StyleMask)


Indicated whether a window button should be enabled or not. If disabled, the button will be greyed out but still visible. The keyboard shortcut of the button won’t be active. Use windowButton(_:hidden:) to hide a window button.

func windowButton(_ button: NSWindow.ButtonType, enabled: Bool)

Indicated whether a window button should be hidden or not. A hidden button can still be triggered with it’s keyboard shortcut, e.g. Cmd+w for closing a window. Use windowButton(_:hidden:) to disable a window button.

func windowButton(_ button: NSWindow.ButtonType, hidden: Bool)


Apply a certain collectionBehavior to the window.

func collectionBehavior(_ behavior: NSWindow.CollectionBehavior)


Set the tabbingMode for the window. If set to preferred, new windows will be opened as tabs.

func tabbingMode(_ mode: NSWindow.TabbingMode)


Sets the background color of the window.

func backgroundColor(_ color: NSColor)


Makes the titlebar transparent.

func titlebarAppearsTransparent(_ value: Bool)


This will stop windows from relaunching if they were open in the last active app state.

Note: While this should work fine, I can’t guarantee it.

func disableRestoreOnLaunch()

Available View modifiers

Inject the current window into the environment.

func injectWindow(_ identifier: String)

Inject the settings window into the environment.

func injectSettingsWindow()

Get the NSWindow from a View.

@Environment(\.window) var window


The following code shows the implementation of the window shown above.

import SwiftUI
import WindowManagement

struct MyApp: App {

    var body: some Scene {
        WindowGroup(id: "MyWindow") {
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        .windowToolbarStyle(.unifiedCompact(showsTitle: false))
        .backgroundColor(.systemGray.withAlphaComponent(0.001)) // Don't use .clear, causes glitches.
        .styleMask([.closable, .fullSizeContentView, .resizable])
        .windowButton(.miniaturizeButton, hidden: true)
        .windowButton(.zoomButton, hidden: true)

struct ContentView: View {
    @Environment(\.window) var window
    var body: some View {
        Text("This windows identifier is \(window.identifier?.rawValue ?? "")")
        Button("Hide this window") {


View Github