Implement X11 dpi autodetection
authorsapier <Sapier at GMX dot net>
Tue, 6 Jan 2015 21:40:34 +0000 (22:40 +0100)
committersapier <Sapier at GMX dot net>
Tue, 6 Jan 2015 21:41:07 +0000 (22:41 +0100)
minetest.conf.example
src/porting.cpp

index 8570eb052ab4c19d6a635fa98aff870fea2a901e..0b137c5a2ad844ef596145c4ff924e756a529ac7 100644 (file)
 #directional_colored_fog = true
 #    Delay showing tooltips, stated in milliseconds
 #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
 #    Default timeout for cURL, stated in milliseconds.
 #    Only has an effect if compiled with cURL.
index 025e5978c7557642ed61d8b092c8f679a22f995d..219e1647dc2fa9337826e9e10db322f8cffb09d2 100644 (file)
@@ -570,17 +570,48 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
 }
 
 #ifndef SERVER
-v2u32 getWindowSize() {
+v2u32 getWindowSize()
+{
        return device->getVideoDriver()->getScreenSize();
 }
 
-#ifndef __ANDROID__
+#ifdef XORG_USED
+float getDisplayDensity()
+{
+       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);
+                       }
+               }
 
-float getDisplayDensity() {
+       /* return manually specified dpi */
        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);
 
        core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();