| 91 | double getDesktopScaleFactor(uintptr_t parentWindowHandle); |
| 92 | #else |
| 93 | static double getDesktopScaleFactor(const uintptr_t parentWindowHandle) |
| 94 | { |
| 95 | // allow custom scale for testing |
| 96 | if (const char* const scale = getenv("DPF_SCALE_FACTOR")) |
| 97 | return std::max(1.0, std::atof(scale)); |
| 98 | |
| 99 | #if defined(DISTRHO_OS_WASM) |
| 100 | return emscripten_get_device_pixel_ratio(); |
| 101 | #elif defined(DISTRHO_OS_WINDOWS) |
| 102 | if (const HMODULE Shcore = LoadLibraryA("Shcore.dll")) |
| 103 | { |
| 104 | typedef HRESULT(WINAPI* PFN_GetProcessDpiAwareness)(HANDLE, DWORD*); |
| 105 | typedef HRESULT(WINAPI* PFN_GetScaleFactorForMonitor)(HMONITOR, DWORD*); |
| 106 | |
| 107 | #if defined(__GNUC__) && (__GNUC__ >= 9) |
| 108 | #pragma GCC diagnostic push |
| 109 | #pragma GCC diagnostic ignored "-Wcast-function-type" |
| 110 | #endif |
| 111 | const PFN_GetProcessDpiAwareness GetProcessDpiAwareness |
| 112 | = (PFN_GetProcessDpiAwareness)GetProcAddress(Shcore, "GetProcessDpiAwareness"); |
| 113 | const PFN_GetScaleFactorForMonitor GetScaleFactorForMonitor |
| 114 | = (PFN_GetScaleFactorForMonitor)GetProcAddress(Shcore, "GetScaleFactorForMonitor"); |
| 115 | #if defined(__GNUC__) && (__GNUC__ >= 9) |
| 116 | #pragma GCC diagnostic pop |
| 117 | #endif |
| 118 | |
| 119 | DWORD dpiAware = 0; |
| 120 | DWORD scaleFactor = 100; |
| 121 | if (GetProcessDpiAwareness && GetScaleFactorForMonitor |
| 122 | && GetProcessDpiAwareness(nullptr, &dpiAware) == 0 && dpiAware != 0) |
| 123 | { |
| 124 | const HMONITOR hMon = parentWindowHandle != 0 |
| 125 | ? MonitorFromWindow((HWND)parentWindowHandle, MONITOR_DEFAULTTOPRIMARY) |
| 126 | : MonitorFromPoint(POINT(), MONITOR_DEFAULTTOPRIMARY); |
| 127 | GetScaleFactorForMonitor(hMon, &scaleFactor); |
| 128 | } |
| 129 | |
| 130 | FreeLibrary(Shcore); |
| 131 | return static_cast<double>(scaleFactor) / 100.0; |
| 132 | } |
| 133 | #elif defined(HAVE_X11) |
| 134 | ::Display* const display = XOpenDisplay(nullptr); |
| 135 | DISTRHO_SAFE_ASSERT_RETURN(display != nullptr, 1.0); |
| 136 | |
| 137 | XrmInitialize(); |
| 138 | |
| 139 | double dpi = 96.0; |
| 140 | if (char* const rms = XResourceManagerString(display)) |
| 141 | { |
| 142 | if (const XrmDatabase db = XrmGetStringDatabase(rms)) |
| 143 | { |
| 144 | char* type = nullptr; |
| 145 | XrmValue value = {}; |
| 146 | |
| 147 | if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value) |
| 148 | && type != nullptr |
| 149 | && std::strcmp(type, "String") == 0 |
| 150 | && value.addr != nullptr) |
no test coverage detected