diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 72396148c..fc5e24bea 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -2210,8 +2210,12 @@ void CarlaPlugin::uiIdle() CarlaString uiTitle(pData->name); uiTitle += " (GUI)"; - if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle, pData->engine->getOptions().frontendWinId, true)) + if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle, + pData->engine->getOptions().frontendWinId, pData->transientFirstTry)) + { pData->transientTryCounter = 0; + pData->transientFirstTry = false; + } } void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept diff --git a/source/backend/plugin/CarlaPluginInternal.cpp b/source/backend/plugin/CarlaPluginInternal.cpp index f33815227..f04eff34d 100644 --- a/source/backend/plugin/CarlaPluginInternal.cpp +++ b/source/backend/plugin/CarlaPluginInternal.cpp @@ -592,6 +592,7 @@ CarlaPlugin::ProtectedData::ProtectedData(CarlaEngine* const eng, const uint idx ctrlChannel(0), extraHints(0x0), transientTryCounter(0), + transientFirstTry(true), name(nullptr), filename(nullptr), iconName(nullptr), diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 8a9a14169..840c0f64e 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -228,6 +228,7 @@ struct CarlaPlugin::ProtectedData { int8_t ctrlChannel; uint extraHints; uint transientTryCounter; + bool transientFirstTry; // data 1 const char* name; diff --git a/source/bridges-ui/CarlaBridgeToolkitNative.cpp b/source/bridges-ui/CarlaBridgeToolkitNative.cpp index 1f8293f86..280a2e190 100644 --- a/source/bridges-ui/CarlaBridgeToolkitNative.cpp +++ b/source/bridges-ui/CarlaBridgeToolkitNative.cpp @@ -68,8 +68,7 @@ public: fHostUI->setTitle(options.windowTitle.buffer()); -#ifdef HAVE_X11 - // Out-of-process reparenting only possible on X11 +#if (defined(CARLA_OS_WIN) && defined(BRIDGE_HWND)) || (defined(HAVE_X11) && defined(BRIDGE_X11)) if (options.transientWindowId != 0) { fHostUI->setTransientWinId(options.transientWindowId); diff --git a/source/modules/dgl/src/Window.cpp b/source/modules/dgl/src/Window.cpp index 723476c15..53f9a29a6 100644 --- a/source/modules/dgl/src/Window.cpp +++ b/source/modules/dgl/src/Window.cpp @@ -346,22 +346,6 @@ struct Window::PrivateData { fModal.enabled = true; fModal.parent->fModal.childFocus = this; -#ifdef DISTRHO_OS_WINDOWS - // Center this window - PuglInternals* const parentImpl = fModal.parent->fView->impl; - - RECT curRect; - RECT parentRect; - GetWindowRect(hwnd, &curRect); - GetWindowRect(parentImpl->hwnd, &parentRect); - - int x = parentRect.left+(parentRect.right-curRect.right)/2; - int y = parentRect.top +(parentRect.bottom-curRect.bottom)/2; - - SetWindowPos(hwnd, 0, x, y, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); - UpdateWindow(hwnd); -#endif - fModal.parent->setVisible(true); setVisible(true); diff --git a/source/utils/CarlaPluginUI.cpp b/source/utils/CarlaPluginUI.cpp index 53fd3525b..a0e32b522 100644 --- a/source/utils/CarlaPluginUI.cpp +++ b/source/utils/CarlaPluginUI.cpp @@ -1046,10 +1046,41 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons XFlush(sd.display); return true; -#else +#endif + +#ifdef CARLA_OS_MAC + // TODO +#endif + +#ifdef CARLA_OS_WIN + if (HWND const childWindow = FindWindowA(nullptr, uiTitle)) + { + HWND const parentWindow = (HWND)winId; + SetWindowLongPtr(childWindow, GWLP_HWNDPARENT, (LONG_PTR)parentWindow); + + if (centerUI) + { + RECT rectChild, rectParent; + + if (GetWindowRect(childWindow, &rectChild) && GetWindowRect(parentWindow, &rectParent)) + { + SetWindowPos(childWindow, parentWindow, + rectParent.left + (rectChild.right-rectChild.left)/2, + rectParent.top + (rectChild.bottom-rectChild.top)/2, + 0, 0, SWP_NOSIZE); + } + } + + carla_stdout("Match found using window name"); + return true; + } + + return false; +#endif + + // fallback, may be unused return true; (void)pid; (void)centerUI; -#endif } // -----------------------------------------------------