jta@prodnet.la.locus.com (JT Anderson) (04/06/91)
Submitted-by: JT Anderson <jta@prodnet.la.locus.com> Posting-number: Volume 12, Issue 52 Archive-name: xroach/patch1 Patch-To: xroach: Volume 12, Issue 51 ------- Patch-To: xroach: Volume 12, Issue 51 # This is a shar archive. Extract with sh, not csh. # The rest of this file will extract: # README squish.xbm xroach.patch1 # ----------------< cut here >---------------------- echo extracting - README sed 's/^X//' > README << '~FUNKY STUFF~' XThis patch to xroach adds two new options and support for virtual root Xwindow managers, such as tvtwm. It also fixes a couple of potential Xmemory faults. X XThe new options are -squish to enable squishing roaches with the mouse Xand -rgc to set the color of the roach guts that splash out. Yellowgreen Xis recommended. X XTo apply the patches, unpack this file in your xroach directory using sh Xthen incant: X X patch -p0 <xroach.patch1 ~FUNKY STUFF~ echo extracting - squish.xbm sed 's/^X//' > squish.xbm << '~FUNKY STUFF~' X#define squish_width 48 X#define squish_height 48 X#define squish_x_hot -1 X#define squish_y_hot -1 Xstatic char squish_bits[] = { X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x20, 0x00, X 0x00, 0x00, 0x18, 0x08, 0x02, 0x00, 0x00, 0x40, 0x41, 0x52, 0x28, 0x00, X 0x00, 0x80, 0x81, 0x1c, 0x13, 0x00, 0x00, 0x00, 0x12, 0x69, 0x00, 0x00, X 0x00, 0x30, 0x88, 0x40, 0x09, 0x00, 0x00, 0x40, 0x40, 0x00, 0x04, 0x00, X 0x00, 0x90, 0x06, 0x01, 0x30, 0x00, 0x00, 0x98, 0x80, 0x02, 0x10, 0x00, X 0x80, 0x20, 0x00, 0x80, 0x44, 0x00, 0x00, 0x0c, 0x82, 0xb0, 0x00, 0x00, X 0x80, 0x22, 0x20, 0x10, 0x44, 0x00, 0x00, 0x04, 0x1e, 0xa1, 0x00, 0x00, X 0x00, 0x04, 0x02, 0xa6, 0x18, 0x06, 0x00, 0x80, 0x00, 0x80, 0x8b, 0x00, X 0x00, 0x88, 0x0e, 0x02, 0x01, 0x00, 0x40, 0x04, 0x05, 0x62, 0x50, 0x04, X 0x40, 0x00, 0x01, 0x50, 0x09, 0x00, 0x00, 0x28, 0x12, 0x13, 0x88, 0x04, X 0x40, 0xc1, 0x30, 0x40, 0x02, 0x00, 0x60, 0x02, 0x03, 0x50, 0xc1, 0x01, X 0x00, 0x42, 0x16, 0x94, 0x80, 0x06, 0x00, 0x00, 0x40, 0x10, 0x40, 0x00, X 0x00, 0x94, 0x10, 0xe4, 0x34, 0x02, 0x00, 0x80, 0x1c, 0x84, 0x89, 0x00, X 0x00, 0x11, 0x00, 0x00, 0x20, 0x02, 0x00, 0x30, 0x10, 0x80, 0x54, 0x00, X 0x00, 0x20, 0x91, 0xa5, 0xc4, 0x00, 0x00, 0x22, 0x20, 0x28, 0x92, 0x00, X 0x00, 0x52, 0x08, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x90, 0x02, 0x2c, 0x00, X 0x00, 0x10, 0x01, 0x49, 0x00, 0x00, 0x00, 0x40, 0x04, 0x12, 0x0e, 0x00, X 0x00, 0x00, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 0x01, 0x00, X 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ~FUNKY STUFF~ echo extracting - xroach.patch1 sed 's/^X//' > xroach.patch1 << '~FUNKY STUFF~' X*** patchlevel.h Tue Apr 02 11:59:19 1991 X--- ../xroach/patchlevel.h Tue Apr 02 11:57:25 1991 X*************** X*** 1 **** X! #define PATCHLEVEL 0 X--- 1,4 ---- X! X! /* @(#)patchlevel.h 1.2 4/2/91 11:57:18 */ X! X! #define PATCHLEVEL 1 X*** roachmap.h Tue Apr 02 11:59:19 1991 X--- ../xroach/roachmap.h Tue Apr 02 11:55:42 1991 X*************** X*** 1,3 **** X--- 1,6 ---- X+ X+ /* @(#)roachmap.h 1.3 4/2/91 11:55:35 */ X+ X #include "roach000.xbm" X #include "roach015.xbm" X #include "roach030.xbm" X*************** X*** 22,27 **** X--- 25,32 ---- X #include "roach315.xbm" X #include "roach330.xbm" X #include "roach345.xbm" X+ X+ #include "squish.xbm" X X #define ROACH_HEADINGS 24 /* number of orientations */ X #define ROACH_ANGLE 15 /* angle between orientations */ X*** xroach.c Tue Apr 02 11:59:18 1991 X--- ../xroach/xroach.c Tue Apr 02 11:53:42 1991 X*************** X*** 12,21 **** X--- 12,31 ---- X cc -o xroach roach.c -lX11 [-lsocketorwhatever] [-lm] [-l...] X X Dedicated to Greg McFarlane. (gregm@otc.otca.oz.au) X+ X+ Squish option contributed by Rick Petkiewizc (rick@locus.com) X+ X+ Virtual root code adapted from patch sent by Colin Rafferty who X+ borrowed it from Tom LaStrange. Several other folks sent similar X+ fixes. X */ X+ X+ /* @(#)xroach.c 1.5 4/2/91 11:53:31 */ X+ X #include <X11/Xlib.h> X #include <X11/Xutil.h> X #include <X11/Xos.h> X+ #include <X11/Xatom.h> X X #include <stdio.h> X #include <math.h> X*************** X*** 49,54 **** X--- 59,65 ---- X unsigned int display_width, display_height; X int center_x, center_y; X GC gc; X+ GC gutsGC; X char *display_name = NULL; X Pixel black, white; X X*************** X*** 55,60 **** X--- 66,74 ---- X int done = 0; X int eventBlock = 0; X int errorVal = 0; X+ Bool squishRoach = False; X+ Pixmap squishMap; X+ Bool squishWinUp = False; X X typedef struct Roach { X RoachMap *rp; X*************** X*** 84,89 **** X--- 98,104 ---- X int CalcRootVisible(); X int MarkHiddenRoaches(); X Pixel AllocNamedColor(); X+ Window FindRootWindow(); X X void X main(ac, av) X*************** X*** 98,105 **** X--- 113,123 ---- X float angle; X XEvent ev; X char *roachColor = "black"; X+ char *gutsColor = NULL; X int nVis; X int needCalc; X+ Window squishWin; X+ XSetWindowAttributes xswa; X X /* X Process command line options. X*************** X*** 118,123 **** X--- 136,147 ---- X else if (strcmp(arg, "-roaches") == 0) { X maxRoaches = strtol(av[++ax], (char **)NULL, 0); X } X+ else if (strcmp(arg, "-squish") == 0) { X+ squishRoach = True; X+ } X+ else if (strcmp(arg, "-rgc") == 0) { X+ gutsColor = av[++ax]; X+ } X else { X Usage(); X } X*************** X*** 142,148 **** X } X X screen = DefaultScreen(display); X! rootWin = RootWindow(display, screen); X black = BlackPixel(display, screen); X white = WhitePixel(display, screen); X X--- 166,172 ---- X } X X screen = DefaultScreen(display); X! rootWin = FindRootWindow(); X black = BlackPixel(display, screen); X white = WhitePixel(display, screen); X X*************** X*** 164,179 **** X--- 188,229 ---- X rp->cosine = cos(angle); X } X X+ /* X+ Create the squished pixmap X+ */ X+ if (squishRoach) { X+ squishMap = XCreateBitmapFromData(display, rootWin, X+ squish_bits, squish_width, squish_height); X+ } X+ X roaches = (Roach *)malloc(sizeof(Roach) * maxRoaches); X X gc = XCreateGC(display, rootWin, 0L, &xgcv); X XSetForeground(display, gc, AllocNamedColor(roachColor, black)); X XSetFillStyle(display, gc, FillStippled); X+ X+ if (squishRoach && gutsColor != NULL) { X+ gutsGC = XCreateGC(display, rootWin, 0L, &xgcv); X+ XSetForeground(display, gutsGC, AllocNamedColor(gutsColor, black)); X+ XSetFillStyle(display, gutsGC, FillStippled); X+ } X+ else X+ gutsGC = gc; X X while (curRoaches < maxRoaches) X AddRoach(); X X XSelectInput(display, rootWin, ExposureMask | SubstructureNotifyMask); X+ X+ if (squishRoach) { X+ xswa.event_mask = ButtonPressMask; X+ xswa.override_redirect = True; X+ squishWin = XCreateWindow(display, rootWin, 0, 0, X+ display_width, display_height, 0, X+ CopyFromParent, InputOnly, CopyFromParent, X+ CWOverrideRedirect | CWEventMask, &xswa); X+ XLowerWindow(display, squishWin); X+ } X X needCalc = 1; X while (!done) { X*************** X*** 184,195 **** X if (needCalc) { X needCalc = CalcRootVisible(); X } X! nVis = MarkHiddenRoaches(); X if (nVis) { X ev.type = SCAMPER_EVENT; X } X else { X! DrawRoaches(); X eventBlock = 1; X XNextEvent(display, &ev); X eventBlock = 0; X--- 234,257 ---- X if (needCalc) { X needCalc = CalcRootVisible(); X } X! if (needCalc) X! nVis = 0; X! else X! nVis = MarkHiddenRoaches(); X if (nVis) { X ev.type = SCAMPER_EVENT; X+ if (!squishWinUp && squishRoach) { X+ XMapWindow(display, squishWin); X+ squishWinUp = True; X+ } X } X else { X! if (squishWinUp && squishRoach) { X! XUnmapWindow(display, squishWin); X! squishWinUp = False; X! } X! if (needCalc == 0) X! DrawRoaches(); X eventBlock = 1; X XNextEvent(display, &ev); X eventBlock = 0; X*************** X*** 207,218 **** X XSync(display, False); X break; X X- case Expose: X- case MapNotify: X case UnmapNotify: X case ConfigureNotify: X needCalc = 1; X break; X X } X } X--- 269,288 ---- X XSync(display, False); X break; X X case UnmapNotify: X+ if (ev.xunmap.window != squishWin) X+ needCalc = 1; X+ break; X+ X+ case MapNotify: X+ case Expose: X case ConfigureNotify: X needCalc = 1; X break; X+ X+ case ButtonPress: X+ checkSquish(&ev); X+ break; X X } X } X*************** X*** 233,238 **** X--- 303,310 ---- X USEPRT(" -rc roachcolor\n"); X USEPRT(" -roaches numroaches\n"); X USEPRT(" -speed roachspeed\n"); X+ USEPRT(" -squish\n"); X+ USEPRT(" -rgc roachgutscolor\n"); X X exit(1); X } X*************** X*** 256,261 **** X--- 328,391 ---- X } X X /* X+ Find the root or virtual root window. X+ */ X+ Window X+ FindRootWindow() X+ { X+ Window rootWin; X+ Window realRoot; X+ Atom swmVroot; X+ Window rootReturn, parentReturn, *children; X+ unsigned int numChildren; X+ int cx; X+ Atom actualType; X+ Atom actualFormat; X+ unsigned long nItems; X+ unsigned long bytesAfter; X+ Window *newRoot; X+ X+ /* X+ Get real root window. X+ */ X+ realRoot = rootWin = RootWindow(display, screen); X+ X+ /* X+ Get atom for virtual root property. If the atom doesn't X+ exist, we can assume the corresponding property does not X+ exist. X+ */ X+ swmVroot = XInternAtom(display, "__SWM_VROOT", True); X+ X+ if (swmVroot == None) X+ return rootWin; X+ X+ /* X+ Run children of root, looking for a virtual root. X+ */ X+ XQueryTree(display, rootWin, &rootReturn, &parentReturn, X+ &children, &numChildren); X+ for (cx=0; cx<numChildren; cx++) { X+ newRoot = NULL; X+ nItems = 0; X+ if (XGetWindowProperty(display, children[cx], swmVroot, 0L, 1L, False, X+ XA_WINDOW, &actualType, &actualFormat, &nItems, X+ &bytesAfter, &newRoot) == Success && actualFormat != None) { X+ if (nItems >= 1) { X+ rootWin = *newRoot; X+ } X+ if (newRoot) { X+ XFree(newRoot); X+ } X+ } X+ if (rootWin != realRoot) break; X+ } X+ XFree(children); X+ X+ return rootWin; X+ } X+ X+ /* X Generate random integer between 0 and maxVal-1. X */ X int X*************** X*** 404,410 **** X for (rx=0; rx<curRoaches; rx++) { X roach = &roaches[rx]; X X! if (roach->intX >= 0) { X XClearArea(display, rootWin, roach->intX, roach->intY, X roach->rp->width, roach->rp->height, False); X } X--- 534,540 ---- X for (rx=0; rx<curRoaches; rx++) { X roach = &roaches[rx]; X X! if (roach->intX >= 0 && roach->rp != NULL) { X XClearArea(display, rootWin, roach->intX, roach->intY, X roach->rp->width, roach->rp->height, False); X } X*************** X*** 505,515 **** X */ X covered = XCreateRegion(); X for (wx=0; wx<nChildren; wx++) { X! if (XEventsQueued(display, QueuedAlready)) return 1; X errorVal = 0; X XGetWindowAttributes(display, children[wx], &wa); X if (errorVal) continue; X! if (wa.map_state == IsViewable) { X XGetGeometry(display, children[wx], &dummy, &winX, &winY, X &winWidth, &winHeight, &borderWidth, &depth); X if (errorVal) continue; X--- 635,648 ---- X */ X covered = XCreateRegion(); X for (wx=0; wx<nChildren; wx++) { X! if (XEventsQueued(display, QueuedAlready)) { X! XDestroyRegion(covered); X! return 1; X! } X errorVal = 0; X XGetWindowAttributes(display, children[wx], &wa); X if (errorVal) continue; X! if (wa.class == InputOutput && wa.map_state == IsViewable) { X XGetGeometry(display, children[wx], &dummy, &winX, &winY, X &winWidth, &winHeight, &borderWidth, &depth); X if (errorVal) continue; X*************** X*** 606,609 **** X--- 739,783 ---- X } X X return pix; X+ } X+ X+ /* X+ * squishCheck - Check to see if we have to squish any roaches. X+ */ X+ checkSquish(buttonEvent) X+ XButtonEvent *buttonEvent; X+ { X+ int x, y; X+ int i; X+ int rx; X+ Roach *r; X+ /* */ X+ x = buttonEvent->x; X+ y = buttonEvent->y; X+ X+ for (rx=0; rx<curRoaches; rx++) { X+ r = &roaches[rx]; X+ if (r->rp == NULL) continue; X+ X+ if (x > r->intX && X+ x < (r->intX + r->rp->width) && X+ y > r->intY && X+ y < (r->intY + r->rp->height)) { X+ XSetStipple(display, gutsGC, squishMap); X+ XSetTSOrigin(display, gutsGC, r->intX, r->intY); X+ XFillRectangle(display, rootWin, gutsGC, X+ r->intX, r->intY, squish_width, squish_height); X+ X+ /* X+ * Delete the roach X+ */ X+ for (i = rx; i < curRoaches - 1; i++) X+ roaches[i] = roaches[i + 1]; X+ X+ curRoaches--; X+ rx--; X+ } X+ } X+ X+ return; X } X*** xroach.man Tue Apr 02 12:26:11 1991 X--- ../xroach/xroach.man Tue Apr 02 12:46:43 1991 X*************** X*** 9,15 **** X displays disgusting cockroaches on your root window. These creapy crawlies X scamper X around until they find a window to hide under. Whenever you move or iconify X! a window, the exposed beetles again scamper for cover. X .SH OPTIONS X .TP 8 X .B \-display \fIdisplay_name\fB X--- 9,15 ---- X displays disgusting cockroaches on your root window. These creapy crawlies X scamper X around until they find a window to hide under. Whenever you move or iconify X! a window, the exposed orthopteras again scamper for cover. X .SH OPTIONS X .TP 8 X .B \-display \fIdisplay_name\fB X*************** X*** 26,31 **** X--- 26,38 ---- X .TP 8 X .B \-roaches \fInum_roaches\fB X This is the number of the little critters. Default is 10. X+ .TP 8 X+ .B \-squish X+ Enables roach squishing. Point and shoot with any mouse button. X+ .TP 8 X+ .B \-rgc \fIroach_gut_color\fB X+ Sets color of the guts that spill out of squished roaches. We recommend X+ yellowgreen. X .SH BUGS X As given by the -roaches option. Default is 10. X .SH COPYRIGHT ~FUNKY STUFF~ -- Dan Heller ------------------------------------------------ O'Reilly && Associates Z-Code Software Senior Writer President