Support for VideoRectangleSelection client message in the server code. The message is read but ignored (only a message will be written to stderr).


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2559 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx
index bede90e..2fde9fb 100644
--- a/common/rfb/SConnection.cxx
+++ b/common/rfb/SConnection.cxx
@@ -46,7 +46,8 @@
   : readyForSetColourMapEntries(false),
     is(0), os(0), reader_(0), writer_(0),
     security(0), securityFactory(secFact), state_(RFBSTATE_UNINITIALISED),
-    reverseConnection(reverseConnection_)
+    reverseConnection(reverseConnection_),
+    m_videoSelectionEnabled(false)
 {
   defaultMajorVersion = 3;
   defaultMinorVersion = 8;
@@ -76,6 +77,11 @@
   os = os_;
 }
 
+void SConnection::setProtocolOptions(bool enableVideoSelection)
+{
+  m_videoSelectionEnabled = enableVideoSelection;
+}
+
 void SConnection::initialiseProtocol()
 {
   cp.writeVersion(os);
@@ -464,10 +470,16 @@
   ccaps.addTightExt(msgTypeFileDeleteRequest,       "FTC_RMRQ");
   */
 
-  // Continuous updates:
   ccaps.addTightExt(msgTypeEnableContinuousUpdates, "CUC_ENCU");
 
+  if (m_videoSelectionEnabled) {
+    ccaps.addTightExt(msgTypeVideoRectangleSelection, "VRECTSEL");
+  }
+
+  //
   // Advertise all supported encoding types (except raw encoding).
+  //
+
   CapsList ecaps;
 
   // First, add true encodings.
diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h
index e41ef5f..2540ed7 100644
--- a/common/rfb/SConnection.h
+++ b/common/rfb/SConnection.h
@@ -50,6 +50,11 @@
     // (i.e. SConnection will not delete them).
     void setStreams(rdr::InStream* is, rdr::OutStream* os);
 
+    // setProtocolOptions() configures TightVNC-specific protocol options.
+    // It can be optionally called before calling initialiseProtocol().
+    // See also: VNCServerST::enableVideoSelection();
+    void setProtocolOptions(bool enableVideoSelection);
+
     // initialiseProtocol() should be called once the streams and security
     // types are set.  Subsequently, processMsg() should be called whenever
     // there is data to read on the InStream.
@@ -198,6 +203,9 @@
     SSecurityFactory* securityFactory;
     stateEnum state_;
     bool reverseConnection;
+
+    // TightVNC-specific protocol options.
+    bool m_videoSelectionEnabled;
   };
 }
 #endif
diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx
index 0e57ea7..4213e72 100644
--- a/common/rfb/SMsgReader.cxx
+++ b/common/rfb/SMsgReader.cxx
@@ -110,3 +110,18 @@
   }
 }
 
+void SMsgReader::readVideoRectangleSelection()
+{
+  (void)is->readU8();
+  int x = is->readU16();
+  int y = is->readU16();
+  int w = is->readU16();
+  int h = is->readU16();
+  bool enable = w > 0 && h > 0;
+
+  // FIXME: Use proper logger.
+  fprintf(stderr, "Ignoring VideoRectangleSelection message\n");
+
+  // FIXME: Implement VideoRectangleSelection message handling.
+}
+
diff --git a/common/rfb/SMsgReader.h b/common/rfb/SMsgReader.h
index 958c03a..997c07b 100644
--- a/common/rfb/SMsgReader.h
+++ b/common/rfb/SMsgReader.h
@@ -49,6 +49,7 @@
 
     // Read TightVNC-specific protocol messages.
     virtual void readEnableContinuousUpdates();
+    virtual void readVideoRectangleSelection();
 
     SMsgReader(SMsgHandler* handler, rdr::InStream* is);
 
diff --git a/common/rfb/SMsgReaderV3.cxx b/common/rfb/SMsgReaderV3.cxx
index e9b020b..468d74a 100644
--- a/common/rfb/SMsgReaderV3.cxx
+++ b/common/rfb/SMsgReaderV3.cxx
@@ -62,6 +62,7 @@
   case msgTypeFileDeleteRequest:        handler->processFTMsg(msgType); break;
 
   case msgTypeEnableContinuousUpdates:  readEnableContinuousUpdates(); break;
+  case msgTypeVideoRectangleSelection:  readVideoRectangleSelection(); break;
 
   default:
     fprintf(stderr, "unknown message type %d\n", msgType);
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index 3929b1f..7c922cf 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -87,6 +87,7 @@
 bool VNCSConnectionST::init()
 {
   try {
+    setProtocolOptions(server->isVideoSelectionEnabled());
     initialiseProtocol();
   } catch (rdr::Exception& e) {
     close(e.str());
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx
index e5354a4..93f947c 100644
--- a/common/rfb/VNCServerST.cxx
+++ b/common/rfb/VNCServerST.cxx
@@ -77,7 +77,8 @@
     securityFactory(sf ? sf : &defaultSecurityFactory),
     queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance),
     useEconomicTranslate(false),
-    lastConnectionTime(0), disableclients(false)
+    lastConnectionTime(0), disableclients(false),
+    m_videoSelectionEnabled(false)
 {
   lastUserInputTime = lastDisconnectTime = time(0);
   slog.debug("creating single-threaded server %s", name.buf);
diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h
index fad8cb9..81ad4ec 100644
--- a/common/rfb/VNCServerST.h
+++ b/common/rfb/VNCServerST.h
@@ -192,6 +192,16 @@
 
     void setFTManager(rfb::SFileTransferManager *pFTManager) { m_pFTManager = pFTManager; };
 
+    // Enable/disable support for TightVNC-specific VideoRectangleSelection
+    // client message. This is a protocol option that lets a client select a
+    // rectangle to be treated by the server as video data. Once selected, this
+    // part of the framebuffer will be sent using JpegEncoder, on each update
+    // request, as we expect that video data is changing continuously. By
+    // default, this option is disabled, as it's rather a specialized feature
+    // and video selection GUI can confuse users of the TightVNC client.
+    void enableVideoSelection(bool enable) { m_videoSelectionEnabled = enable; }
+    bool isVideoSelectionEnabled() { return m_videoSelectionEnabled; }
+
   protected:
 
     friend class VNCSConnectionST;
@@ -239,6 +249,8 @@
     time_t lastConnectionTime;
 
     bool disableclients;
+
+    bool m_videoSelectionEnabled;
   };
 
 };
diff --git a/common/rfb/msgTypes.h b/common/rfb/msgTypes.h
index ec26adc..32b1395 100644
--- a/common/rfb/msgTypes.h
+++ b/common/rfb/msgTypes.h
@@ -57,5 +57,6 @@
   const int msgTypeFileDeleteRequest = 139;
 
   const int msgTypeEnableContinuousUpdates = 150;
+  const int msgTypeVideoRectangleSelection = 151;
 }
 #endif
diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx
index 4eb6b22..ab93984 100644
--- a/unix/x0vncserver/x0vncserver.cxx
+++ b/unix/x0vncserver/x0vncserver.cxx
@@ -455,9 +455,11 @@
     Geometry geo(DisplayWidth(dpy, DefaultScreen(dpy)),
                  DisplayHeight(dpy, DefaultScreen(dpy)));
     XDesktop desktop(dpy, &geo);
+
     VNCServerST server("x0vncserver", &desktop);
     QueryConnHandler qcHandler(dpy, &server);
     server.setQueryConnectionHandler(&qcHandler);
+    server.enableVideoSelection(true);
 
     TcpListener listener((int)rfbport);
     vlog.info("Listening on port %d", (int)rfbport);