--- ray/src/rt/x11.c 1990/03/08 10:09:58 1.12 +++ ray/src/rt/x11.c 1990/12/21 17:27:31 1.17 @@ -45,7 +45,7 @@ static char SCCSid[] = "$SunId$ LBL"; static XEvent currentevent; /* current event */ static int ncolors = 0; /* color table size */ -static int *pixval = NULL; /* allocated pixels */ +static unsigned long *pixval = NULL; /* allocated pixels */ static Display *ourdisplay = NULL; /* our display */ @@ -67,9 +67,9 @@ static GC ourgc = 0; /* our graphics context for dr static Colormap ourmap = 0; /* our color map */ -extern char *malloc(); +extern char *malloc(), *getcombuf(); -int x11_close(), x11_clear(), x11_paintr(), x11_errout(), +static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), x11_getcur(), x11_comout(), x11_comin(), x11_flush(); static struct driver x11_driver = { @@ -100,12 +100,15 @@ char *name, *id; } else if (nplanes <= 12) { if (!XMatchVisualInfo(ourdisplay,ourscreen, nplanes,PseudoColor,&ourvinfo)) { - stderr_v("PseudoColor not supported\n"); + stderr_v("PseudoColor server required\n"); return(NULL); } } else if (!XMatchVisualInfo(ourdisplay,ourscreen, - nplanes,TrueColor,&ourvinfo)) { - stderr_v("TrueColor not supported\n"); + nplanes,TrueColor,&ourvinfo) && + /* kludge for DirectColor */ + !XMatchVisualInfo(ourdisplay,ourscreen, + nplanes,DirectColor,&ourvinfo)) { + stderr_v("TrueColor server required\n"); return(NULL); } ourvisual = ourvinfo.visual; @@ -135,7 +138,7 @@ char *name, *id; XSetNormalHints(ourdisplay, gwind, &oursizhints); XSelectInput(ourdisplay, gwind, ExposureMask); XMapWindow(ourdisplay, gwind); - XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); + XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); gwidth = levptr(XExposeEvent)->width; gheight = levptr(XExposeEvent)->height - COMHEIGHT; x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; @@ -175,9 +178,6 @@ static x11_clear(xres, yres) /* clear our display */ int xres, yres; { - /* destroy command line */ - if (comline != NULL) - xt_close(comline); /* check limits */ if (xres < MINWIDTH) xres = MINWIDTH; @@ -193,7 +193,16 @@ int xres, yres; sleep(2); /* wait for window manager */ XSync(ourdisplay, 1); /* discard input */ } + XClearWindow(ourdisplay, gwind); + /* reinitialize color table */ + if (ourvisual->class == PseudoColor) + if (getpixels() == 0) + stderr_v("cannot allocate colors\n"); + else + new_ctab(ncolors); /* get new command line */ + if (comline != NULL) + xt_close(comline); comline = xt_open(ourdisplay, DefaultGC(ourdisplay,ourscreen), gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); @@ -202,14 +211,6 @@ int xres, yres; quit(1); } XSelectInput(ourdisplay, comline->w, ExposureMask); - /* clear graphics window */ - XClearWindow(ourdisplay, gwind); - /* reinitialize color table */ - if (ourvisual->class == PseudoColor) - if (getpixels() == 0) - stderr_v("cannot allocate colors\n"); - else - new_ctab(ncolors); /* remove earmuffs */ XSelectInput(ourdisplay, gwind, StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); @@ -227,7 +228,7 @@ int xmin, ymin, xmax, ymax; if (ncolors > 0) pixel = pixval[get_pixel(col, xnewcolr)]; - else if (ourvisual->class == TrueColor) + else if (ourvisual->class != PseudoColor) pixel = true_pixel(col); else return; @@ -250,7 +251,7 @@ static x11_comin(inp, prompt) /* read in a command line */ char *inp, *prompt; { - int x11_getc(), x11_comout(); + extern int x11_getc(); if (prompt != NULL) if (fromcombuf(inp, &x11_driver)) @@ -335,8 +336,11 @@ int r, g, b; static int getpixels() /* get the color map */ { + XColor thiscolor; + register int i, j; + if (ncolors > 0) - return(ncolors); + goto donecolors; if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { ourmap = DefaultColormap(ourdisplay,ourscreen); goto loop; @@ -347,7 +351,7 @@ loop: for (ncolors = ourvisual->map_entries; ncolors > ourvisual->map_entries/3; ncolors = ncolors*.937) { - pixval = (int *)malloc(ncolors*sizeof(int)); + pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); if (pixval == NULL) return(ncolors = 0); if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, @@ -362,11 +366,8 @@ loop: else return(ncolors = 0); /* failed */ } - if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { - XColor thiscolor; - register int i, j; - /* reset black and white */ - for (i = 0; i < ncolors; i++) { + if (ourmap != DefaultColormap(ourdisplay,ourscreen)) + for (i = 0; i < ncolors; i++) { /* reset black and white */ if (pixval[i] != ourblack && pixval[i] != ourwhite) continue; thiscolor.pixel = pixval[i]; @@ -380,8 +381,16 @@ loop: ncolors--; i--; } - } XSetWindowColormap(ourdisplay, gwind, ourmap); +donecolors: +#ifdef DEBUG + thiscolor.flags = DoRed|DoGreen|DoBlue; + thiscolor.red = thiscolor.green = thiscolor.blue = 0; + for (i = 0; i < ncolors; i++) { + thiscolor.pixel = pixval[i]; + XStoreColor(ourdisplay, ourmap, &thiscolor); + } +#endif return(ncolors); }