# HG changeset patch
# User oc
# Date 1422505742 -32400
# Node ID 3c63bc88383e0e8a197a32d76fe62e9642683ef4
# Parent  53c1f1663ab79d9a2fb7660c08e6eac6aca99b74
always fit screen, -d mode.

diff -r 53c1f1663ab7 -r 3c63bc88383e src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Thu Jan 29 13:29:02 2015 +0900
@@ -183,6 +183,7 @@
                                     // please remove these numbers.
                                     if (viewer != null) {
                                         changeVNCServer(viewer, newHostName, frameSizeWidth, frameSizeHeight, id);
+                                        viewer.setFitScreen();
                                     }
                                 } else {
                                     continue;
@@ -774,7 +775,7 @@
         stopReceiverTask();
         reconnectingId = id;
         vncProxyService.inhelitClients(vncProxyService, hostName);
-        // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary 
+        // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary
         reconnecting = true;
         if (reconnectingId!=0) {
             waitForVNCConnection();
diff -r 53c1f1663ab7 -r 3c63bc88383e src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java	Thu Jan 29 13:29:02 2015 +0900
@@ -300,4 +300,10 @@
     public java.util.ArrayList<Rectangle> getScreenRectangles() {
         return null;
     }
+
+    @Override
+    public void setFitScreen() {
+        // TODO Auto-generated method stub
+        
+    }
 }
diff -r 53c1f1663ab7 -r 3c63bc88383e src/viewer_swing/java/com/glavsoft/viewer/UiSettings.java
--- a/src/viewer_swing/java/com/glavsoft/viewer/UiSettings.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/UiSettings.java	Thu Jan 29 13:29:02 2015 +0900
@@ -197,7 +197,7 @@
                 '}';
     }
 
-    public double fitScreen(int thisScreenWidth, int thisScreenHeight, int singleWidth, int singleHeight) {
+    public void fitScreen(int thisScreenWidth, int thisScreenHeight, int singleWidth, int singleHeight) {
         double doubleThisWidth = (double) thisScreenWidth;
         double doubleThisHeight = (double) thisScreenHeight;
         double widthScale = (doubleThisWidth/singleWidth);
@@ -217,6 +217,5 @@
         }
         setScalePercent(scaleFactor);
         fireListeners();
-        return scaleFactor;
     }
 }
diff -r 53c1f1663ab7 -r 3c63bc88383e src/viewer_swing/java/com/glavsoft/viewer/Viewer.java
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Thu Jan 29 13:29:02 2015 +0900
@@ -469,4 +469,12 @@
         return rectangles;
     }
 
+    @Override
+    public void setFitScreen() {
+        SwingViewerWindow v = connectionPresenter.getViewer();
+        if (v != null) {
+            v.fitScreen();
+        }
+    }
+
 }
diff -r 53c1f1663ab7 -r 3c63bc88383e src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java	Thu Jan 29 13:29:02 2015 +0900
@@ -46,6 +46,8 @@
     public void setHeight(int height);
 
     public void setFixingSize(int width, int height);
+    
+    public void setFitScreen();
 
     public ArrayList<Rectangle> getScreenRectangles();
 }
diff -r 53c1f1663ab7 -r 3c63bc88383e src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java	Thu Jan 29 11:59:34 2015 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java	Thu Jan 29 13:29:02 2015 +0900
@@ -898,8 +898,8 @@
                 if (!viewer.getRfb().isTreeManager()) {
                     context.sendMessage(new RequestSingleDisplayWidth());
                 }
-                double scalePercent = uiSettings.fitScreen(thisScreenWidth, thisScreenHeight, singleWidth, singleHeight);
                 frame.setSize(thisScreenWidth, thisScreenHeight);
+                uiSettings.fitScreen(thisScreenWidth, thisScreenHeight, singleWidth, singleHeight);
             }
         });
         kbdButtons.add(fitScreenButton);
@@ -930,6 +930,18 @@
 
         setButtonsBarVisible(true, container);
     }
+    
+    public void fitScreen() {
+        ArrayList<Rectangle> rectangles = viewer.getScreenRectangles();
+        int leftScreenNumber = 0;
+        int thisScreenWidth = (int) rectangles.get(leftScreenNumber).getWidth();
+        int thisScreenHeight = (int) rectangles.get(leftScreenNumber).getHeight();
+
+        int singleWidth = viewer.getRfb().getSingleWidth();
+        int singleHeight = viewer.getRfb().getSingleHeight();
+        frame.setSize(thisScreenWidth, thisScreenHeight);
+        uiSettings.fitScreen(thisScreenWidth, thisScreenHeight, singleWidth, singleHeight);
+    }
 
     private void shareSound(boolean isTreeManager, ProtocolContext context) throws SocketException, UnknownHostException {
         viewer.getRfb().createSendSoundThread(viewer.getRfb());