title: Show Window without activating (keep application below it active)
body: <p>I need to show a window (without title bar) above third party applications without my window taking focus. </p>
  
  <p>I have tried using an <code>NSPanel</code> and setting enabling non-activating, but that didn't help. </p>
  
  <p>I tried <code>orderFront:self</code>, but that didn't help either. </p>
  
  <p>I always needed to add <code>[NSApp activateIgnoringOtherApps:YES];</code> because the window wouldn't show otherwise.</p>
  
  <p>I have here a sample project for just this functionality:<br>
  <a href="http://users.telenet.be/prullen/TopW2.zip" rel="noreferrer">http://users.telenet.be/prullen/TopW2.zip</a></p>
  
  <p><code>UIElement</code> is set to <code>true</code> in the application's plist file, so there is no dock. You can activate the window by pressing <code>ALT + SPACE</code> at the same time. You will see that the app below it looses focus. Any thoughts on how to fix this? I've seen other apps do it so I know it's possible. </p>
  
  <p>Edit: here's the code so far. Remember the window is a non-activating NSPanel.
  I still need that last <code>NSApp activateIgnoringOtherApps</code> line or otherwise it doesn't display. But of course that makes the window the active one.</p>
  
  <pre><code> _windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
  
      [[_windowController window] setLevel:NSNormalWindowLevel+1];
      [[_windowController window] orderFrontRegardless];
  
      [_windowController showWindow:self];
  
     [NSApp activateIgnoringOtherApps:YES];
  </code></pre>
  
  <p>I've also subclassed NSPanel and added two methods: </p>
  
  <pre><code>- (BOOL)canBecomeKeyWindow
  {
      return YES;
  }
  
  - (BOOL)canBecomeMainWindow
  {
      return YES;
  }
  </code></pre>
  
  <p>Edit: OK, unchecking setHidesOnDeactivate fixes this, but now the window will never hide. I need it to hide when the user presses the app below it or switches to another app. </p>
  
  <p>Edit 2: OK, this seems to fix the above issue:</p>
  
  <pre><code>- (void)awakeFromNib
  {
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideWindow) name:NSWindowDidResignKeyNotification object:nil];
  }
  - (void)hideWindow {
      [self setHidesOnDeactivate:YES];
  }
  </code></pre>
  
  <p>Not sure if there's a better way.</p>
  
  <p>And for those that want to know how to display the window: </p>
  
  <pre><code>    [[_windowController window] setLevel:NSPopUpMenuWindowLevel];
      [[_windowController window] orderFrontRegardless];
      [[_windowController window] makeKeyWindow];
  
      [_windowController showWindow:self];
  </code></pre>