| 1 |
+ |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
+ |
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
#endif |
| 6 |
|
|
| 5 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
| 6 |
– |
|
| 7 |
|
/* |
| 8 |
< |
* x11.c - driver for X-windows version 11.3 |
| 8 |
> |
* x11.c - driver for X-windows version 11 |
| 9 |
|
* |
| 10 |
|
* Jan 1990 |
| 11 |
|
*/ |
| 21 |
|
#include "color.h" |
| 22 |
|
#include "driver.h" |
| 23 |
|
#include "x11twind.h" |
| 24 |
+ |
#include "x11icon.h" |
| 25 |
|
|
| 26 |
|
#define GAMMA 2.2 /* exponent for color correction */ |
| 27 |
|
|
| 38 |
|
|
| 39 |
|
#define ourscreen DefaultScreen(ourdisplay) |
| 40 |
|
#define ourroot RootWindow(ourdisplay,ourscreen) |
| 40 |
– |
#define ourwhite WhitePixel(ourdisplay,ourscreen) |
| 41 |
– |
#define ourblack BlackPixel(ourdisplay,ourscreen) |
| 41 |
|
|
| 42 |
|
#define levptr(etype) ((etype *)¤tevent) |
| 43 |
|
|
| 44 |
|
static XEvent currentevent; /* current event */ |
| 45 |
|
|
| 46 |
|
static int ncolors = 0; /* color table size */ |
| 47 |
< |
static int *pixval = NULL; /* allocated pixels */ |
| 47 |
> |
static unsigned long *pixval = NULL; /* allocated pixels */ |
| 48 |
> |
static unsigned long ourblack=0, ourwhite=1; |
| 49 |
|
|
| 50 |
|
static Display *ourdisplay = NULL; /* our display */ |
| 51 |
|
|
| 52 |
< |
static Visual *ourvisual; /* our visual structure */ |
| 52 |
> |
static XVisualInfo ourvinfo; /* our visual information */ |
| 53 |
|
|
| 54 |
|
static Window gwind = 0; /* our graphics window */ |
| 55 |
|
|
| 83 |
|
char *name, *id; |
| 84 |
|
{ |
| 85 |
|
int nplanes; |
| 86 |
– |
XVisualInfo ourvinfo; |
| 86 |
|
XSetWindowAttributes ourwinattr; |
| 87 |
|
XWMHints ourxwmhints; |
| 88 |
|
XSizeHints oursizhints; |
| 92 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
| 93 |
|
return(NULL); |
| 94 |
|
} |
| 95 |
+ |
/* find a usable visual */ |
| 96 |
|
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
| 97 |
< |
if (nplanes < 4) { |
| 98 |
< |
stderr_v("not enough colors\n"); |
| 99 |
< |
return(NULL); |
| 100 |
< |
} else if (nplanes <= 12) { |
| 97 |
> |
if (XMatchVisualInfo(ourdisplay,ourscreen, |
| 98 |
> |
24,TrueColor,&ourvinfo) || |
| 99 |
> |
XMatchVisualInfo(ourdisplay,ourscreen, |
| 100 |
> |
24,DirectColor,&ourvinfo)) { |
| 101 |
> |
ourblack = 0; |
| 102 |
> |
ourwhite = ourvinfo.red_mask | |
| 103 |
> |
ourvinfo.green_mask | |
| 104 |
> |
ourvinfo.blue_mask ; |
| 105 |
> |
} else { |
| 106 |
> |
if (nplanes < 4) { |
| 107 |
> |
stderr_v("not enough colors\n"); |
| 108 |
> |
return(NULL); |
| 109 |
> |
} |
| 110 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 111 |
< |
nplanes,PseudoColor,&ourvinfo)) { |
| 112 |
< |
stderr_v("PseudoColor server required\n"); |
| 111 |
> |
nplanes,PseudoColor,&ourvinfo) && |
| 112 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
| 113 |
> |
nplanes,GrayScale,&ourvinfo)) { |
| 114 |
> |
stderr_v("unsupported visual type\n"); |
| 115 |
|
return(NULL); |
| 116 |
|
} |
| 117 |
< |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 118 |
< |
nplanes,TrueColor,&ourvinfo) && |
| 108 |
< |
/* kludge for DirectColor */ |
| 109 |
< |
!XMatchVisualInfo(ourdisplay,ourscreen, |
| 110 |
< |
nplanes,DirectColor,&ourvinfo)) { |
| 111 |
< |
stderr_v("TrueColor server required\n"); |
| 112 |
< |
return(NULL); |
| 117 |
> |
ourblack = BlackPixel(ourdisplay,ourscreen); |
| 118 |
> |
ourwhite = WhitePixel(ourdisplay,ourscreen); |
| 119 |
|
} |
| 114 |
– |
ourvisual = ourvinfo.visual; |
| 120 |
|
make_gmap(GAMMA); |
| 121 |
|
/* open window */ |
| 122 |
|
ourwinattr.background_pixel = ourblack; |
| 123 |
|
ourwinattr.border_pixel = ourblack; |
| 124 |
+ |
/* this is stupid */ |
| 125 |
+ |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
| 126 |
+ |
ourvinfo.visual, AllocNone); |
| 127 |
|
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
| 128 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
| 129 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
| 130 |
< |
BORWIDTH, nplanes, InputOutput, ourvisual, |
| 131 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
| 130 |
> |
BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, |
| 131 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
| 132 |
|
if (gwind == 0) { |
| 133 |
|
stderr_v("cannot create window\n"); |
| 134 |
|
return(NULL); |
| 135 |
|
} |
| 136 |
< |
XStoreName(ourdisplay, gwind, id); |
| 136 |
> |
XStoreName(ourdisplay, gwind, id); |
| 137 |
|
/* create a cursor */ |
| 138 |
|
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
| 139 |
|
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
| 140 |
< |
ourxwmhints.flags = InputHint; |
| 140 |
> |
ourxwmhints.flags = InputHint|IconPixmapHint; |
| 141 |
|
ourxwmhints.input = True; |
| 142 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
| 143 |
+ |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
| 144 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 145 |
|
oursizhints.min_width = MINWIDTH; |
| 146 |
|
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
| 148 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 149 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
| 150 |
|
XMapWindow(ourdisplay, gwind); |
| 151 |
< |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); |
| 151 |
> |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
| 152 |
|
gwidth = levptr(XExposeEvent)->width; |
| 153 |
|
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
| 154 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 205 |
|
} |
| 206 |
|
XClearWindow(ourdisplay, gwind); |
| 207 |
|
/* reinitialize color table */ |
| 208 |
< |
if (ourvisual->class == PseudoColor) |
| 208 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
| 209 |
|
if (getpixels() == 0) |
| 210 |
|
stderr_v("cannot allocate colors\n"); |
| 211 |
|
else |
| 213 |
|
/* get new command line */ |
| 214 |
|
if (comline != NULL) |
| 215 |
|
xt_close(comline); |
| 216 |
< |
comline = xt_open(ourdisplay, |
| 217 |
< |
DefaultGC(ourdisplay,ourscreen), |
| 208 |
< |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
| 216 |
> |
comline = xt_open(ourdisplay, gwind, 0, gheight, |
| 217 |
> |
gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN); |
| 218 |
|
if (comline == NULL) { |
| 219 |
|
stderr_v("Cannot open command line window\n"); |
| 220 |
|
quit(1); |
| 237 |
|
|
| 238 |
|
if (ncolors > 0) |
| 239 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
| 240 |
< |
else if (ourvisual->class != PseudoColor) |
| 240 |
> |
else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor) |
| 241 |
|
pixel = true_pixel(col); |
| 242 |
|
else |
| 243 |
|
return; |
| 345 |
|
static int |
| 346 |
|
getpixels() /* get the color map */ |
| 347 |
|
{ |
| 348 |
+ |
XColor thiscolor; |
| 349 |
+ |
register int i, j; |
| 350 |
+ |
|
| 351 |
|
if (ncolors > 0) |
| 352 |
|
return(ncolors); |
| 353 |
< |
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
| 353 |
> |
if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) { |
| 354 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
| 355 |
|
goto loop; |
| 356 |
|
} |
| 357 |
|
newmap: |
| 358 |
< |
ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone); |
| 358 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone); |
| 359 |
|
loop: |
| 360 |
< |
for (ncolors = ourvisual->map_entries; |
| 361 |
< |
ncolors > ourvisual->map_entries/3; |
| 360 |
> |
for (ncolors = ourvinfo.colormap_size; |
| 361 |
> |
ncolors > ourvinfo.colormap_size/3; |
| 362 |
|
ncolors = ncolors*.937) { |
| 363 |
< |
pixval = (int *)malloc(ncolors*sizeof(int)); |
| 363 |
> |
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
| 364 |
|
if (pixval == NULL) |
| 365 |
|
return(ncolors = 0); |
| 366 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
| 375 |
|
else |
| 376 |
|
return(ncolors = 0); /* failed */ |
| 377 |
|
} |
| 378 |
< |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { |
| 379 |
< |
XColor thiscolor; |
| 368 |
< |
register int i, j; |
| 369 |
< |
/* reset black and white */ |
| 370 |
< |
for (i = 0; i < ncolors; i++) { |
| 378 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
| 379 |
> |
for (i = 0; i < ncolors; i++) { /* reset black and white */ |
| 380 |
|
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
| 381 |
|
continue; |
| 382 |
|
thiscolor.pixel = pixval[i]; |
| 390 |
|
ncolors--; |
| 391 |
|
i--; |
| 392 |
|
} |
| 384 |
– |
} |
| 393 |
|
XSetWindowColormap(ourdisplay, gwind, ourmap); |
| 394 |
|
return(ncolors); |
| 395 |
|
} |
| 416 |
|
BYTE rgb[3]; |
| 417 |
|
|
| 418 |
|
map_color(rgb, col); |
| 419 |
< |
rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask; |
| 420 |
< |
rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask; |
| 421 |
< |
rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask; |
| 419 |
> |
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
| 420 |
> |
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
| 421 |
> |
rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask; |
| 422 |
|
return(rval); |
| 423 |
|
} |
| 424 |
|
|
| 447 |
|
freepixels(); |
| 448 |
|
break; |
| 449 |
|
case MapNotify: |
| 450 |
< |
if (ourvisual->class == PseudoColor) |
| 450 |
> |
if (ourvinfo.class == PseudoColor || |
| 451 |
> |
ourvinfo.class == GrayScale) |
| 452 |
|
if (getpixels() == 0) |
| 453 |
|
stderr_v("Cannot allocate colors\n"); |
| 454 |
|
else |