diff --git a/source/backend/utils/Windows.cpp b/source/backend/utils/Windows.cpp index 0ebc11fbd..756db1f5d 100644 --- a/source/backend/utils/Windows.cpp +++ b/source/backend/utils/Windows.cpp @@ -17,7 +17,7 @@ #include "CarlaUtils.h" -#include "CarlaUtils.hpp" +#include "CarlaMathUtils.hpp" #if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT) # import @@ -25,6 +25,7 @@ #ifdef HAVE_X11 # include +# include #endif namespace CB = CarlaBackend; @@ -43,6 +44,31 @@ double carla_get_desktop_scale_factor() #if defined(CARLA_OS_MAC) && !defined(CARLA_PLUGIN_EXPORT) return [NSScreen mainScreen].backingScaleFactor; #endif +#ifdef HAVE_X11 + if (::Display* const display = XOpenDisplay(nullptr)) + { + XrmInitialize(); + if (char* const rms = XResourceManagerString(display)) + { + if (const XrmDatabase sdb = XrmGetStringDatabase(rms)) + { + char* type = nullptr; + XrmValue ret; + + if (XrmGetResource(sdb, "Xft.dpi", "String", &type, &ret) + && ret.addr != nullptr + && type != nullptr + && std::strncmp("String", type, 6) == 0) + { + const double dpi = std::atof(ret.addr); + if (carla_isNotZero(dpi)) + return dpi / 96; + } + } + } + XCloseDisplay(display); + } +#endif return 1.0; }