[followup] Fix "hidpi" property

This commit is contained in:
Anton Tarasov
2018-03-02 14:19:22 +03:00
parent c6236ebec6
commit 58f2fa7ce0
5 changed files with 18 additions and 17 deletions
@@ -34,6 +34,7 @@ import org.apache.log4j.Level;
import org.apache.log4j.PatternLayout;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.io.BuiltInServer;
import javax.swing.*;
@@ -183,9 +184,13 @@ public class StartupUtil {
return true;
}
// called via reflection from com.intellij.util.ui.HidpiPropTest
@TestOnly
public static void test_checkHiDPISettings() {
checkHiDPISettings();
}
private static void checkHiDPISettings() {
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
if (!SystemProperties.getBooleanProperty("hidpi", true)) {
// suppress JRE-HiDPI mode
System.setProperty("sun.java2d.uiScale.enabled", "false");
}
@@ -2,12 +2,9 @@
package com.intellij.util.ui;
import com.intellij.idea.StartupUtil;
import com.intellij.util.MethodInvocator;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.SystemProperties;
import org.junit.*;
import javax.swing.*;
import java.awt.*;
/**
@@ -28,9 +25,7 @@ public class HidpiPropTest {
@Before
public void setState() {
TestScaleHelper.setProperty(HIDPI_PROP, "false");
MethodInvocator m = new MethodInvocator(StartupUtil.class, "checkHiDPISettings");
Assume.assumeTrue("StartupUtil.checkHiDPISettings method not available", m.isAvailable());
m.invoke(null);
StartupUtil.test_checkHiDPISettings();
}
@After
@@ -1,7 +1,6 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.ui;
import com.intellij.util.FieldAccessor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.After;
@@ -11,16 +10,12 @@ import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author tav
*/
@SuppressWarnings("JUnitTestCaseWithNoTests")
public class TestScaleHelper {
private static final FieldAccessor<UIUtil, AtomicReference<Boolean>> JRE_HIDPI_ACCESSOR =
new FieldAccessor<>(UIUtil.class, "jreHiDPI");
private static final Map<String, String> origProps = new HashMap<>();
private float originalUserScale;
@@ -60,7 +55,7 @@ public class TestScaleHelper {
}
public static void overrideJreHiDPIEnabled(boolean enabled) {
JRE_HIDPI_ACCESSOR.get(null).set(enabled);
UIUtil.test_jreHiDPI().set(enabled);
}
public static Graphics2D createGraphics(double scale) {
@@ -207,7 +207,7 @@ public class JBUI {
@NotNull
@Override
public Float initialize() {
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
if (!SystemProperties.getBooleanProperty("hidpi", true)) {
return 1f;
}
if (UIUtil.isJreHiDPIEnabled()) {
@@ -421,7 +421,7 @@ public class JBUI {
return debugScale;
}
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
if (!SystemProperties.getBooleanProperty("hidpi", true)) {
setUserScaleFactorProperty(1f);
return 1f;
}
@@ -392,6 +392,12 @@ public class UIUtil {
private static final AtomicReference<Boolean> jreHiDPI = new AtomicReference<Boolean>();
private static volatile boolean jreHiDPI_earlierVersion;
@TestOnly
public static final AtomicReference<Boolean> test_jreHiDPI() {
if (jreHiDPI.get() == null) isJreHiDPIEnabled(); // force init
return jreHiDPI;
}
/**
* Returns whether the JRE-managed HiDPI mode is enabled.
* (True for macOS JDK >= 7.10 versions)
@@ -405,7 +411,7 @@ public class UIUtil {
if (jreHiDPI.get() != null) return jreHiDPI.get();
jreHiDPI.set(false);
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
if (!SystemProperties.getBooleanProperty("hidpi", true)) {
return false;
}
jreHiDPI_earlierVersion = true;