From 6f8aee0c1cfadbab0436947a9bb3336bf54610ef Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 29 Jan 2023 19:12:24 +0200 Subject: [PATCH] Use alternative method to query DPI on Linux --- .../Engine/Platform/Linux/LinuxPlatform.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index a5bd099c9..3effd5d03 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -840,17 +840,17 @@ int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event) int32 CalculateDpi() { - // in X11 a screen is not necessarily identical to a desktop - // so we need to stick to one type for pixel and physical size query + int dpi = 96; + char* resourceString = X11::XResourceManagerString(xDisplay); + if (resourceString == NULL) + return dpi; - int screenIdx = 0; - int widthMM = X11_DisplayWidthMM(xDisplay, screenIdx); - int heightMM = X11_DisplayHeightMM(xDisplay, screenIdx); - double xdpi = (widthMM ? X11_DisplayWidth(xDisplay, screenIdx) / (double)widthMM * 25.4 : 0); - double ydpi = (heightMM ? X11_DisplayHeight(xDisplay, screenIdx) / (double)heightMM * 25.4 : 0); - if (xdpi || ydpi) - return (int32)Math::Ceil((xdpi + ydpi) / (xdpi && ydpi ? 2 : 1)); - return 96; + char* type = NULL; + X11::XrmValue value; + X11::XrmDatabase database = X11::XrmGetStringDatabase(resourceString); + if (X11::XrmGetResource(database, "Xft.dpi", "String", &type, &value) == 1 && value.addr != NULL) + dpi = (int)atof(value.addr); + return dpi; } // Maps Flax key codes to X11 names for physical key locations. @@ -2101,6 +2101,7 @@ bool LinuxPlatform::Init() xAtomWmName = X11::XInternAtom(xDisplay, "_NET_WM_NAME", 0); xAtomClipboard = X11::XInternAtom(xDisplay, "CLIPBOARD", 0); + X11::XrmInitialize(); SystemDpi = CalculateDpi(); int cursorSize = X11::XcursorGetDefaultSize(xDisplay);