summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Beier <dontmind@freeshell.org>2009-10-26 22:41:56 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2009-10-30 18:29:08 +0100
commit1f6c5609851f3431f14c275a5e1d3c4900a63baa (patch)
tree2071931c99446a244966e33ac28b23d7451b9e35
parent0a4f1bada4f6e62e1cb4ffd6c34e6c8313c39aef (diff)
downloadlibtdevnc-1f6c5609851f3431f14c275a5e1d3c4900a63baa.tar.gz
libtdevnc-1f6c5609851f3431f14c275a5e1d3c4900a63baa.zip
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>
-rw-r--r--client_examples/SDLvncviewer.c124
1 files changed, 84 insertions, 40 deletions
diff --git a/client_examples/SDLvncviewer.c b/client_examples/SDLvncviewer.c
index 8909b03..c8c63d1 100644
--- a/client_examples/SDLvncviewer.c
+++ b/client_examples/SDLvncviewer.c
@@ -11,7 +11,7 @@ struct { int sdl; int rfb; } buttonMapping[]={
{0,0}
};
-static int enableResizable, viewOnly, buttonMask;
+static int enableResizable, viewOnly, listenLoop, buttonMask;
#ifdef SDL_ASYNCBLIT
int sdlFlags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
#else
@@ -23,7 +23,6 @@ static char *sdlPixels;
static int rightAltKeyDown, leftAltKeyDown;
static rfbBool resize(rfbClient* client) {
- static char first=TRUE;
int width=client->width,height=client->height,
depth=client->format.bitsPerPixel;
@@ -45,17 +44,16 @@ static rfbBool resize(rfbClient* client) {
sdlPixels = NULL;
}
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);
- }
+
+ 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=rfbClientGetClientData(client, SDL_Init);
rfbClientLog("Could not set resolution %dx%d!\n",
@@ -348,7 +346,20 @@ log_to_file(const char *format, ...)
}
#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) {
#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;
break;
case SDL_QUIT:
- rfbClientCleanup(cl);
- exit(0);
+ if(listenLoop)
+ {
+ cleanup(cl);
+ return FALSE;
+ }
+ else
+ {
+ rfbClientCleanup(cl);
+ exit(0);
+ }
case SDL_ACTIVEEVENT:
if (!e->active.gain && rightAltKeyDown) {
SendKeyEvent(cl, XK_Alt_R, FALSE);
@@ -435,6 +454,7 @@ static void handleSDLEvent(rfbClient *cl, SDL_Event *e)
default:
rfbClientLog("ignore SDL event: 0x%x\n", e->type);
}
+ return TRUE;
}
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);
}
+
#ifdef mac
#define main SDLmain
#endif
@@ -460,6 +481,11 @@ int main(int argc,char** argv) {
viewOnly = 1;
else if (!strcmp(argv[i], "-resizable"))
enableResizable = 1;
+ else if (!strcmp(argv[i], "-listen")) {
+ listenLoop = 1;
+ argv[i] = "-listennofork";
+ ++j;
+ }
else {
if (i != j)
argv[j] = argv[i];
@@ -473,32 +499,50 @@ int main(int argc,char** argv) {
SDL_DEFAULT_REPEAT_INTERVAL);
atexit(SDL_Quit);
- /* 16-bit: cl=rfbGetClient(5,3,2); */
- cl=rfbGetClient(8,3,4);
- cl->MallocFrameBuffer=resize;
- cl->canHandleNewFBSize = TRUE;
- cl->GotFrameBufferUpdate=update;
- cl->HandleKeyboardLedState=kbd_leds;
- cl->HandleTextChat=text_chat;
- cl->GotXCutText = got_selection;
- cl->listenPort = LISTEN_PORT_OFFSET;
- if(!rfbInitClient(cl,&argc,argv))
- return 1;
-
- init_scrap();
-
- while(1) {
- if(SDL_PollEvent(&e))
- handleSDLEvent(cl, &e);
- else {
- i=WaitForMessage(cl,500);
- if(i<0)
- return 0;
- if(i)
- if(!HandleRFBServerMessage(cl))
- return 0;
+ do {
+ /* 16-bit: cl=rfbGetClient(5,3,2); */
+ cl=rfbGetClient(8,3,4);
+ cl->MallocFrameBuffer=resize;
+ cl->canHandleNewFBSize = TRUE;
+ cl->GotFrameBufferUpdate=update;
+ cl->HandleKeyboardLedState=kbd_leds;
+ cl->HandleTextChat=text_chat;
+ cl->GotXCutText = got_selection;
+ cl->listenPort = LISTEN_PORT_OFFSET;
+ if(!rfbInitClient(cl,&argc,argv))
+ {
+ cleanup(cl);
+ break;
+ }
+
+ init_scrap();
+
+ while(1) {
+ if(SDL_PollEvent(&e)) {
+ /*
+ handleSDLEvent() return 0 if user requested window close.
+ In this case, handleSDLEvent() will have called cleanup().
+ */
+ 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;
}