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

36
magic.c
View File

@ -49,30 +49,34 @@
int int
main(int argc, char * const argv[]) main(int argc, char * const argv[])
{ {
Display *display; Display *display;
Window w = (Window)0; Window w = (Window)0;
GC egc = (GC)0; GC egc = (GC)0;
XSegment *lines = NULL; XSegment *lines = NULL;
int i; char *winstr = NULL;
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 {
char *end; winstr = argv[i];
}
}
if (! winstr) winstr = getenv("XSS_WINDOW");
if (winstr) {
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

@ -36,12 +36,14 @@ main(int argc, char * const argv[])
} }
try { try {
int screen; int screen;
Cursor invisible; Cursor invisible;
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,29 +67,18 @@ main(int argc, char * const argv[])
XMapRaised(display, w); XMapRaised(display, w);
XSync(display, False); XSync(display, False);
child = fork(); (void)snprintf(id, sizeof(id), "0x%lx", (unsigned long)w);
if (0 == child) { (void)setenv("XSS_WINDOW", id, 1);
char *nargv[argc + 1]; for (i = 0; i < argc; i += 1) {
char id[50]; if (0 == strcmp(argv[i], "XSS_WINDOW")) {
int i; nargv[i] = id;
} else {
(void)snprintf(id, sizeof(id), "0x%lx", (unsigned long)w); nargv[i] = argv[i];
(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);
} }
nargv[argc] = NULL;
/* XXX: maybe important to also watch for X events? */ (void)execvp(nargv[1], nargv + 1);
(void)waitpid(-1, NULL, 0); perror("exec");
} }
if (display) { if (display) {