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 #endif
ignoreUnused (fakeMouseGenerator); ignoreUnused (fakeMouseGenerator);
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
startTimer (500);
#endif
} }
~EditorCompWrapper() override ~EditorCompWrapper() override
@@ -1085,6 +1081,11 @@ public:
#if JUCE_WINDOWS #if JUCE_WINDOWS
addToDesktop (0, args.ptr); addToDesktop (0, args.ptr);
hostWindow = (HWND) args.ptr; hostWindow = (HWND) args.ptr;
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
checkHostWindowScaleFactor();
startTimer (500);
#endif
#elif JUCE_LINUX #elif JUCE_LINUX
addToDesktop (0, args.ptr); addToDesktop (0, args.ptr);
hostWindow = (Window) args.ptr; hostWindow = (Window) args.ptr;
@@ -1317,13 +1318,18 @@ public:
} }
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
void timerCallback() override
void checkHostWindowScaleFactor()
{ {
auto hostWindowScale = (float) getScaleFactorForWindow (hostWindow); auto hostWindowScale = (float) getScaleFactorForWindow (hostWindow);
if (hostWindowScale > 0.0f && ! approximatelyEqual (hostWindowScale, editorScaleFactor)) if (hostWindowScale > 0.0f && ! approximatelyEqual (hostWindowScale, editorScaleFactor))
wrapper.handleSetContentScaleFactor (hostWindowScale); wrapper.handleSetContentScaleFactor (hostWindowScale);
} }
void timerCallback() override
{
checkHostWindowScaleFactor();
}
#endif #endif
#if JUCE_WINDOWS #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), : Vst::EditorView (&ec, nullptr),
owner (&ec), pluginInstance (p) owner (&ec), pluginInstance (p)
{ {
component.reset (new ContentWrapperComponent (*this, p));
createContentWrapperComponentIfNeeded();
#if JUCE_MAC #if JUCE_MAC
if (getHostType().type == PluginHostType::SteinbergCubase10) if (getHostType().type == PluginHostType::SteinbergCubase10)
@@ -1083,13 +1083,20 @@ private:
if (parent == nullptr || isPlatformTypeSupported (type) == kResultFalse) if (parent == nullptr || isPlatformTypeSupported (type) == kResultFalse)
return kResultFalse; return kResultFalse;
if (component == nullptr)
component.reset (new ContentWrapperComponent (*this, pluginInstance));
systemWindow = parent;
createContentWrapperComponentIfNeeded();
#if JUCE_WINDOWS || JUCE_LINUX #if JUCE_WINDOWS || JUCE_LINUX
component->addToDesktop (0, parent); component->addToDesktop (0, parent);
component->setOpaque (true); component->setOpaque (true);
component->setVisible (true); component->setVisible (true);
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
component->checkHostWindowScaleFactor();
component->startTimer (500);
#endif
#if JUCE_LINUX #if JUCE_LINUX
if (auto* runLoop = getHostRunLoop()) if (auto* runLoop = getHostRunLoop())
{ {
@@ -1100,13 +1107,13 @@ private:
} }
} }
#endif #endif
#else #else
isNSView = (strcmp (type, kPlatformTypeNSView) == 0); isNSView = (strcmp (type, kPlatformTypeNSView) == 0);
macHostWindow = juce::attachComponentToWindowRefVST (component.get(), parent, isNSView); macHostWindow = juce::attachComponentToWindowRefVST (component.get(), parent, isNSView);
#endif #endif
component->resizeHostWindow(); component->resizeHostWindow();
systemWindow = parent;
attachedToParent(); attachedToParent();
// Life's too short to faff around with wave lab // Life's too short to faff around with wave lab
@@ -1276,6 +1283,17 @@ private:
#if ! JUCE_MAC #if ! JUCE_MAC
if (! approximatelyEqual ((float) factor, editorScaleFactor)) 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; editorScaleFactor = (float) factor;
if (owner != nullptr) if (owner != nullptr)
@@ -1340,18 +1358,29 @@ private:
//============================================================================== //==============================================================================
struct ContentWrapperComponent : public Component struct ContentWrapperComponent : public Component
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
, private Timer
, public Timer
#endif #endif
{ {
ContentWrapperComponent (JuceVST3Editor& editor, AudioProcessor& plugin)
: pluginEditor (plugin.createEditorIfNeeded()),
owner (editor)
ContentWrapperComponent (JuceVST3Editor& editor) : owner (editor)
{ {
setOpaque (true); setOpaque (true);
setBroughtToFrontOnMouseClick (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) if (pluginEditor != nullptr)
{ {
@@ -1367,20 +1396,10 @@ private:
resizeHostWindow(); 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 #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
void timerCallback() override
void checkHostWindowScaleFactor()
{ {
auto hostWindowScale = (float) getScaleFactorForWindow ((HWND) owner.systemWindow); auto hostWindowScale = (float) getScaleFactorForWindow ((HWND) owner.systemWindow);
if (hostWindowScale > 0.0 && ! approximatelyEqual (hostWindowScale, owner.editorScaleFactor)) if (hostWindowScale > 0.0 && ! approximatelyEqual (hostWindowScale, owner.editorScaleFactor))
owner.setContentScaleFactor (hostWindowScale); owner.setContentScaleFactor (hostWindowScale);
} }
void timerCallback() override
{
checkHostWindowScaleFactor();
}
#endif #endif
std::unique_ptr<AudioProcessorEditor> pluginEditor;
private:
JuceVST3Editor& owner; JuceVST3Editor& owner;
FakeMouseMoveGenerator fakeMouseGenerator; FakeMouseMoveGenerator fakeMouseGenerator;
Rectangle<int> lastBounds; Rectangle<int> lastBounds;
@@ -1514,6 +1538,15 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentWrapperComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentWrapperComponent)
}; };
void createContentWrapperComponentIfNeeded()
{
if (component == nullptr)
{
component.reset (new ContentWrapperComponent (*this));
component->createEditor (pluginInstance);
}
}
//============================================================================== //==============================================================================
ScopedJuceInitialiser_GUI libraryInitialiser; ScopedJuceInitialiser_GUI libraryInitialiser;


Loading…
Cancel
Save