SDLvncviewer: use -listennofork when -listen specified.

As -listen mode isn't really working under UNIX and not at all under
windows, use -listennofork and an outer listen loop instead.

Signed-off-by: Christian Beier <dontmind@freeshell.org>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
pull/1/head
Christian Beier 15 years ago committed by Johannes Schindelin
parent 0a4f1bada4
commit 1f6c560985

@ -11,7 +11,7 @@ struct { int sdl; int rfb; } buttonMapping[]={
{0,0} {0,0}
}; };
static int enableResizable, viewOnly, buttonMask; static int enableResizable, viewOnly, listenLoop, buttonMask;
#ifdef SDL_ASYNCBLIT #ifdef SDL_ASYNCBLIT
int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
#else #else
@ -23,7 +23,6 @@ static char *sdlPixels;
static int rightAltKeyDown, leftAltKeyDown; static int rightAltKeyDown, leftAltKeyDown;
static rfbBool resize(rfbClient* client) { static rfbBool resize(rfbClient* client) {
static char first=TRUE;
int width=client->width,height=client->height, int width=client->width,height=client->height,
depth=client->format.bitsPerPixel; depth=client->format.bitsPerPixel;
@ -45,17 +44,16 @@ static rfbBool resize(rfbClient* client) {
sdlPixels = NULL; sdlPixels = NULL;
} }
client->frameBuffer=sdl->pixels; client->frameBuffer=sdl->pixels;
if(first || depth!=client->format.bitsPerPixel) {
first=FALSE; client->format.bitsPerPixel=depth;
client->format.bitsPerPixel=depth; client->format.redShift=sdl->format->Rshift;
client->format.redShift=sdl->format->Rshift; client->format.greenShift=sdl->format->Gshift;
client->format.greenShift=sdl->format->Gshift; client->format.blueShift=sdl->format->Bshift;
client->format.blueShift=sdl->format->Bshift; client->format.redMax=sdl->format->Rmask>>client->format.redShift;
client->format.redMax=sdl->format->Rmask>>client->format.redShift; client->format.greenMax=sdl->format->Gmask>>client->format.greenShift;
client->format.greenMax=sdl->format->Gmask>>client->format.greenShift; client->format.blueMax=sdl->format->Bmask>>client->format.blueShift;
client->format.blueMax=sdl->format->Bmask>>client->format.blueShift; SetFormatAndEncodings(client);
SetFormatAndEncodings(client);
}
} else { } else {
SDL_Surface* sdl=rfbClientGetClientData(client, SDL_Init); SDL_Surface* sdl=rfbClientGetClientData(client, SDL_Init);
rfbClientLog("Could not set resolution %dx%d!\n", rfbClientLog("Could not set resolution %dx%d!\n",
@ -348,7 +346,20 @@ log_to_file(const char *format, ...)
} }
#endif #endif
static void handleSDLEvent(rfbClient *cl, SDL_Event *e)
static void cleanup(rfbClient* cl)
{
/*
just in case we're running in listenLoop:
close viewer window by restarting SDL video subsystem
*/
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
rfbClientCleanup(cl);
}
static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e)
{ {
switch(e->type) { switch(e->type) {
#if SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION >= 2 #if SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION >= 2
@ -404,8 +415,16 @@ static void handleSDLEvent(rfbClient *cl, SDL_Event *e)
leftAltKeyDown = e->type == SDL_KEYDOWN; leftAltKeyDown = e->type == SDL_KEYDOWN;
break; break;
case SDL_QUIT: case SDL_QUIT:
rfbClientCleanup(cl); if(listenLoop)
exit(0); {
cleanup(cl);
return FALSE;
}
else
{
rfbClientCleanup(cl);
exit(0);
}
case SDL_ACTIVEEVENT: case SDL_ACTIVEEVENT:
if (!e->active.gain && rightAltKeyDown) { if (!e->active.gain && rightAltKeyDown) {
SendKeyEvent(cl, XK_Alt_R, FALSE); SendKeyEvent(cl, XK_Alt_R, FALSE);
@ -435,6 +454,7 @@ static void handleSDLEvent(rfbClient *cl, SDL_Event *e)
default: default:
rfbClientLog("ignore SDL event: 0x%x\n", e->type); rfbClientLog("ignore SDL event: 0x%x\n", e->type);
} }
return TRUE;
} }
static void got_selection(rfbClient *cl, const char *text, int len) static void got_selection(rfbClient *cl, const char *text, int len)
@ -442,6 +462,7 @@ static void got_selection(rfbClient *cl, const char *text, int len)
put_scrap(T('T', 'E', 'X', 'T'), len, text); put_scrap(T('T', 'E', 'X', 'T'), len, text);
} }
#ifdef mac #ifdef mac
#define main SDLmain #define main SDLmain
#endif #endif
@ -460,6 +481,11 @@ int main(int argc,char** argv) {
viewOnly = 1; viewOnly = 1;
else if (!strcmp(argv[i], "-resizable")) else if (!strcmp(argv[i], "-resizable"))
enableResizable = 1; enableResizable = 1;
else if (!strcmp(argv[i], "-listen")) {
listenLoop = 1;
argv[i] = "-listennofork";
++j;
}
else { else {
if (i != j) if (i != j)
argv[j] = argv[i]; argv[j] = argv[i];
@ -473,32 +499,50 @@ int main(int argc,char** argv) {
SDL_DEFAULT_REPEAT_INTERVAL); SDL_DEFAULT_REPEAT_INTERVAL);
atexit(SDL_Quit); atexit(SDL_Quit);
/* 16-bit: cl=rfbGetClient(5,3,2); */ do {
cl=rfbGetClient(8,3,4); /* 16-bit: cl=rfbGetClient(5,3,2); */
cl->MallocFrameBuffer=resize; cl=rfbGetClient(8,3,4);
cl->canHandleNewFBSize = TRUE; cl->MallocFrameBuffer=resize;
cl->GotFrameBufferUpdate=update; cl->canHandleNewFBSize = TRUE;
cl->HandleKeyboardLedState=kbd_leds; cl->GotFrameBufferUpdate=update;
cl->HandleTextChat=text_chat; cl->HandleKeyboardLedState=kbd_leds;
cl->GotXCutText = got_selection; cl->HandleTextChat=text_chat;
cl->listenPort = LISTEN_PORT_OFFSET; cl->GotXCutText = got_selection;
if(!rfbInitClient(cl,&argc,argv)) cl->listenPort = LISTEN_PORT_OFFSET;
return 1; if(!rfbInitClient(cl,&argc,argv))
{
init_scrap(); cleanup(cl);
break;
while(1) { }
if(SDL_PollEvent(&e))
handleSDLEvent(cl, &e); init_scrap();
else {
i=WaitForMessage(cl,500); while(1) {
if(i<0) if(SDL_PollEvent(&e)) {
return 0; /*
if(i) handleSDLEvent() return 0 if user requested window close.
if(!HandleRFBServerMessage(cl)) In this case, handleSDLEvent() will have called cleanup().
return 0; */
if(!handleSDLEvent(cl, &e))
break;
}
else {
i=WaitForMessage(cl,500);
if(i<0)
{
cleanup(cl);
break;
} }
if(i)
if(!HandleRFBServerMessage(cl))
{
cleanup(cl);
break;
}
}
}
} }
while(listenLoop);
return 0; return 0;
} }

Loading…
Cancel
Save