Standalone plugin window appears offscreen

Run standalone plugin host, drag it to second monitor, quit. Disconnect monitor. Run it again, it’s offscreen and can’t be found. This is how I’m currently handling it:

void MyAudioProcessorEditor::handleAsyncUpdate()
#if JucePlugin_Build_Standalone
    if (auto* c = getTopLevelComponent())
        bool onScreen = false;
        for (auto area : Desktop::getInstance().getDisplays().getRectangleList (true))
            if (area.contains (c->getBounds()))
                onScreen = true;
        if (! onScreen)
            c->centreWithSize (c->getWidth(), c->getHeight());
        if (auto* dw = dynamic_cast<DocumentWindow*>(c))
            dw->setResizable (true, false);
1 Like