JRE-1142 [jdk11] hidpi is not detected since Ubuntu 18.04

(cherry picked from commit be4f8c0d9d)
This commit is contained in:
Anton Tarasov
2019-01-18 18:36:52 +03:00
committed by alexey.ushakov@jetbrains.com
parent 58efca2d67
commit 275dc61155

View File

@@ -37,6 +37,8 @@
#include <sun_awt_X11GraphicsConfig.h>
#include <X11/extensions/Xdbe.h>
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#ifndef NO_XRANDR
#include <X11/extensions/Xrandr.h>
#endif
@@ -2063,6 +2065,26 @@ Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
// in case of Xinerama individual screen scales are not supported
char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
double scale = getNativeScaleFactor(name, -1);
#ifndef HEADLESS
// Ubuntu 18.04 introduced a new settings for a scale factor: Settings > Devices > Displays > Scale.
// It is propagated to Xresource (and is read fine with 'xrdb' util) but is not propagated to GSettings
// (gtk3 doesn't see it in 'gtk-xft-dpi'). So, retrieve "Xft.dpi" from Xresource via X11 API call.
if (scale <= 0 && awt_display) {
char *resource_manager = XResourceManagerString(awt_display);
if (resource_manager) {
XrmDatabase db = XrmGetStringDatabase(resource_manager);
if (db) {
XrmValue value;
char *type;
if (XrmGetResource(db, "Xft.dpi", "Xft.dpi", &type, &value)) {
scale = (double)atoi(value.addr) / 96;
}
}
}
}
#endif
if (name) {
free(name);
}