/*
|
/*
|
* Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
|
* Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
|
*
|
*
|
* This is free software; you can redistribute it and/or modify
|
* This is free software; you can redistribute it and/or modify
|
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
* (at your option) any later version.
|
* (at your option) any later version.
|
*
|
*
|
* This software is distributed in the hope that it will be useful,
|
* This software is distributed in the hope that it will be useful,
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
*
|
*
|
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
* along with this software; if not, write to the Free Software
|
* along with this software; if not, write to the Free Software
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
* USA.
|
* USA.
|
*/
|
*/
|
|
|
/*
|
/*
|
* vncviewer.c - VNC viewer for nano-X.
|
* vncviewer.c - VNC viewer for nano-X.
|
*/
|
*/
|
|
|
#include <vncviewer.h>
|
#include <vncviewer.h>
|
|
|
static void HandleEvents(GR_EVENT *ev);
|
static void HandleEvents(GR_EVENT *ev);
|
|
|
int
|
int
|
main(int argc, char **argv)
|
main(int argc, char **argv)
|
{
|
{
|
#ifndef NANOX
|
#ifndef NANOX
|
fd_set fds;
|
fd_set fds;
|
struct timeval tv, *tvp;
|
struct timeval tv, *tvp;
|
int msWait;
|
int msWait;
|
#endif
|
#endif
|
processArgs(argc, argv);
|
processArgs(argc, argv);
|
|
|
if (listenSpecified) {
|
if (listenSpecified) {
|
|
|
#ifndef NANOX
|
#ifndef NANOX
|
listenForIncomingConnections();
|
listenForIncomingConnections();
|
/* returns only with a succesful connection */
|
/* returns only with a succesful connection */
|
#endif
|
#endif
|
|
|
} else {
|
} else {
|
if (!ConnectToRFBServer(hostname, port)) exit(1);
|
if (!ConnectToRFBServer(hostname, port)) exit(1);
|
}
|
}
|
|
|
if (!InitialiseRFBConnection(rfbsock)) exit(1);
|
if (!InitialiseRFBConnection(rfbsock)) exit(1);
|
|
|
if (!CreateXWindow()) exit(1);
|
if (!CreateXWindow()) exit(1);
|
|
|
if (!SetFormatAndEncodings()) {
|
if (!SetFormatAndEncodings()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
if (!SendFramebufferUpdateRequest(updateRequestX, updateRequestY,
|
if (!SendFramebufferUpdateRequest(updateRequestX, updateRequestY,
|
updateRequestW, updateRequestH, False)) {
|
updateRequestW, updateRequestH, False)) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
printf("nanox fd = %d, rfbsock = %d\n", ConnectionNumber(dpy), rfbsock);
|
printf("nanox fd = %d, rfbsock = %d\n", ConnectionNumber(dpy), rfbsock);
|
#ifdef NANOX
|
#ifdef NANOX
|
/* register the RFB socket */
|
/* register the RFB socket */
|
GrRegisterInput(rfbsock);
|
GrRegisterInput(rfbsock);
|
/* call the nanox main loop to wait for all events */
|
/* call the nanox main loop to wait for all events */
|
while (True) {
|
while (True) {
|
GrMainLoop(HandleEvents);
|
GrMainLoop(HandleEvents);
|
}
|
}
|
|
|
#else
|
#else
|
while (True) {
|
while (True) {
|
/*
|
/*
|
* Always handle all X events before doing select. This is the
|
* Always handle all X events before doing select. This is the
|
* simplest way of ensuring that we don't block in select while
|
* simplest way of ensuring that we don't block in select while
|
* Xlib has some events on its queue.
|
* Xlib has some events on its queue.
|
*/
|
*/
|
|
|
if (!HandleXEvents()) {
|
if (!HandleXEvents()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
tvp = NULL;
|
tvp = NULL;
|
|
|
if (sendUpdateRequest) {
|
if (sendUpdateRequest) {
|
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
|
|
msWait = (updateRequestPeriodms +
|
msWait = (updateRequestPeriodms +
|
((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
|
((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
|
((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
|
((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
|
|
|
if (msWait > 0) {
|
if (msWait > 0) {
|
tv.tv_sec = msWait / 1000;
|
tv.tv_sec = msWait / 1000;
|
tv.tv_usec = (msWait % 1000) * 1000;
|
tv.tv_usec = (msWait % 1000) * 1000;
|
|
|
tvp = &tv;
|
tvp = &tv;
|
} else {
|
} else {
|
if (!SendIncrementalFramebufferUpdateRequest()) {
|
if (!SendIncrementalFramebufferUpdateRequest()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
FD_SET(ConnectionNumber(dpy),&fds);
|
FD_SET(ConnectionNumber(dpy),&fds);
|
FD_SET(rfbsock,&fds);
|
FD_SET(rfbsock,&fds);
|
|
|
if (select(FD_SETSIZE, &fds, NULL, NULL, tvp) < 0) {
|
if (select(FD_SETSIZE, &fds, NULL, NULL, tvp) < 0) {
|
perror("select");
|
perror("select");
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
if (FD_ISSET(rfbsock, &fds)) {
|
if (FD_ISSET(rfbsock, &fds)) {
|
if (!HandleRFBServerMessage()) {
|
if (!HandleRFBServerMessage()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
}
|
}
|
#endif /* NANOX */
|
#endif /* NANOX */
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#ifdef NANOX
|
#ifdef NANOX
|
/*
|
/*
|
* call-back routine to handle all events
|
* call-back routine to handle all events
|
*/
|
*/
|
void
|
void
|
HandleEvents(GR_EVENT *ev)
|
HandleEvents(GR_EVENT *ev)
|
{
|
{
|
struct timeval tv, *tvp;
|
struct timeval tv, *tvp;
|
int msWait;
|
int msWait;
|
|
|
/* printf("%2d ", ev->type);
|
/* printf("%2d ", ev->type);
|
fflush(stdout);
|
fflush(stdout);
|
*/
|
*/
|
if (ev->type == GR_EVENT_TYPE_FDINPUT) {
|
if (ev->type == GR_EVENT_TYPE_FDINPUT) {
|
if (!HandleRFBServerMessage()) {
|
if (!HandleRFBServerMessage()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
} else {
|
} else {
|
if (!HandleXEvents(ev)) {
|
if (!HandleXEvents(ev)) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
if (sendUpdateRequest) {
|
if (sendUpdateRequest) {
|
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
|
|
msWait = (updateRequestPeriodms +
|
msWait = (updateRequestPeriodms +
|
((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
|
((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
|
((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
|
((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
|
|
|
if (msWait > 0) {
|
if (msWait > 0) {
|
tv.tv_sec = msWait / 1000;
|
tv.tv_sec = msWait / 1000;
|
tv.tv_usec = (msWait % 1000) * 1000;
|
tv.tv_usec = (msWait % 1000) * 1000;
|
|
|
tvp = &tv;
|
tvp = &tv;
|
} else {
|
} else {
|
if (!SendIncrementalFramebufferUpdateRequest()) {
|
if (!SendIncrementalFramebufferUpdateRequest()) {
|
ShutdownX();
|
ShutdownX();
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
#endif /* NANOX */
|
#endif /* NANOX */
|
|
|
|
|