From fa85c12aa9f552aeafca4099467439d4cf434b79 Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Mon, 24 Sep 2001 07:30:50 +0000
Subject: cursor changes

---
 cursor.c    |  8 ++++++++
 example.c   |  8 ++++++++
 main.c      | 17 +++++++++++++----
 rfb.h       |  2 ++
 rfbserver.c | 31 ++++++++++++++++++-------------
 5 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/cursor.c b/cursor.c
index a47952a..d128254 100644
--- a/cursor.c
+++ b/cursor.c
@@ -495,6 +495,7 @@ void rfbUndrawCursor(rfbClientPtr cl)
    rfbCursorPtr c=s->cursor;
    int j,x1,x2,y1,y2,bpp=s->rfbServerFormat.bitsPerPixel/8,
      rowstride=s->paddedWidthInBytes;
+   return;
    if(!s->cursorIsDrawn)
      return;
    /* restore what is under the cursor */
@@ -512,6 +513,9 @@ void rfbUndrawCursor(rfbClientPtr cl)
      memcpy(s->frameBuffer+(y1+j)*rowstride+x1*bpp,
 	    s->underCursorBuffer+j*x2*bpp,
 	    x2*bpp);
+   
+   rfbMarkRectAsModified(s,x1,y1,x1+x2,y1+y2);
+   s->cursorIsDrawn = FALSE;
 }
 
 void rfbDrawCursor(rfbClientPtr cl)
@@ -521,6 +525,7 @@ void rfbDrawCursor(rfbClientPtr cl)
    int i,j,x1,x2,y1,y2,i1,j1,bpp=s->rfbServerFormat.bitsPerPixel/8,
      rowstride=s->paddedWidthInBytes,
      bufSize=c->width*c->height*bpp,w=(c->width+7)/8;
+   return;
    if(s->cursorIsDrawn)
      rfbUndrawCursor(cl);
    if(s->underCursorBufferLen<bufSize) {
@@ -555,6 +560,9 @@ void rfbDrawCursor(rfbClientPtr cl)
        if((c->mask[(j+j1)*w+(i+i1)/8]<<((i+i1)&7))&0x80)
 	 memcpy(s->frameBuffer+(j+y1)*rowstride+(i+x1)*bpp,
 		c->richSource+(j+j1)*c->width*bpp+(i+i1)*bpp,bpp);
+
+   rfbMarkRectAsModified(s,x1,y1,x1+x2,y1+y2);
+   s->cursorIsDrawn = TRUE;
 }
 
 void rfbPrintXCursor(rfbCursorPtr cursor)
diff --git a/example.c b/example.c
index 24d1c6a..1f53bd9 100644
--- a/example.c
+++ b/example.c
@@ -94,6 +94,10 @@ void drawline(unsigned char* buffer,int rowstride,int bpp,int x1,int y1,int x2,i
 void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
 {
    ClientData* cd=cl->clientData;
+   //if(cl->screen->cursorIsDrawn)
+     //rfbUndrawCursor(cl);
+   //cl->screen->cursorX=x;
+   //cl->screen->cursorY=y;
    if(x>=0 && y>=0 && x<maxx && y<maxy) {
       if(buttonMask) {
 	 int i,j,x1,x2,y1,y2;
@@ -189,11 +193,15 @@ void dokey(Bool down,KeySym key,rfbClientPtr cl)
     if(key==XK_Escape)
       rfbCloseClient(cl);
     else if(key==XK_Page_Up) {
+       //if(cl->screen->cursorIsDrawn)
+	 //rfbUndrawCursor(cl);
       initBuffer(cl->screen->frameBuffer);
       rfbMarkRectAsModified(cl->screen,0,0,maxx,maxy);
     } else if(key>=' ' && key<0x100) {
       ClientData* cd=cl->clientData;
       int x1=cd->oldx,y1=cd->oldy,x2,y2;
+      //if(cl->screen->cursorIsDrawn)
+	 //rfbUndrawCursor(cl);
       cd->oldx+=drawchar(cl->screen->frameBuffer,
 			 cl->screen->paddedWidthInBytes,bpp,cd->oldx,cd->oldy,
 			 key);
diff --git a/main.c b/main.c
index 5f07b86..c67bc61 100644
--- a/main.c
+++ b/main.c
@@ -90,8 +90,8 @@ void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,RegionPtr modRegion)
 
 void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2)
 {
-   BoxRec box;
-   RegionRec region;
+   BoxRec box; //=(BoxRec*)malloc(sizeof(BoxRec));
+   RegionRec* region=(RegionRec*)malloc(sizeof(RegionRec));
    int i;
    if(x1>x2) { i=x1; x1=x2; x2=i; }
    x2++;
@@ -104,8 +104,8 @@ void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y
    if(y2>=rfbScreen->height) { y2=rfbScreen->height-1; if(y1==y2) y1--; }
    
    box.x1=x1; box.y1=y1; box.x2=x2; box.y2=y2;
-   REGION_INIT(cl->screen,&region,&box,0);
-   rfbMarkRegionAsModified(rfbScreen,&region);
+   REGION_INIT(cl->screen,region,&box,0);
+   rfbMarkRegionAsModified(rfbScreen,region);
 }
 
 int rfbDeferUpdateTime = 40; /* ms */
@@ -298,6 +298,15 @@ defaultKbdAddEvent(Bool down, KeySym keySym, rfbClientPtr cl)
 void
 defaultPtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
 {
+   if(x!=cl->screen->cursorX || y!=cl->screen->cursorY) {
+      Bool cursorWasDrawn=cl->screen->cursorIsDrawn;
+      if(cursorWasDrawn)
+	rfbUndrawCursor(cl);
+      cl->screen->cursorX = x;
+      cl->screen->cursorY = y;
+      if(cursorWasDrawn)
+	rfbDrawCursor(cl);
+   }
 }
 
 void defaultSetXCutText(char* text, int len, rfbClientPtr cl)
diff --git a/rfb.h b/rfb.h
index 6de3431..77e7350 100644
--- a/rfb.h
+++ b/rfb.h
@@ -539,6 +539,8 @@ extern char* rfbMakeMaskForXCursor(int width,int height,char* cursorString);
 extern void MakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
 extern void MakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
 extern void rfbFreeCursor(rfbCursorPtr cursor);
+extern void rfbDrawCursor(rfbClientPtr cl);
+extern void rfbUndrawCursor(rfbClientPtr cl);
 
 /* stats.c */
 
diff --git a/rfbserver.c b/rfbserver.c
index 6f48cf1..e97c7d8 100644
--- a/rfbserver.c
+++ b/rfbserver.c
@@ -834,17 +834,20 @@ rfbSendFramebufferUpdate(cl, updateRegion)
      * removed from the framebuffer. Otherwise, make sure it's put up.
      */
 
-    if (cl->enableCursorShapeUpdates) {
-       cursorWasDrawn = cl->screen->cursorIsDrawn;
-       if (cl->screen->cursorIsDrawn) {
-	  fprintf(stderr,"rfbSpriteRemoveCursor(pScreen); not yet!\n");
-       }
-       if (!cl->screen->cursorIsDrawn && cl->cursorWasChanged)
-	 sendCursorShape = TRUE;
-    } else {
-       if (!cl->screen->cursorIsDrawn)
-	 fprintf(stderr,"rfbSpriteRestoreCursor(pScreen); not yet!\n");
-    }
+   cursorWasDrawn = cl->screen->cursorIsDrawn;
+
+   if (cl->enableCursorShapeUpdates) {
+      if (cl->screen->cursorIsDrawn) {
+	 rfbUndrawCursor(cl);
+	 //fprintf(stderr,"rfbSpriteRemoveCursor(pScreen); not yet!\n");
+      }
+      if (!cl->screen->cursorIsDrawn && cl->cursorWasChanged)
+	sendCursorShape = TRUE;
+   } else {
+      if (!cl->screen->cursorIsDrawn)
+	//rfbDrawCursor(cl);
+	fprintf(stderr,"rfbSpriteRestoreCursor(pScreen); not yet!\n");
+   }
    
     /*
      * The modifiedRegion may overlap the destination copyRegion.  We remove
@@ -1046,9 +1049,11 @@ rfbSendFramebufferUpdate(cl, updateRegion)
 
     if(cursorWasDrawn != cl->screen->cursorIsDrawn) {
        if(cursorWasDrawn)
-	  fprintf(stderr,"rfbSpriteRestoreCursor(pScreen); not yet!!\n");
+	  rfbDrawCursor(cl);
+	  //fprintf(stderr,"rfbSpriteRestoreCursor(pScreen); not yet!!\n");
        else
-	  fprintf(stderr,"rfbSpriteRemoveCursor(pScreen); not yet!!\n");
+	  rfbUndrawCursor(cl);
+	  //fprintf(stderr,"rfbSpriteRemoveCursor(pScreen); not yet!!\n");
     }
 
     return TRUE;
-- 
cgit v1.2.3

