Reputation: 663
I am new to the cocoa mac development, Right now i am developing a mac app having several server hit after a particular time. If the hit gets desired data then I need to to show the equivalent window and to show the window i am using [myWindow showWindow:self] method. It shows desired window and set the key window to my visible window is that myWindow.
Each and everything is fine till now but the problem is that suppose when a user start working on any window and open several other child window then unfortunately my show window get called and the focus of my working window transferred to other window.
After several searches i found that i can get the focused window by accessing the [[NSApplication sharedApplication]keyWindow]delegate], I applied several condition that when my this and this window is on key window then don't hit server.
But the problem is not get solved. Now i think setting a keyWindow to my current working window will be best option.
Please suggest me what can i do and how i can forcefully set a window as my key window.
Any Help would be appreciated. Thanks In advance.
Upvotes: 1
Views: 578
Reputation: 53000
If I understand your question correctly you wish to bring a window forward if it receives input from your server but without moving it in front of the current main or key windows.
The method you are using, showWindow:
, belongs to NSWindowController
and both shows a window and makes it key.
What you need to look at are the NSWindow
methods for managing the window levels, orderFront:
et al.
In particular you might want to use orderWindow:relativeTo:
which allows to place a window in front/behind another window. For example:
[<window> orderWindow:NSWindowBelow
relativeTo:NSApp.keyWindow.windowNumber];
will move a window to be immediately behind the current key window, and in front of any other windows behind the key window.
HTH
Upvotes: 2