DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 9b9e0a36187a5a2f76add523f1eadfe8bf22dbdc
parent eaa307bdc222f4a839827c745571c9d93e06c973
Author: falkTX <falktx@falktx.com>
Date:   Fri, 13 Aug 2021 19:20:36 +0100

Implement fetching desktop scale factor on macOS; Tweak d_info size

Diffstat:
Mdgl/src/WindowPrivateData.cpp | 11++++++-----
Mdgl/src/pugl.cpp | 23+++++++++++++++++++++--
Mdgl/src/pugl.hpp | 4++++
Mexamples/Info/InfoExampleUI.cpp | 7+++++--
4 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp @@ -64,12 +64,13 @@ START_NAMESPACE_DGL static const char* const kWin32SelectedFileCancelled = "__dpf_cancelled__"; #endif -static double getDesktopScaleFactor() +static double getDesktopScaleFactor(const PuglView* const view) { + // allow custom scale for testing if (const char* const scale = getenv("DPF_SCALE_FACTOR")) return std::max(1.0, std::atof(scale)); - return 1.0; + return puglGetDesktopScaleFactor(view); } // ----------------------------------------------------------------------- @@ -84,7 +85,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s) isClosed(true), isVisible(false), isEmbed(false), - scaleFactor(getDesktopScaleFactor()), + scaleFactor(getDesktopScaleFactor(view)), autoScaling(false), autoScaleFactor(1.0), minWidth(0), @@ -137,7 +138,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, isClosed(parentWindowHandle == 0), isVisible(parentWindowHandle != 0), isEmbed(parentWindowHandle != 0), - scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()), + scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor(view)), autoScaling(false), autoScaleFactor(1.0), minWidth(0), @@ -167,7 +168,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, isClosed(parentWindowHandle == 0), isVisible(parentWindowHandle != 0), isEmbed(parentWindowHandle != 0), - scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()), + scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor(view)), autoScaling(false), autoScaleFactor(1.0), minWidth(0), diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp @@ -198,12 +198,31 @@ const char* puglGetWindowTitle(const PuglView* const view) } // -------------------------------------------------------------------------------------------------------------------- +// get global scale factor + +double puglGetDesktopScaleFactor(const PuglView* const view) +{ +#if defined(DISTRHO_OS_MAC) + return (view->impl->window ? [view->impl->window screen] + : [NSScreen mainScreen]).backingScaleFactor; +#else + return 1.0; + + // unused + (void)view; +#endif +} + +// -------------------------------------------------------------------------------------------------------------------- // bring view window into the foreground, aka "raise" window -void puglRaiseWindow(PuglView* view) +void puglRaiseWindow(PuglView* const view) { -#if defined(DISTRHO_OS_HAIKU) || defined(DISTRHO_OS_MAC) +#if defined(DISTRHO_OS_HAIKU) // nothing here yet +#elif defined(DISTRHO_OS_MAC) + if (view->impl->window) + [view->impl->window orderFrontRegardless]; #elif defined(DISTRHO_OS_WINDOWS) SetForegroundWindow(view->impl->hwnd); SetActiveWindow(view->impl->hwnd); diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp @@ -67,6 +67,10 @@ puglGetTransientParent(const PuglView* view); PUGL_API const char* puglGetWindowTitle(const PuglView* view); +// get global scale factor +PUGL_API double +puglGetDesktopScaleFactor(const PuglView* view); + // bring view window into the foreground, aka "raise" window PUGL_API void puglRaiseWindow(PuglView* view); diff --git a/examples/Info/InfoExampleUI.cpp b/examples/Info/InfoExampleUI.cpp @@ -34,7 +34,7 @@ public: : UI(kInitialWidth, kInitialHeight), fSampleRate(getSampleRate()), fResizable(isResizable()), - fScale(1.0f), + fScale(getScaleFactor()), fResizeHandle(this) { std::memset(fParameters, 0, sizeof(float)*kParameterCount); @@ -46,7 +46,10 @@ public: loadSharedResources(); #endif - setGeometryConstraints(kInitialWidth, kInitialHeight, true); + if (d_isNotEqual(fScale, 1.0f)) + setSize(kInitialWidth * fScale, kInitialHeight * fScale); + + setGeometryConstraints(kInitialWidth * fScale, kInitialHeight * fScale, true); // no need to show resize handle if window is user-resizable if (fResizable)