--- ray/src/rt/x11.c 1990/02/23 14:50:38 1.7 +++ ray/src/rt/x11.c 1991/11/12 17:10:04 2.1 @@ -21,6 +21,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" #include "driver.h" #include "x11twind.h" +#include "x11icon.h" #define GAMMA 2.2 /* exponent for color correction */ @@ -45,7 +46,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 +68,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 = { @@ -84,8 +85,9 @@ char *name, *id; { int nplanes; XVisualInfo ourvinfo; + XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; - Pixmap bmCursorSrc, bmCursorMsk; + XSizeHints oursizhints; ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) { @@ -99,35 +101,47 @@ 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; make_gmap(GAMMA); - /* create a cursor */ - pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); /* open window */ - gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0, + ourwinattr.background_pixel = ourblack; + ourwinattr.border_pixel = ourblack; + gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, - BORWIDTH, ourblack, ourwhite); + BORWIDTH, nplanes, InputOutput, ourvisual, + CWBackPixel|CWBorderPixel, &ourwinattr); if (gwind == 0) { stderr_v("cannot create window\n"); return(NULL); } XStoreName(ourdisplay, gwind, id); + /* create a cursor */ + pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); - ourxwmhints.flags = InputHint; + ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; + ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, + gwind, x11icon_bits, x11icon_width, x11icon_height); XSetWMHints(ourdisplay, gwind, &ourxwmhints); + oursizhints.min_width = MINWIDTH; + oursizhints.min_height = MINHEIGHT+COMHEIGHT; + oursizhints.flags = PMinSize; + 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; @@ -152,13 +166,11 @@ x11_close() /* close our display */ xt_close(comline); comline = NULL; } - if (gwind != 0) { - freepixels(); - XFreeGC(ourdisplay, ourgc); - XDestroyWindow(ourdisplay, gwind); - gwind = 0; - ourgc = 0; - } + freepixels(); + XFreeGC(ourdisplay, ourgc); + XDestroyWindow(ourdisplay, gwind); + gwind = 0; + ourgc = 0; XFreeCursor(ourdisplay, pickcursor); XCloseDisplay(ourdisplay); ourdisplay = NULL; @@ -169,31 +181,40 @@ static x11_clear(xres, yres) /* clear our display */ int xres, yres; { - if (xres != gwidth || yres != gheight) { /* change window */ - if (comline != NULL) - xt_close(comline); + /* check limits */ + if (xres < MINWIDTH) + xres = MINWIDTH; + if (yres < MINHEIGHT) + yres = MINHEIGHT; + /* resize window */ + if (xres != gwidth || yres != gheight) { XSelectInput(ourdisplay, gwind, 0); XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); - comline = xt_open(ourdisplay, - DefaultGC(ourdisplay,ourscreen), - gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); - if (comline == NULL) { - stderr_v("Cannot open command line window\n"); - quit(1); - } - XSelectInput(ourdisplay, comline->w, ExposureMask); gwidth = xres; gheight = yres; - XSync(ourdisplay, 1); /* discard input */ + XFlush(ourdisplay); sleep(2); /* wait for window manager */ + XSync(ourdisplay, 1); /* discard input */ } XClearWindow(ourdisplay, gwind); - if (ourvisual->class == PseudoColor) /* reinitialize color table */ + /* 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); + if (comline == NULL) { + stderr_v("Cannot open command line window\n"); + quit(1); + } + XSelectInput(ourdisplay, comline->w, ExposureMask); + /* remove earmuffs */ XSelectInput(ourdisplay, gwind, StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); } @@ -210,7 +231,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; @@ -223,8 +244,7 @@ int xmin, ymin, xmax, ymax; static x11_flush() /* flush output */ { - if (ncolors <= 0) /* output necessary for death */ - XFillRectangle(ourdisplay, gwind, ourgc, 0, 0, 1 ,1); + XNoOp(ourdisplay); while (XPending(ourdisplay) > 0) getevent(); } @@ -234,7 +254,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)) @@ -251,9 +271,11 @@ static x11_comout(out) /* output a string to command line */ char *out; { - if (comline != NULL) - xt_puts(out, comline); - XFlush(ourdisplay); + if (comline == NULL) + return; + xt_puts(out, comline); + if (out[strlen(out)-1] == '\n') + XFlush(ourdisplay); } @@ -261,8 +283,8 @@ static x11_errout(msg) /* output an error message */ char *msg; { - x11_comout(msg); stderr_v(msg); /* send to stderr also! */ + x11_comout(msg); } @@ -317,8 +339,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; @@ -329,7 +354,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, @@ -344,11 +369,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]; @@ -362,8 +384,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); } @@ -375,7 +405,7 @@ freepixels() /* free our pixels */ return; XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); ncolors = 0; - if (ourmap != 0 && ourmap != DefaultColormap(ourdisplay,ourscreen)) + if (ourmap != DefaultColormap(ourdisplay,ourscreen)) XFreeColormap(ourdisplay, ourmap); ourmap = 0; } @@ -442,7 +472,7 @@ static getkey(ekey) /* get input key */ register XKeyPressedEvent *ekey; { - int n; + register int n; n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, NULL, NULL);