# HG changeset patch # User e165729 # Date 1580225142 -32400 # Node ID e912db2ab7784f2e9cdf19fa16fc262c575f4282 # Parent 9c0cbe1191553be493c0d8b31c1008e1de65ab9a fix RetinaDisplay API for java9 and above diff -r 9c0cbe119155 -r e912db2ab778 src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java Mon Jan 27 14:40:58 2020 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java Wed Jan 29 00:25:42 2020 +0900 @@ -14,21 +14,9 @@ int scale = 1; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] devices = env.getScreenDevices(); - - try { - Field field = devices[shareScreenNumber].getClass().getDeclaredField("scale"); - - if (field != null) { - field.setAccessible(true); - Object retinaScale = field.get(devices[shareScreenNumber]); - - if (retinaScale instanceof Integer) { - scale = (Integer) retinaScale; - return scale; - } - } - } catch (Exception ignore) {} - return scale; + GraphicsConfiguration conf = devices[shareScreenNumber].getDefaultConfiguration(); + scale = (int)conf.getDefaultTransform().getScaleX(); + return scale; } public static ArrayList getScreenRectangles() { diff -r 9c0cbe119155 -r e912db2ab778 src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Mon Jan 27 14:40:58 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Wed Jan 29 00:25:42 2020 +0900 @@ -184,6 +184,11 @@ } @Override + public boolean getIsRetinaDisplay(int shareScreenNumber) { + return false; + } + + @Override public void windowOpened(WindowEvent e) { /* nop */ } diff -r 9c0cbe119155 -r e912db2ab778 src/viewer_swing/java/com/glavsoft/viewer/FbRectangle.java --- a/src/viewer_swing/java/com/glavsoft/viewer/FbRectangle.java Mon Jan 27 14:40:58 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/FbRectangle.java Wed Jan 29 00:25:42 2020 +0900 @@ -10,11 +10,13 @@ int xfb; int yfb; int screenNumber; + boolean isRetina; - public FbRectangle(int x, int y, int width, int height, int screenNumber, int scale) { + public FbRectangle(int x, int y, int width, int height, int screenNumber, int scale, boolean isRetina) { super(x, y, width, height); this.screenNumber = screenNumber; this.retinaScale = scale; + this.isRetina = isRetina; this.xfb = x; this.yfb = y; } @@ -51,6 +53,10 @@ this.screenNumber = screenNumber; } + public boolean getIsRetina() { + return this.isRetina; + } + @Override public String toString() { return "FRectangle(x="+x+",y="+y+",xFb="+xfb+",yFb="+yfb+",w="+width+",h="+height+")"; diff -r 9c0cbe119155 -r e912db2ab778 src/viewer_swing/java/com/glavsoft/viewer/Viewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Mon Jan 27 14:40:58 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jan 29 00:25:42 2020 +0900 @@ -368,6 +368,14 @@ return broadcastRFBListener; } + @Override + public boolean getIsRetinaDisplay(int shareScreenNumber) { + GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + final GraphicsDevice[] devices = env.getScreenDevices(); + GraphicsConfiguration conf = devices[shareScreenNumber].getDefaultConfiguration(); + return ! conf.getDefaultTransform().isIdentity(); + } + private ConnectionPresenter createNewConnectionPresenter(String hostName, short newVNCServerId, int x, int y, int width, int height, int scale) { final boolean hasJsch = checkJsch(); final boolean allowInteractive = allowAppletInteractiveConnections || ! isApplet; @@ -527,7 +535,7 @@ ArrayList fbRectangles = new ArrayList(); int screenNumber = 0; for (Rectangle rect : rectangles) { - FbRectangle fbrect = new FbRectangle(rect.x, rect.y, rect.width, rect.height, screenNumber, retinaScale(screenNumber)); + FbRectangle fbrect = new FbRectangle(rect.x, rect.y, rect.width, rect.height, screenNumber, retinaScale(screenNumber), getIsRetinaDisplay(screenNumber)); fbrect.setXfb(rect.x + offset.x); fbrect.setYfb(rect.y + offset.y); fbRectangles.add(fbrect); @@ -545,7 +553,7 @@ FbRectangle fbRectanglesPrev = fbRectangles.get(0); for (int i = 1; i < fbRectangles.size(); i++) { FbRectangle fbRect = fbRectangles.get(i); - if (fbRectanglesPrev.getRetinaScale() != 1) { + if (fbRect.getIsRetina()) { if (fbRectanglesPrev.x + fbRectanglesPrev.width <= fbRect.x) { // previous screen is touch with this screen, fix retina scale offset retinaOffsetX += fbRectanglesPrev.getWidth() * (fbRectanglesPrev.retinaScale - 1); @@ -566,7 +574,7 @@ fbRectanglesPrev = fbRectangles.get(0); for (int i = 1; i < fbRectangles.size(); i++) { FbRectangle fbRect = fbRectangles.get(i); - if (fbRectanglesPrev.getRetinaScale() != 1) { + if (fbRect.getIsRetina()) { if (fbRectanglesPrev.y + fbRectanglesPrev.height <= fbRect.y) { // previous screen is touch with this screen, fix retina scale offset retinaOffsetY += fbRectanglesPrev.getHeight() * (fbRectanglesPrev.retinaScale - 1); @@ -594,20 +602,8 @@ int scale = 1; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] devices = env.getScreenDevices(); - - try { - Field field = devices[shareScreenNumber].getClass().getDeclaredField("scale"); - - if (field != null) { - field.setAccessible(true); - Object retinaScale = field.get(devices[shareScreenNumber]); - - if (retinaScale instanceof Integer) { - scale = (Integer) retinaScale; - return scale; - } - } - } catch (Exception ignore) {} + GraphicsConfiguration conf = devices[shareScreenNumber].getDefaultConfiguration(); + scale = (int)conf.getDefaultTransform().getScaleX(); return scale; } diff -r 9c0cbe119155 -r e912db2ab778 src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java --- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Mon Jan 27 14:40:58 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Wed Jan 29 00:25:42 2020 +0900 @@ -67,4 +67,6 @@ public boolean getUseMulticast(); BroadcastRFBListener getRfbBroadcastListener(); + + public boolean getIsRetinaDisplay(int shareScreenNumber); }