diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index f901b4f05..d8348ad99 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -3145,6 +3145,7 @@ bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc, const bool alw case PLUGIN_LV2: case PLUGIN_VST2: case PLUGIN_VST3: + case PLUGIN_CLAP: btype = getBinaryTypeFromFile(stateSave.binary); break; default: diff --git a/source/backend/plugin/CarlaPluginCLAP.cpp b/source/backend/plugin/CarlaPluginCLAP.cpp index 34dee1357..941d83f68 100644 --- a/source/backend/plugin/CarlaPluginCLAP.cpp +++ b/source/backend/plugin/CarlaPluginCLAP.cpp @@ -1101,7 +1101,12 @@ public: uint32_t width, height; if (fExtensions.gui->get_size(fPlugin, &width, &height)) - fUI.window->setSize(width, height, false); + { + fUI.isResizingFromInit = true; + fUI.width = width; + fUI.height = height; + fUI.window->setSize(width, height, true, true); + } fExtensions.gui->show(fPlugin); fUI.window->show(); @@ -1162,7 +1167,48 @@ public: void uiIdle() override { + #ifdef CLAP_WINDOW_API_NATIVE + if (fUI.shouldClose) + { + fUI.shouldClose = false; + fUI.isResizingFromHost = fUI.isResizingFromInit = false; + fUI.isResizingFromPlugin = 0; + + showCustomUI(false); + pData->engine->callback(true, true, + ENGINE_CALLBACK_UI_STATE_CHANGED, + pData->id, + 0, + 0, 0, 0.0f, nullptr); + } + + if (fUI.isResizingFromHost) + { + fUI.isResizingFromHost = false; + + if (fUI.isResizingFromPlugin == 0 && !fUI.isResizingFromInit == false) + { + carla_stdout("Host resize restarted"); + fExtensions.gui->set_size(fPlugin, fUI.width, fUI.height); + } + } + + if (fUI.window != nullptr) + fUI.window->idle(); + + if (fUI.isResizingFromPlugin == 2) + { + fUI.isResizingFromPlugin = 1; + } + else if (fUI.isResizingFromPlugin == 1) + { + fUI.isResizingFromPlugin = 0; + carla_stdout("Plugin resize stopped"); + } + #endif + runIdleCallbacksAsNeeded(); + CarlaPlugin::uiIdle(); } @@ -2451,23 +2497,66 @@ protected: void handlePluginUIClosed() override { CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,); - carla_debug("CarlaPluginCLAP::handlePluginUIClosed()"); + carla_stdout("CarlaPluginCLAP::handlePluginUIClosed()"); - showCustomUI(false); - pData->engine->callback(true, true, - ENGINE_CALLBACK_UI_STATE_CHANGED, - pData->id, - 0, - 0, 0, 0.0f, nullptr); + fUI.shouldClose = true; } void handlePluginUIResized(const uint width, const uint height) override { CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,); - carla_debug("CarlaPluginCLAP::handlePluginUIResized(%u, %u)", width, height); + carla_stdout("CarlaPluginCLAP::handlePluginUIResized(%u, %u | vs %u %u) %d %s %s", + width, height, + fUI.width, fUI.height, + fUI.isResizingFromPlugin, bool2str(fUI.isResizingFromInit), bool2str(fUI.isResizingFromHost)); + + if (fExtensions.gui == nullptr) + return; + + if (fUI.isResizingFromPlugin != 0) + { + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.width == width, fUI.width, width,); + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.height == height, fUI.height, height,); + fUI.isResizingFromPlugin = 2; + return; + } - if (fExtensions.gui != nullptr) - fExtensions.gui->set_size(fPlugin, width, height); + if (fUI.isResizingFromInit) + { + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.width == width, fUI.width, width,); + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.height == height, fUI.height, height,); + fUI.isResizingFromInit = false; + return; + } + + if (fUI.isResizingFromHost) + { + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.width == width, fUI.width, width,); + CARLA_SAFE_ASSERT_UINT2_RETURN(fUI.height == height, fUI.height, height,); + fUI.isResizingFromHost = false; + return; + } + + if (fUI.width != width || fUI.height != height) + { + uint width2 = width; + uint height2 = height; + + if (fExtensions.gui->adjust_size(fPlugin, &width2, &height2)) + { + if (width2 != width || height2 != height) + { + fUI.isResizingFromHost = true; + fUI.width = width2; + fUI.height = height2; + fUI.window->setSize(width2, height2, false, false); + } + else + { + fExtensions.gui->set_size(fPlugin, width2, height2); + } + } + } } #endif @@ -2511,7 +2600,10 @@ protected: CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr, false); carla_stdout("CarlaPluginCLAP::hostRequestResize(%u, %u)", width, height); - fUI.window->setSize(width, height, true); + fUI.isResizingFromPlugin = 3; + fUI.width = width; + fUI.height = height; + fUI.window->setSize(width, height, true, false); return true; } @@ -2964,6 +3056,11 @@ private: bool isCreated; bool isEmbed; bool isVisible; + bool isResizingFromHost; + bool isResizingFromInit; + int isResizingFromPlugin; + bool shouldClose; + uint32_t width, height; CarlaPluginUI* window; UI() @@ -2971,6 +3068,12 @@ private: isCreated(false), isEmbed(false), isVisible(false), + isResizingFromHost(false), + isResizingFromInit(false), + isResizingFromPlugin(0), + shouldClose(false), + width(0), + height(0), window(nullptr) {} ~UI() diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 68f9cd0a9..a3b25f127 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -6181,7 +6181,7 @@ public: else { CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr, 1); - fUI.window->setSize(static_cast(width), static_cast(height), true); + fUI.window->setSize(static_cast(width), static_cast(height), true, true); } return 0; diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index 4a47d9d32..0cfa53d9b 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -589,7 +589,7 @@ public: CARLA_SAFE_ASSERT_INT2(width > 1 && height > 1, width, height); if (width > 1 && height > 1) - fUI.window->setSize(static_cast(width), static_cast(height), true); + fUI.window->setSize(static_cast(width), static_cast(height), true, true); } } else @@ -2213,7 +2213,7 @@ protected: else { CARLA_SAFE_ASSERT_BREAK(fUI.window != nullptr); - fUI.window->setSize(static_cast(index), static_cast(value), true); + fUI.window->setSize(static_cast(index), static_cast(value), true, false); } ret = 1; break; diff --git a/source/backend/plugin/CarlaPluginVST3.cpp b/source/backend/plugin/CarlaPluginVST3.cpp index c575fb594..f4ca677a5 100644 --- a/source/backend/plugin/CarlaPluginVST3.cpp +++ b/source/backend/plugin/CarlaPluginVST3.cpp @@ -799,7 +799,7 @@ public: CARLA_SAFE_ASSERT_INT2(width > 1 && height > 1, width, height); if (width > 1 && height > 1) - fUI.window->setSize(static_cast(width), static_cast(height), true); + fUI.window->setSize(static_cast(width), static_cast(height), true, true); } } else diff --git a/source/bridges-ui/CarlaBridgeToolkitNative.cpp b/source/bridges-ui/CarlaBridgeToolkitNative.cpp index 3003d6c88..61933ad97 100644 --- a/source/bridges-ui/CarlaBridgeToolkitNative.cpp +++ b/source/bridges-ui/CarlaBridgeToolkitNative.cpp @@ -178,7 +178,7 @@ public: CARLA_SAFE_ASSERT_RETURN(height > 0,); carla_debug("CarlaBridgeToolkitNative::resize(%i, %i)", width, height); - fHostUI->setSize(width, height, false); + fHostUI->setSize(width, height, false, false); } void setTitle(const char* const title) override diff --git a/source/utils/CarlaPluginUI.cpp b/source/utils/CarlaPluginUI.cpp index eba303c99..50d63cfd4 100644 --- a/source/utils/CarlaPluginUI.cpp +++ b/source/utils/CarlaPluginUI.cpp @@ -202,7 +202,7 @@ public: } if (width > 1 && height > 1) - setSize(static_cast(width), static_cast(height), false); + setSize(static_cast(width), static_cast(height), false, false); } const Atom _xevp = XInternAtom(fDisplay, "_XEventProc", False); @@ -391,7 +391,7 @@ public: } } - void setSize(const uint width, const uint height, const bool forceUpdate) override + void setSize(const uint width, const uint height, const bool forceUpdate, const bool resizeChild) override { CARLA_SAFE_ASSERT_RETURN(fDisplay != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHostWindow != 0,); @@ -399,7 +399,7 @@ public: fSetSizeCalledAtLeastOnce = true; XResizeWindow(fDisplay, fHostWindow, width, height); - if (fChildWindow != 0) + if (fChildWindow != 0 && resizeChild) XResizeWindow(fDisplay, fChildWindow, width, height); if (! fIsResizable) @@ -763,7 +763,7 @@ public: [NSApp activateIgnoringOtherApps:YES]; } - void setSize(const uint width, const uint height, const bool forceUpdate) override + void setSize(const uint width, const uint height, const bool forceUpdate, const bool resizeChild) override { carla_debug("CocoaPluginUI::setSize(%u, %u, %s)", width, height, bool2str(forceUpdate)); CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); @@ -775,7 +775,7 @@ public: [fWindow setContentSize:size]; // this is needed for a few plugins - if (forceUpdate) + if (forceUpdate && resizeChild) { for (NSView* subview in [fView subviews]) { @@ -978,7 +978,7 @@ public: RECT rectChild, rectParent; if (fChildWindow != nullptr && GetWindowRect(fChildWindow, &rectChild)) - setSize(rectChild.right - rectChild.left, rectChild.bottom - rectChild.top, false); + setSize(rectChild.right - rectChild.left, rectChild.bottom - rectChild.top, false, false); if (fParentWindow != nullptr && GetWindowRect(fWindow, &rectChild) && @@ -1074,7 +1074,7 @@ public: SetFocus(fWindow); } - void setSize(const uint width, const uint height, const bool forceUpdate) override + void setSize(const uint width, const uint height, const bool forceUpdate, bool) override { CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); diff --git a/source/utils/CarlaPluginUI.hpp b/source/utils/CarlaPluginUI.hpp index 341e45c8e..5e459e4b7 100644 --- a/source/utils/CarlaPluginUI.hpp +++ b/source/utils/CarlaPluginUI.hpp @@ -37,7 +37,7 @@ public: virtual void hide() = 0; virtual void focus() = 0; virtual void idle() = 0; - virtual void setSize(uint with, uint height, bool forceUpdate) = 0; + virtual void setSize(uint with, uint height, bool forceUpdate, bool resizeChild) = 0; virtual void setTitle(const char* title) = 0; virtual void setChildWindow(void* ptr) = 0; virtual void setTransientWinId(uintptr_t winId) = 0;