67 |
|
|
68 |
|
static Colormap ourmap = 0; /* our color map */ |
69 |
|
|
70 |
< |
extern char *malloc(); |
70 |
> |
extern char *malloc(), *getcombuf(); |
71 |
|
|
72 |
< |
int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
72 |
> |
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
73 |
|
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
74 |
|
|
75 |
|
static struct driver x11_driver = { |
84 |
|
{ |
85 |
|
int nplanes; |
86 |
|
XVisualInfo ourvinfo; |
87 |
+ |
XSetWindowAttributes ourwinattr; |
88 |
|
XWMHints ourxwmhints; |
89 |
< |
Pixmap bmCursorSrc, bmCursorMsk; |
89 |
> |
XSizeHints oursizhints; |
90 |
|
|
91 |
|
ourdisplay = XOpenDisplay(NULL); |
92 |
|
if (ourdisplay == NULL) { |
100 |
|
} else if (nplanes <= 12) { |
101 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
102 |
|
nplanes,PseudoColor,&ourvinfo)) { |
103 |
< |
stderr_v("PseudoColor not supported\n"); |
103 |
> |
stderr_v("PseudoColor server required\n"); |
104 |
|
return(NULL); |
105 |
|
} |
106 |
|
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
107 |
< |
nplanes,TrueColor,&ourvinfo)) { |
108 |
< |
stderr_v("TrueColor not supported\n"); |
107 |
> |
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); |
113 |
|
} |
114 |
|
ourvisual = ourvinfo.visual; |
115 |
|
make_gmap(GAMMA); |
112 |
– |
/* create a cursor */ |
113 |
– |
pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); |
116 |
|
/* open window */ |
117 |
< |
gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0, |
117 |
> |
ourwinattr.background_pixel = ourblack; |
118 |
> |
ourwinattr.border_pixel = ourblack; |
119 |
> |
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
120 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
121 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
122 |
< |
BORWIDTH, ourblack, ourwhite); |
122 |
> |
BORWIDTH, nplanes, InputOutput, ourvisual, |
123 |
> |
CWBackPixel|CWBorderPixel, &ourwinattr); |
124 |
|
if (gwind == 0) { |
125 |
|
stderr_v("cannot create window\n"); |
126 |
|
return(NULL); |
127 |
|
} |
128 |
|
XStoreName(ourdisplay, gwind, id); |
129 |
+ |
/* create a cursor */ |
130 |
+ |
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
131 |
|
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
132 |
|
ourxwmhints.flags = InputHint; |
133 |
|
ourxwmhints.input = True; |
134 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
135 |
+ |
oursizhints.min_width = MINWIDTH; |
136 |
+ |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
137 |
+ |
oursizhints.flags = PMinSize; |
138 |
+ |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
139 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
140 |
|
XMapWindow(ourdisplay, gwind); |
141 |
|
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); |
163 |
|
xt_close(comline); |
164 |
|
comline = NULL; |
165 |
|
} |
166 |
< |
if (gwind != 0) { |
167 |
< |
freepixels(); |
168 |
< |
XFreeGC(ourdisplay, ourgc); |
169 |
< |
XDestroyWindow(ourdisplay, gwind); |
170 |
< |
gwind = 0; |
160 |
< |
ourgc = 0; |
161 |
< |
} |
166 |
> |
freepixels(); |
167 |
> |
XFreeGC(ourdisplay, ourgc); |
168 |
> |
XDestroyWindow(ourdisplay, gwind); |
169 |
> |
gwind = 0; |
170 |
> |
ourgc = 0; |
171 |
|
XFreeCursor(ourdisplay, pickcursor); |
172 |
|
XCloseDisplay(ourdisplay); |
173 |
|
ourdisplay = NULL; |
178 |
|
x11_clear(xres, yres) /* clear our display */ |
179 |
|
int xres, yres; |
180 |
|
{ |
181 |
< |
if (xres != gwidth || yres != gheight) { /* change window */ |
182 |
< |
if (comline != NULL) |
183 |
< |
xt_close(comline); |
181 |
> |
/* check limits */ |
182 |
> |
if (xres < MINWIDTH) |
183 |
> |
xres = MINWIDTH; |
184 |
> |
if (yres < MINHEIGHT) |
185 |
> |
yres = MINHEIGHT; |
186 |
> |
/* resize window */ |
187 |
> |
if (xres != gwidth || yres != gheight) { |
188 |
|
XSelectInput(ourdisplay, gwind, 0); |
189 |
|
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
177 |
– |
comline = xt_open(ourdisplay, |
178 |
– |
DefaultGC(ourdisplay,ourscreen), |
179 |
– |
gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
180 |
– |
if (comline == NULL) { |
181 |
– |
stderr_v("Cannot open command line window\n"); |
182 |
– |
quit(1); |
183 |
– |
} |
184 |
– |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
190 |
|
gwidth = xres; |
191 |
|
gheight = yres; |
192 |
< |
XSync(ourdisplay, 1); /* discard input */ |
192 |
> |
XFlush(ourdisplay); |
193 |
|
sleep(2); /* wait for window manager */ |
194 |
+ |
XSync(ourdisplay, 1); /* discard input */ |
195 |
|
} |
196 |
|
XClearWindow(ourdisplay, gwind); |
197 |
< |
if (ourvisual->class == PseudoColor) /* reinitialize color table */ |
197 |
> |
/* reinitialize color table */ |
198 |
> |
if (ourvisual->class == PseudoColor) |
199 |
|
if (getpixels() == 0) |
200 |
|
stderr_v("cannot allocate colors\n"); |
201 |
|
else |
202 |
|
new_ctab(ncolors); |
203 |
< |
|
203 |
> |
/* get new command line */ |
204 |
> |
if (comline != NULL) |
205 |
> |
xt_close(comline); |
206 |
> |
comline = xt_open(ourdisplay, |
207 |
> |
DefaultGC(ourdisplay,ourscreen), |
208 |
> |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
209 |
> |
if (comline == NULL) { |
210 |
> |
stderr_v("Cannot open command line window\n"); |
211 |
> |
quit(1); |
212 |
> |
} |
213 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
214 |
> |
/* remove earmuffs */ |
215 |
|
XSelectInput(ourdisplay, gwind, |
216 |
|
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
217 |
|
} |
228 |
|
|
229 |
|
if (ncolors > 0) |
230 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
231 |
< |
else if (ourvisual->class == TrueColor) |
231 |
> |
else if (ourvisual->class != PseudoColor) |
232 |
|
pixel = true_pixel(col); |
233 |
|
else |
234 |
|
return; |
241 |
|
static |
242 |
|
x11_flush() /* flush output */ |
243 |
|
{ |
244 |
< |
if (ncolors <= 0) /* output necessary for death */ |
227 |
< |
XFillRectangle(ourdisplay, gwind, ourgc, 0, 0, 1 ,1); |
244 |
> |
XNoOp(ourdisplay); |
245 |
|
while (XPending(ourdisplay) > 0) |
246 |
|
getevent(); |
247 |
|
} |
251 |
|
x11_comin(inp, prompt) /* read in a command line */ |
252 |
|
char *inp, *prompt; |
253 |
|
{ |
254 |
< |
int x11_getc(), x11_comout(); |
254 |
> |
extern int x11_getc(); |
255 |
|
|
256 |
|
if (prompt != NULL) |
257 |
|
if (fromcombuf(inp, &x11_driver)) |
268 |
|
x11_comout(out) /* output a string to command line */ |
269 |
|
char *out; |
270 |
|
{ |
271 |
< |
if (comline != NULL) |
272 |
< |
xt_puts(out, comline); |
273 |
< |
XFlush(ourdisplay); |
271 |
> |
if (comline == NULL) |
272 |
> |
return; |
273 |
> |
xt_puts(out, comline); |
274 |
> |
if (out[strlen(out)-1] == '\n') |
275 |
> |
XFlush(ourdisplay); |
276 |
|
} |
277 |
|
|
278 |
|
|
280 |
|
x11_errout(msg) /* output an error message */ |
281 |
|
char *msg; |
282 |
|
{ |
264 |
– |
x11_comout(msg); |
283 |
|
stderr_v(msg); /* send to stderr also! */ |
284 |
+ |
x11_comout(msg); |
285 |
|
} |
286 |
|
|
287 |
|
|
336 |
|
static int |
337 |
|
getpixels() /* get the color map */ |
338 |
|
{ |
339 |
+ |
XColor thiscolor; |
340 |
+ |
register int i, j; |
341 |
+ |
|
342 |
|
if (ncolors > 0) |
343 |
< |
return(ncolors); |
343 |
> |
goto donecolors; |
344 |
|
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
345 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
346 |
|
goto loop; |
366 |
|
else |
367 |
|
return(ncolors = 0); /* failed */ |
368 |
|
} |
369 |
< |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { |
370 |
< |
XColor thiscolor; |
349 |
< |
register int i, j; |
350 |
< |
/* reset black and white */ |
351 |
< |
for (i = 0; i < ncolors; i++) { |
369 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
370 |
> |
for (i = 0; i < ncolors; i++) { /* reset black and white */ |
371 |
|
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
372 |
|
continue; |
373 |
|
thiscolor.pixel = pixval[i]; |
381 |
|
ncolors--; |
382 |
|
i--; |
383 |
|
} |
365 |
– |
} |
384 |
|
XSetWindowColormap(ourdisplay, gwind, ourmap); |
385 |
+ |
donecolors: |
386 |
+ |
#ifdef DEBUG |
387 |
+ |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
388 |
+ |
thiscolor.red = thiscolor.green = thiscolor.blue = 0; |
389 |
+ |
for (i = 0; i < ncolors; i++) { |
390 |
+ |
thiscolor.pixel = pixval[i]; |
391 |
+ |
XStoreColor(ourdisplay, ourmap, &thiscolor); |
392 |
+ |
} |
393 |
+ |
#endif |
394 |
|
return(ncolors); |
395 |
|
} |
396 |
|
|
402 |
|
return; |
403 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
404 |
|
ncolors = 0; |
405 |
< |
if (ourmap != 0 && ourmap != DefaultColormap(ourdisplay,ourscreen)) |
405 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
406 |
|
XFreeColormap(ourdisplay, ourmap); |
407 |
|
ourmap = 0; |
408 |
|
} |
469 |
|
getkey(ekey) /* get input key */ |
470 |
|
register XKeyPressedEvent *ekey; |
471 |
|
{ |
472 |
< |
int n; |
472 |
> |
register int n; |
473 |
|
|
474 |
|
n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, |
475 |
|
NULL, NULL); |