acceptsFirstMouse to bypass window focus not working on NSOutlineView

I have two windows and I want to be able to use the mouse on either one, without having to click first to 'activate' the window. I found the -acceptsFirstMouse method to override on NSViews, and it works on my main window. But the other window is an NSOutlineView, which in storyboard is a huge mess of stacked sub-views and controls. I went through and subclassed each of these to add the acceptsFirstMouse function, but it still doesn't work. It makes me click to activate the window before I can click on items in the outline view.


But some of the items in the view hierarchy must not inherit from NSView, because they give me an error when I add the override. Is there any way to do this? NSTableColumn, NSTextFieldCell for example. Given that NSTextFieldCell is the furthest thing in the hierarchy and is probably receiving the mouse click, am I screweed? Is there any way to get this to work???


EDIT: I also tried setting 'RefusesFirstResponder' on these NSTextFieldCells in the storyboard, but that did not help.


Thanks

Accepted Reply

I found the answer to this. Instead of all those subclasses, I only needed to subclass NSOutlineView and override 'needsPanelToBecomeKey' to return false


class myNSOutlineView:NSOutlineView {
   
    override var needsPanelToBecomeKey:Bool { get { return false } }
   
    override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
        return true
    }
}


It works even if I do not override acceptsFirstMouse, but I left that in there just in case.

Replies

I found the answer to this. Instead of all those subclasses, I only needed to subclass NSOutlineView and override 'needsPanelToBecomeKey' to return false


class myNSOutlineView:NSOutlineView {
   
    override var needsPanelToBecomeKey:Bool { get { return false } }
   
    override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
        return true
    }
}


It works even if I do not override acceptsFirstMouse, but I left that in there just in case.