commit bd5afce5ebdc317fe6ed0124e15dd9c07c208284 Author: Neale Pickett Date: Thu Apr 10 14:26:41 2008 -0600 Works for me. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5a0894a --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +CFLAGS = -Wall +LDLIBS = -lX11 -lXss + +all: xss diff --git a/xss.c b/xss.c new file mode 100644 index 0000000..000fa09 --- /dev/null +++ b/xss.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +int child = 0; + +void +sigchld(int signum) +{ + /* Reap zombies */ + int status; + + (void)wait(&status); + child = 0; +} + +int +main(int argc, char *argv[]) +{ + Display *display = NULL; + char *errtxt = "bummer dude."; + Pixmap blank; + int screen; + int ss_event, ss_error; + Window root; + + + if (argc < 2) { + fprintf(stderr, "Usage: %s PROGRAM [ARGUMENT ...]\n", argv[0]); + exit(1); + } + + do { + display = XOpenDisplay(NULL); + if (! display) { + errtxt = "Cannot open display"; + break; + } + + root = DefaultRootWindow(display); + + if (! XScreenSaverQueryExtension(display, &ss_event, &ss_error)) { + errtxt = "X server does not support MIT-SCREEN-SAVER extension."; + break; + } + + XScreenSaverSelectInput(display, root, ScreenSaverNotifyMask); + + signal(SIGCHLD, sigchld); + + while (1) { + XEvent event; + + if (XNextEvent(display, &event)) { + errtxt = NULL; + break; + } + + if (event.type == ss_event) { + XScreenSaverNotifyEvent *sevent; + + sevent = (XScreenSaverNotifyEvent *)&event; + if (ScreenSaverOn == sevent->state) { + if (child) { + /* Don't do anything, we still have a child */ + } else { + child = fork(); + if (0 == child) { + (void)execvp(argv[1], argv + 1); + perror("exec"); + exit(1); + } + } + } + } + } + } while (0); + + if (display) { + (void)XScreenSaverUnregister(display, screen); + (void)XFreePixmap(display, blank); + (void)XCloseDisplay(display); + } + + if (errtxt) { + fprintf(stderr, "Error: %s\n", errtxt); + return 1; + } + + return 0; +}