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
This commit is contained in:
Neale Pickett 2008-04-21 13:58:38 -06:00
parent 6e5a49de25
commit 1b568d19fd
3 changed files with 52 additions and 45 deletions

14
README
View File

@ -1,7 +1,19 @@
== xss == == 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 `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, `xsswin` makes a full-screen black window and runs some other program,
passing along the window ID in the environment (`$XSS_WINDOW`) and passing along the window ID in the environment (`$XSS_WINDOW`) and

16
magic.c
View File

@ -53,26 +53,30 @@ main(int argc, char * const argv[])
Window w = (Window)0; Window w = (Window)0;
GC egc = (GC)0; GC egc = (GC)0;
XSegment *lines = NULL; XSegment *lines = NULL;
char *winstr = NULL;
int i; int i;
for (i = 1; i < argc; i += 1) { for (i = 1; i < argc; i += 1) {
if (0 == strcmp(argv[i], "-window-id")) { if (0 == strcmp(argv[i], "-window-id")) {
/* For compatibility reasons, just ignore */ /* For compatibility reasons, just ignore */
} else if (w) { } else if (winstr) {
w = (Window)-1; w = (Window)-1;
break; break;
} else { } else {
winstr = argv[i];
}
}
if (! winstr) winstr = getenv("XSS_WINDOW");
if (winstr) {
char *end; char *end;
if (argv[i][0] == '0' && argv[i][1] == 'x') { if (winstr[0] == '0' && winstr[1] == 'x') {
w = (Window)strtol(argv[i] + 2, &end, 16); w = (Window)strtol(winstr + 2, &end, 16);
} else { } else {
w = (Window)strtol(argv[i], &end, 10); w = (Window)strtol(winstr, &end, 10);
} }
if ('\0' != *end) { if ('\0' != *end) {
w = (Window)-1; w = (Window)-1;
break;
}
} }
} }
if ((Window)-1 == w) { if ((Window)-1 == w) {

View File

@ -41,7 +41,9 @@ main(int argc, char * const argv[])
XSetWindowAttributes wa; XSetWindowAttributes wa;
Window root; Window root;
XColor black; XColor black;
int child; int i;
char *nargv[argc + 1];
char id[50];
zero(wa); zero(wa);
zero(black); zero(black);
@ -55,7 +57,7 @@ main(int argc, char * const argv[])
w = XCreateWindow(display, root, w = XCreateWindow(display, root,
0, 0, 0, 0,
DisplayWidth(display, screen), DisplayHeight(display, screen), 0, DisplayWidth(display, screen), DisplayHeight(display, screen), 0,
CopyFromParent, InputOutput, CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel, CWOverrideRedirect | CWBackPixel,
&wa); &wa);
pmap = XCreateBitmapFromData(display, w, "\0", 1, 1); pmap = XCreateBitmapFromData(display, w, "\0", 1, 1);
@ -65,12 +67,6 @@ main(int argc, char * const argv[])
XMapRaised(display, w); XMapRaised(display, w);
XSync(display, False); 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)snprintf(id, sizeof(id), "0x%lx", (unsigned long)w);
(void)setenv("XSS_WINDOW", id, 1); (void)setenv("XSS_WINDOW", id, 1);
for (i = 0; i < argc; i += 1) { for (i = 0; i < argc; i += 1) {
@ -83,11 +79,6 @@ main(int argc, char * const argv[])
nargv[argc] = NULL; nargv[argc] = NULL;
(void)execvp(nargv[1], nargv + 1); (void)execvp(nargv[1], nargv + 1);
perror("exec"); perror("exec");
exit(1);
}
/* XXX: maybe important to also watch for X events? */
(void)waitpid(-1, NULL, 0);
} }
if (display) { if (display) {