开发者

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 act开发者_开发知识库ivateIgnoringOtherApps: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];


In case you're using orderFront, try orderFrontRegardless instead. The former isn't consistent every time it's called. The latter seems to work consistently.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜