Plugin editor's sister DocumentWindow


My PluginEditor has an extra DocumentWindow opened sometimes.

How can I bind the visibility of this extra window to the visibility of the main plugin window, so that when Live or Maschine hide the main window, it gets hidden too, and if the main window appears again, it’s visible as well and ideally brought to the top if it was behind?

Appreciate your help, as usual!


You could use ComponentMovementWatcher::componentVisibilityChanged() in your DocumentWindow to hide itself when the editor is hidden, or your editor could override Component::visibilityChanged() and hide the DocumentWindow.

Then when it’s shown again you can use Component::toFront() to bring the window to the front.

Hi Ed,
Thank you for you answer.

I’m afraid Component::visibilityChanged() does not get called in Maschine or Live when you click on another track and your plugin gets hidden.

I’ve also tried calling [view isHiddenOrHasHiddenAncestor] on Mac directly on the native handle, but it says it’s not hidden. I don’t know what OS sorcery do those DAWs use to hide the windows.

How about Process::isForegroundProcess()?

It is still true when I click on another track. But helps with hiding the window when dealing with another app.

Hmm, I suppose you could also check whether the editor has keyboard focus as it’ll lose this when the user clicks on a different track or part of the DAW.

To check, when focus was gained, the FocusChangedListener works great, but if you use it to raise your sister window, you will inevitably get ping pongs, since that one will steal the focus again…
I don’t see, how you can distinguish, if it is a legitimate focus steal or an illegitimate…

I tried this:

void PluginEditor::globalFocusChanged(Component* focusedComponent)
  if(focusedComponent && myOtherWindow)
    auto * parent = focusedComponent->getTopLevelComponent();
    if(parent && (parent == myOtherWindow->getTopLevelComponent() || parent == getTopLevelComponent()))

I figured comparing the top level components would make it work even when a sub-component like a button gains focus.

But it does not fully work. In Maschine, if I am tuning a parameter in my plugin, then click on another track, then click back on this track, my other window is correctly brought to front.

But if my plugin didn’t have the focus before changing tracks, it won’t gain it back when clicking on its track. Despite having checked the option “Plugin Editor requires Keyboard Focus” in the Projucer.

It looks like changing tracks doesn’t necessarily give the focus to the track’s opened VST, despite making it go to the front.