commit 00494798841af86f8dd954f04ac0673d4d8efb36
parent f049ce37805ed9aff64320aa8a4075b8223881a6
Author: falkTX <falktx@falktx.com>
Date: Tue, 20 Sep 2022 22:28:04 +0100
Fix UI size for high-dpi macOS CLAP plugins
Diffstat:
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/distrho/src/DistrhoPluginCLAP.cpp b/distrho/src/DistrhoPluginCLAP.cpp
@@ -256,21 +256,35 @@ public:
{
*width = ui->getWidth();
*height = ui->getHeight();
+ #ifdef DISTRHO_OS_MAC
+ const double scaleFactor = ui->getScaleFactor();
+ *width /= scaleFactor;
+ *height /= scaleFactor;
+ #endif
return true;
}
+ double scaleFactor = fScaleFactor;
#if defined(DISTRHO_UI_DEFAULT_WIDTH) && defined(DISTRHO_UI_DEFAULT_HEIGHT)
*width = DISTRHO_UI_DEFAULT_WIDTH;
*height = DISTRHO_UI_DEFAULT_HEIGHT;
+ if (d_isZero(scaleFactor))
+ scaleFactor = 1.0;
#else
UIExporter tmpUI(nullptr, 0, fPlugin.getSampleRate(),
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, d_nextBundlePath,
fPlugin.getInstancePointer(), fScaleFactor);
*width = tmpUI.getWidth();
*height = tmpUI.getHeight();
+ scaleFactor = tmpUI.getScaleFactor();
tmpUI.quit();
#endif
+ #ifdef DISTRHO_OS_MAC
+ *width /= scaleFactor;
+ *height /= scaleFactor;
+ #endif
+
return true;
}
@@ -291,6 +305,12 @@ public:
bool keepAspectRatio;
fUI->getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio);
+ #ifdef DISTRHO_OS_MAC
+ const double scaleFactor = fUI->getScaleFactor();
+ minimumWidth /= scaleFactor;
+ minimumHeight /= scaleFactor;
+ #endif
+
hints->can_resize_horizontally = true;
hints->can_resize_vertically = true;
hints->preserve_aspect_ratio = keepAspectRatio;
@@ -317,6 +337,12 @@ public:
bool keepAspectRatio;
fUI->getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio);
+ #ifdef DISTRHO_OS_MAC
+ const double scaleFactor = fUI->getScaleFactor();
+ minimumWidth /= scaleFactor;
+ minimumHeight /= scaleFactor;
+ #endif
+
if (keepAspectRatio)
{
if (*width < 1)
@@ -349,10 +375,15 @@ public:
return false;
}
- bool setSizeFromHost(const uint32_t width, const uint32_t height)
+ bool setSizeFromHost(uint32_t width, uint32_t height)
{
if (UIExporter* const ui = fUI.get())
{
+ #ifdef DISTRHO_OS_MAC
+ const double scaleFactor = ui->getScaleFactor();
+ width *= scaleFactor;
+ height *= scaleFactor;
+ #endif
ui->setWindowSizeFromHost(width, height);
return true;
}
@@ -614,7 +645,18 @@ private:
void setSizeFromPlugin(const uint width, const uint height)
{
- if (fHostGui->request_resize(fHost, width, height) && fUI != nullptr)
+ DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
+
+ #ifdef DISTRHO_OS_MAC
+ const double scaleFactor = fUI->getScaleFactor();
+ const uint hostWidth = width / scaleFactor;
+ const uint hostHeight = height / scaleFactor;
+ #else
+ const uint hostWidth = width;
+ const uint hostHeight = height;
+ #endif
+
+ if (fHostGui->request_resize(fHost, hostWidth, hostHeight))
fUI->setWindowSizeFromHost(width, height);
}