Skip to content

Conversation

@kaascevich
Copy link
Contributor

@kaascevich kaascevich commented Jan 5, 2026

This PR adds view modifiers for controlling properties of the attached view's enclosing window. Currently, this includes:

  • windowDismissBehavior(_:)
    • Sets whether the window can be closed by the user
      • This will (ideally) not affect dismissWindow when that's merged in
    • Implemented for AppKitBackend, GtkBackend/Gtk3Backend (broken on macOS at least), and UIKitBackend for iOS/tvOS 16+
    • Implementation for WinUIBackend is possible, but AFAIK requires dropping down to Win32
  • preferredWindowMinimizeBehavior(_:)
    • Sets whether the window can be minimized by the user
    • Implemented for AppKitBackend, UIKitBackend for iOS/tvOS 16+, and WinUIBackend (untested)
    • Implementation for GtkBackend and Gtk3Backend doesn't look like it'll be possible without an entirely custom title bar (and the minimize button is usually hidden on GNOME anyway)
  • windowResizeBehavior(_:)
    • Sets whether the window can be resized by the user
    • Behaves identically to how windowResizability(_:) did before this PR
      • .automatic and .enabled behave like .contentMinSize, .disabled behaves like .contentSize
    • Implemented for all backends except UIKitBackend

They're view modifiers rather than scene modifiers because that's what SwiftUI does.

In addition, windowResizability(_:) has been updated to match SwiftUI's behavior (which resolves #263). .contentMinSize limits the window's minimum size but not its maximum size, while .contentSize limits the minimum and maximum sizes. (An extra computeLayout call is made to the view graph to compute the maximum size, but only when it's actually needed.) Maximum size limits are:

  • implemented in AppKitBackend and UIKitBackend
  • currently unimplemented in WinUIBackend (as are minimum limits), but probably possible with some Win32 trickery
  • not implemented in Gtk[3]Backend, and probably never will be

@stackotter
Copy link
Owner

It seems like windowMinimizeBehavior is kind of impossible to implement for GtkBackend and Gtk3Backend. It could make sense to rename the modifier to preferredWindowMinimizeBehaviour to make it clear that it isn't expected to work on every platform. What do you think about that?

@kaascevich
Copy link
Contributor Author

We could do that, yeah.

Copy link
Owner

@stackotter stackotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend API changes that you've made are well designed. I've just got some requested changes related to parts of the backend implementations and documentation.

@kaascevich kaascevich force-pushed the window-behavior-modifiers branch from 7a43fd7 to abeef16 Compare January 7, 2026 07:15
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.

Support WindowResizability.contentSize properly

2 participants