Skip to content

Commit 0f1d339

Browse files
sapiersapier
sapier
authored and
sapier
committedJan 6, 2015
Implement X11 dpi autodetection
1 parent efdb9da commit 0f1d339

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed
 

‎minetest.conf.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
#directional_colored_fog = true
225225
# Delay showing tooltips, stated in milliseconds
226226
#tooltip_show_delay = 400
227-
# Adjust dpi configuration to your screen (Desktop only) e.g. for 4k screens
227+
# Adjust dpi configuration to your screen (non X11/Android only) e.g. for 4k screens
228228
#screen_dpi = 72
229229
# Default timeout for cURL, stated in milliseconds.
230230
# Only has an effect if compiled with cURL.

‎src/porting.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -570,17 +570,48 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
570570
}
571571

572572
#ifndef SERVER
573-
v2u32 getWindowSize() {
573+
v2u32 getWindowSize()
574+
{
574575
return device->getVideoDriver()->getScreenSize();
575576
}
576577

577-
#ifndef __ANDROID__
578+
#ifdef XORG_USED
579+
float getDisplayDensity()
580+
{
581+
const char* current_display = getenv("DISPLAY");
582+
583+
if (current_display != NULL) {
584+
Display * x11display = XOpenDisplay(current_display);
585+
586+
if (x11display != NULL) {
587+
/* try x direct */
588+
float dpi_height =
589+
floor(DisplayHeight(x11display, 0) /
590+
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
591+
float dpi_width =
592+
floor(DisplayWidth(x11display, 0) /
593+
(DisplayWidthMM(x11display, 0) * 0.039370) +0.5);
594+
595+
XCloseDisplay(x11display);
596+
597+
return (std::max(dpi_height,dpi_width) / 96.0);
598+
}
599+
}
578600

579-
float getDisplayDensity() {
601+
/* return manually specified dpi */
580602
return g_settings->getFloat("screen_dpi")/96.0;
581603
}
582604

583-
v2u32 getDisplaySize() {
605+
#else
606+
float getDisplayDensity()
607+
{
608+
return g_settings->getFloat("screen_dpi")/96.0;
609+
}
610+
#endif
611+
612+
#ifndef __ANDROID__
613+
v2u32 getDisplaySize()
614+
{
584615
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
585616

586617
core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();

0 commit comments

Comments
 (0)
Please sign in to comment.