--- ray/src/rt/x11.c 1992/05/29 10:57:15 2.2 +++ ray/src/rt/x11.c 1992/06/24 09:12:50 2.6 @@ -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,7 +23,7 @@ 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 */ @@ -38,8 +38,6 @@ static char SCCSid[] = "$SunId$ LBL"; #define ourscreen DefaultScreen(ourdisplay) #define ourroot RootWindow(ourdisplay,ourscreen) -#define ourwhite WhitePixel(ourdisplay,ourscreen) -#define ourblack BlackPixel(ourdisplay,ourscreen) #define levptr(etype) ((etype *)¤tevent) @@ -47,6 +45,7 @@ static XEvent currentevent; /* current event */ static int ncolors = 0; /* color table size */ static unsigned long *pixval = NULL; /* allocated pixels */ +static unsigned long ourblack=0, ourwhite=1; static Display *ourdisplay = NULL; /* our display */ @@ -83,6 +82,8 @@ struct driver * x11_init(name, id) /* initialize driver */ char *name, *id; { + extern char *getenv(); + char *gv; int nplanes; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; @@ -95,25 +96,38 @@ 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)) { stderr_v("unsupported visual type\n"); return(NULL); } - make_gmap(GAMMA); - /* open window */ + ourblack = BlackPixel(ourdisplay,ourscreen); + ourwhite = WhitePixel(ourdisplay,ourscreen); + } + /* 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, @@ -125,7 +139,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); @@ -205,9 +219,8 @@ int xres, yres; /* get new command line */ if (comline != NULL) xt_close(comline); - comline = xt_open(ourdisplay, - DefaultGC(ourdisplay,ourscreen), - gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); + comline = xt_open(ourdisplay, gwind, 0, gheight, + gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN); if (comline == NULL) { stderr_v("Cannot open command line window\n"); quit(1);