Question

I have a NSWindow (my main window) and a child window (positioned NSWindowBelow the main window) that has a NSTextView. The child window doesn't have a title bar, nor shadow and its transparent.
Here's the code I use to set up my child window to make it transparent:

- (id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag{
    if (![super initWithContentRect: contentRect styleMask:NSBorderlessWindowMask backing: bufferingType defer:NO]) return nil;

    [self setBackgroundColor: [NSColor clearColor]];
    [self setOpaque:NO];

    return self;
}

But when I try to select the text in it, here's what happens (the black stuff above the child window is the main window):
enter image description here
It looks like the NSTextView is not focused, because the selection is not blue. I've tried calling: [[_childWindow textView] becomeFirstResponder]; but the outcome is the same. Another thing, is that when I scroll it, sometimes it's very laggy and "breaky".

Do you guys have any ideas on whats causing this and how to fix it? I suspect it's because the window doesn't have a title bar, but I'm not sure. Thanks!

Was it helpful?

Solution

From the NSWindow docs:

canBecomeKeyWindow
Indicates whether the window can become the key window.

- (BOOL)canBecomeKeyWindow
Return Value
YES if the window can become the key window, otherwise, NO.

Discussion
Attempts to make the window the key window are abandoned if this method returns 
NO. The NSWindow implementation returns YES if the window has a title bar or a 
resize bar, or NO otherwise.

Try overriding -canBecomeKeyWindow and returning YES.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top