Window NSWindow 0x137632e40 ordered front from a non-active application and may order beneath the active application's windows

This message has started appearing in the Xcode console when I test run my app, I think after the 13.3 macOS update, or the associated Xcode update.

This message is posted:

  • when the app launches (my code does not do anything with the app window).
  • when I right click the app window to open a contextual menu while the application is in the background.
  • when I click a button on the window with the cmd key pressed, while the app is in the background.

I don't see why a warning should be posted in these situations. It looks like log noise to me.

EDIT: this warning is posted even when testing the template Mac app (objective-C, xib) with no additional code. This is on Xcode Version 14.3 (14E222b)

Answered by vicegax in 759734022

I started seeing same warnings but they weren't there before. Not sure if some behaviour on macOS changed or is just noise, but to on the safe side I changed my implementation to open the first window on my app.

The key is to use orderFrontRegardless() instead of makeKeyAndOrderFront(nil)

Example

func applicationDidFinishLaunching(_: Notification) {
   let window = Window()
    window.makeKey()
    window.orderFrontRegardless()
}

I'm seeing something similar. A blank document project generates a similar error code.

Same here

Me too

I'm seeing this in a lot of my apps. Running macOS 13.4, Xcode 14.3. App code unchanged, so this must be new log noise which started with macOS 13.3 or .4...

The warning error log is actually reflecting the actual app behavior. No wonder why sometimes my app window is not opened in frontmost position.

This is not a meaningless issue. This will cause unexpected behavior like error alert doesn't show in SwiftUI. If you encounter the same like me. You can get the window and make it key and front to fix this issue.

I used https://github.com/happycodelucky/SwiftUIWindowBinder to get the NSWindow. And used below func to make it key and front.

var body: some View {
    WindowBinder(window: $window) {
        // content view
    }
    .onAppear {
        makeKeyAndFront()
    }
}

private func makeKeyAndFront() {
    if let window {
        window.makeKeyAndOrderFront(nil)
    } else {
        DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
            makeKeyAndFront()
        }
    }
}
Accepted Answer

I started seeing same warnings but they weren't there before. Not sure if some behaviour on macOS changed or is just noise, but to on the safe side I changed my implementation to open the first window on my app.

The key is to use orderFrontRegardless() instead of makeKeyAndOrderFront(nil)

Example

func applicationDidFinishLaunching(_: Notification) {
   let window = Window()
    window.makeKey()
    window.orderFrontRegardless()
}
Window NSWindow 0x137632e40 ordered front from a non-active application and may order beneath the active application's windows
 
 
Q