Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make NSWindow Front But Not In Focus

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?

like image 222
redhotvengeance Avatar asked Feb 01 '11 07:02

redhotvengeance


3 Answers

Instead of makeKeyAndOrderFront:, try just orderFront: (docs)

like image 67
cobbal Avatar answered Sep 20 '22 13:09

cobbal


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

like image 24
NSGod Avatar answered Sep 20 '22 13:09

NSGod


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];
like image 40
zekel Avatar answered Sep 23 '22 13:09

zekel