Hello! I’m writing a macOS app. I have a custom view in every document window. Suppose I have two documents open at the same time. Call the two corresponding windows A and B.
There are often long background calculations going on in both documents. Suppose A is main. Now, whenever the window behind, B, updates its custom view to reflect the calculations’ progress, B is immediately brought in front of A, but without becoming main! Sometimes both windows will automatically alternate one in front of the other!
How can I draw in the custom view of B, the window behind, without bringing it in front of A?
There are often long background calculations going on in both documents. Suppose A is main. Now, whenever the window behind, B, updates its custom view to reflect the calculations’ progress, B is immediately brought in front of A, but without becoming main! Sometimes both windows will automatically alternate one in front of the other!
How can I draw in the custom view of B, the window behind, without bringing it in front of A?
You might post a little code, and also clarify whether you're using AppKit or SwiftUI.
I'm guessing your background calculation is happening in a background DispatchQueue, and when it completes, you notify the window to redraw its contents using DispatchQueue.main.async to call some UI methods or post a notification?
If so, check this post-calculation UI update code - what does it do? Does it just call the view's setNeedsDisplay? Or does it do some other things like show the window? If you want to keep the window in the background, you should only call the view's setNeedsDisplay - that should make its content redraw but not change anything with regard to the window order or activation status.