diff --git a/runelite-client/src/main/java/net/runelite/client/ui/ContainableFrame.java b/runelite-client/src/main/java/net/runelite/client/ui/ContainableFrame.java index d83740f0679..18b77bb81b4 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/ContainableFrame.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/ContainableFrame.java @@ -24,7 +24,6 @@ */ package net.runelite.client.ui; -import com.google.common.annotations.VisibleForTesting; import java.awt.Dimension; import java.awt.Frame; import java.awt.GraphicsConfiguration; @@ -32,14 +31,12 @@ import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Rectangle; -import java.awt.Toolkit; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.Arrays; import java.util.Comparator; import javax.swing.JFrame; import lombok.extern.slf4j.Slf4j; -import net.runelite.client.util.OSType; @Slf4j public class ContainableFrame extends JFrame @@ -52,115 +49,6 @@ public enum Mode } private static final int SCREEN_EDGE_CLOSE_DISTANCE = 40; - /** - * JDK-8231564 changes Frame#setMaximizedBounds() to apply ui scaling - */ - private static boolean jdk8231564; - /** - * JDK-8243925 changes Toolkit#getScreenInsets() to apply ui scaling - */ - private static boolean jdk8243925; - - static - { - try - { - String javaVersion = System.getProperty("java.version"); - jdk8231564 = jdk8231564(javaVersion); - jdk8243925 = jdk8243925(javaVersion); - } - catch (Exception ex) - { - log.error("error checking java version", ex); - } - } - - @VisibleForTesting - static boolean jdk8231564(String javaVersion) - { - if (isVersionOrGreater(javaVersion, 15, -1, -1)) - { - return true; // JDK-8231564 - } - if (isVersionOrGreater(javaVersion, 14, -1, -1)) - { - return false; // unpatched - } - if (isVersionOrGreater(javaVersion, 13, 0, 4)) - { - return true; // JDK-8247209 - } - if (isVersionOrGreater(javaVersion, 12, -1, -1)) - { - return false; // unpatched - } - return isVersionOrGreater(javaVersion, 11, 0, 8); // JDK-8243374 - } - - @VisibleForTesting - static boolean jdk8243925(String javaVersion) - { - if (isVersionOrGreater(javaVersion, 15, -1, -1)) - { - return true; // JDK-8243925 - } - if (isVersionOrGreater(javaVersion, 14, -1, -1)) - { - return false; // unpatched - } - if (isVersionOrGreater(javaVersion, 13, 0, 7)) - { - return true; // JDK-8261342 - } - if (isVersionOrGreater(javaVersion, 12, -1, -1)) - { - return false; // unpatched - } - return isVersionOrGreater(javaVersion, 11, 0, 9); // JDK-8246659 - } - - private static boolean isVersionOrGreater(String javaVersion, int versionMajor, int versionMinor, int versionPatch) - { - int idx = javaVersion.indexOf('_'); - if (idx != -1) - { - javaVersion = javaVersion.substring(0, idx); - } - String[] s = javaVersion.split("\\."); - int major, minor, patch; - if (s.length >= 3) - { - major = Integer.parseInt(s[0]); - minor = Integer.parseInt(s[1]); - patch = Integer.parseInt(s[2]); - } - else - { - major = Integer.parseInt(s[0]); - minor = -1; - patch = -1; - } - - int i = Integer.compare(major, versionMajor); - if (i != 0) - { - return i > 0; - } - - i = Integer.compare(minor, versionMinor); - if (i != 0) - { - return i > 0; - } - - i = Integer.compare(patch, versionPatch); - if (i != 0) - { - return i > 0; - } - - return true; - } private Mode containedInScreen; private boolean rightSideSuction; @@ -321,26 +209,6 @@ public void containedSetSize(Dimension size) applyChange(getX(), getY(), size.width, size.height, getX(), getY(), this.containedInScreen != Mode.NEVER); } - /** - * Due to Java bug JDK-4737788, maximizing an undecorated frame causes it to cover the taskbar. - * As a workaround, Substance calls this method when the window is maximized to manually set the - * bounds, but its calculation ignores high-DPI scaling. We're overriding it to correctly calculate - * the maximized bounds. - */ - @Override - public void setMaximizedBounds(Rectangle bounds) - { - if (OSType.getOSType() == OSType.MacOS) - { - // OSX seems to correctly handle DPI scaling already - super.setMaximizedBounds(bounds); - } - else - { - super.setMaximizedBounds(getWindowAreaBounds()); - } - } - /** * Finds the {@link GraphicsConfiguration} of the display the window is currently on. If it's on more than * one screen, returns the one it's most on (largest area of intersection) @@ -357,67 +225,6 @@ private GraphicsConfiguration getCurrentDisplayConfiguration() .orElseGet(this::getGraphicsConfiguration); } - /** - * Calculates the bounds of the window area of the screen. - *

- * The bounds returned by {@link GraphicsEnvironment#getMaximumWindowBounds} are incorrectly calculated on - * high-DPI screens. - */ - private Rectangle getWindowAreaBounds() - { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - - log.trace("Current bounds: {}", getBounds()); - for (GraphicsDevice device : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) - { - GraphicsConfiguration graphicsConfiguration = device.getDefaultConfiguration(); - log.trace("Device: {} bounds {} insets {}", device, graphicsConfiguration.getBounds(), - toolkit.getScreenInsets(graphicsConfiguration)); - } - - GraphicsConfiguration config = getCurrentDisplayConfiguration(); - // get screen bounds - Rectangle bounds = config.getBounds(); - log.trace("Chosen device: {} bounds {}", config, bounds); - - // transform bounds to dpi-independent coordinates - if (!jdk8231564) - { - // JDK-8231564 fixed setMaximizedBounds to scale the bounds, so this must only be done on <11.0.8 - bounds = config.getDefaultTransform().createTransformedShape(bounds).getBounds(); - log.trace("Transformed bounds {}", bounds); - } - - // subtract insets (taskbar, etc.) - Insets insets = toolkit.getScreenInsets(config); - if (!jdk8231564) - { - // Prior to JDK-8231564, WFramePeer expects the bounds to be relative to the current monitor instead of the - // primary display. - bounds.x = bounds.y = 0; - - assert !jdk8243925 : "scaled insets without scaled bounds"; - } - else if (!jdk8243925) - { - // The insets from getScreenInsets are not scaled prior to JDK-8243925, we must convert them to DPI scaled - // pixels on 11.0.8 due to JDK-8231564 which expects the bounds to be in DPI-aware pixels. - double scaleX = config.getDefaultTransform().getScaleX(); - double scaleY = config.getDefaultTransform().getScaleY(); - insets.top /= scaleY; - insets.bottom /= scaleY; - insets.left /= scaleX; - insets.right /= scaleX; - } - bounds.x += insets.left; - bounds.y += insets.top; - bounds.height -= (insets.bottom + insets.top); - bounds.width -= (insets.right + insets.left); - - log.trace("Final bounds: {}", bounds); - return bounds; - } - /** * Force minimum size of frame to be it's layout manager's minimum size */