Browse Source

Sync get display factor code with pugl

Signed-off-by: falkTX <falktx@falktx.com>
pull/321/head
falkTX 2 years ago
parent
commit
6ef3fce69a
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 17 additions and 20 deletions
  1. +17
    -18
      distrho/src/DistrhoUI.cpp
  2. +0
    -2
      pugl-updates-notes.txt

+ 17
- 18
distrho/src/DistrhoUI.cpp View File

@@ -108,22 +108,18 @@ static double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
# endif # endif


DWORD dpiAware = 0; DWORD dpiAware = 0;
DWORD scaleFactor = 100;
if (GetProcessDpiAwareness && GetScaleFactorForMonitor if (GetProcessDpiAwareness && GetScaleFactorForMonitor
&& GetProcessDpiAwareness(NULL, &dpiAware) == 0 && dpiAware != 0)
&& GetProcessDpiAwareness(nullptr, &dpiAware) == 0 && dpiAware != 0)
{ {
const HMONITOR hMon = parentWindowHandle != 0 const HMONITOR hMon = parentWindowHandle != 0
? MonitorFromWindow((HWND)parentWindowHandle, MONITOR_DEFAULTTOPRIMARY) ? MonitorFromWindow((HWND)parentWindowHandle, MONITOR_DEFAULTTOPRIMARY)
: MonitorFromPoint(POINT{0,0}, 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); FreeLibrary(Shcore);
return static_cast<double>(scaleFactor) / 100.0;
} }
#elif defined(HAVE_X11) #elif defined(HAVE_X11)
::Display* const display = XOpenDisplay(nullptr); ::Display* const display = XOpenDisplay(nullptr);
@@ -131,28 +127,31 @@ static double getDesktopScaleFactor(const uintptr_t parentWindowHandle)


XrmInitialize(); XrmInitialize();


double dpi = 96.0;
if (char* const rms = XResourceManagerString(display)) if (char* const rms = XResourceManagerString(display))
{ {
if (const XrmDatabase sdb = XrmGetStringDatabase(rms))
if (const XrmDatabase db = XrmGetStringDatabase(rms))
{ {
char* type = nullptr; 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 && 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); XCloseDisplay(display);
return dpi / 96;
#endif #endif


return 1.0; return 1.0;


+ 0
- 2
pugl-updates-notes.txt View File

@@ -1,5 +1,3 @@
puglClearMinSize needed? puglClearMinSize needed?
puglSetWindowSize was used on first show, still needed? puglSetWindowSize was used on first show, still needed?

update distrhoui.cpp get scale factor to match new parent request setup and pugl

Loading…
Cancel
Save