Skip to content

Instantly share code, notes, and snippets.

@Zeno-
Created February 5, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zeno-/1d01769ee969ebeec50c to your computer and use it in GitHub Desktop.
Save Zeno-/1d01769ee969ebeec50c to your computer and use it in GitHub Desktop.
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