Browse Source

VST: Query host window scale factor when opening editor window

tags/2021-05-28
ed 5 years ago
parent
commit
77787bd3ae
2 changed files with 71 additions and 32 deletions
  1. +11
    -5
      modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
  2. +60
    -27
      modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp

+ 11
- 5
modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp View File

@@ -1057,10 +1057,6 @@ public:
#endif
ignoreUnused (fakeMouseGenerator);
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
startTimer (500);
#endif
}
~EditorCompWrapper() override
@@ -1085,6 +1081,11 @@ public:
#if JUCE_WINDOWS
addToDesktop (0, args.ptr);
hostWindow = (HWND) args.ptr;
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
checkHostWindowScaleFactor();
startTimer (500);
#endif
#elif JUCE_LINUX
addToDesktop (0, args.ptr);
hostWindow = (Window) args.ptr;
@@ -1317,13 +1318,18 @@ public:
}
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
void timerCallback() override
void checkHostWindowScaleFactor()
{
auto hostWindowScale = (float) getScaleFactorForWindow (hostWindow);
if (hostWindowScale > 0.0f && ! approximatelyEqual (hostWindowScale, editorScaleFactor))
wrapper.handleSetContentScaleFactor (hostWindowScale);
}
void timerCallback() override
{
checkHostWindowScaleFactor();
}
#endif
#if JUCE_WINDOWS


+ 60
- 27
modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp View File

@@ -1027,7 +1027,7 @@ private:
: Vst::EditorView (&ec, nullptr),
owner (&ec), pluginInstance (p)
{
component.reset (new ContentWrapperComponent (*this, p));
createContentWrapperComponentIfNeeded();
#if JUCE_MAC
if (getHostType().type == PluginHostType::SteinbergCubase10)
@@ -1083,13 +1083,20 @@ private:
if (parent == nullptr || isPlatformTypeSupported (type) == kResultFalse)
return kResultFalse;
if (component == nullptr)
component.reset (new ContentWrapperComponent (*this, pluginInstance));
systemWindow = parent;
createContentWrapperComponentIfNeeded();
#if JUCE_WINDOWS || JUCE_LINUX
component->addToDesktop (0, parent);
component->setOpaque (true);
component->setVisible (true);
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
component->checkHostWindowScaleFactor();
component->startTimer (500);
#endif
#if JUCE_LINUX
if (auto* runLoop = getHostRunLoop())
{
@@ -1100,13 +1107,13 @@ private:
}
}
#endif
#else
isNSView = (strcmp (type, kPlatformTypeNSView) == 0);
macHostWindow = juce::attachComponentToWindowRefVST (component.get(), parent, isNSView);
#endif
component->resizeHostWindow();
systemWindow = parent;
attachedToParent();
// Life's too short to faff around with wave lab
@@ -1276,6 +1283,17 @@ private:
#if ! JUCE_MAC
if (! approximatelyEqual ((float) factor, editorScaleFactor))
{
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
// Cubase 10 only sends integer scale factors, so correct this for fractional scales
if (getHostType().type == PluginHostType::SteinbergCubase10)
{
auto hostWindowScale = (Steinberg::IPlugViewContentScaleSupport::ScaleFactor) getScaleFactorForWindow ((HWND) systemWindow);
if (hostWindowScale > 0.0 && ! approximatelyEqual (factor, hostWindowScale))
factor = hostWindowScale;
}
#endif
editorScaleFactor = (float) factor;
if (owner != nullptr)
@@ -1340,18 +1358,29 @@ private:
//==============================================================================
struct ContentWrapperComponent : public Component
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
, private Timer
, public Timer
#endif
{
ContentWrapperComponent (JuceVST3Editor& editor, AudioProcessor& plugin)
: pluginEditor (plugin.createEditorIfNeeded()),
owner (editor)
ContentWrapperComponent (JuceVST3Editor& editor) : owner (editor)
{
setOpaque (true);
setBroughtToFrontOnMouseClick (true);
// if hasEditor() returns true then createEditorIfNeeded has to return a valid editor
jassert (pluginEditor != nullptr);
ignoreUnused (fakeMouseGenerator);
}
~ContentWrapperComponent() override
{
if (pluginEditor != nullptr)
{
PopupMenu::dismissAllActiveMenus();
pluginEditor->processor.editorBeingDeleted (pluginEditor.get());
}
}
void createEditor (AudioProcessor& plugin)
{
pluginEditor.reset (plugin.createEditorIfNeeded());
if (pluginEditor != nullptr)
{
@@ -1367,20 +1396,10 @@ private:
resizeHostWindow();
}
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
startTimer (500);
#endif
ignoreUnused (fakeMouseGenerator);
}
~ContentWrapperComponent() override
{
if (pluginEditor != nullptr)
else
{
PopupMenu::dismissAllActiveMenus();
pluginEditor->processor.editorBeingDeleted (pluginEditor.get());
// if hasEditor() returns true then createEditorIfNeeded has to return a valid editor
jassertfalse;
}
}
@@ -1493,19 +1512,24 @@ private:
}
}
std::unique_ptr<AudioProcessorEditor> pluginEditor;
private:
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
void timerCallback() override
void checkHostWindowScaleFactor()
{
auto hostWindowScale = (float) getScaleFactorForWindow ((HWND) owner.systemWindow);
if (hostWindowScale > 0.0 && ! approximatelyEqual (hostWindowScale, owner.editorScaleFactor))
owner.setContentScaleFactor (hostWindowScale);
}
void timerCallback() override
{
checkHostWindowScaleFactor();
}
#endif
std::unique_ptr<AudioProcessorEditor> pluginEditor;
private:
JuceVST3Editor& owner;
FakeMouseMoveGenerator fakeMouseGenerator;
Rectangle<int> lastBounds;
@@ -1514,6 +1538,15 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentWrapperComponent)
};
void createContentWrapperComponentIfNeeded()
{
if (component == nullptr)
{
component.reset (new ContentWrapperComponent (*this));
component->createEditor (pluginInstance);
}
}
//==============================================================================
ScopedJuceInitialiser_GUI libraryInitialiser;


Loading…
Cancel
Save