8163100: [hidpi] Linux: display-wise scaling factor issues
authorssadetsky
Fri, 02 Sep 2016 10:36:55 +0300
changeset 40996 60d53c39c1b3
parent 40995 c096d4be5b5e
child 40997 b9a1c4fe2518
8163100: [hidpi] Linux: display-wise scaling factor issues Reviewed-by: alexsch, serb
jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java
jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java
jdk/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c
jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java	Fri Sep 02 10:31:49 2016 +0300
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java	Fri Sep 02 10:36:55 2016 +0300
@@ -1570,6 +1570,10 @@
                                   Integer.valueOf(getMultiClickTime()));
             desktopProperties.put("awt.mouse.numButtons",
                                   Integer.valueOf(getNumberOfButtons()));
+            if(SunGraphicsEnvironment.isUIScaleEnabled()) {
+                addPropertyChangeListener("gnome.Xft/DPI", evt ->
+                                                     localEnv.displayChanged());
+            }
         }
     }
 
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java	Fri Sep 02 10:31:49 2016 +0300
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java	Fri Sep 02 10:36:55 2016 +0300
@@ -63,7 +63,7 @@
     private SunDisplayChanger topLevels = new SunDisplayChanger();
     private DisplayMode origDisplayMode;
     private boolean shutdownHookRegistered;
-    private final int scale;
+    private int scale;
 
     public X11GraphicsDevice(int screennum) {
         this.screen = screennum;
@@ -488,6 +488,7 @@
      * X11GraphicsEnvironment when the display mode has been changed.
      */
     public synchronized void displayChanged() {
+        scale = initScaleFactor();
         // On X11 the visuals do not change, and therefore we don't need
         // to reset the defaultConfig, config, doubleBufferVisuals,
         // neither do we need to reset the native data.
--- a/jdk/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c	Fri Sep 02 10:31:49 2016 +0300
+++ b/jdk/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c	Fri Sep 02 10:36:55 2016 +0300
@@ -148,7 +148,7 @@
                         void *scale = fp_g_variant_get_child_value(entry, 1);
                         if (screen && scale) {
                             char *name = fp_g_variant_get_string(screen, NULL);
-                            if (name && strcmp(name, output_name)) {
+                            if (name && !strcmp(name, output_name)) {
                                 result = fp_g_variant_get_int32(scale) / 8.;
                             }
                             fp_g_variant_unref(screen);
--- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c	Fri Sep 02 10:31:49 2016 +0300
+++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c	Fri Sep 02 10:36:55 2016 +0300
@@ -2181,7 +2181,8 @@
 JNIEXPORT jdouble JNICALL
 Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
     (JNIEnv *env, jobject this, jint screen) {
-    char *name = get_output_screen_name(env, screen);
+    // in case of Xinerama individual screen scales are not supported
+    char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
     double scale = getNativeScaleFactor(name);
     if (name) {
         free(name);