I'm looking to bring a new NSWindow in front of all other windows, but not have it take focus.
I can make it appear in front with focus with the following:
NSApplication *thisApp = [NSApplication sharedApplication]; [thisApp activateIgnoringOtherApps:YES]; [self makeKeyAndOrderFront:self];
Any clues on how to make it appear on top but not take focus away from another application?
Instead of makeKeyAndOrderFront:
, try just orderFront:
(docs)
Try something like this:
[window setLevel:NSScreenSaverWindowLevel + 1];
[window orderFront:nil];
This will show the window above other application's windows, but without making it active. A window with a normal window level in application A cannot be shown in front of a window of application B, if application B is the active application. (There is good reason for this, btw).
Please use this method with discretion. In many cases, it will likely violate the human interface guidelines. If misused, it can have a tendency to piss a user off. (For example, in my testing just now, the window appeared placed directly over the location I happened to be looking at in Safari. The fact that it was in the way of what I was doing, yet had the audacity to not become key, made it even more irritating. If it were up out of the way in a corner of my screen, it might be a different story).
The order front methods and level to the screensaver +1 didn't work for me. This answer from The-Kenny did, though:
[yourPanel setLevel:kCGMaximumWindowLevel];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With