Question

Consider the following scenario. I have an app with two windows:

  1. the main window which contains all of the app's functionality;
  2. and an auxiliary window that can be invoked using a global shortcut or by clicking app's status bar icon. It looks like this: enter image description here It's a simple window for quickly adding data to the application without bringing up the main window — possibly changing spaces and disrupting user's workflow.

    The window floats above everything else (it's on NSModalPanelWindowLevel) and can join all spaces (NSWindowCollectionBehaviorCanJoinAllSpaces)

Here's the problem: when the quick-add window is ordered out (the X button or Esc is pressed), the main window is made key and ordered front (provided that it's somewhere on the window list in the current space).

This isn't the behavior I want. Normally, when an app's window is closed, yes, you want the app's window below to be activated, but not here — this is a "helper" window that should work more-or-less independently from the app itself. When I'm in Safari and invoke the quick-add window, I only want to add some data, click Return, and I want it to go away — I want the previous window (Safari) to be key and on top, not the main window of my app (unless of course the main window of my app was key before invoking quick-add).

So, how to close an NSWindow without activating the window below?

I can't figure this out. The only idea I had is that maybe you could make a helper application that would display this auxiliary window — but that sounds like a lot of work (sending data back and forth between processes, all that…). There must be a simpler way!

Was it helpful?

Solution

i don't think this can be (usefully) done with an NSWindow.
As in this answer, i would recommend trying to use an NSPanel with the style NSNonactivatingPanelMask instead of creating an NSWindow.

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