1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
– |
|
5 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
6 |
– |
|
4 |
|
/* |
5 |
< |
* x11.c - driver for X-windows version 11.3 |
9 |
< |
* |
10 |
< |
* Jan 1990 |
5 |
> |
* x11.c - driver for X-windows version 11 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
+ |
#include "standard.h" |
11 |
|
#include <sys/ioctl.h> |
12 |
+ |
#if !defined(FNDELAY) && defined(O_NONBLOCK) |
13 |
+ |
#define FNDELAY O_NONBLOCK |
14 |
+ |
#endif |
15 |
|
|
16 |
|
#include <X11/Xlib.h> |
17 |
|
#include <X11/cursorfont.h> |
18 |
|
#include <X11/Xutil.h> |
19 |
|
|
20 |
+ |
#include "platform.h" |
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 */ |
29 |
> |
#define MINHEIGHT (MINWIDTH/2) /* minimum graphics window height */ |
30 |
|
|
31 |
|
#define BORWIDTH 5 /* border width */ |
32 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
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 mapped = 0; /* window is mapped? */ |
48 |
|
static unsigned long *pixval = NULL; /* allocated pixels */ |
49 |
+ |
static unsigned long ourblack=0, ourwhite=1; |
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 |
|
|
58 |
|
|
59 |
|
static int gwidth, gheight; /* graphics window size */ |
60 |
|
|
61 |
+ |
static int comheight; /* desired comline height */ |
62 |
|
static TEXTWIND *comline = NULL; /* our command line */ |
63 |
|
|
64 |
|
static char c_queue[64]; /* input queue */ |
69 |
|
|
70 |
|
static Colormap ourmap = 0; /* our color map */ |
71 |
|
|
72 |
< |
extern char *malloc(), *getcombuf(); |
72 |
> |
#define IC_X11 0 |
73 |
> |
#define IC_IOCTL 1 |
74 |
> |
#define IC_READ 2 |
75 |
|
|
76 |
< |
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
73 |
< |
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
76 |
> |
static int inpcheck; /* whence to check input */ |
77 |
|
|
78 |
+ |
static void x11_errout(char *msg); |
79 |
+ |
|
80 |
+ |
static dr_closef_t x11_close; |
81 |
+ |
static dr_clearf_t x11_clear; |
82 |
+ |
static dr_paintrf_t x11_paintr; |
83 |
+ |
static dr_getcurf_t x11_getcur; |
84 |
+ |
static dr_comoutf_t x11_comout; |
85 |
+ |
static dr_cominf_t x11_comin; |
86 |
+ |
static dr_flushf_t x11_flush; |
87 |
+ |
|
88 |
+ |
static dr_cominf_t std_comin; |
89 |
+ |
static dr_comoutf_t std_comout; |
90 |
+ |
|
91 |
|
static struct driver x11_driver = { |
92 |
|
x11_close, x11_clear, x11_paintr, x11_getcur, |
93 |
< |
x11_comout, x11_comin, x11_flush, 1.0 |
93 |
> |
NULL, NULL, x11_flush, 1.0 |
94 |
|
}; |
95 |
|
|
96 |
+ |
static dr_getchf_t x11_getc; |
97 |
|
|
98 |
< |
struct driver * |
99 |
< |
x11_init(name, id) /* initialize driver */ |
100 |
< |
char *name, *id; |
98 |
> |
static void freepixels(void); |
99 |
> |
static int getpixels(void); |
100 |
> |
static dr_newcolrf_t xnewcolr; |
101 |
> |
static unsigned long true_pixel(COLOR col); |
102 |
> |
static void getevent(void); |
103 |
> |
static void getkey(XKeyPressedEvent *ekey); |
104 |
> |
static void fixwindow(XExposeEvent *eexp); |
105 |
> |
static void resizewindow(XConfigureEvent *ersz); |
106 |
> |
|
107 |
> |
extern dr_initf_t x11_init; /* XXX this should be in a seperate header file */ |
108 |
> |
|
109 |
> |
|
110 |
> |
extern struct driver * |
111 |
> |
x11_init( /* initialize driver */ |
112 |
> |
char *name, |
113 |
> |
char *id |
114 |
> |
) |
115 |
|
{ |
116 |
+ |
char *gv; |
117 |
|
int nplanes; |
86 |
– |
XVisualInfo ourvinfo; |
118 |
|
XSetWindowAttributes ourwinattr; |
119 |
|
XWMHints ourxwmhints; |
120 |
|
XSizeHints oursizhints; |
121 |
< |
|
121 |
> |
/* open display server */ |
122 |
|
ourdisplay = XOpenDisplay(NULL); |
123 |
|
if (ourdisplay == NULL) { |
124 |
< |
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
124 |
> |
eputs("cannot open X-windows; DISPLAY variable set?\n"); |
125 |
|
return(NULL); |
126 |
|
} |
127 |
+ |
/* find a usable visual */ |
128 |
|
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
129 |
< |
if (nplanes < 4) { |
130 |
< |
stderr_v("not enough colors\n"); |
131 |
< |
return(NULL); |
132 |
< |
} else if (nplanes <= 12) { |
129 |
> |
if (XMatchVisualInfo(ourdisplay,ourscreen, |
130 |
> |
nplanes>12?nplanes:24,TrueColor,&ourvinfo) || |
131 |
> |
XMatchVisualInfo(ourdisplay,ourscreen, |
132 |
> |
nplanes>12?nplanes:24,DirectColor,&ourvinfo)) { |
133 |
> |
ourblack = 0; |
134 |
> |
ourwhite = ourvinfo.red_mask | |
135 |
> |
ourvinfo.green_mask | |
136 |
> |
ourvinfo.blue_mask ; |
137 |
> |
} else { |
138 |
> |
if (nplanes < 4) { |
139 |
> |
eputs("not enough colors\n"); |
140 |
> |
return(NULL); |
141 |
> |
} |
142 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
143 |
< |
nplanes,PseudoColor,&ourvinfo)) { |
144 |
< |
stderr_v("PseudoColor server required\n"); |
143 |
> |
nplanes,PseudoColor,&ourvinfo) && |
144 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
145 |
> |
nplanes,GrayScale,&ourvinfo)) { |
146 |
> |
eputs("unsupported visual type\n"); |
147 |
|
return(NULL); |
148 |
|
} |
149 |
< |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
150 |
< |
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); |
149 |
> |
ourblack = BlackPixel(ourdisplay,ourscreen); |
150 |
> |
ourwhite = WhitePixel(ourdisplay,ourscreen); |
151 |
|
} |
152 |
< |
ourvisual = ourvinfo.visual; |
153 |
< |
make_gmap(GAMMA); |
154 |
< |
/* open window */ |
152 |
> |
/* set gamma */ |
153 |
> |
if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
154 |
> |
|| (gv = getenv("DISPLAY_GAMMA")) != NULL) |
155 |
> |
make_gmap(atof(gv)); |
156 |
> |
else |
157 |
> |
make_gmap(GAMMA); |
158 |
> |
/* X11 command line or no? */ |
159 |
> |
if (!strcmp(name, "x11")) |
160 |
> |
comheight = COMHEIGHT; |
161 |
> |
else /* "x11d" */ { |
162 |
> |
comheight = 0; |
163 |
> |
#ifndef FNDELAY |
164 |
> |
eputs("warning: x11d driver not fully functional on this machine\n"); |
165 |
> |
#endif |
166 |
> |
} |
167 |
> |
/* open window */ |
168 |
|
ourwinattr.background_pixel = ourblack; |
169 |
|
ourwinattr.border_pixel = ourblack; |
170 |
+ |
/* this is stupid */ |
171 |
+ |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
172 |
+ |
ourvinfo.visual, AllocNone); |
173 |
|
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
174 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
175 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
176 |
< |
BORWIDTH, nplanes, InputOutput, ourvisual, |
177 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
176 |
> |
BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, |
177 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
178 |
|
if (gwind == 0) { |
179 |
< |
stderr_v("cannot create window\n"); |
179 |
> |
eputs("cannot create window\n"); |
180 |
|
return(NULL); |
181 |
|
} |
182 |
< |
XStoreName(ourdisplay, gwind, id); |
182 |
> |
XStoreName(ourdisplay, gwind, id); |
183 |
|
/* create a cursor */ |
184 |
|
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
185 |
|
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
186 |
< |
ourxwmhints.flags = InputHint; |
186 |
> |
ourxwmhints.flags = InputHint|IconPixmapHint; |
187 |
|
ourxwmhints.input = True; |
188 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
189 |
+ |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
190 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
191 |
|
oursizhints.min_width = MINWIDTH; |
192 |
< |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
192 |
> |
oursizhints.min_height = MINHEIGHT+comheight; |
193 |
|
oursizhints.flags = PMinSize; |
194 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
195 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
196 |
|
XMapWindow(ourdisplay, gwind); |
197 |
|
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
198 |
|
gwidth = levptr(XExposeEvent)->width; |
199 |
< |
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
199 |
> |
gheight = levptr(XExposeEvent)->height - comheight; |
200 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
201 |
|
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
202 |
|
x11_driver.inpready = 0; |
203 |
< |
cmdvec = x11_comout; /* set error vectors */ |
204 |
< |
if (wrnvec != NULL) |
205 |
< |
wrnvec = x11_errout; |
203 |
> |
mapped = 1; |
204 |
> |
/* set i/o vectors */ |
205 |
> |
if (comheight) { |
206 |
> |
x11_driver.comin = x11_comin; |
207 |
> |
x11_driver.comout = x11_comout; |
208 |
> |
erract[COMMAND].pf = x11_comout; |
209 |
> |
/* doesn't work with raypcalls.c |
210 |
> |
if (erract[WARNING].pf != NULL) |
211 |
> |
erract[WARNING].pf = x11_errout; |
212 |
> |
*/ |
213 |
> |
inpcheck = IC_X11; |
214 |
> |
} else { |
215 |
> |
x11_driver.comin = std_comin; |
216 |
> |
x11_driver.comout = std_comout; |
217 |
> |
erract[COMMAND].pf = std_comout; |
218 |
> |
inpcheck = IC_IOCTL; |
219 |
> |
} |
220 |
|
return(&x11_driver); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
< |
static |
225 |
< |
x11_close() /* close our display */ |
224 |
> |
static void |
225 |
> |
x11_close(void) /* close our display */ |
226 |
|
{ |
227 |
< |
cmdvec = NULL; /* reset error vectors */ |
228 |
< |
if (wrnvec != NULL) |
229 |
< |
wrnvec = stderr_v; |
227 |
> |
erract[COMMAND].pf = NULL; /* reset error vectors */ |
228 |
> |
if (erract[WARNING].pf != NULL) |
229 |
> |
erract[WARNING].pf = wputs; |
230 |
|
if (ourdisplay == NULL) |
231 |
|
return; |
232 |
|
if (comline != NULL) { |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
< |
static |
248 |
< |
x11_clear(xres, yres) /* clear our display */ |
249 |
< |
int xres, yres; |
247 |
> |
static void |
248 |
> |
x11_clear( /* clear our display */ |
249 |
> |
int xres, |
250 |
> |
int yres |
251 |
> |
) |
252 |
|
{ |
253 |
|
/* check limits */ |
254 |
|
if (xres < MINWIDTH) |
258 |
|
/* resize window */ |
259 |
|
if (xres != gwidth || yres != gheight) { |
260 |
|
XSelectInput(ourdisplay, gwind, 0); |
261 |
< |
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
261 |
> |
XResizeWindow(ourdisplay, gwind, xres, yres+comheight); |
262 |
|
gwidth = xres; |
263 |
|
gheight = yres; |
264 |
|
XFlush(ourdisplay); |
267 |
|
} |
268 |
|
XClearWindow(ourdisplay, gwind); |
269 |
|
/* reinitialize color table */ |
270 |
< |
if (ourvisual->class == PseudoColor) |
270 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) { |
271 |
|
if (getpixels() == 0) |
272 |
< |
stderr_v("cannot allocate colors\n"); |
272 |
> |
eputs("cannot allocate colors\n"); |
273 |
|
else |
274 |
|
new_ctab(ncolors); |
275 |
+ |
} |
276 |
|
/* get new command line */ |
277 |
|
if (comline != NULL) |
278 |
|
xt_close(comline); |
279 |
< |
comline = xt_open(ourdisplay, |
280 |
< |
DefaultGC(ourdisplay,ourscreen), |
281 |
< |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
282 |
< |
if (comline == NULL) { |
283 |
< |
stderr_v("Cannot open command line window\n"); |
284 |
< |
quit(1); |
285 |
< |
} |
286 |
< |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
279 |
> |
if (comheight) { |
280 |
> |
comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth, |
281 |
> |
comheight, 0, ourblack, ourwhite, COMFN); |
282 |
> |
if (comline == NULL) { |
283 |
> |
eputs("cannot open command line window\n"); |
284 |
> |
quit(1); |
285 |
> |
} |
286 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
287 |
|
/* remove earmuffs */ |
288 |
< |
XSelectInput(ourdisplay, gwind, |
288 |
> |
XSelectInput(ourdisplay, gwind, |
289 |
|
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
290 |
+ |
} else /* remove earmuffs */ |
291 |
+ |
XSelectInput(ourdisplay, gwind, |
292 |
+ |
StructureNotifyMask|ExposureMask|ButtonPressMask); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
< |
static |
297 |
< |
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
298 |
< |
COLOR col; |
299 |
< |
int xmin, ymin, xmax, ymax; |
296 |
> |
static void |
297 |
> |
x11_paintr( /* fill a rectangle */ |
298 |
> |
COLOR col, |
299 |
> |
int xmin, |
300 |
> |
int ymin, |
301 |
> |
int xmax, |
302 |
> |
int ymax |
303 |
> |
) |
304 |
|
{ |
225 |
– |
extern int xnewcolr(); /* pixel assignment routine */ |
226 |
– |
extern unsigned long true_pixel(); |
305 |
|
unsigned long pixel; |
306 |
|
|
307 |
+ |
if (!mapped) |
308 |
+ |
return; |
309 |
|
if (ncolors > 0) |
310 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
231 |
– |
else if (ourvisual->class != PseudoColor) |
232 |
– |
pixel = true_pixel(col); |
311 |
|
else |
312 |
< |
return; |
312 |
> |
pixel = true_pixel(col); |
313 |
|
XSetForeground(ourdisplay, ourgc, pixel); |
314 |
|
XFillRectangle(ourdisplay, gwind, |
315 |
|
ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
< |
static |
320 |
< |
x11_flush() /* flush output */ |
319 |
> |
static void |
320 |
> |
x11_flush(void) /* flush output */ |
321 |
|
{ |
322 |
+ |
char buf[256]; |
323 |
+ |
int n; |
324 |
+ |
/* check for input */ |
325 |
|
XNoOp(ourdisplay); |
326 |
< |
while (XPending(ourdisplay) > 0) |
326 |
> |
n = XPending(ourdisplay); /* from X server */ |
327 |
> |
while (n-- > 0) |
328 |
|
getevent(); |
329 |
+ |
#ifdef FNDELAY |
330 |
+ |
if (inpcheck == IC_IOCTL) { /* from stdin */ |
331 |
+ |
#ifdef FIONREAD |
332 |
+ |
if (ioctl(fileno(stdin), FIONREAD, &n) < 0) { |
333 |
+ |
#else |
334 |
+ |
if (1) { |
335 |
+ |
#endif |
336 |
+ |
if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) { |
337 |
+ |
eputs("cannot change input mode\n"); |
338 |
+ |
quit(1); |
339 |
+ |
} |
340 |
+ |
inpcheck = IC_READ; |
341 |
+ |
} else |
342 |
+ |
x11_driver.inpready += n; |
343 |
+ |
} |
344 |
+ |
if (inpcheck == IC_READ) { |
345 |
+ |
n = read(fileno(stdin), buf, sizeof(buf)-1); |
346 |
+ |
if (n > 0) { |
347 |
+ |
buf[n] = '\0'; |
348 |
+ |
tocombuf(buf, &x11_driver); |
349 |
+ |
} |
350 |
+ |
} |
351 |
+ |
#endif |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
< |
static |
356 |
< |
x11_comin(inp, prompt) /* read in a command line */ |
357 |
< |
char *inp, *prompt; |
355 |
> |
static void |
356 |
> |
x11_comin( /* read in a command line */ |
357 |
> |
char *inp, |
358 |
> |
char *prompt |
359 |
> |
) |
360 |
|
{ |
361 |
< |
extern int x11_getc(); |
362 |
< |
|
256 |
< |
if (prompt != NULL) |
361 |
> |
if (prompt != NULL) { |
362 |
> |
x11_flush(); /* make sure we get everything */ |
363 |
|
if (fromcombuf(inp, &x11_driver)) |
364 |
|
return; |
365 |
< |
else |
366 |
< |
xt_puts(prompt, comline); |
365 |
> |
xt_puts(prompt, comline); |
366 |
> |
} |
367 |
|
xt_cursor(comline, TBLKCURS); |
368 |
|
editline(inp, x11_getc, x11_comout); |
369 |
|
xt_cursor(comline, TNOCURS); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
< |
static |
374 |
< |
x11_comout(out) /* output a string to command line */ |
375 |
< |
char *out; |
373 |
> |
static void |
374 |
> |
x11_comout( /* output a string to command line */ |
375 |
> |
const char *outp |
376 |
> |
) |
377 |
|
{ |
378 |
< |
if (comline == NULL) |
378 |
> |
if (comline == NULL || outp == NULL || !outp[0]) |
379 |
|
return; |
380 |
< |
xt_puts(out, comline); |
381 |
< |
if (out[strlen(out)-1] == '\n') |
380 |
> |
xt_puts(outp, comline); |
381 |
> |
if (outp[strlen(outp)-1] == '\n') |
382 |
|
XFlush(ourdisplay); |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
< |
static |
387 |
< |
x11_errout(msg) /* output an error message */ |
388 |
< |
char *msg; |
386 |
> |
static void |
387 |
> |
x11_errout( /* output an error message */ |
388 |
> |
char *msg |
389 |
> |
) |
390 |
|
{ |
391 |
< |
stderr_v(msg); /* send to stderr also! */ |
391 |
> |
eputs(msg); /* send to stderr also! */ |
392 |
|
x11_comout(msg); |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
+ |
static void |
397 |
+ |
std_comin( /* read in command line from stdin */ |
398 |
+ |
char *inp, |
399 |
+ |
char *prompt |
400 |
+ |
) |
401 |
+ |
{ |
402 |
+ |
if (prompt != NULL) { |
403 |
+ |
if (fromcombuf(inp, &x11_driver)) |
404 |
+ |
return; |
405 |
+ |
if (!x11_driver.inpready) |
406 |
+ |
std_comout(prompt); |
407 |
+ |
} |
408 |
+ |
#ifdef FNDELAY |
409 |
+ |
if (inpcheck == IC_READ) { /* turn off FNDELAY */ |
410 |
+ |
if (fcntl(fileno(stdin), F_SETFL, 0) < 0) { |
411 |
+ |
eputs("cannot change input mode\n"); |
412 |
+ |
quit(1); |
413 |
+ |
} |
414 |
+ |
inpcheck = IC_IOCTL; |
415 |
+ |
} |
416 |
+ |
#endif |
417 |
+ |
if (gets(inp) == NULL) { |
418 |
+ |
strcpy(inp, "quit"); |
419 |
+ |
return; |
420 |
+ |
} |
421 |
+ |
x11_driver.inpready -= strlen(inp) + 1; |
422 |
+ |
if (x11_driver.inpready < 0) |
423 |
+ |
x11_driver.inpready = 0; |
424 |
+ |
} |
425 |
+ |
|
426 |
+ |
|
427 |
+ |
static void |
428 |
+ |
std_comout( /* write out string to stdout */ |
429 |
+ |
const char *outp |
430 |
+ |
) |
431 |
+ |
{ |
432 |
+ |
fputs(outp, stdout); |
433 |
+ |
fflush(stdout); |
434 |
+ |
} |
435 |
+ |
|
436 |
+ |
|
437 |
|
static int |
438 |
< |
x11_getcur(xp, yp) /* get cursor position */ |
439 |
< |
int *xp, *yp; |
438 |
> |
x11_getcur( /* get cursor position */ |
439 |
> |
int *xp, |
440 |
> |
int *yp |
441 |
> |
) |
442 |
|
{ |
443 |
|
while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask, |
444 |
|
GrabModeAsync, GrabModeAsync, None, pickcursor, |
455 |
|
if (c_last > c_first) /* key pressed */ |
456 |
|
return(x11_getc()); |
457 |
|
/* button pressed */ |
458 |
< |
if (levptr(XButtonPressedEvent)->button & Button1) |
458 |
> |
if (levptr(XButtonPressedEvent)->button == Button1) |
459 |
|
return(MB1); |
460 |
< |
if (levptr(XButtonPressedEvent)->button & Button2) |
460 |
> |
if (levptr(XButtonPressedEvent)->button == Button2) |
461 |
|
return(MB2); |
462 |
< |
if (levptr(XButtonPressedEvent)->button & Button3) |
462 |
> |
if (levptr(XButtonPressedEvent)->button == Button3) |
463 |
|
return(MB3); |
313 |
– |
if (levptr(XButtonPressedEvent)->button & (Button4|Button5)) |
314 |
– |
return(MB1); |
464 |
|
return(ABORT); |
465 |
|
} |
466 |
|
|
467 |
|
|
468 |
< |
static |
469 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
470 |
< |
int ndx; |
471 |
< |
int r, g, b; |
468 |
> |
static void |
469 |
> |
xnewcolr( /* enter a color into hardware table */ |
470 |
> |
int ndx, |
471 |
> |
int r, |
472 |
> |
int g, |
473 |
> |
int b |
474 |
> |
) |
475 |
|
{ |
476 |
|
XColor xcolor; |
477 |
|
|
486 |
|
|
487 |
|
|
488 |
|
static int |
489 |
< |
getpixels() /* get the color map */ |
489 |
> |
getpixels(void) /* get the color map */ |
490 |
|
{ |
491 |
|
XColor thiscolor; |
492 |
|
register int i, j; |
493 |
|
|
494 |
|
if (ncolors > 0) |
495 |
< |
goto donecolors; |
496 |
< |
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
495 |
> |
return(ncolors); |
496 |
> |
if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) { |
497 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
498 |
|
goto loop; |
499 |
|
} |
500 |
|
newmap: |
501 |
< |
ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone); |
501 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone); |
502 |
|
loop: |
503 |
< |
for (ncolors = ourvisual->map_entries; |
504 |
< |
ncolors > ourvisual->map_entries/3; |
503 |
> |
for (ncolors = ourvinfo.colormap_size; |
504 |
> |
ncolors > ourvinfo.colormap_size/3; |
505 |
|
ncolors = ncolors*.937) { |
506 |
|
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
507 |
|
if (pixval == NULL) |
508 |
|
return(ncolors = 0); |
509 |
< |
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
358 |
< |
pixval,ncolors) != 0) |
509 |
> |
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) |
510 |
|
break; |
511 |
< |
free((char *)pixval); |
511 |
> |
free((void *)pixval); |
512 |
|
pixval = NULL; |
513 |
|
} |
514 |
|
if (pixval == NULL) { |
533 |
|
i--; |
534 |
|
} |
535 |
|
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 |
536 |
|
return(ncolors); |
537 |
|
} |
538 |
|
|
539 |
|
|
540 |
< |
static |
541 |
< |
freepixels() /* free our pixels */ |
540 |
> |
static void |
541 |
> |
freepixels(void) /* free our pixels */ |
542 |
|
{ |
543 |
|
if (ncolors == 0) |
544 |
|
return; |
545 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
546 |
+ |
free((void *)pixval); |
547 |
+ |
pixval = NULL; |
548 |
|
ncolors = 0; |
549 |
|
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
550 |
|
XFreeColormap(ourdisplay, ourmap); |
553 |
|
|
554 |
|
|
555 |
|
static unsigned long |
556 |
< |
true_pixel(col) /* return true pixel value for color */ |
557 |
< |
COLOR col; |
556 |
> |
true_pixel( /* return true pixel value for color */ |
557 |
> |
COLOR col |
558 |
> |
) |
559 |
|
{ |
560 |
|
unsigned long rval; |
561 |
< |
BYTE rgb[3]; |
561 |
> |
uby8 rgb[3]; |
562 |
|
|
563 |
|
map_color(rgb, col); |
564 |
< |
rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask; |
565 |
< |
rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask; |
566 |
< |
rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask; |
564 |
> |
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
565 |
> |
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
566 |
> |
rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask; |
567 |
|
return(rval); |
568 |
|
} |
569 |
|
|
570 |
|
|
571 |
|
static int |
572 |
< |
x11_getc() /* get a command character */ |
572 |
> |
x11_getc(void) /* get a command character */ |
573 |
|
{ |
574 |
|
while (c_last <= c_first) { |
575 |
|
c_first = c_last = 0; /* reset */ |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
< |
static |
584 |
< |
getevent() /* get next event */ |
583 |
> |
static void |
584 |
> |
getevent(void) /* get next event */ |
585 |
|
{ |
586 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
587 |
|
switch (levptr(XEvent)->type) { |
589 |
|
resizewindow(levptr(XConfigureEvent)); |
590 |
|
break; |
591 |
|
case UnmapNotify: |
592 |
+ |
mapped = 0; |
593 |
|
freepixels(); |
594 |
|
break; |
595 |
|
case MapNotify: |
596 |
< |
if (ourvisual->class == PseudoColor) |
596 |
> |
if (ourvinfo.class == PseudoColor || |
597 |
> |
ourvinfo.class == GrayScale) { |
598 |
|
if (getpixels() == 0) |
599 |
< |
stderr_v("Cannot allocate colors\n"); |
599 |
> |
eputs("cannot allocate colors\n"); |
600 |
|
else |
601 |
|
new_ctab(ncolors); |
602 |
+ |
} |
603 |
+ |
mapped = 1; |
604 |
|
break; |
605 |
|
case Expose: |
606 |
|
fixwindow(levptr(XExposeEvent)); |
614 |
|
} |
615 |
|
|
616 |
|
|
617 |
< |
static |
618 |
< |
getkey(ekey) /* get input key */ |
619 |
< |
register XKeyPressedEvent *ekey; |
617 |
> |
static void |
618 |
> |
getkey( /* get input key */ |
619 |
> |
register XKeyPressedEvent *ekey |
620 |
> |
) |
621 |
|
{ |
622 |
|
register int n; |
623 |
|
|
628 |
|
} |
629 |
|
|
630 |
|
|
631 |
< |
static |
632 |
< |
fixwindow(eexp) /* repair damage to window */ |
633 |
< |
register XExposeEvent *eexp; |
631 |
> |
static void |
632 |
> |
fixwindow( /* repair damage to window */ |
633 |
> |
register XExposeEvent *eexp |
634 |
> |
) |
635 |
|
{ |
636 |
+ |
char buf[80]; |
637 |
+ |
|
638 |
|
if (eexp->window == gwind) { |
639 |
< |
sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n", |
639 |
> |
sprintf(buf, "repaint %d %d %d %d\n", |
640 |
|
eexp->x, gheight - eexp->y - eexp->height, |
641 |
|
eexp->x + eexp->width, gheight - eexp->y); |
642 |
+ |
tocombuf(buf, &x11_driver); |
643 |
|
} else if (eexp->window == comline->w) { |
644 |
|
if (eexp->count == 0) |
645 |
|
xt_redraw(comline); |
647 |
|
} |
648 |
|
|
649 |
|
|
650 |
< |
static |
651 |
< |
resizewindow(ersz) /* resize window */ |
652 |
< |
register XConfigureEvent *ersz; |
650 |
> |
static void |
651 |
> |
resizewindow( /* resize window */ |
652 |
> |
register XConfigureEvent *ersz |
653 |
> |
) |
654 |
|
{ |
655 |
< |
if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight) |
655 |
> |
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
656 |
|
return; |
657 |
|
|
658 |
|
gwidth = ersz->width; |
659 |
< |
gheight = ersz->height-COMHEIGHT; |
659 |
> |
gheight = ersz->height-comheight; |
660 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
661 |
|
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
662 |
|
|
663 |
< |
strcpy(getcombuf(&x11_driver), "new\n"); |
663 |
> |
tocombuf("new\n", &x11_driver); |
664 |
|
} |