I wanted to look into this. It seems this is completely unreliable as a method of determine the “front” status of your plugin window.
I built a simple plugin (VST3, AU) to test this a bit (with a few child components, and a message box to print out the results of calls to various focus related functions). You can download the “FocusTest” project here:
FocusTest.zip (35.4 KB)
I implemented the following functions in the AudioProcessorEditor component:
- focusGained()
- focusLost()
- focusOfChildComponentChanged()
- globalFocusChanged()
- broughtToFront() <— never gets called, but it’s in there
It inherits from AsyncUpdater to display the currentlyFocusedComponent when the editor is launched.
“Plugin Editor requires Keyboard Focus” is checked in the Projucer project (although my understanding is this only has an effect on VST and AU, not VST3).
I tested JUCE’s AudioPluginHost (APH) on Mac and Windows, Reaper on Mac and Windows, and Logic on Mac. Of course, this is just a small sampling of hosts, but it shows how different they are.
Reaper Windows: this is the only one I tried that seems to work logically, where selecting another window unfocuses your plugin, while reselecting your plugin’s title bar refocuses the last focused component (and you get a focusOfChildComponentChanged()).
Conclusion: results are inconsistent from host to host, and platform to platform. There is no accurate way to deduce a change in the frontmost position of your plugin editor window from currently available methods. Which is why we need this:
Results of the tests (spreadsheet also included in download):