79091915

Date: 2024-10-15 22:24:08
Score: 0.5
Natty:
Report link

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:)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @mattroberts
  • Low reputation (0.5):
Posted by: josef