diff --git a/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp b/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp index f4fb880ab7..1b9edf9a6f 100644 --- a/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp @@ -29,7 +29,7 @@ #if JucePlugin_Build_AAX && (JUCE_MAC || JUCE_WINDOWS) #include -#include +#include #include #include @@ -454,7 +454,7 @@ namespace AAXClasses #endif { component->setVisible (true); - component->addToDesktop (0, nativeViewToAttachTo); + component->addToDesktop (detail::PluginUtilities::getDesktopFlags (component->pluginEditor.get()), nativeViewToAttachTo); if (ModifierKeyReceiver* modReceiver = dynamic_cast (component->getPeer())) modReceiver->setModifierKeyProvider (this); diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index a97fdee747..dc94ea2fc7 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -58,7 +58,7 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1 -#include +#include #include #include @@ -1600,7 +1600,7 @@ public: object: nil]; activeUIs.add (view); - editorCompHolder->addToDesktop (0, (void*) view); + editorCompHolder->addToDesktop (detail::PluginUtilities::getDesktopFlags (editor), view); editorCompHolder->setVisible (view); return view; diff --git a/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm index 04610cda42..eab87f8495 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm @@ -39,7 +39,7 @@ #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1 #include -#include +#include #import #import @@ -1834,7 +1834,7 @@ public: editor->setVisible (true); #endif - editor->addToDesktop (0, view); + detail::PluginUtilities::addToDesktop (*editor, view); #if JUCE_IOS if (JUCE_IOS_MAC_VIEW* peerView = [[[myself view] subviews] objectAtIndex: 0]) diff --git a/modules/juce_audio_plugin_client/LV2/juce_LV2_Client.cpp b/modules/juce_audio_plugin_client/LV2/juce_LV2_Client.cpp index 2c1619b628..5d1dacd5ea 100644 --- a/modules/juce_audio_plugin_client/LV2/juce_LV2_Client.cpp +++ b/modules/juce_audio_plugin_client/LV2/juce_LV2_Client.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -1534,7 +1535,7 @@ public: setOpaque (true); setVisible (false); removeFromDesktop(); - addToDesktop (0, parent); + addToDesktop (detail::PluginUtilities::getDesktopFlags (editor.get()), parent); editor->addComponentListener (this); *widget = getWindowHandle(); diff --git a/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp b/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp index e889b09ead..86d40226bd 100644 --- a/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp @@ -27,7 +27,7 @@ #if JucePlugin_Build_Unity -#include +#include #include #if JUCE_WINDOWS @@ -298,7 +298,7 @@ public: { pluginInstanceEditor.reset (pluginInstance->createEditorIfNeeded()); pluginInstanceEditor->setVisible (true); - pluginInstanceEditor->addToDesktop (0); + detail::PluginUtilities::addToDesktop (*pluginInstanceEditor, nullptr); } juceParameters.update (*pluginInstance, false); diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 887c0585b3..162d9bef90 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -100,7 +100,7 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE #define JUCE_VSTINTERFACE_H_INCLUDED 1 #define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1 -#include +#include using namespace juce; @@ -123,7 +123,7 @@ namespace juce { #if JUCE_MAC extern JUCE_API void initialiseMacVST(); - extern JUCE_API void* attachComponentToWindowRefVST (Component*, void* parent, bool isNSView); + extern JUCE_API void* attachComponentToWindowRefVST (Component*, int, void* parent, bool isNSView); extern JUCE_API void detachComponentFromWindowRefVST (Component*, void* window, bool isNSView); extern JUCE_API void setNativeHostWindowSizeVST (void* window, Component*, int newWidth, int newHeight, bool isNSView); extern JUCE_API void checkWindowVisibilityVST (void* window, Component*, bool isNSView); @@ -1003,8 +1003,10 @@ public: { setVisible (false); + const auto desktopFlags = detail::PluginUtilities::getDesktopFlags (getEditorComp()); + #if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD - addToDesktop (0, args.ptr); + addToDesktop (desktopFlags, args.ptr); hostWindow = (HostWindowType) args.ptr; #if JUCE_LINUX || JUCE_BSD @@ -1021,7 +1023,7 @@ public: startTimer (500); #endif #elif JUCE_MAC - hostWindow = attachComponentToWindowRefVST (this, args.ptr, wrapper.useNSView); + hostWindow = attachComponentToWindowRefVST (this, desktopflags, args.ptr, wrapper.useNSView); #endif setVisible (true); diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm index 79c0b0ce0d..2b4dd4b6b1 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm @@ -79,8 +79,8 @@ void initialiseMacVST() #endif } -JUCE_API void* attachComponentToWindowRefVST (Component* comp, void* parentWindowOrView, bool isNSView); -void* attachComponentToWindowRefVST (Component* comp, void* parentWindowOrView, [[maybe_unused]] bool isNSView) +JUCE_API void* attachComponentToWindowRefVST (Component* comp, int, void* parentWindowOrView, bool isNSView); +void* attachComponentToWindowRefVST (Component* comp, int desktopFlags, void* parentWindowOrView, [[maybe_unused]] bool isNSView) { JUCE_AUTORELEASEPOOL { @@ -138,11 +138,13 @@ void* attachComponentToWindowRefVST (Component* comp, void* parentWindowOrView, updateEditorCompBoundsVST (comp); - #if ! JucePlugin_EditorRequiresKeyboardFocus - comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses); - #else - comp->addToDesktop (ComponentPeer::windowIsTemporary); - #endif + const auto defaultFlags = + #if ! JucePlugin_EditorRequiresKeyboardFocus + ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses; + #else + ComponentPeer::windowIsTemporary; + #endif + comp->addToDesktop (desktopFlags | defaultFlags); comp->setVisible (true); comp->toFront (false); @@ -163,11 +165,13 @@ void* attachComponentToWindowRefVST (Component* comp, void* parentWindowOrView, NSView* parentView = [(NSView*) parentWindowOrView retain]; - #if JucePlugin_EditorRequiresKeyboardFocus - comp->addToDesktop (0, parentView); - #else - comp->addToDesktop (ComponentPeer::windowIgnoresKeyPresses, parentView); - #endif + const auto defaultFlags = + #if JucePlugin_EditorRequiresKeyboardFocus + 0; + #else + ComponentPeer::windowIgnoresKeyPresses; + #endif + comp->addToDesktop (desktopFlags | defaultFlags, parentView); // (this workaround is because Wavelab provides a zero-size parent view..) if ([parentView frame].size.height == 0) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 33a284d0f4..3bf051c159 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -46,7 +46,7 @@ JUCE_BEGIN_NO_SANITIZE ("vptr") #include #include -#include +#include #include #include #include @@ -108,14 +108,14 @@ using namespace Steinberg; //============================================================================== #if JUCE_MAC - extern void initialiseMacVST(); + void initialiseMacVST(); #if ! JUCE_64BIT - extern void updateEditorCompBoundsVST (Component*); + void updateEditorCompBoundsVST (Component*); #endif - extern JUCE_API void* attachComponentToWindowRefVST (Component*, void* parentWindowOrView, bool isNSView); - extern JUCE_API void detachComponentFromWindowRefVST (Component*, void* nsWindow, bool isNSView); + JUCE_API void* attachComponentToWindowRefVST (Component*, int desktopFlags, void* parentWindowOrView, bool isNSView); + JUCE_API void detachComponentFromWindowRefVST (Component*, void* nsWindow, bool isNSView); #endif #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE @@ -1783,6 +1783,8 @@ private: createContentWrapperComponentIfNeeded(); + const auto desktopFlags = detail::PluginUtilities::getDesktopFlags (component->pluginEditor.get()); + #if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD // If the plugin was last opened at a particular scale, try to reapply that scale here. // Note that we do this during attach(), rather than in JuceVST3Editor(). During the @@ -1798,7 +1800,7 @@ private: #endif component->setOpaque (true); - component->addToDesktop (0, (void*) systemWindow); + component->addToDesktop (desktopFlags, systemWindow); component->setVisible (true); #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE @@ -1807,7 +1809,7 @@ private: #else isNSView = (strcmp (type, kPlatformTypeNSView) == 0); - macHostWindow = juce::attachComponentToWindowRefVST (component.get(), parent, isNSView); + macHostWindow = juce::attachComponentToWindowRefVST (component.get(), desktopFlags, parent, isNSView); #endif component->resizeHostWindow(); diff --git a/modules/juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h b/modules/juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h index d8fc9bc1ce..ad3b99e8a9 100644 --- a/modules/juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h +++ b/modules/juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h @@ -23,8 +23,9 @@ ============================================================================== */ +#pragma once + #include -#include namespace juce { diff --git a/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.h b/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.h new file mode 100644 index 0000000000..aa68d25dae --- /dev/null +++ b/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.h @@ -0,0 +1,55 @@ +/* + ============================================================================== + + This file is part of the JUCE library. + Copyright (c) 2022 - Raw Material Software Limited + + JUCE is an open source library subject to commercial or open-source + licensing. + + By using JUCE, you agree to the terms of both the JUCE 7 End-User License + Agreement and JUCE Privacy Policy. + + End User License Agreement: www.juce.com/juce-7-licence + Privacy Policy: www.juce.com/juce-privacy-policy + + Or: You may also use this code under the terms of the GPL v3 (see + www.gnu.org/licenses). + + JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER + EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE + DISCLAIMED. + + ============================================================================== +*/ + +#pragma once + +#include + +namespace juce::detail +{ + +struct PluginUtilities +{ + PluginUtilities() = delete; + + static int getDesktopFlags (const AudioProcessorEditor& editor) + { + return editor.wantsLayerBackedView() + ? 0 + : ComponentPeer::windowRequiresSynchronousCoreGraphicsRendering; + } + + static int getDesktopFlags (const AudioProcessorEditor* editor) + { + return editor != nullptr ? getDesktopFlags (*editor) : 0; + } + + static void addToDesktop (AudioProcessorEditor& editor, void* parent) + { + editor.addToDesktop (getDesktopFlags (editor), parent); + } +}; + +} // namespace juce::detail