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 */ |
26 |
> |
#define GAMMA 2.2 /* default exponent correction */ |
27 |
|
|
28 |
|
#define MINWIDTH (32*COMCW) /* minimum graphics window width */ |
29 |
|
#define MINHEIGHT MINWIDTH /* minimum graphics window height */ |
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 |
|
|
82 |
|
x11_init(name, id) /* initialize driver */ |
83 |
|
char *name, *id; |
84 |
|
{ |
85 |
+ |
extern char *getenv(); |
86 |
+ |
char *gv; |
87 |
|
int nplanes; |
86 |
– |
XVisualInfo ourvinfo; |
88 |
|
XSetWindowAttributes ourwinattr; |
89 |
|
XWMHints ourxwmhints; |
90 |
|
XSizeHints oursizhints; |
94 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
95 |
|
return(NULL); |
96 |
|
} |
97 |
+ |
/* find a usable visual */ |
98 |
|
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
99 |
< |
if (nplanes < 4) { |
100 |
< |
stderr_v("not enough colors\n"); |
101 |
< |
return(NULL); |
102 |
< |
} else if (nplanes <= 12) { |
99 |
> |
if (XMatchVisualInfo(ourdisplay,ourscreen, |
100 |
> |
24,TrueColor,&ourvinfo) || |
101 |
> |
XMatchVisualInfo(ourdisplay,ourscreen, |
102 |
> |
24,DirectColor,&ourvinfo)) { |
103 |
> |
ourblack = 0; |
104 |
> |
ourwhite = ourvinfo.red_mask | |
105 |
> |
ourvinfo.green_mask | |
106 |
> |
ourvinfo.blue_mask ; |
107 |
> |
} else { |
108 |
> |
if (nplanes < 4) { |
109 |
> |
stderr_v("not enough colors\n"); |
110 |
> |
return(NULL); |
111 |
> |
} |
112 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
113 |
< |
nplanes,PseudoColor,&ourvinfo)) { |
114 |
< |
stderr_v("PseudoColor server required\n"); |
113 |
> |
nplanes,PseudoColor,&ourvinfo) && |
114 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
115 |
> |
nplanes,GrayScale,&ourvinfo)) { |
116 |
> |
stderr_v("unsupported visual type\n"); |
117 |
|
return(NULL); |
118 |
|
} |
119 |
< |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
120 |
< |
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); |
119 |
> |
ourblack = BlackPixel(ourdisplay,ourscreen); |
120 |
> |
ourwhite = WhitePixel(ourdisplay,ourscreen); |
121 |
|
} |
122 |
< |
ourvisual = ourvinfo.visual; |
123 |
< |
make_gmap(GAMMA); |
124 |
< |
/* open window */ |
122 |
> |
/* set gamma */ |
123 |
> |
if ((gv = getenv("GAMMA")) != NULL) |
124 |
> |
make_gmap(atof(gv)); |
125 |
> |
else |
126 |
> |
make_gmap(GAMMA); |
127 |
> |
/* open window */ |
128 |
|
ourwinattr.background_pixel = ourblack; |
129 |
|
ourwinattr.border_pixel = ourblack; |
130 |
+ |
/* this is stupid */ |
131 |
+ |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
132 |
+ |
ourvinfo.visual, AllocNone); |
133 |
|
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
134 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
135 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
136 |
< |
BORWIDTH, nplanes, InputOutput, ourvisual, |
137 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
136 |
> |
BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, |
137 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
138 |
|
if (gwind == 0) { |
139 |
|
stderr_v("cannot create window\n"); |
140 |
|
return(NULL); |
141 |
|
} |
142 |
< |
XStoreName(ourdisplay, gwind, id); |
142 |
> |
XStoreName(ourdisplay, gwind, id); |
143 |
|
/* create a cursor */ |
144 |
|
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
145 |
|
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
146 |
< |
ourxwmhints.flags = InputHint; |
146 |
> |
ourxwmhints.flags = InputHint|IconPixmapHint; |
147 |
|
ourxwmhints.input = True; |
148 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
149 |
+ |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
150 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
151 |
|
oursizhints.min_width = MINWIDTH; |
152 |
|
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
154 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
155 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
156 |
|
XMapWindow(ourdisplay, gwind); |
157 |
< |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); |
157 |
> |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
158 |
|
gwidth = levptr(XExposeEvent)->width; |
159 |
|
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
160 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
211 |
|
} |
212 |
|
XClearWindow(ourdisplay, gwind); |
213 |
|
/* reinitialize color table */ |
214 |
< |
if (ourvisual->class == PseudoColor) |
214 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
215 |
|
if (getpixels() == 0) |
216 |
|
stderr_v("cannot allocate colors\n"); |
217 |
|
else |
219 |
|
/* get new command line */ |
220 |
|
if (comline != NULL) |
221 |
|
xt_close(comline); |
222 |
< |
comline = xt_open(ourdisplay, |
223 |
< |
DefaultGC(ourdisplay,ourscreen), |
208 |
< |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
222 |
> |
comline = xt_open(ourdisplay, gwind, 0, gheight, |
223 |
> |
gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN); |
224 |
|
if (comline == NULL) { |
225 |
|
stderr_v("Cannot open command line window\n"); |
226 |
|
quit(1); |
243 |
|
|
244 |
|
if (ncolors > 0) |
245 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
246 |
< |
else if (ourvisual->class != PseudoColor) |
246 |
> |
else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor) |
247 |
|
pixel = true_pixel(col); |
248 |
|
else |
249 |
|
return; |
351 |
|
static int |
352 |
|
getpixels() /* get the color map */ |
353 |
|
{ |
354 |
+ |
XColor thiscolor; |
355 |
+ |
register int i, j; |
356 |
+ |
|
357 |
|
if (ncolors > 0) |
358 |
|
return(ncolors); |
359 |
< |
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
359 |
> |
if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) { |
360 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
361 |
|
goto loop; |
362 |
|
} |
363 |
|
newmap: |
364 |
< |
ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone); |
364 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone); |
365 |
|
loop: |
366 |
< |
for (ncolors = ourvisual->map_entries; |
367 |
< |
ncolors > ourvisual->map_entries/3; |
366 |
> |
for (ncolors = ourvinfo.colormap_size; |
367 |
> |
ncolors > ourvinfo.colormap_size/3; |
368 |
|
ncolors = ncolors*.937) { |
369 |
< |
pixval = (int *)malloc(ncolors*sizeof(int)); |
369 |
> |
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
370 |
|
if (pixval == NULL) |
371 |
|
return(ncolors = 0); |
372 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
381 |
|
else |
382 |
|
return(ncolors = 0); /* failed */ |
383 |
|
} |
384 |
< |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { |
385 |
< |
XColor thiscolor; |
368 |
< |
register int i, j; |
369 |
< |
/* reset black and white */ |
370 |
< |
for (i = 0; i < ncolors; i++) { |
384 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
385 |
> |
for (i = 0; i < ncolors; i++) { /* reset black and white */ |
386 |
|
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
387 |
|
continue; |
388 |
|
thiscolor.pixel = pixval[i]; |
396 |
|
ncolors--; |
397 |
|
i--; |
398 |
|
} |
384 |
– |
} |
399 |
|
XSetWindowColormap(ourdisplay, gwind, ourmap); |
400 |
|
return(ncolors); |
401 |
|
} |
407 |
|
if (ncolors == 0) |
408 |
|
return; |
409 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
410 |
+ |
free((char *)pixval); |
411 |
+ |
pixval = NULL; |
412 |
|
ncolors = 0; |
413 |
|
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
414 |
|
XFreeColormap(ourdisplay, ourmap); |
424 |
|
BYTE rgb[3]; |
425 |
|
|
426 |
|
map_color(rgb, col); |
427 |
< |
rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask; |
428 |
< |
rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask; |
429 |
< |
rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask; |
427 |
> |
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
428 |
> |
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
429 |
> |
rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask; |
430 |
|
return(rval); |
431 |
|
} |
432 |
|
|
455 |
|
freepixels(); |
456 |
|
break; |
457 |
|
case MapNotify: |
458 |
< |
if (ourvisual->class == PseudoColor) |
458 |
> |
if (ourvinfo.class == PseudoColor || |
459 |
> |
ourvinfo.class == GrayScale) |
460 |
|
if (getpixels() == 0) |
461 |
|
stderr_v("Cannot allocate colors\n"); |
462 |
|
else |