Mercurial > hg > Applications > TreeVNC
changeset 551:e912db2ab778
fix RetinaDisplay API for java9 and above
author | e165729 <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 29 Jan 2020 00:25:42 +0900 |
parents | 9c0cbe119155 |
children | ff4c1972aa2e 214ebc49b5bd |
files | src/main/java/jp/ac/u_ryukyu/treevnc/test/IsRetina.java src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java src/viewer_swing/java/com/glavsoft/viewer/FbRectangle.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java |
diffstat | 5 files changed, 30 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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<Rectangle> getScreenRectangles() {
--- 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 */ }
--- 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+")";
--- 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<FbRectangle> fbRectangles = new ArrayList<FbRectangle>(); 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; }
--- 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); }