50 |
|
|
51 |
|
static Display *ourdisplay = NULL; /* our display */ |
52 |
|
|
53 |
< |
static Visual *ourvisual; /* our visual structure */ |
53 |
> |
static XVisualInfo ourvinfo; /* our visual information */ |
54 |
|
|
55 |
|
static Window gwind = 0; /* our graphics window */ |
56 |
|
|
84 |
|
char *name, *id; |
85 |
|
{ |
86 |
|
int nplanes; |
87 |
– |
XVisualInfo ourvinfo; |
87 |
|
XSetWindowAttributes ourwinattr; |
88 |
|
XWMHints ourxwmhints; |
89 |
|
XSizeHints oursizhints; |
93 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
94 |
|
return(NULL); |
95 |
|
} |
96 |
+ |
/* find a usable visual */ |
97 |
|
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
98 |
< |
if (nplanes < 4) { |
99 |
< |
stderr_v("not enough colors\n"); |
100 |
< |
return(NULL); |
101 |
< |
} else if (nplanes <= 12) { |
102 |
< |
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
103 |
< |
nplanes,PseudoColor,&ourvinfo)) { |
104 |
< |
stderr_v("PseudoColor server required\n"); |
98 |
> |
if ( !XMatchVisualInfo(ourdisplay,ourscreen, |
99 |
> |
24,TrueColor,&ourvinfo) && |
100 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
101 |
> |
24,DirectColor,&ourvinfo) ) |
102 |
> |
if (nplanes < 4) { |
103 |
> |
stderr_v("not enough colors\n"); |
104 |
|
return(NULL); |
105 |
+ |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
106 |
+ |
nplanes,PseudoColor,&ourvinfo) && |
107 |
+ |
!XMatchVisualInfo(ourdisplay,ourscreen, |
108 |
+ |
nplanes,GrayScale,&ourvinfo)) { |
109 |
+ |
stderr_v("unsupported visual type\n"); |
110 |
+ |
return(NULL); |
111 |
|
} |
107 |
– |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
108 |
– |
nplanes,TrueColor,&ourvinfo) && |
109 |
– |
/* kludge for DirectColor */ |
110 |
– |
!XMatchVisualInfo(ourdisplay,ourscreen, |
111 |
– |
nplanes,DirectColor,&ourvinfo)) { |
112 |
– |
stderr_v("TrueColor server required\n"); |
113 |
– |
return(NULL); |
114 |
– |
} |
115 |
– |
ourvisual = ourvinfo.visual; |
112 |
|
make_gmap(GAMMA); |
113 |
|
/* open window */ |
114 |
|
ourwinattr.background_pixel = ourblack; |
115 |
|
ourwinattr.border_pixel = ourblack; |
116 |
+ |
/* this is a waste! */ |
117 |
+ |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
118 |
+ |
ourvinfo.visual, AllocNone); |
119 |
|
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
120 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
121 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
122 |
< |
BORWIDTH, nplanes, InputOutput, ourvisual, |
123 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
122 |
> |
BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, |
123 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
124 |
|
if (gwind == 0) { |
125 |
|
stderr_v("cannot create window\n"); |
126 |
|
return(NULL); |
197 |
|
} |
198 |
|
XClearWindow(ourdisplay, gwind); |
199 |
|
/* reinitialize color table */ |
200 |
< |
if (ourvisual->class == PseudoColor) |
200 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
201 |
|
if (getpixels() == 0) |
202 |
|
stderr_v("cannot allocate colors\n"); |
203 |
|
else |
230 |
|
|
231 |
|
if (ncolors > 0) |
232 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
233 |
< |
else if (ourvisual->class != PseudoColor) |
233 |
> |
else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor) |
234 |
|
pixel = true_pixel(col); |
235 |
|
else |
236 |
|
return; |
342 |
|
register int i, j; |
343 |
|
|
344 |
|
if (ncolors > 0) |
345 |
< |
goto donecolors; |
346 |
< |
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
345 |
> |
return(ncolors); |
346 |
> |
if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) { |
347 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
348 |
|
goto loop; |
349 |
|
} |
350 |
|
newmap: |
351 |
< |
ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone); |
351 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone); |
352 |
|
loop: |
353 |
< |
for (ncolors = ourvisual->map_entries; |
354 |
< |
ncolors > ourvisual->map_entries/3; |
353 |
> |
for (ncolors = ourvinfo.colormap_size; |
354 |
> |
ncolors > ourvinfo.colormap_size/3; |
355 |
|
ncolors = ncolors*.937) { |
356 |
|
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
357 |
|
if (pixval == NULL) |
384 |
|
i--; |
385 |
|
} |
386 |
|
XSetWindowColormap(ourdisplay, gwind, ourmap); |
388 |
– |
donecolors: |
389 |
– |
#ifdef DEBUG |
390 |
– |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
391 |
– |
thiscolor.red = thiscolor.green = thiscolor.blue = 0; |
392 |
– |
for (i = 0; i < ncolors; i++) { |
393 |
– |
thiscolor.pixel = pixval[i]; |
394 |
– |
XStoreColor(ourdisplay, ourmap, &thiscolor); |
395 |
– |
} |
396 |
– |
#endif |
387 |
|
return(ncolors); |
388 |
|
} |
389 |
|
|
409 |
|
BYTE rgb[3]; |
410 |
|
|
411 |
|
map_color(rgb, col); |
412 |
< |
rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask; |
413 |
< |
rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask; |
414 |
< |
rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask; |
412 |
> |
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
413 |
> |
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
414 |
> |
rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask; |
415 |
|
return(rval); |
416 |
|
} |
417 |
|
|
440 |
|
freepixels(); |
441 |
|
break; |
442 |
|
case MapNotify: |
443 |
< |
if (ourvisual->class == PseudoColor) |
443 |
> |
if (ourvinfo.class == PseudoColor || |
444 |
> |
ourvinfo.class == GrayScale) |
445 |
|
if (getpixels() == 0) |
446 |
|
stderr_v("Cannot allocate colors\n"); |
447 |
|
else |