8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
Reviewed-by: alexsch
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java Fri Jul 29 10:56:30 2016 +0300
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java Fri Jul 29 10:59:43 2016 +0300
@@ -266,6 +266,12 @@
return new Insets(i.top, i.left, i.bottom, i.right);
}
+ private Insets copyAndScaleDown(Insets i) {
+ return new Insets(scaleDown(i.top), scaleDown(i.left),
+ scaleDown(i.bottom), scaleDown(i.right));
+ }
+
+
// insets which we get from WM (e.g from _NET_FRAME_EXTENTS)
private Insets wm_set_insets;
@@ -289,7 +295,7 @@
}
if (wm_set_insets != null) {
- wm_set_insets = copy(wm_set_insets);
+ wm_set_insets = copyAndScaleDown(wm_set_insets);
}
return wm_set_insets;
}
@@ -386,6 +392,9 @@
}
} else {
correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
+ if (correctWM != null) {
+ correctWM = copyAndScaleDown(correctWM);
+ }
if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
if (correctWM != null) {
@@ -470,6 +479,9 @@
Insets res = getWMSetInsets(null);
if (res == null) {
res = XWM.getWM().guessInsets(this);
+ if (res != null) {
+ res = copyAndScaleDown(res);
+ }
}
return res;
}
@@ -756,7 +768,7 @@
}
}
if (correctWM != null) {
- handleCorrectInsets(correctWM);
+ handleCorrectInsets(copyAndScaleDown(correctWM));
} else {
//Only one attempt to correct insets is made (to lower risk)
//if insets are still not available we simply set the flag
--- a/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java Fri Jul 29 10:56:30 2016 +0300
+++ b/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java Fri Jul 29 10:59:43 2016 +0300
@@ -23,8 +23,9 @@
/**
* @test @summary setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
- * @bug 8036915
- * @run main GetScreenLocationTest
+ * @bug 8036915 8161273
+ * @run main/othervm -Dsun.java2d.uiScale=1 GetScreenLocationTest
+ * @run main/othervm -Dsun.java2d.uiScale=2 GetScreenLocationTest
*/
import java.awt.*;
@@ -33,28 +34,28 @@
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
Window frame = null;
- for(int i = 0; i < 50; i++) {
+ for(int i = 0; i < 30; i++) {
if(frame != null) frame.dispose();
frame = new Dialog((Frame)null);
- frame.setBounds(0, 0, 200, 200);
+ frame.setBounds(0, 0, 200, 100);
frame.setVisible(true);
robot.waitForIdle();
robot.delay(200);
- frame.setLocation(321, 321);
+ frame.setLocation(321, 121);
robot.waitForIdle();
robot.delay(200);
Dimension size = frame.getSize();
- if(size.width != 200 || size.height != 200) {
+ if(size.width != 200 || size.height != 100) {
frame.dispose();
throw new RuntimeException("getSize() is wrong " + size);
}
Rectangle r = frame.getBounds();
frame.dispose();
- if(r.x != 321 || r.y != 321) {
+ if(r.x != 321 || r.y != 121) {
throw new RuntimeException("getLocation() returns " +
"wrong coordinates " + r.getLocation());
}
- if(r.width != 200 || r.height != 200) {
+ if(r.width != 200 || r.height != 100) {
throw new RuntimeException("getSize() is wrong " + r.getSize());
}
}