Revert bad change, xss now has -w option for leaving out xsswin

This commit is contained in:
Neale Pickett 2008-04-21 16:11:21 -06:00
parent 1b568d19fd
commit 6c39cd126e
3 changed files with 67 additions and 27 deletions

4
README
View File

@ -42,6 +42,10 @@ Run like `xautolock`:
xss xlock -mode qix & xss xlock -mode qix &
Just run a screen saver, don't lock
xss -w /usr/lib/xscreensaver/deco -window-id XSS_WINDOW
Launch a program called "screenlock" when you're idle: Launch a program called "screenlock" when you're idle:
xss screenlock xss screenlock

60
xss.c
View File

@ -38,19 +38,29 @@ sigchld(int signum)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
Display *display = NULL; Display *display = NULL;
int screen;
int bigwindow = 0;
if (argc < 2) { if ((argc > 1) && (0 == (strcmp(argv[1], "-w")))) {
(void)fprintf(stderr, "Usage: %s PROGRAM [ARGUMENT ...]\n", argv[0]); bigwindow = 1;
}
if (argc - bigwindow < 2) {
(void)fprintf(stderr, "Usage: %s [-w] PROGRAM [ARGUMENT ...]\n", argv[0]);
(void)fprintf(stderr, "\n");
(void)fprintf(stderr, "-w Map X server window, export $XSS_WINDOW. This window\n");
(void)fprintf(stderr, " will be unmapped by any keypress or mouse movement.\n");
return 64; /* EX_USAGE */ return 64; /* EX_USAGE */
} }
signal(SIGCHLD, sigchld); signal(SIGCHLD, sigchld);
try { try {
int ss_event, ss_error; int ss_event, ss_error;
int screen; XEvent event;
XEvent event; Window root;
Window root; char *nargv[argc+1];
char id[50];
int i;
if (! (display = XOpenDisplay(NULL))) raise("cannot open display"); if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
screen = DefaultScreen(display); screen = DefaultScreen(display);
@ -63,21 +73,39 @@ main(int argc, char *argv[])
root = RootWindow(display, screen); root = RootWindow(display, screen);
XScreenSaverSelectInput(display, root, ScreenSaverNotifyMask); XScreenSaverSelectInput(display, root, ScreenSaverNotifyMask);
/* Tell X to show its provided window off the screen. We make our own. */
{ {
XSetWindowAttributes attr; XSetWindowAttributes wa;
XScreenSaverInfo info;
Pixmap pmap;
XColor black;
attr.background_pixel = BlackPixel(display, screen); pmap = XCreateBitmapFromData(display, root, "\0", 1, 1);
black.pixel = BlackPixel(display, screen);
wa.cursor = XCreatePixmapCursor(display, pmap, pmap, &black, &black, 0, 0);
wa.background_pixel = BlackPixel(display, screen);
if (! (XFreePixmap(display, pmap))) break;
XScreenSaverSetAttributes(display, root, XScreenSaverSetAttributes(display, root,
-1, -1, bigwindow?0:-1, bigwindow?0:-1,
1, 1, bigwindow?DisplayWidth(display, screen):1,
bigwindow?DisplayHeight(display, screen):1,
0, 0,
CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent,
CopyFromParent, CopyFromParent,
CWBackPixel, CWBackPixel | CWCursor,
&attr); &wa);
XScreenSaverQueryInfo(display, (Drawable)root, &info);
(void)snprintf(id, sizeof(id), "0x%lx", (unsigned long)info.window);
(void)setenv("XSS_WINDOW", id, 1);
} }
for (i = 0; i < argc; i += 1) {
if (bigwindow && (0 == strcmp(argv[i], "XSS_WINDOW"))) {
nargv[i] = id;
} else {
nargv[i] = argv[i];
}
}
nargv[argc] = NULL;
while (! XNextEvent(display, &event)) { while (! XNextEvent(display, &event)) {
if (ss_event == event.type) { if (ss_event == event.type) {
@ -87,10 +115,11 @@ main(int argc, char *argv[])
if (! child) { if (! child) {
child = fork(); child = fork();
if (0 == child) { if (0 == child) {
(void)execvp(argv[1], argv + 1); (void)execvp(nargv[1+bigwindow], nargv+1+bigwindow);
perror("exec"); perror("exec");
exit(1); exit(1);
} }
} else {
} }
} }
} }
@ -98,6 +127,7 @@ main(int argc, char *argv[])
} while (0); } while (0);
if (display) { if (display) {
(void)XScreenSaverUnregister(display, screen);
(void)XCloseDisplay(display); (void)XCloseDisplay(display);
} }

View File

@ -37,33 +37,33 @@ main(int argc, char * const argv[])
try { try {
int screen; int screen;
Cursor invisible;
XSetWindowAttributes wa; XSetWindowAttributes wa;
Window root; Window root;
XColor black;
int i; int i;
char *nargv[argc + 1]; char *nargv[argc + 1];
char id[50]; char id[50];
zero(wa);
zero(black);
if (! (display = XOpenDisplay(NULL))) raise("cannot open display"); if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
screen = DefaultScreen(display); screen = DefaultScreen(display);
root = RootWindow(display, screen); root = RootWindow(display, screen);
wa.override_redirect = 1; wa.override_redirect = 1;
wa.background_pixel = BlackPixel(display, screen); wa.background_pixel = BlackPixel(display, screen);
{
Pixmap pmap;
XColor black;
pmap = XCreateBitmapFromData(display, root, "\0", 1, 1);
black.pixel = BlackPixel(display, screen);
wa.cursor = XCreatePixmapCursor(display, pmap, pmap, &black, &black, 0, 0);
if (! (XFreePixmap(display, pmap))) break;
}
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, CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel, CWOverrideRedirect | CWBackPixel | CWCursor,
&wa); &wa);
pmap = XCreateBitmapFromData(display, w, "\0", 1, 1);
black.pixel = BlackPixel(display, screen);
invisible = XCreatePixmapCursor(display, pmap, pmap, &black, &black, 0, 0);
XDefineCursor(display, w, invisible);
XMapRaised(display, w); XMapRaised(display, w);
XSync(display, False); XSync(display, False);
@ -77,8 +77,14 @@ main(int argc, char * const argv[])
} }
} }
nargv[argc] = NULL; nargv[argc] = NULL;
(void)execvp(nargv[1], nargv + 1);
perror("exec"); i = fork();
if (0 == i) {
(void)execvp(nargv[1], nargv + 1);
perror("exec");
return 1;
}
(void)waitpid(-1, NULL, 0);
} }
if (display) { if (display) {