Commit 1f6c5609 authored by Christian Beier's avatar Christian Beier Committed by Johannes Schindelin

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: 's avatarChristian Beier <dontmind@freeshell.org>
Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent 0a4f1bad
...@@ -11,7 +11,7 @@ struct { int sdl; int rfb; } buttonMapping[]={ ...@@ -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; ...@@ -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,8 +44,7 @@ static rfbBool resize(rfbClient* client) { ...@@ -45,8 +44,7 @@ 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;
...@@ -55,7 +53,7 @@ static rfbBool resize(rfbClient* client) { ...@@ -55,7 +53,7 @@ static rfbBool resize(rfbClient* client) {
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, ...) ...@@ -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) ...@@ -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:
if(listenLoop)
{
cleanup(cl);
return FALSE;
}
else
{
rfbClientCleanup(cl); rfbClientCleanup(cl);
exit(0); 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) ...@@ -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) ...@@ -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) { ...@@ -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,6 +499,7 @@ int main(int argc,char** argv) { ...@@ -473,6 +499,7 @@ int main(int argc,char** argv) {
SDL_DEFAULT_REPEAT_INTERVAL); SDL_DEFAULT_REPEAT_INTERVAL);
atexit(SDL_Quit); atexit(SDL_Quit);
do {
/* 16-bit: cl=rfbGetClient(5,3,2); */ /* 16-bit: cl=rfbGetClient(5,3,2); */
cl=rfbGetClient(8,3,4); cl=rfbGetClient(8,3,4);
cl->MallocFrameBuffer=resize; cl->MallocFrameBuffer=resize;
...@@ -483,22 +510,39 @@ int main(int argc,char** argv) { ...@@ -483,22 +510,39 @@ int main(int argc,char** argv) {
cl->GotXCutText = got_selection; cl->GotXCutText = got_selection;
cl->listenPort = LISTEN_PORT_OFFSET; cl->listenPort = LISTEN_PORT_OFFSET;
if(!rfbInitClient(cl,&argc,argv)) if(!rfbInitClient(cl,&argc,argv))
return 1; {
cleanup(cl);
break;
}
init_scrap(); init_scrap();
while(1) { while(1) {
if(SDL_PollEvent(&e)) if(SDL_PollEvent(&e)) {
handleSDLEvent(cl, &e); /*
handleSDLEvent() return 0 if user requested window close.
In this case, handleSDLEvent() will have called cleanup().
*/
if(!handleSDLEvent(cl, &e))
break;
}
else { else {
i=WaitForMessage(cl,500); i=WaitForMessage(cl,500);
if(i<0) if(i<0)
return 0; {
cleanup(cl);
break;
}
if(i) if(i)
if(!HandleRFBServerMessage(cl)) if(!HandleRFBServerMessage(cl))
return 0; {
cleanup(cl);
break;
}
}
} }
} }
while(listenLoop);
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