Implement X11 dpi autodetection

This commit is contained in:
sapier 2015-01-06 22:40:34 +01:00
parent efdb9da619
commit 0f1d33933d
2 changed files with 36 additions and 5 deletions

@ -224,7 +224,7 @@
#directional_colored_fog = true #directional_colored_fog = true
# Delay showing tooltips, stated in milliseconds # Delay showing tooltips, stated in milliseconds
#tooltip_show_delay = 400 #tooltip_show_delay = 400
# Adjust dpi configuration to your screen (Desktop only) e.g. for 4k screens # Adjust dpi configuration to your screen (non X11/Android only) e.g. for 4k screens
#screen_dpi = 72 #screen_dpi = 72
# Default timeout for cURL, stated in milliseconds. # Default timeout for cURL, stated in milliseconds.
# Only has an effect if compiled with cURL. # Only has an effect if compiled with cURL.

@ -570,17 +570,48 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
} }
#ifndef SERVER #ifndef SERVER
v2u32 getWindowSize() { v2u32 getWindowSize()
{
return device->getVideoDriver()->getScreenSize(); return device->getVideoDriver()->getScreenSize();
} }
#ifndef __ANDROID__ #ifdef XORG_USED
float getDisplayDensity()
{
const char* current_display = getenv("DISPLAY");
float getDisplayDensity() { 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; return g_settings->getFloat("screen_dpi")/96.0;
} }
v2u32 getDisplaySize() { #else
float getDisplayDensity()
{
return g_settings->getFloat("screen_dpi")/96.0;
}
#endif
#ifndef __ANDROID__
v2u32 getDisplaySize()
{
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL); IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution(); core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();