home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Portions written by Tim Bray AND
- ** Portions stolen from 'xphoon' with grateful acknowledgement are
- ** Copyright (C) 1988 by Jef Poskanzer and Craig Leres.
- **
- ** Permission to use, copy, modify, and distribute this software and its
- ** documentation for any purpose and without fee is hereby granted, provided
- ** that the above copyright notice appear in all copies and that both that
- ** copyright notice and this permission notice appear in supporting
- ** documentation. This software is provided "as is" without express or
- ** implied warranty.
- */
-
- #include <X11/Xlib.h>
- #include <X11/Xatom.h>
- #include <stdio.h>
-
- extern double atof();
- extern char * malloc();
-
- static char * argv0;
-
- main(argc, argv)
- int argc;
- char * argv[];
- {
- XWindowAttributes attributes;
- char * bits;
- int bytecount;
- char * display = NULL;
- Display * dpy = NULL;
- void genbits();
- double percent = 0.5;
-
- argv0 = argv[0];
- if ((dpy = XOpenDisplay(display)) == 0)
- {
- fprintf(stderr, "%s: Can't open display \"%s\"\n", argv0,
- XDisplayName(display));
- exit(1);
- }
-
- /* make sure percent is reasonable */
- if (argc > 1)
- percent = atof(argv[1]) / 100.0;
- if (percent < 0.0 || percent > 1.0)
- {
- fprintf(stderr, "%s: bogus percentage\n", argv0);
- exit(1);
- }
-
- /* how many bits to fill the window? */
- XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attributes);
-
- /* compute the byte count, rounding up, and get some memory */
- bytecount = ((attributes.width * attributes.height) + 7) / 8;
- if ((bits = malloc((unsigned) bytecount)) == NULL)
- {
- fprintf(stderr, "%s: Can't malloc\n", argv0);
- exit(1);
- }
-
- genbits(percent, bytecount, bits);
- setroot(attributes.width, attributes.height, bits, dpy);
- XCloseDisplay(dpy);
- exit(0);
- }
-
- setroot(w, h, bits, dpy)
- int w, h;
- char *bits;
- Display * dpy;
- {
- Pixmap bitmap;
- Pixmap pixmap;
- GC gc;
- XGCValues gcv;
- unsigned long length, after;
- int format;
- Atom prop, type;
- unsigned char *data;
-
- bitmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, w, h);
- if (bitmap == 0)
- {
- fprintf(stderr, "%s: Unable to store Bitmap\n", argv0);
- exit(1);
- }
-
- /* xphoon had these the other way round - why? */
- gcv.background = BlackPixel(dpy,DefaultScreen(dpy));
- gcv.foreground = WhitePixel(dpy,DefaultScreen(dpy));
- gc = XCreateGC(dpy, DefaultRootWindow(dpy), GCForeground|GCBackground, &gcv);
-
- pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), w, h,
- DefaultDepth(dpy, DefaultScreen(dpy)));
- if (pixmap == 0)
- {
- fprintf(stderr, "%s: Unable to create Pixmap", argv0);
- exit(1);
- }
-
- XCopyPlane(dpy, bitmap, pixmap, gc, 0, 0, w, h, 0, 0, 1L);
- XSetWindowBackgroundPixmap(dpy, DefaultRootWindow(dpy), pixmap);
- XFreeGC(dpy, gc);
- XFreePixmap(dpy, bitmap);
- XFreePixmap(dpy, pixmap);
- XClearWindow(dpy, DefaultRootWindow(dpy));
- XFlush(dpy);
-
- /* Not sure what this garbage does, but xsetroot has it, so... */
- prop = XInternAtom(dpy, "_XSETROOT_ID", False);
- (void) XGetWindowProperty(dpy, DefaultRootWindow(dpy), prop, 0L, 1L, True,
- AnyPropertyType, &type, &format, &length, &after, &data);
- if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
- XKillClient(dpy, *((Pixmap *)data));
- else if (type != None)
- fprintf(stderr, "%s: warning: _XSETROOT_ID property is garbage\n", argv0);
- XFlush(dpy);
- }
-
-