From 584d9a4ec06015a476fc12966a8bf37df921bfc7 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 28 Oct 2010 17:53:52 +0100 Subject: [PATCH] Fixes for ComponentBoundsConstrainer, linux VSTs, and firefox NPAPI. --- .../wrapper/VST/juce_VST_Wrapper.cpp | 153 +++++++++--------- .../wrapper/juce_NPAPI_GlueCode.cpp | 6 + juce_amalgamated.cpp | 41 ++--- juce_amalgamated.h | 2 +- src/core/juce_StandardHeader.h | 2 +- .../juce_ComponentBoundsConstrainer.cpp | 2 +- src/native/linux/juce_linux_Messaging.cpp | 39 ++--- 7 files changed, 126 insertions(+), 119 deletions(-) diff --git a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp index d1d53f760b..ef637f951c 100644 --- a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp +++ b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp @@ -328,27 +328,32 @@ public: { JUCE_AUTORELEASEPOOL - stopTimer(); - deleteEditor (false); + { + #if JUCE_LINUX + MessageManagerLock mmLock; + #endif + stopTimer(); + deleteEditor (false); - hasShutdown = true; + hasShutdown = true; - delete filter; - filter = 0; + delete filter; + filter = 0; - jassert (editorComp == 0); + jassert (editorComp == 0); - channels.free(); - deleteTempChannels(); + channels.free(); + deleteTempChannels(); - jassert (activePlugins.contains (this)); - activePlugins.removeValue (this); + jassert (activePlugins.contains (this)); + activePlugins.removeValue (this); + } if (activePlugins.size() == 0) { -#if JUCE_LINUX + #if JUCE_LINUX SharedMessageThread::deleteInstance(); -#endif + #endif shutdownJuce_GUI(); } } @@ -1195,25 +1200,14 @@ public: { if (editorComp != 0) { -#if ! JUCE_LINUX // linux hosts shouldn't be trusted! if (! (canHostDo (const_cast ("sizeWindow")) && sizeWindow (newWidth, newHeight))) -#endif { // some hosts don't support the sizeWindow call, so do it manually.. #if JUCE_MAC setNativeHostWindowSize (hostWindow, editorComp, newWidth, newHeight, getHostType()); #elif JUCE_LINUX - Window root; - int x, y; - unsigned int width, height, border, depth; - - XGetGeometry (display, hostWindow, &root, - &x, &y, &width, &height, &border, &depth); - - newWidth += (width + border) - editorComp->getWidth(); - newHeight += (height + border) - editorComp->getHeight(); - - XResizeWindow (display, hostWindow, newWidth, newHeight); + // (Currently, all linux hosts support sizeWindow, so this should never need to happen) + editorComp->setSize (newWidth, newHeight); #else int dw = 0; int dh = 0; @@ -1347,11 +1341,16 @@ public: const int ch = child->getHeight(); wrapper.resizeHostWindow (cw, ch); - setSize (cw, ch); - #if JUCE_MAC + #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail. + setSize (cw, ch); + #else + XResizeWindow (display, (Window) getWindowHandle(), cw, ch); + #endif + + #if JUCE_MAC wrapper.resizeHostWindow (cw, ch); // (doing this a second time seems to be necessary in tracktion) - #endif + #endif } void handleAsyncUpdate() @@ -1487,6 +1486,10 @@ namespace { if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0) { + #if JUCE_LINUX + MessageManagerLock mmLock; + #endif + AudioProcessor* const filter = createPluginFilter(); if (filter != 0) @@ -1507,74 +1510,66 @@ namespace // Mac startup code.. #if JUCE_MAC -extern "C" __attribute__ ((visibility("default"))) AEffect* VSTPluginMain (audioMasterCallback audioMaster) -{ - initialiseMac(); - return pluginEntryPoint (audioMaster); -} + extern "C" __attribute__ ((visibility("default"))) AEffect* VSTPluginMain (audioMasterCallback audioMaster) + { + initialiseMac(); + return pluginEntryPoint (audioMaster); + } -extern "C" __attribute__ ((visibility("default"))) AEffect* main_macho (audioMasterCallback audioMaster) -{ - initialiseMac(); - return pluginEntryPoint (audioMaster); -} + extern "C" __attribute__ ((visibility("default"))) AEffect* main_macho (audioMasterCallback audioMaster) + { + initialiseMac(); + return pluginEntryPoint (audioMaster); + } //============================================================================== // Linux startup code.. #elif JUCE_LINUX -extern "C" AEffect* VSTPluginMain (audioMasterCallback audioMaster) -{ - SharedMessageThread::getInstance(); + extern "C" __attribute__ ((visibility("default"))) AEffect* VSTPluginMain (audioMasterCallback audioMaster) + { + SharedMessageThread::getInstance(); + return pluginEntryPoint (audioMaster); + } - return pluginEntryPoint (audioMaster); -} + extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main"); -extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main"); + extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster) + { + return VSTPluginMain (audioMaster); + } -extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster) -{ - return VSTPluginMain (audioMaster); -} - -__attribute__((constructor)) void myPluginInit() -{ - // don't put initialiseJuce_GUI here... it will crash ! -} - -__attribute__((destructor)) void myPluginFini() -{ - // don't put shutdownJuce_GUI here... it will crash ! -} + // don't put initialiseJuce_GUI or shutdownJuce_GUI in these... it will crash! + __attribute__((constructor)) void myPluginInit() {} + __attribute__((destructor)) void myPluginFini() {} //============================================================================== // Win32 startup code.. #else -extern "C" __declspec (dllexport) AEffect* VSTPluginMain (audioMasterCallback audioMaster) -{ - return pluginEntryPoint (audioMaster); -} + extern "C" __declspec (dllexport) AEffect* VSTPluginMain (audioMasterCallback audioMaster) + { + return pluginEntryPoint (audioMaster); + } -#ifndef _WIN64 // (can't compile this on win64, but it's not needed anyway with VST2.4) -extern "C" __declspec (dllexport) void* main (audioMasterCallback audioMaster) -{ - return (void*) pluginEntryPoint (audioMaster); -} -#endif + #ifndef _WIN64 // (can't compile this on win64, but it's not needed anyway with VST2.4) + extern "C" __declspec (dllexport) void* main (audioMasterCallback audioMaster) + { + return (void*) pluginEntryPoint (audioMaster); + } + #endif -#if JucePlugin_Build_RTAS -BOOL WINAPI DllMainVST (HINSTANCE instance, DWORD dwReason, LPVOID) -#else -extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID) -#endif -{ - if (dwReason == DLL_PROCESS_ATTACH) - PlatformUtilities::setCurrentModuleInstanceHandle (instance); - - return TRUE; -} + #if JucePlugin_Build_RTAS + BOOL WINAPI DllMainVST (HINSTANCE instance, DWORD dwReason, LPVOID) + #else + extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID) + #endif + { + if (dwReason == DLL_PROCESS_ATTACH) + PlatformUtilities::setCurrentModuleInstanceHandle (instance); + return TRUE; + } #endif #endif diff --git a/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp b/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp index 286d88e28e..2ad78a1b95 100644 --- a/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp +++ b/extras/browser plugins/wrapper/juce_NPAPI_GlueCode.cpp @@ -512,6 +512,12 @@ public: if (! isBrowserContentView (parentView)) parentView = currentParentView; } + else if (currentParentView != 0 && ! target.isEmpty()) + { + // Firefox can send lots of spurious resize messages when updating its pages, so this is a + // bodge to avoid flickering caused by repeatedly removing and re-adding the view.. + parentView = currentParentView; + } log ("parent: " + nsStringToJuce ([parentView description])); } diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index c02de9d801..8c9cb9dafd 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -62026,7 +62026,7 @@ void ComponentBoundsConstrainer::checkBounds (Rectangle& bounds, if (minOffTop > 0) { - const int limit = limits.getY() + jmin (minOffLeft - bounds.getWidth(), 0); + const int limit = limits.getY() + jmin (minOffTop - bounds.getHeight(), 0); if (bounds.getY() < limit) { @@ -257257,11 +257257,14 @@ namespace LinuxErrorHandling static void removeXErrorHandlers() { - XSetIOErrorHandler (oldIOErrorHandler); - oldIOErrorHandler = 0; + if (JUCEApplication::isStandaloneApp()) + { + XSetIOErrorHandler (oldIOErrorHandler); + oldIOErrorHandler = 0; - XSetErrorHandler (oldErrorHandler); - oldErrorHandler = 0; + XSetErrorHandler (oldErrorHandler); + oldErrorHandler = 0; + } } static void keyboardBreakSignalHandler (int sig) @@ -257284,28 +257287,28 @@ namespace LinuxErrorHandling void MessageManager::doPlatformSpecificInitialisation() { - // Initialise xlib for multiple thread support - static bool initThreadCalled = false; - - if (! initThreadCalled) + if (JUCEApplication::isStandaloneApp()) { - if (! XInitThreads()) + // Initialise xlib for multiple thread support + static bool initThreadCalled = false; + + if (! initThreadCalled) { - // This is fatal! Print error and closedown - Logger::outputDebugString ("Failed to initialise xlib thread support."); - - if (JUCEApplication::isStandaloneApp()) + if (! XInitThreads()) + { + // This is fatal! Print error and closedown + Logger::outputDebugString ("Failed to initialise xlib thread support."); Process::terminate(); + return; + } - return; + initThreadCalled = true; } - initThreadCalled = true; + LinuxErrorHandling::installXErrorHandlers(); + LinuxErrorHandling::installKeyboardBreakHandler(); } - LinuxErrorHandling::installXErrorHandlers(); - LinuxErrorHandling::installKeyboardBreakHandler(); - // Create the internal message queue InternalMessageQueue::getInstance(); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 3e1163cfa6..d2b65ce693 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -64,7 +64,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 83 +#define JUCE_BUILDNUMBER 84 /** Current Juce version number. diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 7c6a08c09a..69404a11e0 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 83 +#define JUCE_BUILDNUMBER 84 /** Current Juce version number. diff --git a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp index 23832df271..65e0df2261 100644 --- a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp +++ b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp @@ -221,7 +221,7 @@ void ComponentBoundsConstrainer::checkBounds (Rectangle& bounds, if (minOffTop > 0) { - const int limit = limits.getY() + jmin (minOffLeft - bounds.getWidth(), 0); + const int limit = limits.getY() + jmin (minOffTop - bounds.getHeight(), 0); if (bounds.getY() < limit) { diff --git a/src/native/linux/juce_linux_Messaging.cpp b/src/native/linux/juce_linux_Messaging.cpp index 2fc11e8d60..34c85f40be 100644 --- a/src/native/linux/juce_linux_Messaging.cpp +++ b/src/native/linux/juce_linux_Messaging.cpp @@ -283,11 +283,14 @@ namespace LinuxErrorHandling static void removeXErrorHandlers() { - XSetIOErrorHandler (oldIOErrorHandler); - oldIOErrorHandler = 0; + if (JUCEApplication::isStandaloneApp()) + { + XSetIOErrorHandler (oldIOErrorHandler); + oldIOErrorHandler = 0; - XSetErrorHandler (oldErrorHandler); - oldErrorHandler = 0; + XSetErrorHandler (oldErrorHandler); + oldErrorHandler = 0; + } } //============================================================================== @@ -312,28 +315,28 @@ namespace LinuxErrorHandling //============================================================================== void MessageManager::doPlatformSpecificInitialisation() { - // Initialise xlib for multiple thread support - static bool initThreadCalled = false; - - if (! initThreadCalled) + if (JUCEApplication::isStandaloneApp()) { - if (! XInitThreads()) + // Initialise xlib for multiple thread support + static bool initThreadCalled = false; + + if (! initThreadCalled) { - // This is fatal! Print error and closedown - Logger::outputDebugString ("Failed to initialise xlib thread support."); - - if (JUCEApplication::isStandaloneApp()) + if (! XInitThreads()) + { + // This is fatal! Print error and closedown + Logger::outputDebugString ("Failed to initialise xlib thread support."); Process::terminate(); + return; + } - return; + initThreadCalled = true; } - initThreadCalled = true; + LinuxErrorHandling::installXErrorHandlers(); + LinuxErrorHandling::installKeyboardBreakHandler(); } - LinuxErrorHandling::installXErrorHandlers(); - LinuxErrorHandling::installKeyboardBreakHandler(); - // Create the internal message queue InternalMessageQueue::getInstance();