--- vnc-4_1_1-unixsrc/unix/vncviewer/vncviewer.cxx.xscreensaver 2005-09-06 13:39:13.000000000 +0100 +++ vnc-4_1_1-unixsrc/unix/vncviewer/vncviewer.cxx 2005-09-06 14:46:29.000000000 +0100 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,45 @@ exit(1); } +static void deactivate_xscreensaver (void) +{ + if (!fullScreen) + return; + + pid_t pid = fork(); + + if (pid < 0) { + perror("fork"); + return; + } + + if (pid == 0) { + // child + close (STDIN_FILENO); + close (STDOUT_FILENO); + close (STDERR_FILENO); + int null = open ("/dev/null", O_RDWR); + if (null != STDIN_FILENO) + dup2 (null, STDIN_FILENO); + if (null != STDOUT_FILENO) + dup2 (null, STDOUT_FILENO); + if (null != STDERR_FILENO) + dup2 (null, STDERR_FILENO); + execlp ("xscreensaver-command", + "xscreensaver-command", "-deactivate", NULL); + } + + // reap previous child + while (wait3(NULL, WNOHANG, 0) > 0) ; +} + +static const unsigned int alarm_period = 59; +static int alarm_caught; +static void AlarmSignalHandler(int sig) +{ + alarm_caught = 1; +} + // XLoginIconifier is a class which iconifies the XDM login window when it has // grabbed the keyboard, thus releasing the grab, allowing the viewer to use // the keyboard. It remaps the xlogin window on exit. @@ -230,6 +270,7 @@ signal(SIGHUP, CleanupSignalHandler); signal(SIGINT, CleanupSignalHandler); signal(SIGTERM, CleanupSignalHandler); + signal(SIGALRM, AlarmSignalHandler); programName = argv[0]; char* vncServerName = 0; @@ -312,9 +353,16 @@ // X events are processed whenever reading from the socket would block. + alarm (alarm_period); while (true) { cc.getInStream()->check(1); cc.processMsg(); + + if (alarm_caught) { + alarm_caught = 0; + deactivate_xscreensaver (); + alarm (alarm_period); + } } } catch (rdr::EndOfStream& e) { --- vnc-4_1_1-unixsrc/unix/vncviewer/CConn.cxx.xscreensaver 2005-09-06 13:49:22.000000000 +0100 +++ vnc-4_1_1-unixsrc/unix/vncviewer/CConn.cxx 2005-09-06 14:50:05.000000000 +0100 @@ -184,7 +184,11 @@ FD_SET(ConnectionNumber(dpy), &rfds); FD_SET(sock->getFd(), &rfds); int n = select(FD_SETSIZE, &rfds, 0, 0, tvp); - if (n < 0) throw rdr::SystemException("select",errno); + if (n < 0) { + if (errno == EINTR) + continue; + throw rdr::SystemException("select",errno); + } } while (!(FD_ISSET(sock->getFd(), &rfds))); }