Fix for initial client side cursor

Improve the tracking of what cursor we've sent to the client to make
sure the initial cursor is sent properly. We previously tried to infer
this information based on if we've rendered a server side cursor or
not. This logic broke down if things triggered before we've sent the
first update to the client.
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index 0e97a78..6a3e1c7 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -80,6 +80,7 @@
     server(server_), updates(false),
     updateRenderedCursor(false), removeRenderedCursor(false),
     continuousUpdates(false), encodeManager(this), pointerEventTime(0),
+    clientHasCursor(false),
     accessRights(AccessDefault), startTime(time(0))
 {
   setStreams(&sock->inStream(), &sock->outStream());
@@ -379,9 +380,9 @@
 {
   if (state() != RFBSTATE_NORMAL) return;
   // Are we switching between client-side and server-side cursor?
-  bool hasRenderedCursor = !damagedCursorRegion.is_empty();
-  if (hasRenderedCursor != needRenderedCursor())
+  if (clientHasCursor == needRenderedCursor())
     setCursorOrClose();
+  bool hasRenderedCursor = !damagedCursorRegion.is_empty();
   if (hasRenderedCursor)
     removeRenderedCursor = true;
   if (needRenderedCursor()) {
@@ -1256,10 +1257,13 @@
     return;
 
   // We need to blank out the client's cursor or there will be two
-  if (needRenderedCursor())
+  if (needRenderedCursor()) {
     cp.setCursor(emptyCursor);
-  else
+    clientHasCursor = false;
+  } else {
     cp.setCursor(*server->cursor);
+    clientHasCursor = true;
+  }
 
   if (!writer()->writeSetCursorWithAlpha()) {
     if (!writer()->writeSetCursor()) {
diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h
index 42eb85a..8d6a7bc 100644
--- a/common/rfb/VNCSConnectionST.h
+++ b/common/rfb/VNCSConnectionST.h
@@ -215,6 +215,7 @@
     time_t lastEventTime;
     time_t pointerEventTime;
     Point pointerEventPos;
+    bool clientHasCursor;
 
     AccessRights accessRights;