Skip to content

Conversation

@kaascevich
Copy link
Contributor

@kaascevich kaascevich commented Dec 28, 2025

This PR:

  • Fixes handling of closed windows (fixes Properly handle closed windows #249)
    • Scene graph nodes will now drop their window reference(s) when a window is closed, allowing the window object to deallocate properly (fixes (AppKit backend) Closed windows still show up in Stage Manager #280)
    • The backend methods used for this, close(window:) and setCloseHandler(ofWindow:to:), have been implemented in all supported backends as well as in DummyBackend
      • Currently these methods do nothing in UIKitBackend; we may implement them properly in the future for Mac Catalyst and visionOS (and perhaps iPadOS, if it'll let us)
  • Adds a Window scene and its associated WindowNode
    • Only one instance of Window can be open at a time
    • Window requires a title and an ID
  • Implement multi-window support for WindowGroup
  • Implements the dismissWindow environment action, which closes the enclosing window
  • Implements the openWindow environment action, which opens a Window or WindowGroup given its ID (partially deals with Add a way for window groups to be reopened #250)
  • Factors out the window setup and view graph updating code into a new (internal) WindowReference type
  • Adds the defaultLaunchBehavior(_:) scene modifier, which controls whether scenes appear on app launch
    • The automatic option matches the current behavior, namely that WindowGroups are opened on app launch but Windows aren't
  • Adds the supportsMultipleWindows environment value, which can be used to check whether the current platform supports multi-window
    • As far as the SCUI-side implementation is concerned, they all do, but practically speaking mobile backends don't typically support it

@kaascevich kaascevich marked this pull request as draft January 2, 2026 00:04
#Conflicts:
#	Examples/Sources/WindowingExample/WindowingApp.swift
#	Sources/SwiftCrossUI/Environment/Actions/DismissAction.swift
#	Sources/SwiftCrossUI/Environment/EnvironmentValues.swift
@kaascevich kaascevich marked this pull request as ready for review January 2, 2026 04:01
@kaascevich kaascevich changed the title Add Window scene and openWindow environment action Add Window scene and openWindow environment action, and add multi-window support to WindowGroup Jan 2, 2026
@stackotter stackotter changed the title Add Window scene and openWindow environment action, and add multi-window support to WindowGroup Add Window scene, openWindow action, dismissWindow action, fix window close handling, and add multi-window support to WindowGroup Jan 2, 2026
@stackotter
Copy link
Owner

While reviewing #299, I realised that closing windows will need special consideration in WinUIBackend. Currently, WinUIBackend stores a list of all open windows, for the purpose of selecting one of them to attach to when modals are presented without a specific window.

You'll either need to update that list when windows get closed, or update WinUIBackend's various modal implementations to get a default window to use in some other way.

@kaascevich
Copy link
Contributor Author

I'll take the "update the window list" route, thanks for the catch!

@kaascevich
Copy link
Contributor Author

While reviewing #299, I realised that closing windows will need special consideration in WinUIBackend. Currently, WinUIBackend stores a list of all open windows, for the purpose of selecting one of them to attach to when modals are presented without a specific window.

You'll either need to update that list when windows get closed, or update WinUIBackend's various modal implementations to get a default window to use in some other way.

It looks like you're way ahead of yourself here:

window.closed.addHandler { _, _ in
    self.windows.removeAll { other in
        window === other
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(AppKit backend) Closed windows still show up in Stage Manager Properly handle closed windows

2 participants