[FR] Ability to disable restoring of focus on bringToFront in GUI Apps

it’s fine and wonderful that JUCE GUI Apps do all sorts of stuff in ComponentPeer to restore the focus of a window to the last previously focused component, when a TopLevelWindow (DocumentWindow) is brought to the front (say by resuming your app from another one), or when you switch between multiple document windows. but what if you would like to disable that behavior?

I discovered, after a deep dive into it, that it’s almost impossible to override this in any effective way. What is really needed is a simple method to disable this functionality, i.e.

void ComponentPeer::setRestoreFocusOnBringToFront(bool state = true)

I disabled this ONE LINE in juce_ComponentPeer.cpp and it does exactly what I want: bringing a window to the front does not restore the previous focus, but sets it to null. You then need to click in a component in order to focus something. But it’s impossible to subclass this variable or get access to it…

(Why? I was trying to make my standalone version, which is a real GUI App, behave in a similar fashion to the plugin version, where restoring the last focus is apparently impossible, see:
Is it impossible to know when your plugin is brought to the front or gains focus?)

void ComponentPeer::handleFocusLoss()
{
    if (component.hasKeyboardFocus (true))
    {
        lastFocusedComponent = Component::currentlyFocusedComponent;

        if (lastFocusedComponent != nullptr)
        {
            Component::currentlyFocusedComponent = nullptr;
            Desktop::getInstance().triggerFocusCallback();
            lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
        }
        // added: this makes it NOT restore a previously focused component on bringing a window to the front
        lastFocusedComponent = nullptr;
    }
}