static rfbBool resize(rfbClient* client) { static char first=TRUE; #ifdef SDL_ASYNCBLIT int flags=SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL; #else int flags=SDL_HWSURFACE|SDL_HWACCEL; #endif int width=client->width,height=client->height, depth=client->format.bitsPerPixel; client->updateRect.x = client->updateRect.y = 0; client->updateRect.w = width; client->updateRect.h = height; rfbBool okay=SDL_VideoModeOK(width,height,depth,flags); if(!okay) for(depth=24;!okay && depth>4;depth/=2) okay=SDL_VideoModeOK(width,height,depth,flags); if(okay) { SDL_Surface* sdl=SDL_SetVideoMode(width,height,depth,flags); rfbClientSetClientData(client, SDL_Init, sdl); client->width = sdl->pitch / (depth / 8); client->frameBuffer=sdl->pixels; if(first || depth!=client->format.bitsPerPixel) { first=FALSE; client->format.bitsPerPixel=depth; client->format.redShift=sdl->format->Rshift; client->format.greenShift=sdl->format->Gshift; client->format.blueShift=sdl->format->Bshift; client->format.redMax=sdl->format->Rmask>>client->format.redShift; client->format.greenMax=sdl->format->Gmask>>client->format.greenShift; client->format.blueMax=sdl->format->Bmask>>client->format.blueShift; SetFormatAndEncodings(client); } } else {
/* Redraw the screen from the backing pixmap */ static gboolean expose_event (GtkWidget *widget, GdkEventExpose *event) { static GdkImage *image = NULL; GdkCursor *cursor; GdkPixbuf *pixbuf; if (framebuffer_allocated == FALSE) { rfbClientSetClientData (cl, gtk_init, widget); image = gdk_drawable_get_image (widget->window, 0, 0, widget->allocation.width, widget->allocation.height); cl->frameBuffer= image->mem; cl->width = widget->allocation.width; cl->height = widget->allocation.height; cl->format.bitsPerPixel = image->bits_per_pixel; cl->format.redShift = image->visual->red_shift; cl->format.greenShift = image->visual->green_shift; cl->format.blueShift = image->visual->blue_shift; cl->format.redMax = (1 << image->visual->red_prec) - 1; cl->format.greenMax = (1 << image->visual->green_prec) - 1; cl->format.blueMax = (1 << image->visual->blue_prec) - 1; #ifdef LIBVNCSERVER_CONFIG_LIBVA /* Allow libvncclient to use a more efficient way * of putting the framebuffer on the screen when * using the H.264 format. */ cl->outputWindow = GDK_WINDOW_XID(widget->window); #endif SetFormatAndEncodings (cl); framebuffer_allocated = TRUE; /* Also disable local cursor */ pixbuf = gdk_pixbuf_new_from_xpm_data(dot_cursor_xpm); cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, dot_cursor_x_hot, dot_cursor_y_hot); g_object_unref(pixbuf); gdk_window_set_cursor (gtk_widget_get_window(GTK_WIDGET(window)), cursor); gdk_cursor_unref(cursor); } #ifndef LIBVNCSERVER_CONFIG_LIBVA gdk_draw_image (GDK_DRAWABLE (widget->window), widget->style->fg_gc[gtk_widget_get_state(widget)], image, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); #endif return FALSE; }
static rfbBool rfbInitConnection(rfbClient* client) { /* Unless we accepted an incoming connection, make a TCP connection to the given VNC server */ if (!client->listenSpecified) { if (!client->serverHost) return FALSE; if (client->destHost) { if (!ConnectToRFBRepeater(client,client->serverHost,client->serverPort,client->destHost,client->destPort)) return FALSE; } else { if (!ConnectToRFBServer(client,client->serverHost,client->serverPort)) return FALSE; } } /* Initialise the VNC connection, including reading the password */ if (!InitialiseRFBConnection(client)) return FALSE; client->width=client->si.framebufferWidth; client->height=client->si.framebufferHeight; if (!client->MallocFrameBuffer(client)) return FALSE; if (!SetFormatAndEncodings(client)) return FALSE; if (client->updateRect.x < 0) { client->updateRect.x = client->updateRect.y = 0; client->updateRect.w = client->width; client->updateRect.h = client->height; } if (client->appData.scaleSetting>1) { if (!SendScaleSetting(client, client->appData.scaleSetting)) return FALSE; if (!SendFramebufferUpdateRequest(client, client->updateRect.x / client->appData.scaleSetting, client->updateRect.y / client->appData.scaleSetting, client->updateRect.w / client->appData.scaleSetting, client->updateRect.h / client->appData.scaleSetting, FALSE)) return FALSE; } else { if (!SendFramebufferUpdateRequest(client, client->updateRect.x, client->updateRect.y, client->updateRect.w, client->updateRect.h, FALSE)) return FALSE; } return TRUE; }
rfbBool VncClientThread::newclient(rfbClient *cl) { VncClientThread *t = static_cast<VncClientThread*>(rfbClientGetClientData(cl, 0)); Q_ASSERT(t); switch (t->quality()) { case RemoteView::High: cl->format.bitsPerPixel = MAX_COLOR_DEPTH; cl->appData.useBGR233 = 0; cl->appData.encodingsString = "copyrect hextile raw"; cl->appData.compressLevel = 0; cl->appData.qualityLevel = 9; break; case RemoteView::Medium: cl->format.bitsPerPixel = 16; cl->appData.useBGR233 = 0; cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw"; cl->appData.compressLevel = 5; cl->appData.qualityLevel = 7; break; case RemoteView::Low: case RemoteView::Unknown: default: cl->format.bitsPerPixel = 16; //TODO: add support for 8bit (needs color map) cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw"; cl->appData.compressLevel = 9; cl->appData.qualityLevel = 1; } if(cl->format.bitsPerPixel == 16) { cl->format.depth = 16; //number of useful bits in the pixel value cl->format.redShift = 11; cl->format.greenShift = 5; cl->format.blueShift = 0; cl->format.redMax = 0x1f; cl->format.greenMax = 0x3f; cl->format.blueMax = 0x1f; } else { cl->format.depth = 24; //number of useful bits in the pixel value cl->format.redShift = 16; cl->format.greenShift = 8; cl->format.blueShift = 0; cl->format.redMax = 0xff; cl->format.greenMax = 0xff; cl->format.blueMax = 0xff; } delete [] t->m_frameBuffer; // do not leak if we get a new framebuffer size const int size = cl->width * cl->height * (cl->format.bitsPerPixel / 8); t->m_frameBuffer = new uint8_t[size]; cl->frameBuffer = t->m_frameBuffer; memset(cl->frameBuffer, '\0', size); SetFormatAndEncodings(cl); return true; }
static rfbBool resize(rfbClient* client) { int width=client->width,height=client->height, depth=client->format.bitsPerPixel; client->updateRect.x = client->updateRect.y = 0; client->updateRect.w = width; client->updateRect.h = height; sdlWindow = SDL_CreateWindow("DRC VNC Viewer",//client->desktopName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED); // SDL_RENDERER_SOFTWARE); sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); // blank the window SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255); SDL_RenderClear(sdlRenderer); SDL_RenderPresent(sdlRenderer); SDL_PixelFormat *fmt = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888); uint8_t *pixels = static_cast<uint8_t*> (malloc(drc::kScreenWidth * drc::kScreenHeight * fmt->BytesPerPixel)); SDL_RenderReadPixels(sdlRenderer, NULL, SDL_PIXELFORMAT_ARGB8888, pixels, drc::kScreenWidth * fmt->BytesPerPixel); client->frameBuffer=pixels; client->format.bitsPerPixel = fmt->BitsPerPixel; client->format.redShift = fmt->Rshift; client->format.greenShift = fmt->Gshift; client->format.blueShift = fmt->Bshift; client->format.redMax = fmt->Rmask>>client->format.redShift; client->format.greenMax = fmt->Gmask>>client->format.greenShift; client->format.blueMax = fmt->Bmask>>client->format.blueShift; SetFormatAndEncodings(client); return TRUE; }
rfbBool VncClientThread::newclient(rfbClient *cl) { VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0); Q_ASSERT(t); const int width = cl->width, height = cl->height, depth = cl->format.bitsPerPixel; const int size = width * height * (depth / 8); if (t->frameBuffer) delete [] t->frameBuffer; // do not leak if we get a new framebuffer size t->frameBuffer = new uint8_t[size]; cl->frameBuffer = t->frameBuffer; memset(cl->frameBuffer, '\0', size); cl->format.bitsPerPixel = 32; cl->format.redShift = 16; cl->format.greenShift = 8; cl->format.blueShift = 0; cl->format.redMax = 0xff; cl->format.greenMax = 0xff; cl->format.blueMax = 0xff; switch (t->quality()) { case RemoteView::High: cl->appData.useBGR233 = 0; cl->appData.encodingsString = "copyrect hextile raw"; cl->appData.compressLevel = 0; cl->appData.qualityLevel = 9; break; case RemoteView::Medium: cl->appData.useBGR233 = 0; cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw"; cl->appData.compressLevel = 5; cl->appData.qualityLevel = 7; break; case RemoteView::Low: case RemoteView::Unknown: default: cl->appData.useBGR233 = 1; cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw"; cl->appData.compressLevel = 9; cl->appData.qualityLevel = 1; } SetFormatAndEncodings(cl); return true; }
rfbBool VncClientThread::newclient(rfbClient *cl) { VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0); Q_ASSERT(t); //8bit color hack for Intel(r) AMT KVM "classic vnc" = vnc server built in in Intel Vpro chipsets. if (INTEL_AMT_KVM_STRING == cl->desktopName) { kDebug(5011) << "Intel(R) AMT KVM: switching to 8 bit color depth (workaround, recent libvncserver needed)"; t->setColorDepth(bpp8); } setClientColorDepth(cl, t->colorDepth()); const int width = cl->width, height = cl->height, depth = cl->format.bitsPerPixel; const int size = width * height * (depth / 8); if (t->frameBuffer) delete [] t->frameBuffer; // do not leak if we get a new framebuffer size t->frameBuffer = new uint8_t[size]; cl->frameBuffer = t->frameBuffer; memset(cl->frameBuffer, '\0', size); switch (t->quality()) { case RemoteView::High: cl->appData.encodingsString = "copyrect zlib hextile raw"; cl->appData.compressLevel = 0; cl->appData.qualityLevel = 9; break; case RemoteView::Medium: cl->appData.encodingsString = "copyrect tight zrle ultra zlib hextile corre rre raw"; cl->appData.compressLevel = 5; cl->appData.qualityLevel = 7; break; case RemoteView::Low: case RemoteView::Unknown: default: cl->appData.encodingsString = "copyrect tight zrle ultra zlib hextile corre rre raw"; cl->appData.compressLevel = 9; cl->appData.qualityLevel = 1; } SetFormatAndEncodings(cl); kDebug(5011) << "Client created"; return true; }
rfbBool vncResizeCallback(rfbClient* client) { unsigned int* vncFrame = _qvrApp->vncResize(client->width, client->height); client->frameBuffer = reinterpret_cast<uint8_t*>(vncFrame); client->updateRect.x = 0; client->updateRect.y = 0; client->updateRect.w = client->width; client->updateRect.h = client->height; client->format.bitsPerPixel = 32; client->format.depth = 8; client->format.redMax = 255; client->format.greenMax = 255; client->format.blueMax = 255; client->format.redShift = 16; client->format.greenShift = 8; client->format.blueShift = 0; SetFormatAndEncodings(client); return TRUE; }
static rfbBool mallocFrameBufferHandler( rfbClient* p_client ) { vlc_fourcc_t i_chroma; demux_t *p_demux = (demux_t *) rfbClientGetClientData( p_client, DemuxThread ); demux_sys_t *p_sys = p_demux->p_sys; if ( p_sys->es ) /* Source has changed resolution */ { es_out_Del( p_demux->out, p_sys->es ); p_sys->es = NULL; } int i_width = p_client->width; int i_height = p_client->height; int i_depth = p_client->format.bitsPerPixel; switch( i_depth ) { case 8: i_chroma = VLC_CODEC_RGB8; break; default: case 16: i_chroma = VLC_CODEC_RGB16; break; case 24: i_chroma = VLC_CODEC_RGB24; break; case 32: i_chroma = VLC_CODEC_RGB32; break; } switch( i_chroma ) { case VLC_CODEC_RGB16: p_client->format.redShift = 11; p_client->format.greenShift = 5; p_client->format.blueShift = 0; p_client->format.redMax = 0x1f; p_client->format.greenMax = 0x3f; p_client->format.blueMax = 0x1f; break; case VLC_CODEC_RGB24: case VLC_CODEC_RGB32: p_client->format.redShift = 16; p_client->format.greenShift = 8; p_client->format.blueShift = 0; p_client->format.redMax = 0xff; p_client->format.greenMax = 0xff; p_client->format.blueMax = 0xff; break; } /* Set up framebuffer */ p_sys->i_framebuffersize = i_width * i_height * i_depth / 8; /* Reuse unsent block */ if ( p_sys->p_block ) p_sys->p_block = block_Realloc( p_sys->p_block, 0, p_sys->i_framebuffersize ); else p_sys->p_block = block_Alloc( p_sys->i_framebuffersize ); if ( p_sys->p_block ) p_sys->p_block->i_buffer = p_sys->i_framebuffersize; else return FALSE; /* Push our VNC config */ SetFormatAndEncodings( p_client ); /* Now init and fill es format */ es_format_t fmt; es_format_Init( &fmt, VIDEO_ES, i_chroma ); /* Fill input format */ fmt.video.i_chroma = i_chroma; fmt.video.i_visible_width = fmt.video.i_width = i_width; fmt.video.i_visible_height = fmt.video.i_height = i_height; fmt.video.i_frame_rate_base = 1000; fmt.video.i_frame_rate = 1000 * p_sys->f_fps; fmt.video.i_bits_per_pixel = i_depth; fmt.video.i_rmask = p_client->format.redMax << p_client->format.redShift; fmt.video.i_gmask = p_client->format.greenMax << p_client->format.greenShift; fmt.video.i_bmask = p_client->format.blueMax << p_client->format.blueShift; fmt.video.i_sar_num = fmt.video.i_sar_den = 1; /* declare the new es */ p_sys->es = es_out_Add( p_demux->out, &fmt ); return TRUE; }
int main(int argc, char **argv) { #ifndef NANOX fd_set fds; struct timeval tv, *tvp; int msWait; #endif processArgs(argc, argv); if (listenSpecified) { #ifndef NANOX listenForIncomingConnections(); /* returns only with a succesful connection */ #endif } else { if (!ConnectToRFBServer(hostname, port)) exit(1); } if (!InitialiseRFBConnection(rfbsock)) exit(1); if (!CreateXWindow()) exit(1); if (!SetFormatAndEncodings()) { ShutdownX(); exit(1); } if (!SendFramebufferUpdateRequest(updateRequestX, updateRequestY, updateRequestW, updateRequestH, False)) { ShutdownX(); exit(1); } printf("nanox fd = %d, rfbsock = %d\n", ConnectionNumber(dpy), rfbsock); #ifdef NANOX /* register the RFB socket */ GrRegisterInput(rfbsock); /* call the nanox main loop to wait for all events */ while (True) { GrMainLoop(HandleEvents); } #else while (True) { /* * Always handle all X events before doing select. This is the * simplest way of ensuring that we don't block in select while * Xlib has some events on its queue. */ if (!HandleXEvents()) { ShutdownX(); exit(1); } tvp = NULL; if (sendUpdateRequest) { gettimeofday(&tv, NULL); msWait = (updateRequestPeriodms + ((updateRequestTime.tv_sec - tv.tv_sec) * 1000) + ((updateRequestTime.tv_usec - tv.tv_usec) / 1000)); if (msWait > 0) { tv.tv_sec = msWait / 1000; tv.tv_usec = (msWait % 1000) * 1000; tvp = &tv; } else { if (!SendIncrementalFramebufferUpdateRequest()) { ShutdownX(); exit(1); } } } FD_ZERO(&fds); FD_SET(ConnectionNumber(dpy),&fds); FD_SET(rfbsock,&fds); if (select(FD_SETSIZE, &fds, NULL, NULL, tvp) < 0) { perror("select"); ShutdownX(); exit(1); } if (FD_ISSET(rfbsock, &fds)) { if (!HandleRFBServerMessage()) { ShutdownX(); exit(1); } } } #endif /* NANOX */ return 0; }
rfbBool ItalcVncConnection::hookNewClient( rfbClient *cl ) { ItalcVncConnection * t = (ItalcVncConnection *) rfbClientGetClientData( cl, 0) ; const int size = (int) cl->width * cl->height * ( cl->format.bitsPerPixel / 8 ); if( t->m_frameBuffer ) { // do not leak if we get a new framebuffer size delete [] t->m_frameBuffer; } t->m_frameBuffer = new uint8_t[size]; t->m_framebufferInitialized = false; cl->frameBuffer = t->m_frameBuffer; memset( cl->frameBuffer, '\0', size ); cl->format.bitsPerPixel = 32; cl->format.redShift = 16; cl->format.greenShift = 8; cl->format.blueShift = 0; cl->format.redMax = 0xff; cl->format.greenMax = 0xff; cl->format.blueMax = 0xff; // only use remote cursor for remote control cl->appData.useRemoteCursor = false; cl->appData.compressLevel = 0; cl->appData.useBGR233 = 0; cl->appData.qualityLevel = 9; cl->appData.enableJPEG = false; switch( t->quality() ) { case SnapshotQuality: cl->appData.encodingsString = "raw"; break; case RemoteControlQuality: cl->appData.encodingsString = "copyrect hextile raw"; cl->appData.useRemoteCursor = true; break; case ThumbnailQuality: cl->appData.useBGR233 = 1; cl->appData.encodingsString = "tight zrle ultra " "copyrect hextile zlib " "corre rre raw"; cl->appData.compressLevel = 9; cl->appData.qualityLevel = 5; cl->appData.enableJPEG = true; break; case DemoServerQuality: cl->appData.encodingsString = "copyrect corre rre raw"; //cl->appData.useRemoteCursor = true; break; case DemoClientQuality: //cl->appData.useRemoteCursor = true; cl->appData.encodingsString = "tight ultra copyrect " "hextile zlib corre rre raw"; cl->appData.compressLevel = 9; cl->appData.qualityLevel = 9; cl->appData.enableJPEG = true; break; default: cl->appData.encodingsString = "zrle ultra copyrect " "hextile zlib corre rre raw"; break; } SetFormatAndEncodings( cl ); return true; }
int main(int argc, char **argv) { fd_set fds; struct timeval tv, *tvp; int msWait; processArgs(argc, argv); if (listenSpecified) { listenForIncomingConnections(); /* returns only with a succesful connection */ } else { if(reconnect) { long last_fork=0; char *tmpdir="/tmp"; char tmpfile[1024]; if(getenv("TMPDIR") && strlen(tmpdir) < 900) tmpdir=getenv("TMPDIR"); sprintf(tmpfile, "%s/x2vnc-%d-%d", tmpdir, getpid(), time(0)); temp_file_fd=open(tmpfile, O_RDWR | O_CREAT | O_EXCL, 0600); unlink(tmpfile); while(1) { int status, pid; /* limit how often we restart */ if(time(0) - last_fork < 1) sleep(2); last_fork=time(0); switch (pid=fork()) { case -1: perror("fork"); exit(1); case 0: break; default: while(waitpid(pid, &status, 0) < 0 && errno==EINTR); if(debug) fprintf(stderr,"Child exited with status %d\n",status); continue; } break; } } if (!ConnectToRFBServer(hostname, port)) exit(1); } if (!InitialiseRFBConnection(rfbsock)) exit(1); if (!CreateXWindow()) exit(1); if (!SetFormatAndEncodings()) { exit(1); } while (1) { /* * Always handle all X events before doing select. This is the * simplest way of ensuring that we don't block in select while * Xlib has some events on its queue. */ if (!HandleXEvents()) { exit(1); } tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&fds); FD_SET(ConnectionNumber(dpy),&fds); FD_SET(rfbsock,&fds); if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 0) { perror("select"); exit(1); } if (FD_ISSET(rfbsock, &fds)) { if (!HandleRFBServerMessage()) { exit(1); } } } return 0; }
void ConnectionWindow::doConnect() { if (connected()) return; switch ( surfaceType() ) { case QVNCVIEWER_SURFACE_RASTER: default: surfaceWidget()->setDefaultMessage(tr("Connecting...")); surfaceWidget()->update(); break; } qApp->processEvents(QEventLoop::AllEvents, 100); // prepare RFB client structure m_rfbClient = rfbGetClient(QVNCVIEWER_BITS_PER_SAMPLE, QVNCVIEWER_SAMPLES_PER_PIXEL, QVNCVIEWER_BYTES_PER_PIXEL); m_rfbClient->MallocFrameBuffer = rfbResize; m_rfbClient->GotFrameBufferUpdate = rfbUpdate; /* FIXME: we currently don't need these functions m_rfbClient->FinishedFrameBufferUpdate = rfbUpdateFinished; m_rfbClient->GotCopyRect = rfbUpdateCopyRect; m_rfbClient->HandleCursorPos = rfbHandleCursorPos; */ m_rfbClient->programName = QVNCVIEWER_APP_TITLE_CSTR; m_rfbClient->frameBuffer = 0; m_rfbClient->canHandleNewFBSize = true; m_rfbClient->canUseCoRRE = true; m_rfbClient->canUseHextile = true; m_rfbClient->appData.forceTrueColour = true; m_rfbClient->appData.useRemoteCursor = true; m_rfbClient->appData.enableJPEG = true; m_clientToWindowHash[m_rfbClient] = this; PollServerThread::setConnecting(true); if ( ConnectToRFBServer(m_rfbClient, mHostName.toLocal8Bit().constData(), mDisplayNumber + QVNCVIEWER_VNC_BASE_PORT) ) { PollServerThread::setConnecting(false); if ( InitialiseRFBConnection(m_rfbClient) ) { QString rfbDesktopName(m_rfbClient->desktopName); if ( !rfbDesktopName.isEmpty() ) setWindowTitle(rfbDesktopName); VncMainWindow::log(tr("Setting encoding to '%1'").arg(m_currentEncoding)); m_rfbClient->appData.encodingsString = (const char*)m_currentEncoding.constData(); m_rfbClient->appData.qualityLevel = 95; m_rfbClient->appData.compressLevel = 9; if ( !SetFormatAndEncodings(m_rfbClient) ) VncMainWindow::log(tr("WARNING: Failed sending formats and encondings to %1:%2").arg(mHostName).arg(mDisplayNumber)); m_rfbClient->width = m_rfbClient->si.framebufferWidth; m_rfbClient->height = m_rfbClient->si.framebufferHeight; m_rfbClient->frameBuffer = (uint8_t *)malloc(m_rfbClient->width * m_rfbClient->height * QVNCVIEWER_BYTES_PER_PIXEL); setConnected(true); } else { PollServerThread::setConnecting(false); setConnected(false); ::close(m_rfbClient->sock); free(m_rfbClient->frameBuffer); m_rfbClient->frameBuffer = 0; rfbClientCleanup(m_rfbClient); m_clientToWindowHash.remove(m_rfbClient); m_rfbClient = 0; setWindowTitle(m_defaultWindowTitle); } } else { PollServerThread::setConnecting(false); setConnected(false); rfbClientCleanup(m_rfbClient); m_clientToWindowHash.remove(m_rfbClient); m_rfbClient = 0; setWindowTitle(m_defaultWindowTitle); VncMainWindow::log(tr("WARNING: Failed connection to %1:%2").arg(mHostName).arg(mDisplayNumber)); } }
int main(int argc, char **argv) { int i; programName = argv[0]; /* The -listen option is used to make us a daemon process which listens for incoming connections from servers, rather than actively connecting to a given server. The -tunnel and -via options are useful to create connections tunneled via SSH port forwarding. We must test for the -listen option before invoking any Xt functions - this is because we use forking, and Xt doesn't seem to cope with forking very well. For -listen option, when a successful incoming connection has been accepted, listenForIncomingConnections() returns, setting the listenSpecified flag. */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-listen") == 0) { listenForIncomingConnections(&argc, argv, i); break; } if (strcmp(argv[i], "-tunnel") == 0 || strcmp(argv[i], "-via") == 0) { if (!createTunnel(&argc, argv, i)) exit(1); break; } } /* Call the main Xt initialisation function. It parses command-line options, generating appropriate resource specs, and makes a connection to the X display. */ toplevel = XtVaAppInitialize(&appContext, "Vncviewer", cmdLineOptions, numCmdLineOptions, &argc, argv, fallback_resources, XtNborderWidth, 0, NULL); dpy = XtDisplay(toplevel); /* Interpret resource specs and process any remaining command-line arguments (i.e. the VNC server name). If the server name isn't specified on the command line, getArgsAndResources() will pop up a dialog box and wait for one to be entered. */ GetArgsAndResources(argc, argv); /* Unless we accepted an incoming connection, make a TCP connection to the given VNC server */ if (!listenSpecified) { if (!ConnectToRFBServer(vncServerHost, vncServerPort)) exit(1); } /* Initialise the VNC connection, including reading the password */ if (!InitialiseRFBConnection()) exit(1); /* Create the "popup" widget - this won't actually appear on the screen until some user-defined event causes the "ShowPopup" action to be invoked */ CreatePopup(); /* Find the best pixel format and X visual/colormap to use */ SetVisualAndCmap(); /* Create the "desktop" widget, and perform initialisation which needs doing before the widgets are realized */ ToplevelInitBeforeRealization(); DesktopInitBeforeRealization(); /* "Realize" all the widgets, i.e. actually create and map their X windows */ XtRealizeWidget(toplevel); /* Perform initialisation that needs doing after realization, now that the X windows exist */ InitialiseSelection(); ToplevelInitAfterRealization(); DesktopInitAfterRealization(); /* Spawn daemon thread to listen to vmgl libs */ if (appData.glStubPort == 7000) appData.glStubPort += (vncServerPort-5900); daemonStart(desktopWin, (unsigned short) appData.glStubPort, NULL); /* Tell the VNC server which pixel format and encodings we want to use */ SetFormatAndEncodings(); /* Now enter the main loop, processing VNC messages. X events will automatically be processed whenever the VNC connection is idle. */ while (1) { if (!HandleRFBServerMessage()) break; } Cleanup(); return 0; }