diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-13 15:45:42 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-13 15:45:42 -0300 |
commit | 7526b14afdd6668498fa0ac4ce912930b8235532 (patch) | |
tree | f88f1f997dcbd30c11a9fa7405642e09d86d7987 /platform/x11/os_x11.cpp | |
parent | 28034190a9757bc0cbfbf6b2f9582009776b1399 (diff) | |
parent | eaa34f21236757758920efed631d51068e9767fd (diff) |
Merge pull request #5173 from Hinsbart/fix_xrandr
x11: fix XRandr GetMonitors
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r-- | platform/x11/os_x11.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index eb576b11f4..1ca779ef7c 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -120,15 +120,33 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi const char* err; xrr_get_monitors = NULL; + xrr_free_monitors = NULL; + int xrandr_major = 0; + int xrandr_minor = 0; + int event_base, error_base; + xrandr_ext_ok = XRRQueryExtension(x11_display,&event_base, &error_base); xrandr_handle = dlopen("libXrandr.so", RTLD_LAZY); err = dlerror(); if (!xrandr_handle) { - fprintf(stderr, "could not load libXrandr.so, dpi detection disabled. Error: %s\n", err); + fprintf(stderr, "could not load libXrandr.so, Error: %s\n", err); } else { - xrr_get_monitors = (xrr_get_monitors_t) dlsym(xrandr_handle, "XRRGetMonitors"); - if (!xrr_get_monitors) - fprintf(stderr, "could not find symbol XRRGetMonitors, dpi detection will only work on the first screen\nError: %s\n", err); + XRRQueryVersion(x11_display, &xrandr_major, &xrandr_minor); + if (((xrandr_major << 8) | xrandr_minor) >= 0x0105) { + xrr_get_monitors = (xrr_get_monitors_t) dlsym(xrandr_handle, "XRRGetMonitors"); + if (!xrr_get_monitors) { + err = dlerror(); + fprintf(stderr, "could not find symbol XRRGetMonitors\nError: %s\n", err); + } + else { + xrr_free_monitors = (xrr_free_monitors_t) dlsym(xrandr_handle, "XRRFreeMonitors"); + if (!xrr_free_monitors) { + err = dlerror(); + fprintf(stderr, "could not find XRRFreeMonitors\nError: %s\n", err); + xrr_get_monitors = NULL; + } + } + } } xim = XOpenIM (x11_display, NULL, NULL, NULL); @@ -745,19 +763,18 @@ int OS_X11::get_screen_dpi(int p_screen) const { ERR_FAIL_INDEX_V(p_screen, get_screen_count(), 0); //Get physical monitor Dimensions through XRandR and calculate dpi - int event_base, error_base; - const Bool ext_okay = XRRQueryExtension(x11_display,&event_base, &error_base); - Size2 sc = get_screen_size(p_screen); - if (ext_okay) { + if (xrandr_ext_ok) { int count = 0; if (xrr_get_monitors) { xrr_monitor_info *monitors = xrr_get_monitors(x11_display, x11_window, true, &count); if (p_screen < count) { double xdpi = sc.width / (double) monitors[p_screen].mwidth * 25.4; double ydpi = sc.height / (double) monitors[p_screen].mheight * 25.4; + xrr_free_monitors(monitors); return (xdpi + ydpi) / 2; } + xrr_free_monitors(monitors); } else if (p_screen == 0) { XRRScreenSize *sizes = XRRSizes(x11_display, 0, &count); |