# HG changeset patch # User oc # Date 1421537766 -32400 # Node ID ae7deb002b5fac6a20183e2b6522313a7b91626a # Parent 0b75fdbb8c118b2ef2d0798b037996d4059db31d send and receive single display size diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java --- a/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Sun Jan 18 08:36:06 2015 +0900 @@ -36,7 +36,7 @@ byte CLIENT_CUT_TEXT = 6; byte SERVER_CHANGE_REQUEST = (byte) 240; // TreeVNC extension byte CHECK_DELAY_REPLY = 70; - byte REQUEST_SINGLE_DISPLAY_WIDTH = 71; + byte REQUEST_SINGLE_DISPLAY_SIZE = 71; byte READY_SHARE_SOUND = 72; void send(Writer writer) throws TransportException; diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/com/glavsoft/rfb/encoding/EncodingType.java --- a/src/main/java/com/glavsoft/rfb/encoding/EncodingType.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/EncodingType.java Sun Jan 18 08:36:06 2015 +0900 @@ -72,7 +72,7 @@ /** * TreeVNC single display width size. */ - SEND_SINGLE_DISPLAY_WIDTH(18, "SEND_SINGLE_DISPLAY_WIDTH"), + SEND_SINGLE_DISPLAY_SIZE(18, "SEND_SINGLE_DISPLAY_SIZE"), /** * share sound. diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java --- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sun Jan 18 08:36:06 2015 +0900 @@ -297,8 +297,10 @@ int port = rfb.acceptPort; String address = rfb.getMyAddress(); sendCheckDelayReply(rect.time, port, address); - } else if (rect.getEncodingType() == EncodingType.SEND_SINGLE_DISPLAY_WIDTH) { + } else if (rect.getEncodingType() == EncodingType.SEND_SINGLE_DISPLAY_SIZE) { rfb.singleWidth = rect.width; + rfb.singleHeight = rect.height; + // 下に送る } else if (rect.getEncodingType() == EncodingType.SOUND) { // SOUNDを受信した時の処理を } else diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/RequestSingleDisplayWidth.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/RequestSingleDisplayWidth.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/RequestSingleDisplayWidth.java Sun Jan 18 08:36:06 2015 +0900 @@ -2,12 +2,10 @@ import com.glavsoft.exceptions.TransportException; import com.glavsoft.rfb.client.ClientToServerMessage; -import com.glavsoft.rfb.encoding.EncodingType; import com.glavsoft.transport.Writer; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.LinkedList; /** * Created by OcBookPro on 15/01/10. @@ -23,7 +21,7 @@ public void send(Writer writer) throws TransportException { ByteBuffer out = ByteBuffer.allocate(2); out.order(ByteOrder.BIG_ENDIAN); - out.put(REQUEST_SINGLE_DISPLAY_WIDTH); + out.put(REQUEST_SINGLE_DISPLAY_SIZE); out.put((byte)0); // padding writer.write(out.array(), 0, out.position()); writer.flush(); diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/SendSingleDisplaySize.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/SendSingleDisplaySize.java Sun Jan 18 08:36:06 2015 +0900 @@ -0,0 +1,35 @@ +package jp.ac.u_ryukyu.treevnc; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import com.glavsoft.rfb.encoding.EncodingType; + +/** + * Created by OcBookPro on 15/01/10. + */ +public class SendSingleDisplaySize { + + private ByteBuffer msg; + private TreeRFBProto rfb; + private int singleDisplayWidth; + + public SendSingleDisplaySize() { + } + + public ByteBuffer singleDisplaySize(int i, int j, int singleDisplayWidth, int height) throws UnsupportedEncodingException { + msg = ByteBuffer.allocate(24).order(ByteOrder.BIG_ENDIAN); + msg.put((byte) 0); // FrameBufferUpdate + msg.put((byte) 0); // padding + msg.putShort((short) 1); // number of rectangle + msg.putShort((short) i); + msg.putShort((short) j); + msg.putShort((short) singleDisplayWidth); + msg.putShort((short) height); + msg.putInt(EncodingType.SEND_SINGLE_DISPLAY_SIZE.getId()); + msg.flip(); + return msg; + } + +} diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/SendSingleDisplayWidth.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/SendSingleDisplayWidth.java Sat Jan 17 04:58:03 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package jp.ac.u_ryukyu.treevnc; - -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.LinkedList; -import com.glavsoft.rfb.encoding.EncodingType; - -/** - * Created by OcBookPro on 15/01/10. - */ -public class SendSingleDisplayWidth { - - private ByteBuffer msg; - private TreeRFBProto rfb; - private int singleDisplayWidth; - - public SendSingleDisplayWidth() { - } - - public ByteBuffer singleDisplayWidth(int i, int j, int singleDisplayWidth, int height) throws UnsupportedEncodingException { - msg = ByteBuffer.allocate(24).order(ByteOrder.BIG_ENDIAN); - msg.put((byte) 0); // FrameBufferUpdate - msg.put((byte) 0); // padding - msg.putShort((short) 1); // number of rectangle - msg.putShort((short) i); - msg.putShort((short) j); - msg.putShort((short) singleDisplayWidth); - msg.putShort((short) height); - msg.putInt(EncodingType.SEND_SINGLE_DISPLAY_WIDTH.getId()); - msg.flip(); - return msg; - } - -} diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sun Jan 18 08:36:06 2015 +0900 @@ -24,8 +24,6 @@ import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.ConnectionParams; -import javax.xml.crypto.Data; - public class TreeRFBProto { @@ -75,6 +73,8 @@ public int fixingSizeHeight; public int singleWidth = 0; + public int singleHeight = 0; + private DatagramSocket socket = null; public TreeRFBProto(boolean isTreeManager) { @@ -177,8 +177,8 @@ String newHostName = new String(byteAddress, "UTF-8"); int frameSizeWidth = buf.getInt(); int frameSizeHeight = buf.getInt(); - singleWidth = frameSizeWidth; - sendSingleDisplayWidth(singleWidth); + // send single display widht other node. + sendSingleDisplaySize(frameSizeWidth, frameSizeWidth); System.out.println("Root server change request :" + newHostName); // please remove these numbers. if (viewer != null) { @@ -187,11 +187,11 @@ } else { continue; } - } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_WIDTH) { + } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_SIZE) { ByteBuffer buf = ByteBuffer.wrap(b); buf.order(ByteOrder.BIG_ENDIAN); buf.get(); - sendSingleDisplayWidth(singleWidth); + sendSingleDisplaySize(singleWidth, singleHeight); } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { System.out.println("rootは受信準備を始める。"); int rtpPort = selectPort(ConnectionParams.DEFAULT_RTP_PORT); @@ -224,7 +224,7 @@ } }; context.sendMessage(serverChangeRequest); - } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_WIDTH) { + } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_SIZE) { ClientToServerMessage requestSingeDisplayWidth = new ClientToServerMessage() { @Override public void send(Writer writer) @@ -316,10 +316,10 @@ new Thread(sender, "writer-to-lower-node").start(); } - public void sendSingleDisplayWidth(int singleDisplayWidth) throws UnsupportedEncodingException { + public void sendSingleDisplaySize(int singleDisplayWidth, int singleDisplayHeight) throws UnsupportedEncodingException { LinkedList linkedListSendSingleDisplayWidth = new LinkedList(); - SendSingleDisplayWidth sendSingleDisplayWidth = new SendSingleDisplayWidth(); - linkedListSendSingleDisplayWidth.add(sendSingleDisplayWidth.singleDisplayWidth(0, 0, singleDisplayWidth, 0)); + SendSingleDisplaySize sendSingleDisplaySize = new SendSingleDisplaySize(); + linkedListSendSingleDisplayWidth.add(sendSingleDisplaySize.singleDisplaySize(0, 0, singleDisplayWidth, singleDisplayHeight)); addSerialNumber(linkedListSendSingleDisplayWidth); multicastqueue.put(linkedListSendSingleDisplayWidth); System.out.println(singleDisplayWidth + " : send single display width"); @@ -742,7 +742,12 @@ this.frameSizeWidth = width; this.frameSizeHeight = height; + singleWidth = frameSizeWidth; + singleHeight = frameSizeHeight; + + // send single display width to other node. + sendSingleDisplaySize(singleWidth, singleHeight); // stop reader stop stopReceiverTask(); @@ -867,5 +872,4 @@ } return socket; } - } \ No newline at end of file diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Sun Jan 18 08:36:06 2015 +0900 @@ -57,6 +57,7 @@ port = port * 256 + reply[11]; TreeVncProtocol t = new TreeVncProtocol(hostname, port); + t.setSingleSize(vps.getRfb().singleWidth, vps.getRfb().singleHeight); try { t.findRootReply(vps.getRfb().getAcceptPort()); } catch (IOException e) { diff -r 0b75fdbb8c11 -r ae7deb002b5f src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Sun Jan 18 08:36:06 2015 +0900 @@ -12,12 +12,19 @@ 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 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sun Jan 18 08:36:06 2015 +0900 @@ -295,4 +295,9 @@ @Override public void setFixingSize(int width, int height) { } + + @Override + public java.util.ArrayList getScreenRectangles() { + return null; + } } diff -r 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Sun Jan 18 08:36:06 2015 +0900 @@ -1,5 +1,6 @@ package com.glavsoft.viewer; +import com.glavsoft.viewer.swing.SwingViewerWindow; import jp.ac.u_ryukyu.treevnc.VncProxyService; import java.io.FileNotFoundException; @@ -53,6 +54,7 @@ if (viewer) { ViewerInterface v = cui ? new CuiViewer() : new Viewer(); setWidthAndHeight(v); +// if(filterSingleDisplay) if(fixingSizeDisplay) setFixingSizeDisplay(v); if (treeProxy) { @@ -69,7 +71,7 @@ public void rootStart(String[] args, ViewerInterface v) throws SocketException, UnknownHostException { v.setNoConnection(noConnection); // should we accept host name here? - v.proxyStart(args,width,height, showTree, checkDelay, addSerialNum, fixingSizeDisplay, filterSingleDisplay); + v.proxyStart(args, width, height, showTree, checkDelay, addSerialNum, fixingSizeDisplay, filterSingleDisplay); v.getRfb().setHasViewer(viewer); if (!permitChangeScreen ) v.getRfb().setPermitChangeScreen(false); v.getRfb().getAcceptThread().waitForShutdown(); diff -r 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/Viewer.java --- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sun Jan 18 08:36:06 2015 +0900 @@ -42,6 +42,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.Socket; +import java.util.ArrayList; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.logging.*; @@ -397,6 +398,12 @@ isApplet = true; settings.setViewOnly(true); // too avoid unnecessary upward traffic rfb.setReconnecting(true); + + ArrayList rectangles = getScreenRectangles(); + int leftScreenNumber = 0; + getRfb().singleWidth = (int) rectangles.get(leftScreenNumber).getWidth(); + getRfb().singleHeight = (int) rectangles.get(leftScreenNumber).getHeight(); + run(); } @@ -441,4 +448,27 @@ this.fixingSizeWidth = width; this.fixingSizeHeight = height; } + + @Override + public ArrayList getScreenRectangles() { + // before change server, data from previous server + // should be stopped. + setCuiVersion(false); + // Host have screens. + // Each screen number in order from left. + // put screens in rectangles. + ArrayList rectangles = new ArrayList(); + GraphicsConfiguration[] gc = null; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + for (int j = 0; j < gs.length; j++) { + GraphicsDevice gd = gs[j]; + gc = gd.getConfigurations(); + for (int i=0; i < gc.length; i++) { + rectangles.add(gc[i].getBounds()); + } + } + return rectangles; + } + } diff -r 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java --- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sun Jan 18 08:36:06 2015 +0900 @@ -1,7 +1,9 @@ package com.glavsoft.viewer; +import java.awt.*; import java.io.IOException; import java.net.Socket; +import java.util.ArrayList; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; @@ -45,4 +47,5 @@ public void setFixingSize(int width, int height); + public ArrayList getScreenRectangles(); } diff -r 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java --- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sun Jan 18 08:36:06 2015 +0900 @@ -104,6 +104,7 @@ this.presenter = presenter; this.width = w; this.height = h; + if(viewer instanceof Viewer) createContainer(surface, isApplet, (Viewer)viewer); @@ -277,6 +278,7 @@ if ( ! isWidthChangeable) { dim.width = frame.getWidth(); } else { + // このあたり、scalepercentを計算するのに使えそう if (isVScrollBar) dim.width += scroller.getVerticalScrollBar().getWidth(); if (dim.width < minDimension.width) dim.width = minDimension.width; @@ -319,6 +321,7 @@ } } } + // set full size dim.width = workareaRectangle.width; dim.height = workareaRectangle.height; if ( ! location.equals(frame.getLocation())) { @@ -848,11 +851,18 @@ @Override public void actionPerformed(ActionEvent e) { - ArrayList rectangles = getScreenRectangles(); + ArrayList rectangles = viewer.getScreenRectangles(); int leftScreenNumber = 0; int rightScreenNumber = 1; - viewer.getRfb().singleWidth = (int) rectangles.get(leftScreenNumber).getWidth(); + int singleWidth = (int) rectangles.get(leftScreenNumber).getWidth(); + int singleHeight = (int) rectangles.get(leftScreenNumber).getHeight(); + viewer.getRfb().singleWidth = singleWidth; + viewer.getRfb().singleHeight = singleHeight; + singleWidth = 600; + singleHeight = 600; + + /* // show share sound dialog. boolean setShareSound = presenter.showShareSoundDialog(); if (setShareSound) { @@ -864,13 +874,14 @@ e1.printStackTrace(); } } + */ if (viewer.getRfb().isTreeManager()) { - changeVncServer(viewer, (int) rectangles.get(leftScreenNumber).getWidth(), (int) rectangles.get(leftScreenNumber).getHeight(), viewer.getRfb().getId()); + changeVncServer(viewer, singleWidth, singleHeight, viewer.getRfb().getId()); return; } String adr = viewer.getRfb().getMyAddress(); - context.sendMessage(new ScreenChangeRequest(adr, viewer.getRfb().getId(), (int) rectangles.get(leftScreenNumber).getWidth(), (int) rectangles.get(leftScreenNumber).getHeight())); + context.sendMessage(new ScreenChangeRequest(adr, viewer.getRfb().getId(), singleWidth, singleHeight)); } }); kbdButtons.add(screenButton); @@ -1005,27 +1016,6 @@ frame.setVisible(b); } - private ArrayList getScreenRectangles() { - // before change server, data from previous server - // should be stopped. - viewer.setCuiVersion(false); - // Host have screens. - // Each screen number in order from left. - // put screens in rectangles. - ArrayList rectangles = new ArrayList(); - GraphicsConfiguration[] gc = null; - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice[] gs = ge.getScreenDevices(); - for (int j = 0; j < gs.length; j++) { - GraphicsDevice gd = gs[j]; - gc = gd.getConfigurations(); - for (int i=0; i < gc.length; i++) { - rectangles.add(gc[i].getBounds()); - } - } - return rectangles; - } - private void changeVncServer(ViewerInterface viewer, int width, int height, short id) { String localhost = "127.0.0.1"; try { diff -r 0b75fdbb8c11 -r ae7deb002b5f src/viewer_swing/java/com/glavsoft/viewer/swing/gui/ConnectionsHistory.java --- a/src/viewer_swing/java/com/glavsoft/viewer/swing/gui/ConnectionsHistory.java Sat Jan 17 04:58:03 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/gui/ConnectionsHistory.java Sun Jan 18 08:36:06 2015 +0900 @@ -261,6 +261,7 @@ if (uiSettingsData != null) { uiSettingsDataMap.put(new ConnectionParams(connectionParams), new UiSettingsData(uiSettingsData)); } + uiSettingsData.setScalePercent(50); } /**