Skip to content

Instantly share code, notes, and snippets.

@sapier
Last active August 29, 2015 14:12
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 sapier/95e7c31c69419502977e to your computer and use it in GitHub Desktop.
Save sapier/95e7c31c69419502977e to your computer and use it in GitHub Desktop.
float getDisplayDensity()
{
const char* current_display = getenv("DISPLAY");
if (current_display == 0)
return g_settings->getFloat("screen_dpi")/96.0;
Display * x11display = XOpenDisplay(current_display);
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);
errorstream << "DPIH: " << dpi_height << " DPIW: " << dpi_width << std::endl;
return (std::max(dpi_height,dpi_width) / 96.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment