Cocoa / Objective-C - a child window with text input without the main window becomes inactive

I need to create a window that will hang over my main window in the cocoa application. I want this main window to allow the user to enter text in the input field. Everything is fine until the text input field actually reaches focus. The main window becomes "deactivated". This is a borderless window with a slightly customizable shape - it looks more like a guidance map than anything else, I suppose.

Basically, I would like this thing to work in much the same way as Spotlight (Apple + Space) - you can enter text, but this is such an auxiliary operation that in the context of a larger UX, you do not want the sharp effect of the main window to fly out ( became inactive). You will notice that when you have the application and focus open, the spotlight will not cause the window of this application to become inactive.

This problem arises because the text input seems necessary for the child window to become the key window (this will not allow the cursor to be placed in the text input field). When it becomes key, the main window becomes inactive.

So far I have tried:

  • Subclassing NSWindow for my main application and overriding isKeyWindow so that it loses the key only when the application stops focusing on users (as opposed to a window). This had an unintended effect of a collision with the key status of the child window and had very strange effects on entering the keyboard (some keys are not recorded, for example delete)
  • Create a view instead of a window. Doesn't work due to this problem - you cannot draw Webkit WebView these days.

Does any Cocoa / OSX wizard have any ideas? I became a little obsessed with it. Itching I can not scratch.

Edit: also tried to override the following in the child window. When a window is clicked, the main application window becomes inactive.

- (BOOL)canBecomeKeyWindow {
    return YES;
}

- (BOOL)canBecomeMainWindow {
    return NO;
}

2: NSMenu . , - . NSPanel :

NSNonactivatingPanelMask
The panel can receive keyboard input without activating the owning application.
Valid only for an instance of NSPanel or its subclasses; not valid for a window.

...

3: NSNonactivatingPanelMask . .

+5
2

- , , . , NSPanel, .

0

, :   [self.childWindow makeKeyAndOrderFront: self];

0

All Articles