Commit bbcc2f51 authored by dscho's avatar dscho

works, but loads high

parent d9214f99
...@@ -20,7 +20,7 @@ LIBS=$(LDFLAGS) $(VNCSERVERLIB) $(PTHREADLIB) ...@@ -20,7 +20,7 @@ LIBS=$(LDFLAGS) $(VNCSERVERLIB) $(PTHREADLIB)
OSX_LIBS = -framework ApplicationServices -framework Carbon OSX_LIBS = -framework ApplicationServices -framework Carbon
# for x11vnc # for x11vnc
XLIBS = -L/usr/X11R6/lib -lX11 -lXext XLIBS = -L/usr/X11R6/lib -lX11 -lXext -lXtst
SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \ SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \
stats.c corre.c hextile.c rre.c translate.c cutpaste.c \ stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
...@@ -58,7 +58,8 @@ OSXvnc-server: mac.o libvncserver.a ...@@ -58,7 +58,8 @@ OSXvnc-server: mac.o libvncserver.a
$(CC) -o OSXvnc-server mac.o $(LIBS) $(OSX_LIBS) $(CC) -o OSXvnc-server mac.o $(LIBS) $(OSX_LIBS)
x11vnc: x11vnc.o libvncserver.a x11vnc: x11vnc.o libvncserver.a
$(CC) -o x11vnc x11vnc.o $(LIBS) $(XLIBS) $(CC) -o x11vnc x11vnc.o libvncserver.a /usr/lib/libz.a /usr/lib/libjpeg.a $(XLIBS)
#$(LIBS) $(XLIBS)
storepasswd: storepasswd.o d3des.o vncauth.o storepasswd: storepasswd.o d3des.o vncauth.o
$(CC) -o storepasswd storepasswd.o d3des.o vncauth.o $(CC) -o storepasswd storepasswd.o d3des.o vncauth.o
......
/* This file is part of LibVNCServer. It is a small clone of x0rfbserver by HexoNet, demonstrating the
capabilities of LibVNCServer.
*/
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#ifndef NO_SHM #ifndef NO_SHM
...@@ -7,20 +11,65 @@ ...@@ -7,20 +11,65 @@
#define KEYSYM_H #define KEYSYM_H
#include "rfb.h" #include "rfb.h"
Display *dpy = 0;
int c=0,blockLength = 32; int c=0,blockLength = 32;
Bool gotInput = FALSE;
Bool disconnectAfterFirstClient = TRUE;
/* the hooks */
void clientGone(rfbClientPtr cl)
{
exit(0);
}
void newClient(rfbClientPtr cl)
{
if(disconnectAfterFirstClient)
cl->clientGoneHook = clientGone;
}
void keyboard(Bool down,KeySym keySym,rfbClientPtr cl)
{
KeyCode k = XKeysymToKeycode( dpy,keySym );
if(k!=NoSymbol)
XTestFakeKeyEvent(dpy,k,down,CurrentTime);
gotInput = TRUE;
}
int oldButtonMask = 0;
void mouse(int buttonMask,int x,int y,rfbClientPtr cl)
{
int i=0;
//fprintf(stderr,"/");
XTestFakeMotionEvent(dpy,0,x,y,CurrentTime );
while(i<5) {
if ((oldButtonMask&(1<<i))!=(buttonMask&(1<<i)))
XTestFakeButtonEvent(dpy,i+1,(buttonMask&(1<<i))?True:False,CurrentTime);
i++;
}
oldButtonMask = buttonMask;
//fprintf(stderr,"-");
gotInput = TRUE;
}
/* the X11 interaction */
Bool useSHM =
#ifndef NO_SHM #ifndef NO_SHM
TRUE; Bool useSHM = TRUE;
XShmSegmentInfo shminfo; XShmSegmentInfo shminfo;
#else #else
FALSE; Bool useSHM = FALSE;
#endif #endif
void getImage(int bpp,Display *dpy,int xscreen,XImage **i) void getImage(int bpp,Display *dpy,int xscreen,XImage **i)
{ {
if(useSHM && bpp>0) { if(useSHM && bpp>0) {
static Bool firstTime = TRUE;
if(firstTime) {
firstTime = FALSE;
*i = XShmCreateImage( dpy, *i = XShmCreateImage( dpy,
DefaultVisual( dpy, xscreen ), DefaultVisual( dpy, xscreen ),
bpp, bpp,
...@@ -30,13 +79,19 @@ void getImage(int bpp,Display *dpy,int xscreen,XImage **i) ...@@ -30,13 +79,19 @@ void getImage(int bpp,Display *dpy,int xscreen,XImage **i)
DisplayWidth(dpy,xscreen), DisplayWidth(dpy,xscreen),
DisplayHeight(dpy,xscreen)); DisplayHeight(dpy,xscreen));
if(*i == 0) {
useSHM = FALSE;
getImage(bpp,dpy,xscreen,i);
return;
}
shminfo.shmid = shmget( IPC_PRIVATE, shminfo.shmid = shmget( IPC_PRIVATE,
(*i)->bytes_per_line * (*i)->height, (*i)->bytes_per_line * (*i)->height,
IPC_CREAT | 0777 ); IPC_CREAT | 0777 );
shminfo.shmaddr = (*i)->data = (char *) shmat( shminfo.shmid, 0, 0 ); shminfo.shmaddr = (*i)->data = (char *) shmat( shminfo.shmid, 0, 0 );
shminfo.readOnly = False; shminfo.readOnly = False;
XShmAttach( dpy, &shminfo ); XShmAttach( dpy, &shminfo );
}
XShmGetImage(dpy,RootWindow(dpy,xscreen),*i,0,0,AllPlanes); XShmGetImage(dpy,RootWindow(dpy,xscreen),*i,0,0,AllPlanes);
} else { } else {
...@@ -56,7 +111,7 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b) ...@@ -56,7 +111,7 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b)
y1*=s->paddedWidthInBytes; y1*=s->paddedWidthInBytes;
x1*=s->bitsPerPixel/8; x1*=s->bitsPerPixel/8;
changed=FALSE; changed=FALSE;
for(l=j*s->paddedWidthInBytes;!changed&&l<y1;l+=s->paddedWidthInBytes) for(l=j*s->paddedWidthInBytes;l<y1;l+=s->paddedWidthInBytes)
for(k=i*s->bitsPerPixel/8;k<x1;k++) for(k=i*s->bitsPerPixel/8;k<x1;k++)
if(s->frameBuffer[l+k]!=b[l+k]) { if(s->frameBuffer[l+k]!=b[l+k]) {
// fprintf(stderr,"changed: %d, %d\n",k,l); // fprintf(stderr,"changed: %d, %d\n",k,l);
...@@ -72,14 +127,28 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b) ...@@ -72,14 +127,28 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b)
} }
} }
/* the main program */
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
XImage *framebufferImage; XImage *framebufferImage;
char *backupImage; char *backupImage;
Display *dpy; int xscreen,i;
int xscreen;
rfbScreenInfoPtr screen; rfbScreenInfoPtr screen;
int maxMsecsToConnect = 5000; /* a maximum of 5 seconds to connect */
int updateCounter = 20; /* about every 50 ms a screen update should be made. */
for(i=argc-1;i>0;i--)
if(i<argc-1 && strcmp(argv[i],"-display")==0) {
dpy = XOpenDisplay(argv[i+1]);
if(dpy==0) {
fprintf(stderr,"Couldn't connect to display \"%s\".\n",argv[i+1]);
exit(1);
}
} else if(strcmp(argv[i],"-noshm")==0) {
useSHM = FALSE;
}
if(dpy==0)
dpy = XOpenDisplay(""); dpy = XOpenDisplay("");
xscreen = DefaultScreen(dpy); xscreen = DefaultScreen(dpy);
...@@ -95,7 +164,7 @@ int main(int argc,char** argv) ...@@ -95,7 +164,7 @@ int main(int argc,char** argv)
screen->rfbServerFormat.bitsPerPixel = framebufferImage->bits_per_pixel; screen->rfbServerFormat.bitsPerPixel = framebufferImage->bits_per_pixel;
screen->rfbServerFormat.depth = framebufferImage->depth; screen->rfbServerFormat.depth = framebufferImage->depth;
rfbEndianTest = framebufferImage->bitmap_bit_order != MSBFirst; //rfbEndianTest = framebufferImage->bitmap_bit_order != MSBFirst;
screen->rfbServerFormat.trueColour = TRUE; screen->rfbServerFormat.trueColour = TRUE;
if ( screen->rfbServerFormat.bitsPerPixel == 8 ) { if ( screen->rfbServerFormat.bitsPerPixel == 8 ) {
...@@ -125,25 +194,43 @@ int main(int argc,char** argv) ...@@ -125,25 +194,43 @@ int main(int argc,char** argv)
backupImage = malloc(screen->height*screen->paddedWidthInBytes); backupImage = malloc(screen->height*screen->paddedWidthInBytes);
memcpy(backupImage,framebufferImage->data,screen->height*screen->paddedWidthInBytes); memcpy(backupImage,framebufferImage->data,screen->height*screen->paddedWidthInBytes);
screen->frameBuffer = backupImage; screen->frameBuffer = backupImage;
screen->rfbDeferUpdateTime = 50;
screen->cursor = 0; screen->cursor = 0;
screen->newClientHook = newClient;
screen->kbdAddEvent = keyboard;
screen->ptrAddEvent = mouse;
screen->rfbDeferUpdateTime = 1;
updateCounter /= screen->rfbDeferUpdateTime;
rfbInitServer(screen); rfbInitServer(screen);
c=0;
while(1) { while(1) {
//fprintf(stderr,"%d\r",c++); if(screen->rfbClientHead)
maxMsecsToConnect = 5000;
maxMsecsToConnect -= screen->rfbDeferUpdateTime;
if(maxMsecsToConnect<0) {
fprintf(stderr,"Maximum time to connect reached. Exiting.\n");
exit(2);
}
rfbProcessEvents(screen,-1); rfbProcessEvents(screen,-1);
//if(1 || /*c++>7 &&*/ (!screen->rfbClientHead || !FB_UPDATE_PENDING(screen->rfbClientHead))) {
//c=0; if(gotInput) {
gotInput = FALSE;
c=updateCounter;
} else if(screen->rfbClientHead && c++>updateCounter) {
c=0;
//fprintf(stderr,"*");
if(!useSHM)
framebufferImage->f.destroy_image(framebufferImage); framebufferImage->f.destroy_image(framebufferImage);
getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage); getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage);
checkForImageUpdates(screen,framebufferImage->data); checkForImageUpdates(screen,framebufferImage->data);
//} //fprintf(stderr,"+");
//fprintf(stderr,"%x\n%x\n---\n",screen->frameBuffer,framebufferImage->data); }
//memcpy(screen->frameBuffer,framebufferImage->data,screen->height*screen->paddedWidthInBytes); #ifdef WRITE_SNAPS
rfbMarkRectAsModified(screen,0,0,screen->width,screen->height);
#if 0
{ {
int i,j,r,g,b; int i,j,r,g,b;
FILE* f=fopen("test.pnm","wb"); FILE* f=fopen("test.pnm","wb");
...@@ -161,7 +248,7 @@ int main(int argc,char** argv) ...@@ -161,7 +248,7 @@ int main(int argc,char** argv)
#endif #endif
} }
#ifndef NO_SHM #ifndef NO_SHM
XShmDetach(dpy,framebufferImage); //XShmDetach(dpy,framebufferImage);
#endif #endif
return(0); return(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment