aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Ushakov <alexey.ushakov@jetbrains.com>2017-04-14 14:08:14 +0300
committerAlexey Ushakov <alexey.ushakov@jetbrains.com>2017-04-14 14:08:14 +0300
commitf50772e77d75e80c5df70c48e8a0ca57b1b2a60b (patch)
tree105d7a5417cff283faa8ff859b281b5af1dd3879
parentdd6f147f30b74e610016a847dbe7ca8abad7d820 (diff)
downloadjdk8u_jdk-f50772e77d75e80c5df70c48e8a0ca57b1b2a60b.tar.gz
JRE-307 Wrong dpi reported on Waylandjb8u152-b827
Fallback to default (96) dpi if wrong display width reported
-rw-r--r--src/solaris/classes/sun/awt/X11/XToolkit.java10
-rw-r--r--test/jb/java/awt/Toolkit/ScreenResolution.java32
2 files changed, 40 insertions, 2 deletions
diff --git a/src/solaris/classes/sun/awt/X11/XToolkit.java b/src/solaris/classes/sun/awt/X11/XToolkit.java
index 3774b0594d..a09351be5a 100644
--- a/src/solaris/classes/sun/awt/X11/XToolkit.java
+++ b/src/solaris/classes/sun/awt/X11/XToolkit.java
@@ -68,6 +68,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
//We use the same hardcoded constant.
private final static int AWT_MULTICLICK_DEFAULT_TIME = 500;
+ private final static int DEFAULT_SCREEN_RESOLUTION = 96;
+
static final boolean PRIMARY_LOOP = false;
static final boolean SECONDARY_LOOP = true;
@@ -1278,10 +1280,14 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
long display = getDisplay();
awtLock();
try {
+ long displayWidthMM = XlibWrapper.DisplayWidthMM(
+ display, XlibWrapper.DefaultScreen(display));
+
+ if (displayWidthMM <= 0) return DEFAULT_SCREEN_RESOLUTION;
+
return (int) ((XlibWrapper.DisplayWidth(display,
XlibWrapper.DefaultScreen(display)) * 25.4) /
- XlibWrapper.DisplayWidthMM(display,
- XlibWrapper.DefaultScreen(display)));
+ displayWidthMM);
} finally {
awtUnlock();
}
diff --git a/test/jb/java/awt/Toolkit/ScreenResolution.java b/test/jb/java/awt/Toolkit/ScreenResolution.java
new file mode 100644
index 0000000000..a93aa47c33
--- /dev/null
+++ b/test/jb/java/awt/Toolkit/ScreenResolution.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import java.awt.Toolkit;
+
+/* @test
+ * @summary checks that screen resolution is in acceptable range
+ */
+
+public class ScreenResolution {
+
+ public static void main(String[] args) throws Exception {
+ int pixelPerInch = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
+
+ if (pixelPerInch <= 0 || pixelPerInch > 1000)
+ throw new RuntimeException("Invalid resolution: " + pixelPerInch);
+ }
+}