I am implementing a child borderless search results window that floats under a NSSearchField and displays the results of the search as the user types. The NSWindow does not need to be key because the NSSearchField forwards appropriate commands (up arrow, down arrow, enter key) to a custom search results view in the window which let's the user navigate through the results anytime during the search. This all works great except for one use case: I want to easily close the window when the user clicks anywhere else in the app.
I would normally do this in the windowDidResignKey
notification but this won't be sent in this case since the window is never key. Is there another way to easily handle this situation?
--Edit with solution--
Using a variation of Rob's idea below I simply implemented controlTextDidEndEditing:
, a delegate method of NSSearchField, which is called (among other times) when the search field loses focus. If the search field is not my main parent window's first responder I close the search results window.