Merged r4342 - r4359 from 1_1 branch.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4383 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/CConn.cxx b/win/vncviewer/CConn.cxx
index 3585966..b067134 100644
--- a/win/vncviewer/CConn.cxx
+++ b/win/vncviewer/CConn.cxx
@@ -80,7 +80,7 @@
   : window(0), sameMachine(false), encodingChange(false), formatChange(false), 
     lastUsedEncoding_(encodingRaw), sock(0), sockEvent(CreateEvent(0, TRUE, FALSE, 0)), 
     reverseConnection(false), requestUpdate(false), firstUpdate(true),
-    isClosed_(false) {
+    pendingUpdate(false), isClosed_(false) {
 }
 
 CConn::~CConn() {
@@ -184,11 +184,6 @@
   calculateFullColourPF();
 }
 
-void
-CConn::paintCompleted() {
-  // A repaint message has just completed - request next update if necessary
-  requestNewUpdate();
-}
 
 bool
 CConn::sysCommand(WPARAM wParam, LPARAM lParam) {
@@ -362,10 +357,7 @@
 
     // Wait for socket data, or a message to process
     DWORD result = MsgWaitForMultipleObjects(1, &sockEvent.h, FALSE, INFINITE, QS_ALLINPUT);
-    if (result == WAIT_OBJECT_0) {
-      // - Network event notification.  Return control to I/O routine.
-      break;
-    } else if (result == WAIT_FAILED) {
+    if (result == WAIT_FAILED) {
       // - The wait operation failed - raise an exception
       throw rdr::SystemException("blockCallback wait error", GetLastError());
     }
@@ -380,6 +372,10 @@
       // ToAscii() internally).
       DispatchMessage(&msg);
     }
+
+    if (result == WAIT_OBJECT_0)
+      // - Network event notification.  Return control to I/O routine.
+      break;
   }
 
   // Before we return control to the InStream, reset the network event
@@ -522,6 +518,16 @@
 
 
 void
+CConn::framebufferUpdateStart() {
+  if (!formatChange) {
+    requestUpdate = pendingUpdate = true;
+    requestNewUpdate();
+  } else
+    pendingUpdate = false;
+}
+
+
+void
 CConn::framebufferUpdateEnd() {
   if (debugDelay != 0) {
     vlog.debug("debug delay %d",(int)debugDelay);
@@ -571,12 +577,17 @@
     firstUpdate = false;
   }
 
-  if (options.autoSelect)
-    autoSelectFormatAndEncoding();
-
   // Always request the next update
   requestUpdate = true;
 
+  // A format change prevented us from sending this before the update,
+  // so make sure to send it now.
+  if (formatChange && !pendingUpdate)
+    requestNewUpdate();
+
+  if (options.autoSelect)
+    autoSelectFormatAndEncoding();
+
   // Check that at least part of the window has changed
   if (!GetUpdateRect(window->getHandle(), 0, FALSE)) {
     if (!(GetWindowLong(window->getHandle(), GWL_STYLE) & WS_MINIMIZE))
@@ -662,6 +673,10 @@
   if (!requestUpdate) return;
 
   if (formatChange) {
+
+    /* Catch incorrect requestNewUpdate calls */
+    assert(pendingUpdate == false);
+
     // Select the required pixel format
     if (options.fullColour) {
       window->setPF(fullColourPF);