summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordscho <dscho>2004-06-07 08:31:57 +0000
committerdscho <dscho>2004-06-07 08:31:57 +0000
commit2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9 (patch)
tree66e59b58f919f5848780d5c7d6c954160e289cff
parent98e4f89569587c143a56e4dcf8162a035efc361e (diff)
downloadlibtdevnc-2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9.tar.gz
libtdevnc-2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9.zip
add client_examples/, add SDLvncviewer, libvncclient API changes, suppress automake CFLAGS nagging
-rw-r--r--ChangeLog5
-rw-r--r--Makefile.am4
-rw-r--r--TODO1
-rw-r--r--client_examples/Makefile.am13
-rw-r--r--client_examples/SDLvncviewer.c236
-rw-r--r--client_examples/ppmtest.c93
-rw-r--r--configure.ac13
-rw-r--r--contrib/Makefile.am2
-rw-r--r--examples/Makefile.am11
-rw-r--r--examples/blooptest.c2
-rw-r--r--libvncclient/Makefile.am7
-rw-r--r--libvncclient/client_test.c128
-rw-r--r--libvncclient/sockets.c21
-rw-r--r--libvncclient/vncviewer.c61
-rw-r--r--libvncserver/Makefile.am2
-rw-r--r--prepare_x11vnc_dist.sh2
-rw-r--r--rfb/rfbclient.h30
-rw-r--r--test/Makefile.am11
-rwxr-xr-xtest/blooptest.c2
-rw-r--r--test/copyrecttest.c (renamed from examples/copyrecttest.c)0
-rw-r--r--test/tight-1.c2
-rw-r--r--x11vnc/Makefile.am2
22 files changed, 471 insertions, 177 deletions
diff --git a/ChangeLog b/ChangeLog
index 52e68e3..959b536 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-06-07 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
+ * */Makefile.am: stop automake nagging
+ * libvncclient/*, client_examples/*: streamline API, SDLvncviewer added
+ * examples/, libvncclient/, test/: moved tests to test/
+
2004-06-05 Karl Runge <runge@karlrunge.com>
* x11vnc: rearrange file for easier maintenance
* add RFB_CLIENT_COUNT to -accept and -gone commands
diff --git a/Makefile.am b/Makefile.am
index d61ae3c..6398b5e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
CFLAGS=-g -Wall
-SUBDIRS=libvncserver examples contrib x11vnc vncterm classes libvncclient test
-DIST_SUBDIRS=libvncserver examples contrib x11vnc vncterm classes libvncclient test
+SUBDIRS=libvncserver examples contrib x11vnc vncterm classes libvncclient client_examples test
+DIST_SUBDIRS=libvncserver examples contrib x11vnc vncterm classes libvncclient client_examples test
bin_SCRIPTS = libvncserver-config
diff --git a/TODO b/TODO
index ef09115..8f6d0f9 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,7 @@
immediate:
----------
+cursor drawing does not get undone prior to sending
TightVNC encoding!!! Regression!!!
extra_bytes in rfbDrawCharWithClip.
tested mouse buttons make copy rect, but text is not marked as mod.
diff --git a/client_examples/Makefile.am b/client_examples/Makefile.am
new file mode 100644
index 0000000..d2a3e29
--- /dev/null
+++ b/client_examples/Makefile.am
@@ -0,0 +1,13 @@
+DEFINES=-I.. -g -Wall
+LDADD = ../libvncclient/libvncclient.a
+
+if HAVE_LIBSDL
+SDLVIEWER=SDLvncviewer
+
+SDLvncviewer_CFLAGS=`sdl-config --cflags`
+
+SDLvncviewer_LDFLAGS=`sdl-config --libs`
+endif
+
+noinst_PROGRAMS=ppmtest $(SDLVIEWER)
+
diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c
new file mode 100644
index 0000000..58884cf
--- /dev/null
+++ b/client_examples/SDLvncviewer.c
@@ -0,0 +1,236 @@
+#include <SDL/SDL.h>
+#include <rfb/rfbclient.h>
+
+static rfbBool resize(rfbClient* client) {
+ static char first=TRUE;
+ int flags=SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
+ int width=client->width,height=client->height,
+ depth=client->format.bitsPerPixel;
+ 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);
+ client->clientData=sdl;
+ 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 {
+ SDL_Surface* sdl=client->clientData;
+ fprintf(stderr,"Could not set resolution %dx%d!\n",
+ client->width,client->height);
+ if(sdl) {
+ client->width=sdl->w;
+ client->height=sdl->h;
+ } else {
+ client->width=0;
+ client->height=0;
+ }
+ return FALSE;
+ }
+ SDL_WM_SetCaption(client->desktopName, "SDL");
+ return TRUE;
+}
+
+rfbKeySym SDL_keysym2rfbKeySym(int keysym) {
+ switch(keysym) {
+ case SDLK_BACKSPACE: return XK_BackSpace;
+ case SDLK_TAB: return XK_ISO_Left_Tab;
+ case SDLK_CLEAR: return XK_Clear;
+ case SDLK_RETURN: return XK_Return;
+ case SDLK_PAUSE: return XK_Pause;
+ case SDLK_ESCAPE: return XK_Escape;
+ case SDLK_SPACE: return XK_space;
+ case SDLK_EXCLAIM: return XK_exclam;
+ case SDLK_QUOTEDBL: return XK_quotedbl;
+ case SDLK_HASH: return XK_numbersign;
+ case SDLK_DOLLAR: return XK_dollar;
+ case SDLK_AMPERSAND: return XK_ampersand;
+ case SDLK_QUOTE: return XK_apostrophe;
+ case SDLK_LEFTPAREN: return XK_parenleft;
+ case SDLK_RIGHTPAREN: return XK_parenright;
+ case SDLK_ASTERISK: return XK_asterisk;
+ case SDLK_PLUS: return XK_plus;
+ case SDLK_COMMA: return XK_comma;
+ case SDLK_MINUS: return XK_minus;
+ case SDLK_PERIOD: return XK_period;
+ case SDLK_SLASH: return XK_slash;
+ case SDLK_0: return XK_0;
+ case SDLK_1: return XK_1;
+ case SDLK_2: return XK_2;
+ case SDLK_3: return XK_3;
+ case SDLK_4: return XK_4;
+ case SDLK_5: return XK_5;
+ case SDLK_6: return XK_6;
+ case SDLK_7: return XK_7;
+ case SDLK_8: return XK_8;
+ case SDLK_9: return XK_9;
+ case SDLK_COLON: return XK_colon;
+ case SDLK_SEMICOLON: return XK_semicolon;
+ case SDLK_LESS: return XK_less;
+ case SDLK_EQUALS: return XK_equal;
+ case SDLK_GREATER: return XK_greater;
+ case SDLK_QUESTION: return XK_question;
+ case SDLK_AT: return XK_at;
+ case SDLK_LEFTBRACKET: return XK_bracketleft;
+ case SDLK_BACKSLASH: return XK_backslash;
+ case SDLK_RIGHTBRACKET: return XK_bracketright;
+ case SDLK_CARET: return XK_asciicircum;
+ case SDLK_UNDERSCORE: return XK_underscore;
+ case SDLK_BACKQUOTE: return XK_grave;
+ case SDLK_a: return XK_a;
+ case SDLK_b: return XK_b;
+ case SDLK_c: return XK_c;
+ case SDLK_d: return XK_d;
+ case SDLK_e: return XK_e;
+ case SDLK_f: return XK_f;
+ case SDLK_g: return XK_g;
+ case SDLK_h: return XK_h;
+ case SDLK_i: return XK_i;
+ case SDLK_j: return XK_j;
+ case SDLK_k: return XK_k;
+ case SDLK_l: return XK_l;
+ case SDLK_m: return XK_m;
+ case SDLK_n: return XK_n;
+ case SDLK_o: return XK_o;
+ case SDLK_p: return XK_p;
+ case SDLK_q: return XK_q;
+ case SDLK_r: return XK_r;
+ case SDLK_s: return XK_s;
+ case SDLK_t: return XK_t;
+ case SDLK_u: return XK_u;
+ case SDLK_v: return XK_v;
+ case SDLK_w: return XK_w;
+ case SDLK_x: return XK_x;
+ case SDLK_y: return XK_y;
+ case SDLK_z: return XK_z;
+ case SDLK_DELETE: return XK_Delete;
+ case SDLK_KP0: return XK_KP_0;
+ case SDLK_KP1: return XK_KP_1;
+ case SDLK_KP2: return XK_KP_2;
+ case SDLK_KP3: return XK_KP_3;
+ case SDLK_KP4: return XK_KP_4;
+ case SDLK_KP5: return XK_KP_5;
+ case SDLK_KP6: return XK_KP_6;
+ case SDLK_KP7: return XK_KP_7;
+ case SDLK_KP8: return XK_KP_8;
+ case SDLK_KP9: return XK_KP_9;
+ case SDLK_KP_PERIOD: return XK_KP_Decimal;
+ case SDLK_KP_DIVIDE: return XK_KP_Divide;
+ case SDLK_KP_MULTIPLY: return XK_KP_Multiply;
+ case SDLK_KP_MINUS: return XK_KP_Subtract;
+ case SDLK_KP_PLUS: return XK_KP_Add;
+ case SDLK_KP_ENTER: return XK_KP_Enter;
+ case SDLK_KP_EQUALS: return XK_KP_Equal;
+ case SDLK_UP: return XK_Up;
+ case SDLK_DOWN: return XK_Down;
+ case SDLK_RIGHT: return XK_Right;
+ case SDLK_LEFT: return XK_Left;
+ case SDLK_INSERT: return XK_Insert;
+ case SDLK_HOME: return XK_Home;
+ case SDLK_END: return XK_End;
+ case SDLK_PAGEUP: return XK_Page_Up;
+ case SDLK_PAGEDOWN: return XK_Page_Down;
+ case SDLK_F1: return XK_F1;
+ case SDLK_F2: return XK_F2;
+ case SDLK_F3: return XK_F3;
+ case SDLK_F4: return XK_F4;
+ case SDLK_F5: return XK_F5;
+ case SDLK_F6: return XK_F6;
+ case SDLK_F7: return XK_F7;
+ case SDLK_F8: return XK_F8;
+ case SDLK_F9: return XK_F9;
+ case SDLK_F10: return XK_F10;
+ case SDLK_F11: return XK_F11;
+ case SDLK_F12: return XK_F12;
+ case SDLK_F13: return XK_F13;
+ case SDLK_F14: return XK_F14;
+ case SDLK_F15: return XK_F15;
+ case SDLK_NUMLOCK: return XK_Num_Lock;
+ case SDLK_CAPSLOCK: return XK_Caps_Lock;
+ case SDLK_SCROLLOCK: return XK_Scroll_Lock;
+ case SDLK_RSHIFT: return XK_Shift_R;
+ case SDLK_LSHIFT: return XK_Shift_L;
+ case SDLK_RCTRL: return XK_Control_R;
+ case SDLK_LCTRL: return XK_Control_L;
+ case SDLK_RALT: return XK_Alt_R;
+ case SDLK_LALT: return XK_Alt_L;
+ case SDLK_RMETA: return XK_Meta_R;
+ case SDLK_LMETA: return XK_Meta_L;
+ //case SDLK_LSUPER: return XK_LSuper; /* left "windows" key */
+ //case SDLK_RSUPER: return XK_RSuper; /* right "windows" key */
+ case SDLK_MODE: return XK_Mode_switch;
+ //case SDLK_COMPOSE: return XK_Compose;
+ case SDLK_HELP: return XK_Help;
+ case SDLK_PRINT: return XK_Print;
+ case SDLK_SYSREQ: return XK_Sys_Req;
+ case SDLK_BREAK: return XK_Break;
+ default: fprintf(stderr,"Unknown keysym: %d\n",keysym);
+ }
+}
+
+#define main main1
+#include "ppmtest.c"
+#undef main
+
+void update(rfbClient* cl,int x,int y,int w,int h) {
+ SDL_UpdateRect(cl->clientData, x, y, w, h);
+ SaveFramebufferAsPPM(cl,x,y,w,h);
+}
+
+int main(int argc,char** argv) {
+ rfbClient* cl;
+ int i,buttonMask=0;
+ SDL_Event e;
+
+ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
+
+ cl=rfbGetClient(5,3,2);
+ //cl=rfbGetClient(8,3,4);
+ cl->MallocFrameBuffer=resize;
+ cl->GotFrameBufferUpdate=update;
+ if(!rfbInitClient(cl,&argc,argv))
+ return 1;
+
+ while(1) {
+ if(SDL_PollEvent(&e))
+ switch(e.type) {
+ case SDL_VIDEOEXPOSE:
+ SendFramebufferUpdateRequest(cl,0,0,cl->width,cl->height,FALSE);
+ break;
+ case SDL_MOUSEMOTION: {
+ int x,y;
+ SDL_GetMouseState(&x,&y);
+ SendPointerEvent(cl,x,y,buttonMask);
+ }
+ break;
+ case SDL_KEYUP: case SDL_KEYDOWN:
+ SendKeyEvent(cl,SDL_keysym2rfbKeySym(e.key.keysym.sym),(e.type==SDL_KEYDOWN)?TRUE:FALSE);
+ break;
+ case SDL_QUIT:
+ rfbClientCleanup(cl);
+ return 0;
+ }
+ else {
+ i=WaitForMessage(cl,500);
+ if(i<0)
+ return 0;
+ if(i)
+ if(!HandleRFBServerMessage(cl))
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/client_examples/ppmtest.c b/client_examples/ppmtest.c
new file mode 100644
index 0000000..01ee6a7
--- /dev/null
+++ b/client_examples/ppmtest.c
@@ -0,0 +1,93 @@
+/* A simple example of an RFB client */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
+#include <rfb/rfbclient.h>
+
+void PrintRect(rfbClient* client, int x, int y, int w, int h) {
+ rfbClientLog("Received an update for %d,%d,%d,%d.\n",x,y,w,h);
+}
+
+void SaveFramebufferAsPPM(rfbClient* client, int x, int y, int w, int h) {
+ static time_t t=0,t1;
+ FILE* f;
+ int i,j;
+ rfbPixelFormat* pf=&client->format;
+ int bpp=pf->bitsPerPixel/8;
+ int row_stride=client->width*bpp;
+
+ /* save one picture only if the last is older than 2 seconds */
+ t1=time(0);
+ if(t1-t>2)
+ t=t1;
+ else
+ return;
+
+ /* assert bpp=4 */
+ if(bpp!=4 && bpp!=2) {
+ rfbClientLog("bpp = %d (!=4)\n",bpp);
+ return;
+ }
+
+ f=fopen("/tmp/framebuffer.ppm","wb");
+
+ fprintf(f,"P6\n# %s\n%d %d\n255\n",client->desktopName,client->width,client->height);
+ for(j=0;j<client->height*row_stride;j+=row_stride)
+ for(i=0;i<client->width*bpp;i+=bpp) {
+ const char* p=client->frameBuffer+j+i;
+ unsigned int v;
+ if(bpp==4)
+ v=*(unsigned int*)p;
+ else if(bpp==2)
+ v=*(unsigned short*)p;
+ fputc((v>>pf->redShift)*256/(pf->redMax+1),f);
+ fputc((v>>pf->greenShift)*256/(pf->greenMax+1),f);
+ fputc((v>>pf->blueShift)*256/(pf->blueMax+1),f);
+ }
+ fclose(f);
+}
+
+ int
+main(int argc, char **argv)
+{
+ int i;
+ rfbClient* client = rfbGetClient(8,3,4);
+ const char* vncServerHost="";
+ int vncServerPort=5900;
+ time_t t=time(0);
+
+ if(argc>1 && !strcmp("-print",argv[1])) {
+ client->GotFrameBufferUpdate = PrintRect;
+ argv[1]=argv[0]; argv++; argc--;
+ } else
+ client->GotFrameBufferUpdate = SaveFramebufferAsPPM;
+
+ /* 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. */
+
+ if (!rfbInitClient(client,&argc,argv))
+ return 1;
+
+ while (time(0)-t<5) {
+ static int i=0;
+ fprintf(stderr,"\r%d",i++);
+ if(WaitForMessage(client,50)<0)
+ break;
+ if(!HandleRFBServerMessage(client))
+ break;
+ }
+
+ rfbClientCleanup(client);
+
+ return 0;
+}
+
diff --git a/configure.ac b/configure.ac
index dec4e20..0ea9ebb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,10 @@ AC_ARG_WITH(24bpp,
if test "x$with_24bpp" = "xyes"; then
AC_DEFINE(ALLOW24BPP)
fi
+AH_TEMPLATE(SDL_CONFIG, [Use sdl-config (for SDLvncviewer)])
+AC_ARG_WITH(sdl,
+ [ --with-sdl use sdl-config],
+ , [ with_sdl=yes ])
# Checks for X libraries
HAVE_X="false"
@@ -84,6 +88,14 @@ fi
AM_CONDITIONAL(HAVE_LIBPTHREAD, test ! -z "$HAVE_LIBPTHREAD")
AM_CONDITIONAL(HAVE_LIBZ, test ! -z "$HAVE_ZLIB_H")
AM_CONDITIONAL(HAVE_LIBJPEG, test ! -z "$HAVE_JPEGLIB_H")
+if test -z "$with_sdl"; then
+ if sdl-config >/dev/null 2>&1; then
+ with_sdl=yes
+ else
+ with_sdl=no
+ fi
+fi
+AM_CONDITIONAL(HAVE_LIBSDL, test "x$with_sdl" = "xyes")
# Checks for header files.
AC_HEADER_STDC
@@ -141,6 +153,7 @@ AC_CONFIG_FILES([Makefile
vncterm/Makefile
classes/Makefile
libvncclient/Makefile
+ client_examples/Makefile
test/Makefile
libvncserver.spec
libvncserver-config])
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 568d8b8..5add61c 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS = -I ..
+DEFINES = -I ..
LDADD = ../libvncserver/libvncserver.a
noinst_PROGRAMS=zippy
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 18f3726..ff816ac 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,21 +1,14 @@
-CFLAGS=-I.. -g -Wall
+DEFINES=-I.. -g -Wall
LDADD = ../libvncserver/libvncserver.a
-if HAVE_LIBPTHREAD
-BACKGROUND_TEST=blooptest
-endif
-
if OSX
MAC=mac
mac_LDFLAGS=-framework ApplicationServices -framework Carbon -framework IOKit
endif
-copyrecttest_LDADD=$(LDADD) -lm
-
noinst_HEADERS=radon.h
noinst_PROGRAMS=example pnmshow regiontest pnmshow24 fontsel \
- vncev storepasswd colourmaptest simple simple15 copyrecttest \
- $(BACKGROUND_TEST) $(MAC)
+ vncev storepasswd colourmaptest simple simple15 $(MAC)
diff --git a/examples/blooptest.c b/examples/blooptest.c
deleted file mode 100644
index f0e411c..0000000
--- a/examples/blooptest.c
+++ /dev/null
@@ -1,2 +0,0 @@
-#define BACKGROUND_LOOP_TEST
-#include "example.c"
diff --git a/libvncclient/Makefile.am b/libvncclient/Makefile.am
index 78b5620..88bd363 100644
--- a/libvncclient/Makefile.am
+++ b/libvncclient/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS=-g -I.. -I. -Wall
+DEFINES=-g -I.. -I. -Wall
libvncclient_a_SOURCES=cursor.c listen.c rfbproto.c sockets.c vncviewer.c
@@ -10,9 +10,4 @@ $(libvncclient_a_OBJECTS): ../rfb/rfbclient.h
lib_LIBRARIES=libvncclient.a
-client_test_SOURCES=client_test.c
-noinst_PROGRAMS=client_test
-
-#client_test_LDADD=libvncclient.a ../libvncserver.a
-client_test_LDADD=libvncclient.a
diff --git a/libvncclient/client_test.c b/libvncclient/client_test.c
deleted file mode 100644
index 16429b0..0000000
--- a/libvncclient/client_test.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* A simple example of an RFB client */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <errno.h>
-#include <rfb/rfbclient.h>
-
-void PrintRect(rfbClient* client, int x, int y, int w, int h) {
- rfbClientLog("Received an update for %d,%d,%d,%d.\n",x,y,w,h);
-}
-
-void SaveFramebufferAsPGM(rfbClient* client, int x, int y, int w, int h) {
- static time_t t=0,t1;
- FILE* f;
- int i,j;
- int bpp=client->format.bitsPerPixel/8;
- int row_stride=client->width*bpp;
-
- /* save one picture only if the last is older than 2 seconds */
- t1=time(0);
- if(t1-t>2)
- t=t1;
- else
- return;
-
- /* assert bpp=4 */
- if(bpp!=4) {
- rfbClientLog("bpp = %d (!=4)\n",bpp);
- return;
- }
-
- f=fopen("/tmp/framebuffer.ppm","wb");
-
- fprintf(f,"P6\n# %s\n%d %d\n255\n",client->desktopName,client->width,client->height);
- for(j=0;j<client->height*row_stride;j+=row_stride)
- for(i=0;i<client->width*bpp;i+=bpp) {
- if(client->format.bigEndian) {
- fputc(client->frameBuffer[j+i+bpp-1],f);
- fputc(client->frameBuffer[j+i+bpp-2],f);
- fputc(client->frameBuffer[j+i+bpp-3],f);
- } else {
- fputc(client->frameBuffer[j+i+0],f);
- fputc(client->frameBuffer[j+i+1],f);
- fputc(client->frameBuffer[j+i+2],f);
- }
- }
- fclose(f);
-}
-
-int WaitForMessage(rfbClient* client,unsigned int usecs)
-{
- fd_set fds;
- struct timeval timeout;
- int num;
-
- timeout.tv_sec=(usecs/1000000);
- timeout.tv_usec=(usecs%1000000);
-
- FD_ZERO(&fds);
- FD_SET(client->sock,&fds);
-
- num=select(client->sock+1, &fds, NULL, NULL, &timeout);
- if(num<0)
- rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno));
-
- return num;
-}
-
-int
-main(int argc, char **argv)
-{
- int i;
- rfbClient* client = rfbGetClient(&argc,argv,8,3,4);
- const char* vncServerHost="";
- int vncServerPort=5900;
- time_t t=time(0);
-
- client->GotFrameBufferUpdate = PrintRect;
- //client->GotFrameBufferUpdate = SaveFramebufferAsPGM;
-
- /* 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(client);
- break;
- } else {
- char* colon=strchr(argv[i],':');
-
- vncServerHost=argv[i];
- if(colon) {
- *colon=0;
- vncServerPort=atoi(colon+1);
- } else
- vncServerPort=0;
- vncServerPort+=5900;
- }
- }
-
- client->appData.encodingsString="tight";
- if(!rfbInitClient(client,vncServerHost,vncServerPort)) {
- rfbClientCleanup(client);
- return 1;
- }
-
- while (time(0)-t<5) {
- static int i=0;
- fprintf(stderr,"\r%d",i++);
- if(WaitForMessage(client,500)<0)
- break;
- if(!HandleRFBServerMessage(client))
- break;
- }
-
- rfbClientCleanup(client);
-
- return 0;
-}
-
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c
index 77dec7c..6954ed3 100644
--- a/libvncclient/sockets.c
+++ b/libvncclient/sockets.c
@@ -422,3 +422,24 @@ PrintInHex(char *buf, int len)
fflush(stderr);
}
+
+int WaitForMessage(rfbClient* client,unsigned int usecs)
+{
+ fd_set fds;
+ struct timeval timeout;
+ int num;
+
+ timeout.tv_sec=(usecs/1000000);
+ timeout.tv_usec=(usecs%1000000);
+
+ FD_ZERO(&fds);
+ FD_SET(client->sock,&fds);
+
+ num=select(client->sock+1, &fds, NULL, NULL, &timeout);
+ if(num<0)
+ rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno));
+
+ return num;
+}
+
+
diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c
index 6288485..6a58e78 100644
--- a/libvncclient/vncviewer.c
+++ b/libvncclient/vncviewer.c
@@ -43,15 +43,35 @@ static rfbBool MallocFrameBuffer(rfbClient* client) {
return client->frameBuffer?TRUE:FALSE;
}
-rfbClient* rfbGetClient(int* argc,char** argv,
- int bitsPerSample,int samplesPerPixel,
+static void initAppData(AppData* data) {
+ data->shareDesktop=TRUE;
+ data->viewOnly=FALSE;
+ data->encodingsString="tight hextile zlib corre rre raw";
+ data->useBGR233=FALSE;
+ data->nColours=0;
+ data->forceOwnCmap=FALSE;
+ data->forceTrueColour=FALSE;
+ data->requestedDepth=0;
+ data->compressLevel=3;
+ data->qualityLevel=5;
+#ifdef LIBVNCSERVER_HAVE_LIBJPEG
+ data->enableJPEG=TRUE;
+#else
+ data->enableJPEG=FALSE;
+#endif
+ data->useRemoteCursor=FALSE;
+}
+
+rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
int bytesPerPixel) {
rfbClient* client=(rfbClient*)calloc(sizeof(rfbClient),1);
- client->programName = argv[0];
+ initAppData(&client->appData);
+ client->programName = 0;
client->endianTest = 1;
client->format.bitsPerPixel = bytesPerPixel*8;
client->format.depth = bitsPerSample*samplesPerPixel;
+ client->appData.requestedDepth=client->format.depth;
client->format.bigEndian = *(char *)&client->endianTest?FALSE:TRUE;
client->format.trueColour = TRUE;
@@ -94,13 +114,13 @@ rfbClient* rfbGetClient(int* argc,char** argv,
return client;
}
-rfbBool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerPort)
+static rfbBool rfbInitConnection(rfbClient* client)
{
/* Unless we accepted an incoming connection, make a TCP connection to the
given VNC server */
if (!client->listenSpecified) {
- if (!ConnectToRFBServer(client,vncServerHost, vncServerPort))
+ if (!client->serverHost || !ConnectToRFBServer(client,client->serverHost,client->serverPort))
return FALSE;
}
@@ -122,6 +142,37 @@ rfbBool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerP
return TRUE;
}
+rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
+ int i;
+
+ if(client->programName==0)
+ client->programName=argv[0];
+
+ for (i = 1; i < *argc; i++) {
+ if (strcmp(argv[i], "-listen") == 0) {
+ listenForIncomingConnections(client);
+ break;
+ } else {
+ char* colon=strchr(argv[i],':');
+
+ client->serverHost=argv[i];
+ if(colon) {
+ *colon=0;
+ client->serverPort=atoi(colon+1);
+ } else
+ client->serverPort=0;
+ client->serverPort+=5900;
+ }
+ }
+
+ if(!rfbInitConnection(client)) {
+ rfbClientCleanup(client);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
void rfbClientCleanup(rfbClient* client) {
free(client);
}
diff --git a/libvncserver/Makefile.am b/libvncserver/Makefile.am
index 0a14983..a8fb971 100644
--- a/libvncserver/Makefile.am
+++ b/libvncserver/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS=-g -Wall
+DEFINES=-g -Wall
includedir=$(prefix)/include/rfb
#include_HEADERS=rfb.h rfbconfig.h rfbint.h rfbproto.h keysym.h rfbregion.h
diff --git a/prepare_x11vnc_dist.sh b/prepare_x11vnc_dist.sh
index 0f287e3..0b4aaad 100644
--- a/prepare_x11vnc_dist.sh
+++ b/prepare_x11vnc_dist.sh
@@ -8,7 +8,7 @@ mv configure.ac configure.ac.LibVNCServer
cat configure.ac.LibVNCServer | \
sed -e "s/LibVNCServer, [^,)]*\([(,]\)*/x11vnc, $VERSION\1/g" \
- -e "s/\(contrib\|examples\|vncterm\|libvncclient\|test\)\/Makefile//g" \
+ -e "s/\(contrib\|examples\|vncterm\|libvncclient\|test\|client_examples\)\/Makefile//g" \
-e "s/libvncserver.spec/x11vnc.spec/g" \
-e "s/^.*libvncserver-config//g" \
> configure.ac
diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h
index c738409..e6e43bf 100644
--- a/rfb/rfbclient.h
+++ b/rfb/rfbclient.h
@@ -1,3 +1,6 @@
+#ifndef RFBCLIENT_H
+#define RFBCLIENT_H
+
/*
* Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved.
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
@@ -55,31 +58,15 @@
typedef struct {
rfbBool shareDesktop;
rfbBool viewOnly;
- rfbBool fullScreen;
- rfbBool grabKeyboard;
- rfbBool raiseOnBeep;
const char* encodingsString;
rfbBool useBGR233;
int nColours;
- rfbBool useSharedColours;
rfbBool forceOwnCmap;
rfbBool forceTrueColour;
int requestedDepth;
- rfbBool useShm;
-
- int wmDecorationWidth;
- int wmDecorationHeight;
-
- rfbBool debug;
-
- int popupButtonCount;
-
- int bumpScrollTime;
- int bumpScrollPixels;
-
int compressLevel;
int qualityLevel;
rfbBool enableJPEG;
@@ -133,6 +120,9 @@ typedef struct _rfbClient {
/* cursor.c */
uint8_t *rcSource, *rcMask;
+ /* private data pointer */
+ void* clientData;
+
/* hooks */
HandleCursorPosProc HandleCursorPos;
SoftCursorLockAreaProc SoftCursorLockArea;
@@ -183,8 +173,12 @@ extern rfbBool SetNonBlocking(int sock);
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
extern rfbBool SameMachine(int sock);
+extern int WaitForMessage(rfbClient* client,unsigned int usecs);
/* vncviewer.c */
-rfbClient* rfbGetClient(int* argc,char** argv,int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
-rfbBool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerPort);
+rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
+rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
void rfbClientCleanup(rfbClient* client);
+
+#endif
+
diff --git a/test/Makefile.am b/test/Makefile.am
index 1ca7941..33839d5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,6 +1,13 @@
-CFLAGS=-I.. -g -Wall
+DEFINES=-I.. -g -Wall
+
+if HAVE_LIBPTHREAD
+BACKGROUND_TEST=blooptest
+endif
+
+copyrecttest_LDADD=$(LDADD) -lm
+
+noinst_PROGRAMS=tight-1 cargstest copyrecttest $(BACKGROUND_TEST)
-noinst_PROGRAMS=tight-1 cargstest
LDADD = ../libvncserver/libvncserver.a ../libvncclient/libvncclient.a
diff --git a/test/blooptest.c b/test/blooptest.c
new file mode 100755
index 0000000..a2661e8
--- /dev/null
+++ b/test/blooptest.c
@@ -0,0 +1,2 @@
+#define BACKGROUND_LOOP_TEST
+#include "../examples/example.c"
diff --git a/examples/copyrecttest.c b/test/copyrecttest.c
index ff278b4..ff278b4 100644
--- a/examples/copyrecttest.c
+++ b/test/copyrecttest.c
diff --git a/test/tight-1.c b/test/tight-1.c
index 987d481..fa22ea7 100644
--- a/test/tight-1.c
+++ b/test/tight-1.c
@@ -8,7 +8,7 @@ int main(int argc,char** argv)
time_t t=time(0);
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
- rfbClient* client=rfbGetClient(&argc,argv,8,3,4);
+ rfbClient* client=rfbGetClient(8,3,4);
server->frameBuffer=malloc(400*300*4);
for(j=0;j<400*300*4;j++)
diff --git a/x11vnc/Makefile.am b/x11vnc/Makefile.am
index d06d694..f467e3e 100644
--- a/x11vnc/Makefile.am
+++ b/x11vnc/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS = -I ..
+DEFINES = -I ..
LDADD = ../libvncserver/libvncserver.a
EXTRA_DIST=ChangeLog