JRE-1162 [jdk11] support on-the-fly DPI change on linux

(cherry picked from commit c06c4c69d3)
This commit is contained in:
Anton Tarasov
2019-01-28 18:45:26 +03:00
committed by jbrbot
parent f27f0cf777
commit a85c41943a
3 changed files with 21 additions and 10 deletions

View File

@@ -350,7 +350,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
@Override
public void dispatchEvent(XEvent ev) {
if (ev.get_type() == XConstants.ConfigureNotify) {
if (ev.get_type() == XConstants.ConfigureNotify ||
(ev.get_type() == XConstants.PropertyNotify &&
ev.get_xproperty().get_atom() == XWM.XA_NET_DESKTOP_GEOMETRY.getAtom())) // possible DPI change
{
awtUnlock();
try {
((X11GraphicsEnvironment)GraphicsEnvironment.

View File

@@ -89,6 +89,9 @@ final class XWM
static final XAtom XA_NET_FRAME_EXTENTS = new XAtom();
static final XAtom XA_NET_REQUEST_FRAME_EXTENTS = new XAtom();
/* Root window */
static final XAtom XA_NET_DESKTOP_GEOMETRY = new XAtom();
static final int
UNDETERMINED_WM = 1,
NO_WM = 2,
@@ -206,6 +209,7 @@ final class XWM
{ XA_MWM_HINTS, "_MOTIF_WM_HINTS" },
{ XA_NET_FRAME_EXTENTS, "_NET_FRAME_EXTENTS" },
{ XA_NET_REQUEST_FRAME_EXTENTS, "_NET_REQUEST_FRAME_EXTENTS" },
{ XA_NET_DESKTOP_GEOMETRY, "_NET_DESKTOP_GEOMETRY" }
};
String[] names = new String[atomInitList.length];

View File

@@ -2083,17 +2083,21 @@ Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
// 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;
if (scale <= 0) {
Display *display = XOpenDisplay(NULL); // need to open new display to get up-to-date XResource value
if (display) {
char *resource_manager = XResourceManagerString(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;
}
}
}
XCloseDisplay(display);
}
}
#endif