From 04032b02e3aef7f176bba86b729ef93b3e99f9c0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 14 May 2021 22:48:35 +0100 Subject: [PATCH] Allow DPF_SCALE_FACTOR env var for quickly testing scale factors Signed-off-by: falkTX --- dgl/TopLevelWidget.hpp | 1 + dgl/Window.hpp | 4 ++-- dgl/src/TopLevelWidget.cpp | 5 +++++ dgl/src/Window.cpp | 8 ++++---- dgl/src/WindowPrivateData.cpp | 18 ++++++++++++++---- distrho/src/DistrhoPluginJack.cpp | 12 +----------- distrho/src/DistrhoUIInternal.hpp | 2 +- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp index deca78bf..fe859766 100644 --- a/dgl/TopLevelWidget.hpp +++ b/dgl/TopLevelWidget.hpp @@ -67,6 +67,7 @@ public: Window& getWindow() const noexcept; // TODO group stuff after here, convenience functions present in Window class + double getScaleFactor() const noexcept; void repaint() noexcept; void repaint(const Rectangle& rect) noexcept; void setGeometryConstraints(uint minimumWidth, diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 7bfe1c90..9c5e18eb 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -61,7 +61,7 @@ public: */ explicit Window(Application& app, uintptr_t parentWindowHandle, - double scaling, + double scaleFactor, bool resizable); /** @@ -72,7 +72,7 @@ public: uintptr_t parentWindowHandle, uint width, uint height, - double scaling, + double scaleFactor, bool resizable); /** diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp index 85612ef5..9d553604 100644 --- a/dgl/src/TopLevelWidget.cpp +++ b/dgl/src/TopLevelWidget.cpp @@ -40,6 +40,11 @@ Window& TopLevelWidget::getWindow() const noexcept return pData->window; } +double TopLevelWidget::getScaleFactor() const noexcept +{ + return pData->window.getScaleFactor(); +} + void TopLevelWidget::repaint() noexcept { pData->window.repaint(); diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index d8014434..1b77915f 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -31,17 +31,17 @@ Window::Window(Application& app) Window::Window(Application& app, const uintptr_t parentWindowHandle, - const double scaling, + const double scaleFactor, const bool resizable) - : pData(new PrivateData(app, this, parentWindowHandle, scaling, resizable)) {} + : pData(new PrivateData(app, this, parentWindowHandle, scaleFactor, resizable)) {} Window::Window(Application& app, const uintptr_t parentWindowHandle, const uint width, const uint height, - const double scaling, + const double scaleFactor, const bool resizable) - : pData(new PrivateData(app, this, parentWindowHandle, width, height, scaling, resizable)) {} + : pData(new PrivateData(app, this, parentWindowHandle, width, height, scaleFactor, resizable)) {} Window::~Window() { diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index fc92e4ea..8f163667 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -40,6 +40,16 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- +static double getDesktopScaleFactor() +{ + if (const char* const scale = getenv("DPF_SCALE_FACTOR")) + return std::max(1.0, std::atof(scale)); + + return 1.0; +} + +// ----------------------------------------------------------------------- + Window::PrivateData::PrivateData(Application& a, Window* const s) : app(a), appData(a.pData), @@ -49,7 +59,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s) isClosed(true), isVisible(false), isEmbed(false), - scaleFactor(1.0), + scaleFactor(getDesktopScaleFactor()), autoScaling(false), autoScaleFactor(1.0), minWidth(0), @@ -68,7 +78,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, Window& transi isClosed(true), isVisible(false), isEmbed(false), - scaleFactor(1.0), + scaleFactor(getDesktopScaleFactor()), autoScaling(false), autoScaleFactor(1.0), minWidth(0), @@ -91,7 +101,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, isClosed(parentWindowHandle == 0), isVisible(parentWindowHandle != 0), isEmbed(parentWindowHandle != 0), - scaleFactor(scale), + scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()), autoScaling(false), autoScaleFactor(1.0), minWidth(0), @@ -125,7 +135,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, isClosed(parentWindowHandle == 0), isVisible(parentWindowHandle != 0), isEmbed(parentWindowHandle != 0), - scaleFactor(scale), + scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor()), autoScaling(false), autoScaleFactor(1.0), minWidth(0), diff --git a/distrho/src/DistrhoPluginJack.cpp b/distrho/src/DistrhoPluginJack.cpp index 59393472..5e4f3d98 100644 --- a/distrho/src/DistrhoPluginJack.cpp +++ b/distrho/src/DistrhoPluginJack.cpp @@ -82,16 +82,6 @@ static void initSignalHandler() // ----------------------------------------------------------------------- -#if DISTRHO_PLUGIN_HAS_UI -// TODO -static double getDesktopScaleFactor() noexcept -{ - return 1.0; -} -#endif - -// ----------------------------------------------------------------------- - #if DISTRHO_PLUGIN_HAS_UI class PluginJack : public IdleCallback #else @@ -111,7 +101,7 @@ public: nullptr, // file request nullptr, // bundle fPlugin.getInstancePointer(), - getDesktopScaleFactor()), + 0.0), #endif fClient(client) { diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp index 73b923ad..786bca7c 100644 --- a/distrho/src/DistrhoUIInternal.hpp +++ b/distrho/src/DistrhoUIInternal.hpp @@ -137,7 +137,7 @@ public: const fileRequestFunc fileRequestCall, const char* const bundlePath = nullptr, void* const dspPtr = nullptr, - const float scaleFactor = 1.0f, + const double scaleFactor = 1.0, const uint32_t bgColor = 0, const uint32_t fgColor = 0xffffffff) #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI