From cb959adf02e60e5db8f6bd6bf787838668ead401 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Fri, 29 Jul 2016 10:59:43 +0300 Subject: [PATCH] 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled Reviewed-by: alexsch --- .../classes/sun/awt/X11/XDecoratedPeer.java | 16 ++++++++++++++-- .../GetScreenLocationTest.java | 17 +++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java index a392a307adb..66fc0272279 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java @@ -266,6 +266,12 @@ abstract class XDecoratedPeer extends XWindowPeer { 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 @@ abstract class XDecoratedPeer extends XWindowPeer { } 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 @@ abstract class XDecoratedPeer extends XWindowPeer { } } 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 @@ abstract class XDecoratedPeer extends XWindowPeer { Insets res = getWMSetInsets(null); if (res == null) { res = XWM.getWM().guessInsets(this); + if (res != null) { + res = copyAndScaleDown(res); + } } return res; } @@ -756,7 +768,7 @@ abstract class XDecoratedPeer extends XWindowPeer { } } 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 diff --git a/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java b/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java index 5aba90b4b80..af7940bc5a7 100644 --- a/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java +++ b/jdk/test/java/awt/Window/GetScreenLocation/GetScreenLocationTest.java @@ -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 class GetScreenLocationTest { 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()); } }