--- ray/src/rt/x11.c 1992/05/29 15:42:49 2.3 +++ ray/src/rt/x11.c 1993/02/11 16:33:10 2.9 @@ -1,11 +1,11 @@ +/* Copyright (c) 1992 Regents of the University of California */ + #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif -/* Copyright (c) 1989 Regents of the University of California */ - /* - * x11.c - driver for X-windows version 11.3 + * x11.c - driver for X-windows version 11 * * Jan 1990 */ @@ -23,10 +23,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "x11twind.h" #include "x11icon.h" -#define GAMMA 2.2 /* exponent for color correction */ +#define GAMMA 2.2 /* default exponent correction */ #define MINWIDTH (32*COMCW) /* minimum graphics window width */ -#define MINHEIGHT MINWIDTH /* minimum graphics window height */ +#define MINHEIGHT (MINWIDTH/2) /* minimum graphics window height */ #define BORWIDTH 5 /* border width */ #define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ @@ -44,6 +44,7 @@ static char SCCSid[] = "$SunId$ LBL"; static XEvent currentevent; /* current event */ static int ncolors = 0; /* color table size */ +static int mapped = 0; /* window is mapped? */ static unsigned long *pixval = NULL; /* allocated pixels */ static unsigned long ourblack=0, ourwhite=1; @@ -82,6 +83,8 @@ struct driver * x11_init(name, id) /* initialize driver */ char *name, *id; { + extern char *getenv(); + char *gv; int nplanes; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; @@ -94,14 +97,20 @@ char *name, *id; } /* find a usable visual */ nplanes = DisplayPlanes(ourdisplay, ourscreen); - if ( !XMatchVisualInfo(ourdisplay,ourscreen, - 24,TrueColor,&ourvinfo) && - !XMatchVisualInfo(ourdisplay,ourscreen, - 24,DirectColor,&ourvinfo) ) { + if (XMatchVisualInfo(ourdisplay,ourscreen, + 24,TrueColor,&ourvinfo) || + XMatchVisualInfo(ourdisplay,ourscreen, + 24,DirectColor,&ourvinfo)) { + ourblack = 0; + ourwhite = ourvinfo.red_mask | + ourvinfo.green_mask | + ourvinfo.blue_mask ; + } else { if (nplanes < 4) { stderr_v("not enough colors\n"); return(NULL); - } else if (!XMatchVisualInfo(ourdisplay,ourscreen, + } + if (!XMatchVisualInfo(ourdisplay,ourscreen, nplanes,PseudoColor,&ourvinfo) && !XMatchVisualInfo(ourdisplay,ourscreen, nplanes,GrayScale,&ourvinfo)) { @@ -110,15 +119,16 @@ char *name, *id; } ourblack = BlackPixel(ourdisplay,ourscreen); ourwhite = WhitePixel(ourdisplay,ourscreen); - } else { - ourblack = 0; - ourwhite = ~0; } - make_gmap(GAMMA); - /* open window */ + /* set gamma */ + if ((gv = getenv("GAMMA")) != NULL) + make_gmap(atof(gv)); + else + make_gmap(GAMMA); + /* open window */ ourwinattr.background_pixel = ourblack; ourwinattr.border_pixel = ourblack; - /* this is a waste! */ + /* this is stupid */ ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, ourvinfo.visual, AllocNone); gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, @@ -130,7 +140,7 @@ char *name, *id; stderr_v("cannot create window\n"); return(NULL); } - XStoreName(ourdisplay, gwind, id); + XStoreName(ourdisplay, gwind, id); /* create a cursor */ pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); @@ -151,6 +161,7 @@ char *name, *id; x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; x11_driver.inpready = 0; + mapped = 1; cmdvec = x11_comout; /* set error vectors */ if (wrnvec != NULL) wrnvec = x11_errout; @@ -232,12 +243,12 @@ int xmin, ymin, xmax, ymax; extern unsigned long true_pixel(); unsigned long pixel; + if (!mapped) + return; if (ncolors > 0) pixel = pixval[get_pixel(col, xnewcolr)]; - else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor) - pixel = true_pixel(col); else - return; + pixel = true_pixel(col); XSetForeground(ourdisplay, ourgc, pixel); XFillRectangle(ourdisplay, gwind, ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); @@ -360,8 +371,7 @@ loop: pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); if (pixval == NULL) return(ncolors = 0); - if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, - pixval,ncolors) != 0) + if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) break; free((char *)pixval); pixval = NULL; @@ -398,6 +408,8 @@ freepixels() /* free our pixels */ if (ncolors == 0) return; XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); + free((char *)pixval); + pixval = NULL; ncolors = 0; if (ourmap != DefaultColormap(ourdisplay,ourscreen)) XFreeColormap(ourdisplay, ourmap); @@ -441,6 +453,7 @@ getevent() /* get next event */ resizewindow(levptr(XConfigureEvent)); break; case UnmapNotify: + mapped = 0; freepixels(); break; case MapNotify: @@ -450,6 +463,7 @@ getevent() /* get next event */ stderr_v("Cannot allocate colors\n"); else new_ctab(ncolors); + mapped = 1; break; case Expose: fixwindow(levptr(XExposeEvent));