Use alternative method to query DPI on Linux
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user