aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2015-01-06 22:40:34 +0100
committersapier <Sapier at GMX dot net>2015-01-06 22:41:07 +0100
commit0f1d33933d264fa84b2d97668258d066da0ca01c (patch)
treed703349feac79fad42909cfd16665df6f818cc87 /src
parentefdb9da6197665d9ab1f8282aca00e905ea0321b (diff)
downloadminetest-0f1d33933d264fa84b2d97668258d066da0ca01c.tar.gz
minetest-0f1d33933d264fa84b2d97668258d066da0ca01c.tar.bz2
minetest-0f1d33933d264fa84b2d97668258d066da0ca01c.zip
Implement X11 dpi autodetection
Diffstat (limited to 'src')
-rw-r--r--src/porting.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 025e5978c..219e1647d 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -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();