From 1b568d19fd1e7e20cc10ea6a45666c012ae04001 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 21 Apr 2008 13:58:38 -0600 Subject: [PATCH] A couple little tweaks * magic now looks for the XSS_WINDOW environment variable * xsswin doesn't bother forking before execing now * README provides a little introduction --- README | 14 +++++++++++++- magic.c | 36 ++++++++++++++++++++---------------- xsswin.c | 47 +++++++++++++++++++---------------------------- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/README b/README index 801df0f..ef57ee9 100644 --- a/README +++ b/README @@ -1,7 +1,19 @@ == xss == +[xss](http://woozle.org/~neale/src/xss) is a suite of X screensaver +utilities. With them, you can use shell scripts to glue the tools +together to build your own screen saver and/or locker. You can use any +`xscreensaver` hack instead of the built-in `magic` hack, or you can use +`xlock` if you prefer. + + +The programs +------------ + `xss` uses the decades-old MIT-SCREEN-SAVER extension to launch a -program when the X server turns on the built-in screen saver. +program when the X server turns on the built-in screen saver. Unlike +`xautolock`, `xss` blocks until the X server says it's time to do +something. `xsswin` makes a full-screen black window and runs some other program, passing along the window ID in the environment (`$XSS_WINDOW`) and diff --git a/magic.c b/magic.c index c59add1..83bda7c 100644 --- a/magic.c +++ b/magic.c @@ -49,30 +49,34 @@ int main(int argc, char * const argv[]) { - Display *display; - Window w = (Window)0; - GC egc = (GC)0; - XSegment *lines = NULL; - int i; + Display *display; + Window w = (Window)0; + GC egc = (GC)0; + XSegment *lines = NULL; + char *winstr = NULL; + int i; for (i = 1; i < argc; i += 1) { if (0 == strcmp(argv[i], "-window-id")) { /* For compatibility reasons, just ignore */ - } else if (w) { + } else if (winstr) { w = (Window)-1; break; } else { - char *end; + winstr = argv[i]; + } + } + if (! winstr) winstr = getenv("XSS_WINDOW"); + if (winstr) { + char *end; - if (argv[i][0] == '0' && argv[i][1] == 'x') { - w = (Window)strtol(argv[i] + 2, &end, 16); - } else { - w = (Window)strtol(argv[i], &end, 10); - } - if ('\0' != *end) { - w = (Window)-1; - break; - } + if (winstr[0] == '0' && winstr[1] == 'x') { + w = (Window)strtol(winstr + 2, &end, 16); + } else { + w = (Window)strtol(winstr, &end, 10); + } + if ('\0' != *end) { + w = (Window)-1; } } if ((Window)-1 == w) { diff --git a/xsswin.c b/xsswin.c index e1be891..d2acae9 100644 --- a/xsswin.c +++ b/xsswin.c @@ -36,12 +36,14 @@ main(int argc, char * const argv[]) } try { - int screen; - Cursor invisible; - XSetWindowAttributes wa; - Window root; - XColor black; - int child; + int screen; + Cursor invisible; + XSetWindowAttributes wa; + Window root; + XColor black; + int i; + char *nargv[argc + 1]; + char id[50]; zero(wa); zero(black); @@ -55,7 +57,7 @@ main(int argc, char * const argv[]) w = XCreateWindow(display, root, 0, 0, DisplayWidth(display, screen), DisplayHeight(display, screen), 0, - CopyFromParent, InputOutput, CopyFromParent, + CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect | CWBackPixel, &wa); pmap = XCreateBitmapFromData(display, w, "\0", 1, 1); @@ -65,29 +67,18 @@ main(int argc, char * const argv[]) XMapRaised(display, w); XSync(display, False); - child = fork(); - if (0 == child) { - char *nargv[argc + 1]; - char id[50]; - int i; - - (void)snprintf(id, sizeof(id), "0x%lx", (unsigned long)w); - (void)setenv("XSS_WINDOW", id, 1); - for (i = 0; i < argc; i += 1) { - if (0 == strcmp(argv[i], "XSS_WINDOW")) { - nargv[i] = id; - } else { - nargv[i] = argv[i]; - } + (void)snprintf(id, sizeof(id), "0x%lx", (unsigned long)w); + (void)setenv("XSS_WINDOW", id, 1); + for (i = 0; i < argc; i += 1) { + if (0 == strcmp(argv[i], "XSS_WINDOW")) { + nargv[i] = id; + } else { + nargv[i] = argv[i]; } - nargv[argc] = NULL; - (void)execvp(nargv[1], nargv + 1); - perror("exec"); - exit(1); } - - /* XXX: maybe important to also watch for X events? */ - (void)waitpid(-1, NULL, 0); + nargv[argc] = NULL; + (void)execvp(nargv[1], nargv + 1); + perror("exec"); } if (display) {