Getting the correct size of a hosted plugin

Is it possible to get the current scale factor from a plugin running in Windows? I am using the following code to get the scale:

const auto scale = juce::Desktop::getInstance().getDisplays().getDisplayForRect(comp.getTopLevelComponent()->getScreenBounds())->scale;

This works fine for a standalone build but when running as a plugin in FL Studio I always get 1.0.

I need this as I’m hosting plugins and showing their editor within my plugin window, and when I get the hosted plugin’s editor component the reported bounds are incorrect and need to have the Windows DPI scaling applied.

EDIT: The issue essentially seems to be that the bounds reported by AudioProcessor::activeEditor are incorrect, and do not take into account the Windows system scaling settings.
This does not seem to be an issue when the AudioProcessorEditor is in it’s own OS window.

2 Likes

Further testing has revealed that setting JUCE_WIN_PER_MONITOR_DPI_AWARE to 0 solves this issue in Reaper (but not FL Studio).

Setting “High DPI scaling override” to “System” solves this issue but makes the host look rubbish on a high res monitor.

1 Like

Alright, I’ve found a clue to a possible solution:

Currently, Desktop::getDefaultMasterScale() will return 1.0 if called from a plugin or a “per monitor aware process”.

double Desktop::getDefaultMasterScale()
{
    if (! JUCEApplicationBase::isStandaloneApp() || isPerMonitorDPIAwareProcess())
        return 1.0;

    return getGlobalDPI() / USER_DEFAULT_SCREEN_DPI; // <-- this is the value I need
}

That seems to make sense because commenting those lines mashes up all sorts of things regarding plugin window sizes.

However, I think that “defaultMasterScale” value is still needed to report the size of a hosted plugin’s editor. Or I just need to get at the value of getGlobalDPI() / USER_DEFAULT_SCREEN_DPI so I can determine the actual size of the plugin’s editor.

@reuk any thoughts or ideas on this?

EDIT: Here’s a suggested patch to expose this value
0001-Add-getDesktopScaleFactor-method-to-Desktop-to-get-n.patch (2.7 KB)

1 Like

Hi @adamwilson ,
Did you ever solve this? Would be nice adding something similar to your patch into JUCE.

I’m having similar issue where the scale seems to be spoofed but the DPI is the one I’d expect.

Since updating to JUCE 7 the issue seems to be resolved, at least from my initial testing.