|
|
1.1 ! root 1: /* ! 2: * $Locker: sun $ ! 3: */ ! 4: static char *rcsid = "$Header: plaid.c,v 1.2 87/09/07 16:07:45 sun Locked $"; ! 5: /*********************************************************** ! 6: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, ! 7: and the Massachusetts Institute of Technology, Cambridge, Massachusetts. ! 8: ! 9: All Rights Reserved ! 10: ! 11: Permission to use, copy, modify, and distribute this software and its ! 12: documentation for any purpose and without fee is hereby granted, ! 13: provided that the above copyright notice appear in all copies and that ! 14: both that copyright notice and this permission notice appear in ! 15: supporting documentation, and that the names of Digital or MIT not be ! 16: used in advertising or publicity pertaining to distribution of the ! 17: software without specific, written prior permission. ! 18: ! 19: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 20: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 21: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 22: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 23: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 24: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 25: SOFTWARE. ! 26: ! 27: ******************************************************************/ ! 28: #include "X11/Xlib.h" ! 29: #include "X11/Xatom.h" ! 30: #include <stdio.h> ! 31: #include <errno.h> ! 32: ! 33: extern int errno; ! 34: ! 35: int rand(); ! 36: char *malloc(); ! 37: ! 38: Window XCreateWindow(); ! 39: ! 40: Window myWin, newWin, threeWin; ! 41: ! 42: Display *dpy; ! 43: ! 44: #define NUMRECTS 10 ! 45: XRectangle rects[NUMRECTS]; ! 46: GContext gc; ! 47: ! 48: main(argc, argv) ! 49: int argc; ! 50: char *argv[]; ! 51: { ! 52: int amount, i, j ; ! 53: char *geom = NULL; ! 54: int winx, winy, winw, winh; ! 55: register int xdir, ydir; ! 56: register int xoff, yoff; ! 57: register int centerX, centerY; ! 58: XGCValues xgcv; ! 59: XSetWindowAttributes xswa; ! 60: XEvent pe; ! 61: XExposeEvent *ee; ! 62: Window root; ! 63: int x, y, w, h; ! 64: unsigned int bw, d; ! 65: char *display; ! 66: int bs = NotUseful; ! 67: Visual visual; ! 68: ! 69: for (i=1; i < argc; i++) ! 70: { ! 71: if (argv [i] [0] == '=') ! 72: geom = argv[i]; ! 73: else if (index(argv[i], ':') != NULL) ! 74: display = argv[i]; ! 75: else if (argv[i][0] == 'b') ! 76: bs = Always; ! 77: } ! 78: ! 79: if (!(dpy = XOpenDisplay(display))) ! 80: { ! 81: perror("Cannot open display\n"); ! 82: exit(-1); ! 83: } ! 84: ! 85: winx = 0; ! 86: winy = 0; ! 87: winw = 101; ! 88: winh = 201; ! 89: ! 90: if (geom) ! 91: { ! 92: if (XParseGeometry(geom, &winx, &winy, &winw, &winh)) ! 93: { ! 94: printf("Geometry specified incorrectly. Using default\n"); ! 95: } ! 96: } ! 97: ! 98: xswa.backing_store = bs; ! 99: xswa.event_mask = ExposureMask | StructureNotifyMask; ! 100: xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy)); ! 101: xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy)); ! 102: visual.visualid = CopyFromParent; ! 103: myWin = XCreateWindow(dpy, ! 104: RootWindow(dpy, DefaultScreen(dpy)), ! 105: winx, winy, winw, winh, 1, ! 106: DefaultDepth(dpy, DefaultScreen(dpy)), InputOutput, ! 107: &visual, ! 108: CWEventMask | CWBackingStore | CWBorderPixel | CWBackPixel, ! 109: &xswa); ! 110: ! 111: XChangeProperty(dpy, myWin, XA_WM_NAME, XA_STRING, 8, ! 112: PropModeReplace, "Plaid", 5); ! 113: XMapWindow(dpy, myWin); ! 114: ! 115: xgcv.function = GXinvert; ! 116: xgcv.fill_style = FillSolid; ! 117: gc = (GContext)XCreateGC(dpy, myWin, GCFunction | GCFillStyle, &xgcv); ! 118: j=0; ! 119: while(1) ! 120: { ! 121: XNextEvent(dpy, &pe); /* this should get first exposure event */ ! 122: if (pe.type == Expose) ! 123: { ! 124: ee = (XExposeEvent *) &pe; ! 125: while (ee->count) ! 126: { ! 127: XNextEvent(dpy, &pe); ! 128: ee = (XExposeEvent *) &pe; ! 129: } ! 130: } ! 131: else if (pe.type == ConfigureNotify) ! 132: { ! 133: XConfigureEvent *ce = (XConfigureEvent *)&pe; ! 134: winx = ce->x; ! 135: winy = ce->y; ! 136: winw = ce->width; ! 137: winh = ce->height; ! 138: } ! 139: else ! 140: printf("Unknown event type: %d\n", pe.type); ! 141: ! 142: printf("PLAID: Dealing with exposures\n"); ! 143: XClearArea(dpy, myWin, 0, 0, winw, winh, 0); ! 144: printf("PLAID: drawing rects\n"); ! 145: ! 146: centerX = winw / 2; ! 147: centerY = winh / 2; ! 148: xdir = ydir = -2; ! 149: xoff = yoff = 2; ! 150: ! 151: i = 0; ! 152: while (! XPending(dpy)) ! 153: { ! 154: ! 155: rects[i].x = centerX - xoff; ! 156: rects[i].y = centerY - yoff; ! 157: rects[i].width = 2 * xoff; ! 158: rects[i].height = 2 * yoff; ! 159: xoff += xdir; ! 160: yoff += ydir; ! 161: if ((xoff <= 0) || (xoff >= centerX)) ! 162: { ! 163: xoff -= 2*xdir; ! 164: xdir = -xdir; ! 165: } ! 166: if ((yoff <= 0) || (yoff >= centerY)) ! 167: { ! 168: yoff -= 2*ydir; ! 169: ydir = -ydir; ! 170: } ! 171: if (i == (NUMRECTS - 1)) ! 172: { ! 173: XFillRectangles(dpy, myWin, gc, rects, NUMRECTS); ! 174: i = 0; ! 175: } ! 176: else ! 177: i++; ! 178: } ! 179: } ! 180: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.