DPF

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

commit 6ef3fce69a543f63549eae8fc64e5bf8aca8b35d
parent 3d0d31c5941e3156e9cdcbcfa59655737a1391de
Author: falkTX <falktx@falktx.com>
Date:   Fri, 17 Jun 2022 21:46:43 +0100

Sync get display factor code with pugl

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdistrho/src/DistrhoUI.cpp | 35+++++++++++++++++------------------
Mpugl-updates-notes.txt | 2--
2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp @@ -108,22 +108,18 @@ static double getDesktopScaleFactor(const uintptr_t parentWindowHandle) # endif DWORD dpiAware = 0; + DWORD scaleFactor = 100; if (GetProcessDpiAwareness && GetScaleFactorForMonitor - && GetProcessDpiAwareness(NULL, &dpiAware) == 0 && dpiAware != 0) + && GetProcessDpiAwareness(nullptr, &dpiAware) == 0 && dpiAware != 0) { const HMONITOR hMon = parentWindowHandle != 0 ? MonitorFromWindow((HWND)parentWindowHandle, MONITOR_DEFAULTTOPRIMARY) : MonitorFromPoint(POINT{0,0}, MONITOR_DEFAULTTOPRIMARY); - - DWORD scaleFactor = 0; - if (GetScaleFactorForMonitor(hMon, &scaleFactor) == 0 && scaleFactor != 0) - { - FreeLibrary(Shcore); - return static_cast<double>(scaleFactor) / 100.0; - } + GetScaleFactorForMonitor(hMon, &scaleFactor); } FreeLibrary(Shcore); + return static_cast<double>(scaleFactor) / 100.0; } #elif defined(HAVE_X11) ::Display* const display = XOpenDisplay(nullptr); @@ -131,28 +127,31 @@ static double getDesktopScaleFactor(const uintptr_t parentWindowHandle) XrmInitialize(); + double dpi = 96.0; if (char* const rms = XResourceManagerString(display)) { - if (const XrmDatabase sdb = XrmGetStringDatabase(rms)) + if (const XrmDatabase db = XrmGetStringDatabase(rms)) { char* type = nullptr; - XrmValue ret; + XrmValue value = {}; - if (XrmGetResource(sdb, "Xft.dpi", "String", &type, &ret) - && ret.addr != nullptr + if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value) && type != nullptr - && std::strncmp("String", type, 6) == 0) + && std::strcmp(type, "String") == 0 + && value.addr != nullptr) { - if (const double dpi = std::atof(ret.addr)) - { - XCloseDisplay(display); - return dpi / 96; - } + char* end = nullptr; + const double xftDpi = std::strtod(value.addr, &end); + if (xftDpi > 0.0 && xftDpi < HUGE_VAL) + dpi = xftDpi; } + + XrmDestroyDatabase(db); } } XCloseDisplay(display); + return dpi / 96; #endif return 1.0; diff --git a/pugl-updates-notes.txt b/pugl-updates-notes.txt @@ -1,5 +1,3 @@ puglClearMinSize needed? puglSetWindowSize was used on first show, still needed? - -update distrhoui.cpp get scale factor to match new parent request setup and pugl