Skip to content

Commit

Permalink
Plugin Client: Respect requested layer-backedness of editor
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk authored and reuk committed Mar 9, 2023
1 parent 926bbda commit c5ddf64
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 33 deletions.
4 changes: 2 additions & 2 deletions modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp
Expand Up @@ -29,7 +29,7 @@
#if JucePlugin_Build_AAX && (JUCE_MAC || JUCE_WINDOWS)

#include <juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h>
#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>
#include <juce_audio_plugin_client/utility/juce_WindowsHooks.h>

#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>
Expand Down Expand Up @@ -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<ModifierKeyReceiver*> (component->getPeer()))
modReceiver->setModifierKeyProvider (this);
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm
Expand Up @@ -58,7 +58,7 @@

#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1

#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>

#include <juce_audio_basics/native/juce_mac_CoreAudioLayouts.h>
#include <juce_audio_basics/native/juce_mac_CoreAudioTimeConversions.h>
Expand Down Expand Up @@ -1600,7 +1600,7 @@ OSStatus NewFactoryPresetSet (const AUPreset& inNewFactoryPreset) override
object: nil];
activeUIs.add (view);

editorCompHolder->addToDesktop (0, (void*) view);
editorCompHolder->addToDesktop (detail::PluginUtilities::getDesktopFlags (editor), view);
editorCompHolder->setVisible (view);

return view;
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm
Expand Up @@ -39,7 +39,7 @@
#define JUCE_CORE_INCLUDE_OBJC_HELPERS 1

#include <juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h>
#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>

#import <CoreAudioKit/CoreAudioKit.h>
#import <AudioToolbox/AudioToolbox.h>
Expand Down Expand Up @@ -1834,7 +1834,7 @@ void loadView()
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])
Expand Down
3 changes: 2 additions & 1 deletion modules/juce_audio_plugin_client/LV2/juce_LV2_Client.cpp
Expand Up @@ -39,6 +39,7 @@

#include <juce_audio_plugin_client/juce_audio_plugin_client.h>
#include <juce_audio_plugin_client/utility/juce_CheckSettingMacros.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>
#include <juce_audio_plugin_client/utility/juce_LinuxMessageThread.h>

#include <juce_audio_processors/utilities/juce_FlagCache.h>
Expand Down Expand Up @@ -1534,7 +1535,7 @@ class LV2UIInstance : private Component,
setOpaque (true);
setVisible (false);
removeFromDesktop();
addToDesktop (0, parent);
addToDesktop (detail::PluginUtilities::getDesktopFlags (editor.get()), parent);
editor->addComponentListener (this);

*widget = getWindowHandle();
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_audio_plugin_client/Unity/juce_Unity_Wrapper.cpp
Expand Up @@ -27,7 +27,7 @@

#if JucePlugin_Build_Unity

#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>
#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>

#if JUCE_WINDOWS
Expand Down Expand Up @@ -298,7 +298,7 @@ class AudioProcessorUnityWrapper
{
pluginInstanceEditor.reset (pluginInstance->createEditorIfNeeded());
pluginInstanceEditor->setVisible (true);
pluginInstanceEditor->addToDesktop (0);
detail::PluginUtilities::addToDesktop (*pluginInstanceEditor, nullptr);
}

juceParameters.update (*pluginInstance, false);
Expand Down
10 changes: 6 additions & 4 deletions modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
Expand Up @@ -100,7 +100,7 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE
#define JUCE_VSTINTERFACE_H_INCLUDED 1
#define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1

#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>

using namespace juce;

Expand All @@ -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);
Expand Down Expand Up @@ -1003,8 +1003,10 @@ class JuceVSTWrapper : public AudioProcessorListener,
{
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
Expand All @@ -1021,7 +1023,7 @@ class JuceVSTWrapper : public AudioProcessorListener,
startTimer (500);
#endif
#elif JUCE_MAC
hostWindow = attachComponentToWindowRefVST (this, args.ptr, wrapper.useNSView);
hostWindow = attachComponentToWindowRefVST (this, desktopflags, args.ptr, wrapper.useNSView);
#endif

setVisible (true);
Expand Down
28 changes: 16 additions & 12 deletions modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.mm
Expand Up @@ -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
{
Expand Down Expand Up @@ -138,11 +138,13 @@ void initialiseMacVST()

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);
Expand All @@ -163,11 +165,13 @@ void initialiseMacVST()

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)
Expand Down
16 changes: 9 additions & 7 deletions modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
Expand Up @@ -46,7 +46,7 @@ JUCE_BEGIN_NO_SANITIZE ("vptr")

#include <juce_audio_plugin_client/utility/juce_CheckSettingMacros.h>
#include <juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h>
#include <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>
#include <juce_audio_plugin_client/utility/juce_PluginUtilities.h>
#include <juce_audio_plugin_client/utility/juce_WindowsHooks.h>
#include <juce_audio_plugin_client/utility/juce_LinuxMessageThread.h>
#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1783,6 +1783,8 @@ class JuceVST3EditController : public Vst::EditController,

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
Expand All @@ -1798,7 +1800,7 @@ class JuceVST3EditController : public Vst::EditController,
#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
Expand All @@ -1807,7 +1809,7 @@ class JuceVST3EditController : public Vst::EditController,

#else
isNSView = (strcmp (type, kPlatformTypeNSView) == 0);
macHostWindow = juce::attachComponentToWindowRefVST (component.get(), parent, isNSView);
macHostWindow = juce::attachComponentToWindowRefVST (component.get(), desktopFlags, parent, isNSView);
#endif

component->resizeHostWindow();
Expand Down
Expand Up @@ -23,8 +23,9 @@
==============================================================================
*/

#pragma once

#include <juce_audio_plugin_client/juce_audio_plugin_client.h>
#include <juce_audio_plugin_client/utility/juce_CreatePluginFilter.h>

namespace juce
{
Expand Down
55 changes: 55 additions & 0 deletions 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 <juce_audio_plugin_client/utility/juce_IncludeModuleHeaders.h>

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

0 comments on commit c5ddf64

Please sign in to comment.