4

I'm trying to make an app that sort-of functions like the spotlight search that was demonstrated on WWDC.

I managed to get it to the floating level with kCGFloatingWindowLevelKey, however the window steals the focus from whatever window was previously active. I would like it to keep the focus, and still take input in the textfield from the user. Is that doable?

Answers in swift is preferred, but objective-c works as well.

hannesr
  • 449
  • 5
  • 12
  • It's definitely possible, but I'm not sure how. Spotlight might not be a window, it's probably an `NSMenu` with a custom control inside. – Abhi Beckert Jun 24 '14 at 22:22
  • I just tried creating an NSMenu with a menu item and a custom view. But as soon as it's given keyboard focus other windows loose their "main" window state and become "inactive" (https://developer.apple.com/library/mac/Documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html). I have no idea what to try next. – Abhi Beckert Jun 24 '14 at 22:30
  • In mavericks and before I would say you are spot on. I'm however referring to the demo from WWDC of spotlight in 10.10 Yosemite. http://appleinsider.com/articles/14/06/05/os-x-yosemite-first-look-spotlight-search – hannesr Jun 24 '14 at 22:34
  • those screenshots do not show whether or not other windows become inactive when spotlight is the key window. On mavericks the spotlight menu has key without making other windows inactive. – Abhi Beckert Jun 24 '14 at 22:37
  • The screenshots does't show it, but it doesn't. Works the same way as in mavericks but in separate window... The problem definitely seems to be the textfield though. – hannesr Jun 24 '14 at 22:42
  • 1
    I don't think the problem is the text field. The problem is making the window "key" makes all windows from every other app inactive. Activating the text field also makes the window key. I'm surer it can be done, somehow. – Abhi Beckert Jun 24 '14 at 22:48
  • Hmm, if I do resignKeyWindow on the window, I think I get the desired result. I just have to switch back to an other window and then back to mine. So now it is just a matter of never giving it key, I guess... Thanks for pointing me in right direction! – hannesr Jun 24 '14 at 22:57
  • My bad, it was me making it a NSPanel instead... – hannesr Jun 24 '14 at 23:00
  • If both windows are in the same application you can do it by subclassing the window and returning NO in `canBecomeMainWindow`. But if the other window is in another application that doesn't work. – Abhi Beckert Jun 24 '14 at 23:26
  • 4
    I believe you want an `NSPanel` with `NSNonactivatingPanelMask` in its style mask. – Ken Thomases Jun 25 '14 at 04:35

0 Answers0