Reputation: 143
My app consists of several windows that all exist at the NSNormalWindowLevel. I recently added a new window that opens as a utility panel (and, hence, NSFloatingWindowLevel). This utility panel correctly opens as a floating window and stays on top of the other windows, and I can change focus by clicking in any of the "normal" windows, or clicking again on the utility panel when I want interactions to take place there.
The problem I'm having, though, is that I don't want the utility panel to always grab focus when it is opened; I'd like focus to remain with the top window at the NSNormalWindowLevel so the user does not have to click on the top "normal" window in order to continue working there.
The basic code looks like this:
storyBoard = [NSStoryboard storyboardWithName:@"UtilityPanel" bundle:nil];
utilityPanelController = [storyBoard instantiateControllerWithIdentifier:@"Utility Panel"];
[utilityPanelController showWindow:sender];
I've tried to force the top normal window to the front by getting a reference to the top window and calling orderFront:
NSWindow *topWindow = [[NSApplication sharedApplication] keyWindow];
[topWindow orderFront:nil];
But the utility panel still has the focus, requiring a click in the top window to return focus where it was. I've also tried using orderFrontRegardless with the same result.
It occurs to be that both orderFront and orderFrontRegardless only operate on windows at the same window level, and here the windows are at different levels.
I've looked through the Window manager, but have yet to find a way to change the focus to a particular window level (say, NSNormalWindowLevel) in code at the time that I open the utility panel. Have I missed something obvious?
Thanks!
Upvotes: 0
Views: 63
Reputation: 143
Solution provided by NSGod in the comments:
Set becomesKeyOnlyIfNeeded to YES.
Upvotes: 0