Mercurial > hg > Applications > TreeVNC
changeset 456:34277b436cac
Using retina scale to share screnn if minus postion
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Jun 2016 19:11:37 +0900 |
parents | 6f3d3da40940 |
children | effba48b76f3 |
files | src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java |
diffstat | 4 files changed, 40 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Wed Jun 22 12:29:57 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Wed Jun 22 19:11:37 2016 +0900 @@ -309,6 +309,11 @@ } @Override + public int retinaScale(int shareScreenNumber) { + return 1; + } + + @Override public void setFitScreen() { } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jun 22 12:29:57 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jun 22 19:11:37 2016 +0900 @@ -40,6 +40,7 @@ import java.awt.event.WindowListener; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; import java.net.Socket; import java.util.ArrayList; import java.util.jar.Attributes; @@ -487,9 +488,12 @@ GraphicsDevice[] gs = ge.getScreenDevices(); for (GraphicsDevice gd : gs) { + int screenNumber = 0; for (GraphicsConfiguration r : gd.getConfigurations()) { Rectangle rect = r.getBounds(); + //System.out.println("screen "+ screenNumber +":"+rect); rectangles.add(rect); + screenNumber++; } } return rectangles; @@ -500,13 +504,38 @@ // compute offset to make them positive int offsetx = 0; int offsety = 0; + int screenNumber = 0; for (Rectangle rect : rectangles) { - if (rect.x < offsetx) offsetx = rect.x; - if (rect.y < offsety) offsety = rect.y; + int scale = retinaScale(screenNumber); + int x = rect.x < 0 ? rect.x * scale : rect.x; + int y = rect.y < 0 ? rect.y * scale : rect.y; + if (x < offsetx) offsetx = x; + if (y < offsety) offsety = y; + screenNumber++; } return new Point(-offsetx,-offsety); } + public int retinaScale(int shareScreenNumber) { + 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; + } @Override public void setFitScreen() {
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Wed Jun 22 12:29:57 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Wed Jun 22 19:11:37 2016 +0900 @@ -53,6 +53,8 @@ public Point getScreenOffset(ArrayList<Rectangle> rectangles); + public int retinaScale(int shareScreenNumber); + public ConnectionPresenter getConnectionPresenter(); public void setConnectionPresenter(ConnectionPresenter connectionPresenter);
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Wed Jun 22 12:29:57 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Wed Jun 22 19:11:37 2016 +0900 @@ -923,7 +923,7 @@ int singleHeight = (int) (rectangle1.getHeight()); int x = (int) (rectangle1.getX()) + offset.x; // convert double to int int y = (int) (rectangle1.getY()) + offset.y; - int scale = retinaScale(shareScreenNumber); + int scale = viewer.retinaScale(shareScreenNumber); showScreenInfo("request screen change", 0, x, y, singleWidth, singleHeight, scale); if (viewer.getRfb().isTreeManager()) { changeVncServer(viewer, x, y, singleWidth * scale, singleHeight * scale, scale, viewer.getRfb().getId()); @@ -938,27 +938,6 @@ } } - private int retinaScale(int shareScreenNumber) { - 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; - } - private boolean scanPort(String adr, int port) { try { Socket socket = new Socket(adr, port); @@ -984,7 +963,7 @@ int thisScreenWidth = (int) rectangles.get(thisScreenNumber).getWidth(); int thisScreenHeight = (int) rectangles.get(thisScreenNumber).getHeight(); - int thisRetinaScale = retinaScale(thisScreenNumber); + int thisRetinaScale = viewer.retinaScale(thisScreenNumber); final int thatScreenX = presenter.getX(); final int thatScreenY = presenter.getY();