Reputation: 4533
I have a custom NSBorderlessWindowMask
window in my application that I show when user taps a certain hot key.
This window has a `NSTextField, that has to become first responder when the window shows up.
This window is not a main window, but it can take focus from the main window.
This what I do to show it and make it key:
[self.myCustomWindow makeKeyAndOrderFront:sender];
and then to set the first responder
[self.myTextField becomeFirstResponder];
Everything works as expected when the application is a frontmost application, but if it's not, the window appears, but doesn't become key and i have to click it to become active.
I override in my CustomWindow
class:
- (BOOL)canBecomeKeyWindow {
return YES;
}
What might be the problem?
Thanks!
Upvotes: 2
Views: 203
Reputation: 9721
According to the Cocoa Event Handling Guide, only the frontmost application can have main and key window status:
When an application is displaying both a main window and a key window, the responder chains of both windows can be involved in an action message. As explained in “Window Layering and Types of Windows”, the main window is the frontmost document or application window. Often main windows also have key status, meaning they are the current focus of user input. But a main window can have a secondary window or panel associated with it, such as the Find panel or a Info window showing details of a selection in the document window. When this secondary window is the focus of user input, then it is the key window.
I don't see any way around this.
EDIT: Also from the Window Programming Guide:
Since the key window belongs to the active application, its highlighted title bar has the secondary effect of helping to show which application is currently active. The key window is the most prominently marked window in the active application, making it “key” in a second sense: it’s the main focus of the user’s attention on the screen.
Upvotes: 0