Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
static float getDisplayDensity_init()
{
const char* current_display = getenv("DISPLAY");
if (current_display != NULL) {
Display * x11display = XOpenDisplay(current_display);
if (x11display != NULL) {
/* try x direct */
float dpi_height =
floor(DisplayHeight(x11display, 0) /
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
float dpi_width =
floor(DisplayWidth(x11display, 0) /
(DisplayWidthMM(x11display, 0) * 0.039370) +0.5);
XCloseDisplay(x11display);
return std::max(dpi_height,dpi_width) / 96.0;
}
}
/* return manually specified dpi */
return g_settings->getFloat("screen_dpi")/96.0;
}
static float cached_display_density = getDisplayDensity_init();
float getDisplayDensity()
{
return cached_display_density;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.