void RemoteControl::startServer() { if ( (display=XOpenDisplay(NULL)) == NULL ) { fprintf( stderr, "Cannot connect to X server\n"); exit( -1 ); } winRoot = DefaultRootWindow(display); int display_width = DisplayWidth(display, DefaultScreen(display)); int display_height = DisplayHeight(display, DefaultScreen(display)); maxx = display_width*3/4; maxy = display_height*3/4; rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen) return; rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->alwaysShared = TRUE; rfbScreen->ptrAddEvent = doptr; rfbScreen->kbdAddEvent = dokey; rfbScreen->newClientHook = newclient; initBuffer((unsigned char*)rfbScreen->frameBuffer); //rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff); MakeRichCursor(rfbScreen); rfbInitServer(rfbScreen); rfbRunEventLoop(rfbScreen,-1,TRUE); return; }
int main(int argc,char** argv) { rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->alwaysShared = TRUE; rfbScreen->ptrAddEvent = doptr; rfbScreen->kbdAddEvent = dokey; rfbScreen->newClientHook = newclient; rfbScreen->httpDir = "../classes"; rfbScreen->httpEnableProxyConnect = TRUE; initBuffer((unsigned char*)rfbScreen->frameBuffer); rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff); /* This call creates a mask and then a cursor: */ /* rfbScreen->defaultCursor = rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0); */ MakeRichCursor(rfbScreen); /* initialize the server */ rfbInitServer(rfbScreen); #ifndef BACKGROUND_LOOP_TEST #ifdef USE_OWN_LOOP { int i; for(i=0;rfbIsActive(rfbScreen);i++) { fprintf(stderr,"%d\r",i); rfbProcessEvents(rfbScreen,100000); } } #else /* this is the blocking event loop, i.e. it never returns */ /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */ rfbRunEventLoop(rfbScreen,40000,FALSE); #endif /* OWN LOOP */ #else #if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) #error "I need pthreads for that." #endif /* this is the non-blocking event loop; a background thread is started */ rfbRunEventLoop(rfbScreen,-1,TRUE); /* now we could do some cool things like rendering in idle time */ while(1) sleep(5); /* render(); */ #endif /* BACKGROUND_LOOP */ free(rfbScreen->frameBuffer); rfbScreenCleanup(rfbScreen); return(0); }