39 static const int bpp=4;
40 static int maxx=800, maxy=600;
45 static int maintain_connection = 1;
49 static void initBuffer(
unsigned char* buffer)
54 buffer[(j*maxx+i)*bpp+0]=(i+j)*128/(maxx+maxy);
55 buffer[(j*maxx+i)*bpp+1]=i*128/maxx;
56 buffer[(j*maxx+i)*bpp+2]=j*256/maxy;
58 buffer[j*maxx*bpp+0]=0xff;
59 buffer[j*maxx*bpp+1]=0xff;
60 buffer[j*maxx*bpp+2]=0xff;
61 buffer[j*maxx*bpp+3]=0xff;
72 static void clientgone(rfbClientPtr cl)
75 cl->clientData = NULL;
80 cl->clientData = (
void*)calloc(
sizeof(
ClientData),1);
81 cl->clientGoneHook = clientgone;
87 static void newframebuffer(rfbScreenInfoPtr screen,
int width,
int height)
89 unsigned char *oldfb, *newfb;
93 oldfb = (
unsigned char*)screen->frameBuffer;
94 newfb = (
unsigned char*)malloc(maxx * maxy * bpp);
104 static void drawline(
unsigned char* buffer,
int rowstride,
int bpp,
int x1,
int y1,
int x2,
int y2)
110 buffer[y1*rowstride+x1*bpp+i]=0xff;
116 if(y1>y2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
119 buffer[j*rowstride+(x1+(j-y1)*(x2-x1)/(y2-y1))*bpp+i]=0xff;
121 if(x1>x2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
124 buffer[(y1+(i-x1)*(y2-y1)/(x2-x1))*rowstride+i*bpp+j]=0xff;
130 static void doptr(
int buttonMask,
int x,
int y,rfbClientPtr cl)
134 if(
x>=0 &&
y>=0 &&
x<maxx &&
y<maxy) {
139 drawline((
unsigned char*)cl->screen->frameBuffer,cl->screen->paddedWidthInBytes,bpp,
142 if(x1>cd->
oldx) x1++;
else cd->
oldx++;
143 if(y1>cd->
oldy) y1++;
else cd->
oldy++;
146 int w=cl->screen->paddedWidthInBytes;
147 x1=
x-buttonMask;
if(x1<0) x1=0;
148 x2=
x+buttonMask;
if(x2>maxx) x2=maxx;
149 y1=
y-buttonMask;
if(y1<0) y1=0;
150 y2=
y+buttonMask;
if(y2>maxy) y2=maxy;
152 for(i=x1*bpp;i<x2*bpp;i++)
154 cl->screen->frameBuffer[j*w+i]=(
char)0xff;
186 initBuffer((
unsigned char*)cl->screen->frameBuffer);
188 }
else if (key ==
XK_Up) {
191 newframebuffer(cl->screen, 800, 600);
193 newframebuffer(cl->screen, 1024, 768);
199 newframebuffer(cl->screen, 800, 600);
201 newframebuffer(cl->screen, 640, 480);
204 }
else if(key>=
' ' && key<0x100) {
207 cd->
oldx+=
rfbDrawCharWithClip(cl->screen,&radonFont,cd->
oldx,cd->
oldy,(
char)key,0,0,cl->screen->width,cl->screen->height,0x00ffffff,0x00ffffff);
216 #ifdef JUST_AN_EXAMPLE
218 static int exampleXCursorWidth=9,exampleXCursorHeight=7;
219 static char exampleXCursor[]=
232 static void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
239 " xxxxxxxxxxxxxxxxx "
240 " xxxxxxxxxxxxxxxxxxxxxx "
241 " xxxxx xxxxxxxx xxxxxxxx "
242 " xxxxxxxxxxxxxxxxxxxxxxxxxxx "
243 " xxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
244 " xxxxx xxxxxxxxxxx xxxxxxx "
245 " xxxx xxxxxxxxx xxxxxx "
246 " xxxxx xxxxxxxxxxx xxxxxxx "
247 " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
248 " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
249 " xxxxxxxxxxxx xxxxxxxxxxxxxxx "
250 " xxxxxxxxxxxxxxxxxxxxxxxxxxxx "
251 " xxxxxxxxxxxxxxxxxxxxxxxxxxxx "
252 " xxxxxxxxxxx xxxxxxxxxxxxxx "
253 " xxxxxxxxxx xxxxxxxxxxxx "
254 " xxxxxxxxx xxxxxxxxx "
255 " xxxxxxxxxx xxxxxxxxx "
256 " xxxxxxxxxxxxxxxxxxx "
257 " xxxxxxxxxxxxxxxxxxx "
258 " xxxxxxxxxxxxxxxxxxx "
259 " xxxxxxxxxxxxxxxxx "
261 " xxxx xxxxxxxxxxxxx "
265 " xxxxxx xxxxxxxxxxxx "
266 " xxxxxxxxxxxxxxxxxxxxxx "
270 c->xhot = 16; c->yhot = 24;
272 c->richSource = (
unsigned char*)malloc(w*h*bpp);
275 c->cleanupRichSource =
TRUE;
278 c->richSource[j*w*bpp+i*bpp+0]=i*0xff/w;
279 c->richSource[j*w*bpp+i*bpp+1]=(i+j)*0xff/(w+h);
280 c->richSource[j*w*bpp+i*bpp+2]=j*0xff/h;
281 c->richSource[j*w*bpp+i*bpp+3]=0;
287 maintain_connection = 0;
294 rfbScreenInfoPtr rfbScreen =
rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
297 rfbScreen->desktopName =
"LibVNCServer Example";
298 rfbScreen->frameBuffer = (
char*)malloc(maxx*maxy*bpp);
299 rfbScreen->alwaysShared =
TRUE;
300 rfbScreen->ptrAddEvent = doptr;
301 rfbScreen->kbdAddEvent = dokey;
302 rfbScreen->newClientHook = newclient;
303 rfbScreen->httpDir =
"../webclients";
304 rfbScreen->httpEnableProxyConnect =
TRUE;
306 initBuffer((
unsigned char*)rfbScreen->frameBuffer);
307 rfbDrawString(rfbScreen,&radonFont,20,100,
"Hello, World!",0xffffff);
314 MakeRichCursor(rfbScreen);
319 #ifndef BACKGROUND_LOOP_TEST
324 fprintf(stderr,
"%d\r",i);
334 #if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) && !defined(LIBVNCSERVER_HAVE_WIN32THREADS)
335 #error "I need pthreads or win32 threads for that."
341 fprintf(stderr,
"Running background loop...\n");
343 while (maintain_connection) {
346 fprintf(stderr,
"\nShutting down...\n");
350 free(rfbScreen->frameBuffer);
void intHandler(int dummy)
int main(int argc, char **argv)
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground)
int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen, rfbFontDataPtr font, int x, int y, unsigned char c, int x1, int y1, int x2, int y2, rfbPixel colour, rfbPixel backColour)
if colour==backColour, background is transparent
void rfbCloseClient(rfbClientPtr cl)
void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen, int x1, int y1, int x2, int y2)
void rfbShutdownServer(rfbScreenInfoPtr rfbScreen, rfbBool disconnectClients)
void rfbDefaultPtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
cursor handling for the pointer
void rfbScreenCleanup(rfbScreenInfoPtr screenInfo)
rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo)
rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo, long usec)
void rfbDrawString(rfbScreenInfoPtr rfbScreen, rfbFontDataPtr font, int x, int y, const char *string, rfbPixel colour)
void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen, char *framebuffer, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbCursorPtr rfbMakeXCursor(int width, int height, char *cursorString, char *maskString)
void rfbFontBBox(rfbFontDataPtr font, unsigned char c, int *x1, int *y1, int *x2, int *y2)