10 |
|
* 5/7/87 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include <stdio.h> |
13 |
> |
#include "standard.h" |
14 |
|
|
15 |
– |
#include <sys/ioctl.h> |
16 |
– |
|
15 |
|
#include <X/Xlib.h> |
16 |
|
#include <X/cursors/bcross.cursor> |
17 |
|
#include <X/cursors/bcross_mask.cursor> |
27 |
|
#define BORWIDTH 5 /* border width */ |
28 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
29 |
|
#define MINWIDTH (32*COMCW) /* minimum graphics window width */ |
30 |
< |
#define MINHEIGHT 64 /* minimum graphics window height */ |
30 |
> |
#define MINHEIGHT MINWIDTH /* minimum graphics window height */ |
31 |
|
|
32 |
|
#define COMFN "8x13" /* command line font name */ |
33 |
|
#define COMLH 3 /* number of command lines */ |
34 |
|
#define COMCW 8 /* approx. character width (pixels) */ |
35 |
|
#define COMCH 13 /* approx. character height (pixels) */ |
36 |
|
|
39 |
– |
#ifndef WFLUSH |
40 |
– |
#define WFLUSH 30 /* flush after this many rays */ |
41 |
– |
#endif |
42 |
– |
|
43 |
– |
#define checkinp() while (XPending() > 0) getevent() |
44 |
– |
|
37 |
|
#define levptr(etype) ((etype *)&thisevent) |
38 |
|
|
39 |
|
static XEvent thisevent; /* current event */ |
47 |
|
|
48 |
|
static Cursor pickcursor = 0; /* cursor used for picking */ |
49 |
|
|
50 |
< |
static int gwidth = 0; /* graphics window width */ |
59 |
< |
static int gheight = 0; /* graphics window height */ |
50 |
> |
static int gwidth, gheight; /* graphics window size */ |
51 |
|
|
52 |
|
static TEXTWIND *comline = NULL; /* our command line */ |
53 |
|
|
59 |
|
|
60 |
|
extern char *progname; |
61 |
|
|
62 |
< |
int x_close(), x_clear(), x_paintr(), x_errout(), |
63 |
< |
x_getcur(), x_comout(), x_comin(); |
62 |
> |
static int x_close(), x_clear(), x_paintr(), x_errout(), |
63 |
> |
x_getcur(), x_comout(), x_comin(), x_flush(); |
64 |
|
|
65 |
|
static struct driver x_driver = { |
66 |
|
x_close, x_clear, x_paintr, x_getcur, |
67 |
< |
x_comout, x_comin, 1.0 |
67 |
> |
x_comout, x_comin, x_flush, 1.0 |
68 |
|
}; |
69 |
|
|
70 |
|
|
72 |
|
x_init(name, id) /* initialize driver */ |
73 |
|
char *name, *id; |
74 |
|
{ |
75 |
+ |
extern char *getenv(); |
76 |
+ |
char *gv; |
77 |
|
char defgeom[32]; |
78 |
|
OpaqueFrame mainframe; |
79 |
|
|
80 |
|
ourdisplay = XOpenDisplay(NULL); |
81 |
|
if (ourdisplay == NULL) { |
82 |
< |
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
82 |
> |
eputs("cannot open X-windows; DISPLAY variable set?\n"); |
83 |
|
return(NULL); |
84 |
|
} |
85 |
|
if (DisplayPlanes() < 4) { |
86 |
< |
stderr_v("not enough colors\n"); |
86 |
> |
eputs("not enough colors\n"); |
87 |
|
return(NULL); |
88 |
|
} |
89 |
< |
make_gmap(GAMMA); /* make color map */ |
89 |
> |
/* make color map */ |
90 |
> |
if ((gv = getenv("DISPLAY_GAMMA")) != NULL) |
91 |
> |
make_gmap(atof(gv)); |
92 |
> |
else |
93 |
> |
make_gmap(GAMMA); |
94 |
|
|
95 |
|
pickcursor = XCreateCursor(bcross_width, bcross_height, |
96 |
|
bcross_bits, bcross_mask_bits, |
104 |
|
gwind = XCreate("X10 display driver", progname, NULL, defgeom, |
105 |
|
&mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT); |
106 |
|
if (gwind == 0) { |
107 |
< |
stderr_v("can't create window\n"); |
107 |
> |
eputs("can't create window\n"); |
108 |
|
return(NULL); |
109 |
|
} |
110 |
|
XStoreName(gwind, id); |
114 |
– |
XMapWindow(gwind); |
111 |
|
XSelectInput(gwind, KeyPressed|ButtonPressed| |
112 |
|
ExposeWindow|ExposeRegion|UnmapWindow); |
113 |
< |
x_driver.xsiz = mainframe.width; |
114 |
< |
x_driver.ysiz = mainframe.height-COMHEIGHT; |
113 |
> |
gwidth = mainframe.width; |
114 |
> |
gheight = mainframe.height-COMHEIGHT; |
115 |
> |
x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
116 |
> |
x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
117 |
|
x_driver.inpready = 0; |
118 |
< |
cmdvec = x_comout; /* set error vectors */ |
119 |
< |
if (wrnvec != NULL) |
120 |
< |
wrnvec = x_errout; |
118 |
> |
erract[COMMAND].pf = x_comout; /* set error vectors */ |
119 |
> |
if (erract[WARNING].pf != NULL) |
120 |
> |
erract[WARNING].pf = x_errout; |
121 |
|
return(&x_driver); |
122 |
|
} |
123 |
|
|
125 |
|
static |
126 |
|
x_close() /* close our display */ |
127 |
|
{ |
128 |
< |
cmdvec = NULL; /* reset error vectors */ |
129 |
< |
if (wrnvec != NULL) |
130 |
< |
wrnvec = stderr_v; |
128 |
> |
erract[COMMAND].pf = NULL; /* reset error vectors */ |
129 |
> |
if (erract[WARNING].pf != NULL) |
130 |
> |
erract[WARNING].pf = wputs; |
131 |
|
if (ourdisplay == NULL) |
132 |
|
return; |
133 |
|
if (comline != NULL) { |
137 |
|
if (gwind != 0) { |
138 |
|
XDestroyWindow(gwind); |
139 |
|
gwind = 0; |
142 |
– |
gwidth = gheight = 0; |
140 |
|
} |
141 |
|
XFreeCursor(pickcursor); |
142 |
|
freepixels(); |
149 |
|
x_clear(xres, yres) /* clear our display */ |
150 |
|
int xres, yres; |
151 |
|
{ |
155 |
– |
if (xres < MINWIDTH) |
156 |
– |
xres = MINWIDTH; |
157 |
– |
if (yres < MINHEIGHT) |
158 |
– |
yres = MINHEIGHT; |
152 |
|
if (xres != gwidth || yres != gheight) { /* new window */ |
160 |
– |
if (comline != NULL) |
161 |
– |
xt_close(comline); |
153 |
|
XChangeWindow(gwind, xres, yres+COMHEIGHT); |
163 |
– |
comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
164 |
– |
if (comline == NULL) { |
165 |
– |
stderr_v("Cannot open command line window\n"); |
166 |
– |
quit(1); |
167 |
– |
} |
154 |
|
gwidth = xres; |
155 |
|
gheight = yres; |
156 |
|
} else /* just clear */ |
157 |
|
XClear(gwind); |
158 |
|
/* reinitialize color table */ |
159 |
|
if (getpixels() == 0) |
160 |
< |
stderr_v("cannot allocate colors\n"); |
160 |
> |
eputs("cannot allocate colors\n"); |
161 |
|
else |
162 |
|
new_ctab(ncolors); |
163 |
+ |
/* open new command line */ |
164 |
+ |
if (comline != NULL) |
165 |
+ |
xt_close(comline); |
166 |
+ |
comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
167 |
+ |
if (comline == NULL) { |
168 |
+ |
eputs("Cannot open command line window\n"); |
169 |
+ |
quit(1); |
170 |
+ |
} |
171 |
+ |
XMapWindow(gwind); /* make sure it's mapped */ |
172 |
|
XSync(1); /* discard input */ |
173 |
|
return; |
174 |
|
} |
179 |
|
COLOR col; |
180 |
|
int xmin, ymin, xmax, ymax; |
181 |
|
{ |
187 |
– |
extern long nrays; /* global ray count */ |
182 |
|
extern int xnewcolr(); /* pixel assignment routine */ |
189 |
– |
static long lastflush = 0; /* ray count at last flush */ |
183 |
|
|
184 |
|
if (ncolors > 0) { |
185 |
|
XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin, |
186 |
|
pixval[get_pixel(col, xnewcolr)]); |
187 |
|
} |
195 |
– |
if (nrays - lastflush >= WFLUSH) { |
196 |
– |
if (ncolors <= 0) /* output necessary for death */ |
197 |
– |
XPixSet(gwind,0,0,1,1,BlackPixel); |
198 |
– |
checkinp(); |
199 |
– |
lastflush = nrays; |
200 |
– |
} |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
static |
192 |
< |
x_comin(inp) /* read in a command line */ |
206 |
< |
char *inp; |
192 |
> |
x_flush() /* flush output */ |
193 |
|
{ |
194 |
< |
int x_getc(), x_comout(); |
194 |
> |
if (ncolors <= 0) /* output necessary for death */ |
195 |
> |
XPixSet(gwind,0,0,1,1,BlackPixel); |
196 |
> |
while (XPending() > 0) |
197 |
> |
getevent(); |
198 |
|
|
199 |
< |
if (fromcombuf(inp, &x_driver)) |
200 |
< |
return; |
199 |
> |
} |
200 |
> |
|
201 |
> |
|
202 |
> |
static |
203 |
> |
x_comin(inp, prompt) /* read in a command line */ |
204 |
> |
char *inp, *prompt; |
205 |
> |
{ |
206 |
> |
extern int x_getc(); |
207 |
> |
|
208 |
> |
if (prompt != NULL) |
209 |
> |
if (fromcombuf(inp, &x_driver)) |
210 |
> |
return; |
211 |
> |
else |
212 |
> |
xt_puts(prompt, comline); |
213 |
|
xt_cursor(comline, TBLKCURS); |
214 |
|
editline(inp, x_getc, x_comout); |
215 |
|
xt_cursor(comline, TNOCURS); |
220 |
|
x_comout(out) /* output a string to command line */ |
221 |
|
char *out; |
222 |
|
{ |
223 |
< |
if (comline != NULL) |
224 |
< |
xt_puts(out, comline); |
225 |
< |
XFlush(); |
223 |
> |
if (comline == NULL) |
224 |
> |
return; |
225 |
> |
xt_puts(out, comline); |
226 |
> |
if (out[strlen(out)-1] == '\n') |
227 |
> |
XFlush(); |
228 |
|
} |
229 |
|
|
230 |
|
|
232 |
|
x_errout(msg) /* output an error message */ |
233 |
|
char *msg; |
234 |
|
{ |
235 |
+ |
eputs(msg); /* send to stderr also! */ |
236 |
|
x_comout(msg); |
233 |
– |
stderr_v(msg); /* send to stderr also! */ |
237 |
|
} |
238 |
|
|
239 |
|
|
359 |
|
} |
360 |
|
/* check for change in size */ |
361 |
|
if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) { |
362 |
< |
x_driver.xsiz = eexp->width; |
363 |
< |
x_driver.ysiz = eexp->height-COMHEIGHT; |
362 |
> |
gwidth = eexp->width; |
363 |
> |
gheight = eexp->height-COMHEIGHT; |
364 |
> |
x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
365 |
> |
x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
366 |
|
strcpy(getcombuf(&x_driver), "new\n"); |
367 |
|
return; |
368 |
|
} |
369 |
|
/* remap colors */ |
370 |
|
if (getpixels() == 0) { |
371 |
< |
stderr_v("cannot allocate colors\n"); |
371 |
> |
eputs("cannot allocate colors\n"); |
372 |
|
return; |
373 |
|
} |
374 |
|
new_ctab(ncolors); |