Slight update to @mattroberts code for macOS 14:
ContentView()
.background(WindowAccessor(window: $window))
.onChange(of: window) { _, newWindow in
if windowFloats {
newWindow?.level = .floating
} else {
newWindow?.level = .normal
}
}
.onChange(of: windowFloats) {
if windowFloats {
window?.level = .floating
} else {
window?.level = .normal
}
}
If you just want it to always float you dont need the second onChange(of:)