# HG changeset patch # User Shinji KONO # Date 1466564145 -32400 # Node ID 432e2967eaabe82425945090ba5e7fc89a1a38b4 # Parent d0ca1be5c47c7b1e1ebb9e45fb63eb0eb42ad925 All screen sharing request information is now in ConnectionPresenter only diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/com/glavsoft/rfb/protocol/Protocol.java --- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Wed Jun 22 11:55:45 2016 +0900 @@ -329,16 +329,6 @@ } @Override - public void setX(int x) { - if (rfb != null) rfb.setX(x); - } - - @Override - public void setY(int y) { - if (rfb != null) rfb.setY(y); - } - - @Override public void setTight(boolean isTight) { this.isTight = isTight; } diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java --- a/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java Wed Jun 22 11:55:45 2016 +0900 @@ -80,10 +80,6 @@ TreeRFBProto getRfb(); - void setX(int x); - - void setY(int y); - /** * TreeVNC expension command (server to client) * 0 : command byte diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java --- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Wed Jun 22 11:55:45 2016 +0900 @@ -91,16 +91,18 @@ context.setFbWidth(rfb.fixingSizeWidth); context.setFbHeight(rfb.fixingSizeHeight); } + ConnectionPresenter cp = rfb.getViewer().getConnectionPresenter(); if(!rfb.getCuiVersion()) { - if (rfb.getSingleWidth()==0) { + if (cp.getSingleWidth()==0) { // request full screen for the first time - rfb.setSingleDisplaySize(context.getFbWidth(),context.getFbHeight()); + cp.setSingleWidth(context.getFbWidth()); + cp.setSingleHeight(context.getFbHeight()); } renderer = repaintController.createRenderer(reader, context.getFbWidth(), context.getFbHeight(), context.getPixelFormat()); - System.out.println("ReceiverTask: FB x="+context.getFbWidth() + " y="+context.getFbHeight()); + // System.out.println("ReceiverTask: FB x="+context.getFbWidth() + " y="+context.getFbHeight()); } if(rfb.isTreeManager()) { - fullscreenFbUpdateIncrementalRequest = new FramebufferUpdateRequestMessage(rfb.getX(), rfb.getY(), rfb.getSingleWidth(), rfb.getSingleHeight(), false); + fullscreenFbUpdateIncrementalRequest = new FramebufferUpdateRequestMessage(cp.getX(), cp.getY(), cp.getSingleWidth(), cp.getSingleHeight(), false); fullscreenFbUpdateIncrementalRequest.sendFullScreenRequest(); connectionFinished(); } @@ -296,8 +298,6 @@ context.setInitData(initData); context.setFbWidth(rect.width); context.setFbHeight(rect.height); - context.setX(rect.x); - context.setY(rect.y); repaintController.updateRemoteDesktopName(context); reader.reset(); // request one screen @@ -355,12 +355,14 @@ private void setScreenParameter(FramebufferUpdateRectangle rect,int singleWidth ,int singleHeight) { ViewerInterface v = rfb.getViewer(); - rfb.setSingleDisplaySize(singleWidth,singleHeight); ConnectionPresenter cp = v.getConnectionPresenter(); cp.setX(rect.x); cp.setY(rect.y); cp.setFrameSizeWidth(rect.width); cp.setFrameSizeHeight(rect.height); + cp.setSingleWidth(singleWidth); + cp.setSingleHeight(singleHeight); + rfb.setConnectionPresenter(cp); v.setFitScreen(); } diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Wed Jun 22 11:55:45 2016 +0900 @@ -46,6 +46,7 @@ private TreeVncCommandChannelListener acceptThread; private TreeRootFinderListener getCast; private CreateConnectionParam cp; + private ConnectionPresenter connectionPresenter; private TreeVNCNetwork nets = new TreeVNCNetwork(); private TreeVncRootSelectionPanel rootSelectionPanel; private String vncInterface; @@ -66,21 +67,14 @@ public boolean fixingSize = false; public int fixingSizeWidth; public int fixingSizeHeight; - private int singleWidth = 0; // only one screen - private int singleHeight = 0; // specified in SeverChangeRequest - private int x; - private int y; private DatagramSocket socket = null; private byte[] originalInitData = null; private boolean childrenMulticast = true; - private int retinaScale = 1; - public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) { nets.setMyRfb(this); this.isTreeManager = isTreeManager; this.viewer = viewer; -// this.socket = createSocket(); startTreeRootFindThread(); } @@ -209,8 +203,8 @@ String newHostName = new String(byteAddress, "UTF-8"); int x = buf.getInt(); int y = buf.getInt(); - singleWidth = buf.getInt(); - singleHeight = buf.getInt(); + int singleWidth = buf.getInt(); + int singleHeight = buf.getInt(); int port = buf.getInt(); int scale = buf.getInt(); System.out.println("Root server change request :" + newHostName + " : " + port); @@ -483,6 +477,10 @@ public void sendDesktopSizeChange(short id) { LinkedList desktopSize = new LinkedList(); + int singleWidth = connectionPresenter.getSingleWidth(); + int singleHeight = connectionPresenter.getSingleHeight(); + int x = connectionPresenter.getX(); + int y = connectionPresenter.getY(); desktopSize.add(new ChangeDesktopSize(context.getFbWidth(), context.getFbHeight(), singleWidth,singleHeight, x, y, EncodingType.INIT_DATA, context.getInitData(), id).getMessage()); if (addSerialNum) { addSerialNumber(desktopSize); @@ -778,11 +776,6 @@ return; } // serverChangeの処理 - // keep requested screen size ( not frame buffer size ) - singleWidth = width; - singleHeight = height; - this.x = x; - this.y = y; vncProxyService.inhelitClients(hostName, newVNCServerId, x, y, width, height, scale); // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary // stop reader stop @@ -848,32 +841,6 @@ this.fixingSize = fixingSize; } - public void setSingleDisplaySize(int singleWidth, int singleHeight) { - this.singleWidth = singleWidth; - this.singleHeight = singleHeight; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getSingleWidth() { - return singleWidth; - } - - public int getSingleHeight() { - return singleHeight; - } - - public int getRetinaScale() { - return retinaScale; - } - - public boolean hasParent() { return id != -1; } @@ -890,9 +857,12 @@ */ public void exchangeDirectConnectedServer(Reader previousReader, Writer previousWriter) { String adr = viewer.getRfb().getMyAddress(); - int scale = viewer.getRfb().getRetinaScale(); - int x = 0; - int y = 0; + ConnectionPresenter cp1 = viewer.getConnectionPresenter(); + int scale = cp1.getRetinaScale(); + int singleWidth = cp1.getSingleWidth(); + int singleHeight = cp1.getSingleHeight(); + int x = cp1.getX(); + int y = cp1.getY(); ScreenChangeRequest scr = new ScreenChangeRequest(adr, ConnectionParams.DEFAULT_VNC_ROOT, (short) -1, x, y, singleWidth, singleHeight, scale); try { scr.send(previousWriter); @@ -915,11 +885,9 @@ ProtocolContext previousContext = getContext(); stopReceiverTask(); setProtocolContext(workingProtocol); + this.connectionPresenter = connectionPresenter; connectionPresenter.viewer.setConnectionPresenter(connectionPresenter); - connectionPresenter.viewer.getConnectionPresenter().addModel("ConnectionParamsModel", connectionPresenter.getConnectionParams()); - this.x = connectionPresenter.getX(); - this.y = connectionPresenter.getY(); - this.retinaScale = connectionPresenter.getRetinaScale(); + connectionPresenter.addModel("ConnectionParamsModel", connectionPresenter.getConnectionParams()); if (previousContext != null && isTreeManager() && hasParent()) { Reader previousReader = previousContext.getReader(); Writer previousWriter = previousContext.getWriter(); @@ -939,12 +907,8 @@ multicastqueue.put(errorAnnounce); } - public void setX(int x) { - this.x = x; + + public void setConnectionPresenter(ConnectionPresenter connectionPresenter) { + this.connectionPresenter = connectionPresenter; } - - public void setY(int y) { - this.y = y; - } - } \ No newline at end of file diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Wed Jun 22 11:55:45 2016 +0900 @@ -65,9 +65,6 @@ port = port * 256 + reply[11]; TreeVncProtocol t = new TreeVncProtocol(hostname, port); - int singleWidth = vps.getRfb().getSingleWidth(); - int singleHeight = vps.getRfb().getSingleHeight(); - t.setSingleSize(singleWidth, singleHeight); t.findRootReply(vps.getRfb().getAcceptPort()); if(stopFlag) break; } diff -r d0ca1be5c47c -r 432e2967eaab src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Wed Jun 22 11:55:45 2016 +0900 @@ -1,10 +1,14 @@ package jp.ac.u_ryukyu.treevnc; -import java.io.*; -import java.net.*; +import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Socket; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; public class TreeVncProtocol { private BufferedReader is = null; @@ -12,19 +16,12 @@ private Socket echoSocket = null; private int rootPort; private String rootAddress; - private int singleWidth; - private int singleHeight; public TreeVncProtocol(String name, int echoPort) { this.rootPort = echoPort; this.rootAddress = name; } - public void setSingleSize(int singleWidth, int singleHeight) { - this.singleWidth = singleWidth; - this.singleHeight = singleHeight; - } - public void openport() throws IOException { echoSocket = new Socket(rootAddress, rootPort); // echoSocket.setReuseAddress(true); diff -r d0ca1be5c47c -r 432e2967eaab src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java --- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Wed Jun 22 11:55:45 2016 +0900 @@ -69,10 +69,12 @@ public ViewerInterface viewer; private ConnectionParams connectionParams; private short reconnectingId = -1; - private int frameSizeWidth; + private int frameSizeWidth; // contains multi screens private int frameSizeHeight; - private int retinaScale = 1; - private int x; + private int singleWidth = 0; // requested single screen in frame buffer + private int singleHeight = 0; + private int retinaScale = 1; // we don't use it now + private int x; // requested single screen offset private int y; public short getReconnectingId() { @@ -435,4 +437,22 @@ setNeedReconnection(!viewer.noConnection); startConnection(viewer.settings, viewer.uiSettings, viewer.paramsMask, exchangeSocket, is, os); } + + + public int getSingleWidth() { + return singleWidth; + } + + public int getSingleHeight() { + return singleHeight; + } + + public void setSingleWidth(int singleWidth) { + this.singleWidth = singleWidth; + } + + public void setSingleHeight(int signleHeight) { + this.singleHeight = signleHeight; + } + } diff -r d0ca1be5c47c -r 432e2967eaab src/viewer_swing/java/com/glavsoft/viewer/Viewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Wed Jun 22 11:55:45 2016 +0900 @@ -358,8 +358,8 @@ connectionPresenter.setNoConnection(false); connectionPresenter.setX(x); connectionPresenter.setY(y); - connectionPresenter.setFrameSizeWidth(width); - connectionPresenter.setFrameSizeHeight(height); + connectionPresenter.setSingleWidth(width); + connectionPresenter.setSingleHeight(height); connectionPresenter.setRetinaScale(scale); return connectionPresenter; } @@ -434,10 +434,6 @@ connectionParams.setConnectionParam(hostName, vncport); isApplet = true; settings.setViewOnly(true); // to avoid unnecessary upward traffic - - // single display size = 0 means, request all screen - getRfb().setSingleDisplaySize(0,0); - run(); } diff -r d0ca1be5c47c -r 432e2967eaab src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java --- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Tue Jun 21 20:39:23 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Wed Jun 22 11:55:45 2016 +0900 @@ -876,7 +876,7 @@ @Override public void actionPerformed(ActionEvent e) { // adjustHdSizeButton.setSelected(false); - int singleWidth = viewer.getRfb().getSingleWidth(); + int singleWidth = viewer.getConnectionPresenter().getSingleWidth(); uiSettings.adjustHdSize(singleWidth); } }); @@ -924,9 +924,7 @@ int x = (int) (rectangle1.getX()) + offset.x; // convert double to int int y = (int) (rectangle1.getY()) + offset.y; int scale = retinaScale(shareScreenNumber); - viewer.getRfb().setSingleDisplaySize(singleWidth, singleHeight); 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()); } @@ -981,14 +979,9 @@ public void fitScreen() { ArrayList rectangles = viewer.getScreenRectangles(); if (rectangles.size()<=0) return; // no screens, nothing to do + int thisScreenNumber = getThisScreenNumber(rectangles); - // find which screen we are on - Point thisScreenLocation = frame.getLocation(); - int thisScreenNumber = 0; - for(Rectangle rect : rectangles) { - if ( rect.contains(thisScreenLocation) ) break; - thisScreenNumber++; - } + int thisScreenWidth = (int) rectangles.get(thisScreenNumber).getWidth(); int thisScreenHeight = (int) rectangles.get(thisScreenNumber).getHeight(); int thisRetinaScale = retinaScale(thisScreenNumber); @@ -996,8 +989,8 @@ final int thatScreenX = presenter.getX(); final int thatScreenY = presenter.getY(); int thatRetinaScale = presenter.getRetinaScale(); - final int thatScreenWidth = viewer.getRfb().getSingleWidth(); - final int thatScreenHeight = viewer.getRfb().getSingleHeight(); + final int thatScreenWidth = presenter.getSingleWidth(); + final int thatScreenHeight = presenter.getSingleHeight(); showScreenInfo("that", 0, thatScreenX, thatScreenY, thatScreenWidth, thatScreenHeight, thatRetinaScale); System.out.println("that FB x:" + viewer.getRfb().getContext().getFbWidth() + " y:" + viewer.getRfb().getContext().getFbHeight()); @@ -1018,6 +1011,31 @@ }); } + private int getThisScreenNumber(ArrayList rectangles) { + // find which screen we are on + Point thisScreenLocation = frame.getLocation(); + Point mouse = frame.getMousePosition(); + int thisScreenNumber = 0; + for(Rectangle rect : rectangles) { + if ( rect.contains(thisScreenLocation) ) break; + thisScreenNumber++; + } + if (thisScreenNumber