I was wondering how could spotlight floating with focus, and another window still has focus!
I could easy make a window floating over all other window with window?.level = Int(CGWindowLevelForKey(.maximumWindow))
,but I cannot let two windows both has focus, help!
Is there any function like ShowWithoutActivating
in Cocoa?
I've been playing around with this a bit, and I seem to be able to produce this effect when the frontmost window is not from the same process as the frontmost application, which is what I suspect Spotlight is probably doing. I can achieve this like so:
Set LSUIElement to YES in my app's Info.plist.
In Interface Builder, set the window's class to NSPanel, check "Non Activating" in the Attributes Inspector, and set "isFloatingPanel" to YES in the User Defined Runtime Attributes under the Identity Inspector.
During some time that some other application is in front (I just used a 5-second delay to give myself time to pop some other app to the front and select a text field), call
makeKeyAndOrderFront()
followed byorderFrontRegardless()
on the window.
When I do this, I get the following (note the focus ring still drawn on Xcode's "Module" field):
来源:https://stackoverflow.com/questions/46023769/how-to-show-a-window-without-stealing-focus-on-macos