29 |
|
#define BORWIDTH 5 /* border width */ |
30 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
31 |
|
#define MINWIDTH (32*COMCW) /* minimum graphics window width */ |
32 |
< |
#define MINHEIGHT 64 /* minimum graphics window height */ |
32 |
> |
#define MINHEIGHT MINWIDTH /* minimum graphics window height */ |
33 |
|
|
34 |
|
#define COMFN "8x13" /* command line font name */ |
35 |
|
#define COMLH 3 /* number of command lines */ |
36 |
|
#define COMCW 8 /* approx. character width (pixels) */ |
37 |
|
#define COMCH 13 /* approx. character height (pixels) */ |
38 |
|
|
39 |
– |
#ifndef WFLUSH |
40 |
– |
#define WFLUSH 30 /* flush after this many rays */ |
41 |
– |
#endif |
42 |
– |
|
43 |
– |
#define checkinp() while (XPending() > 0) getevent() |
44 |
– |
|
39 |
|
#define levptr(etype) ((etype *)&thisevent) |
40 |
|
|
47 |
– |
static char *clientname; /* calling client's name */ |
48 |
– |
|
41 |
|
static XEvent thisevent; /* current event */ |
42 |
|
|
43 |
|
static int ncolors = 0; /* color table size */ |
49 |
|
|
50 |
|
static Cursor pickcursor = 0; /* cursor used for picking */ |
51 |
|
|
52 |
< |
static int gwidth = 0; /* graphics window width */ |
61 |
< |
static int gheight = 0; /* graphics window height */ |
52 |
> |
static int gwidth, gheight; /* graphics window size */ |
53 |
|
|
54 |
|
static TEXTWIND *comline = NULL; /* our command line */ |
55 |
|
|
59 |
|
|
60 |
|
extern char *malloc(), *getcombuf(); |
61 |
|
|
62 |
+ |
extern char *progname; |
63 |
+ |
|
64 |
|
int x_close(), x_clear(), x_paintr(), x_errout(), |
65 |
< |
x_getcur(), x_comout(), x_comin(); |
65 |
> |
x_getcur(), x_comout(), x_comin(), x_flush(); |
66 |
|
|
67 |
|
static struct driver x_driver = { |
68 |
|
x_close, x_clear, x_paintr, x_getcur, |
69 |
< |
x_comout, x_comin, 1.0 |
69 |
> |
x_comout, x_comin, x_flush, 1.0 |
70 |
|
}; |
71 |
|
|
72 |
|
|
74 |
|
x_init(name, id) /* initialize driver */ |
75 |
|
char *name, *id; |
76 |
|
{ |
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"); |
92 |
|
bcross_bits, bcross_mask_bits, |
93 |
|
bcross_x_hot, bcross_y_hot, |
94 |
|
BlackPixel, WhitePixel, GXcopy); |
95 |
< |
clientname = id; |
96 |
< |
x_driver.xsiz = DisplayWidth()-(2*BORWIDTH); |
97 |
< |
x_driver.ysiz = DisplayHeight()-(COMHEIGHT+2*BORWIDTH); |
95 |
> |
mainframe.bdrwidth = BORWIDTH; |
96 |
> |
mainframe.border = BlackPixmap; |
97 |
> |
mainframe.background = BlackPixmap; |
98 |
> |
sprintf(defgeom, "=%dx%d+0+22", DisplayWidth()-(2*BORWIDTH), |
99 |
> |
DisplayHeight()-(2*BORWIDTH+22)); |
100 |
> |
gwind = XCreate("X10 display driver", progname, NULL, defgeom, |
101 |
> |
&mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT); |
102 |
> |
if (gwind == 0) { |
103 |
> |
stderr_v("can't create window\n"); |
104 |
> |
return(NULL); |
105 |
> |
} |
106 |
> |
XStoreName(gwind, id); |
107 |
> |
XSelectInput(gwind, KeyPressed|ButtonPressed| |
108 |
> |
ExposeWindow|ExposeRegion|UnmapWindow); |
109 |
> |
gwidth = mainframe.width; |
110 |
> |
gheight = mainframe.height-COMHEIGHT; |
111 |
> |
x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
112 |
> |
x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
113 |
|
x_driver.inpready = 0; |
114 |
|
cmdvec = x_comout; /* set error vectors */ |
115 |
|
if (wrnvec != NULL) |
133 |
|
if (gwind != 0) { |
134 |
|
XDestroyWindow(gwind); |
135 |
|
gwind = 0; |
125 |
– |
gwidth = gheight = 0; |
136 |
|
} |
137 |
|
XFreeCursor(pickcursor); |
138 |
|
freepixels(); |
145 |
|
x_clear(xres, yres) /* clear our display */ |
146 |
|
int xres, yres; |
147 |
|
{ |
138 |
– |
if (xres < MINWIDTH) |
139 |
– |
xres = MINWIDTH; |
140 |
– |
if (yres < MINHEIGHT) |
141 |
– |
yres = MINHEIGHT; |
148 |
|
if (xres != gwidth || yres != gheight) { /* new window */ |
149 |
|
if (comline != NULL) |
150 |
|
xt_close(comline); |
151 |
< |
if (gwind == 0) { |
146 |
< |
gwind = XCreateWindow(RootWindow, 0, 0, |
147 |
< |
xres, yres+COMHEIGHT, BORWIDTH, |
148 |
< |
BlackPixmap, BlackPixmap); |
149 |
< |
if (gwind == 0) |
150 |
< |
goto fail; |
151 |
< |
XStoreName(gwind, clientname); |
152 |
< |
XSelectInput(gwind, KeyPressed|ButtonPressed| |
153 |
< |
ExposeWindow|ExposeRegion|UnmapWindow); |
154 |
< |
XMapWindow(gwind); |
155 |
< |
} else |
156 |
< |
XChangeWindow(gwind, xres, yres+COMHEIGHT); |
151 |
> |
XChangeWindow(gwind, xres, yres+COMHEIGHT); |
152 |
|
comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
153 |
< |
if (comline == NULL) |
154 |
< |
goto fail; |
153 |
> |
if (comline == NULL) { |
154 |
> |
stderr_v("Cannot open command line window\n"); |
155 |
> |
quit(1); |
156 |
> |
} |
157 |
|
gwidth = xres; |
158 |
|
gheight = yres; |
159 |
|
} else /* just clear */ |
160 |
|
XClear(gwind); |
161 |
|
/* reinitialize color table */ |
162 |
< |
if (ncolors == 0 && getpixels() == 0) |
162 |
> |
if (getpixels() == 0) |
163 |
|
stderr_v("cannot allocate colors\n"); |
164 |
|
else |
165 |
|
new_ctab(ncolors); |
166 |
+ |
|
167 |
+ |
XMapWindow(gwind); /* make sure it's mapped */ |
168 |
|
XSync(1); /* discard input */ |
169 |
|
return; |
171 |
– |
fail: |
172 |
– |
stderr_v("Failure opening window in x_clear\n"); |
173 |
– |
quit(1); |
170 |
|
} |
171 |
|
|
172 |
|
|
175 |
|
COLOR col; |
176 |
|
int xmin, ymin, xmax, ymax; |
177 |
|
{ |
182 |
– |
extern long nrays; /* global ray count */ |
178 |
|
extern int xnewcolr(); /* pixel assignment routine */ |
184 |
– |
static long lastflush = 0; /* ray count at last flush */ |
179 |
|
|
180 |
|
if (ncolors > 0) { |
181 |
|
XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin, |
182 |
|
pixval[get_pixel(col, xnewcolr)]); |
183 |
|
} |
190 |
– |
if (nrays - lastflush >= WFLUSH) { |
191 |
– |
if (ncolors <= 0) /* output necessary for death */ |
192 |
– |
XPixSet(gwind,0,0,1,1,BlackPixel); |
193 |
– |
checkinp(); |
194 |
– |
lastflush = nrays; |
195 |
– |
} |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
static |
188 |
< |
x_comin(inp) /* read in a command line */ |
201 |
< |
char *inp; |
188 |
> |
x_flush() /* flush output */ |
189 |
|
{ |
190 |
+ |
if (ncolors <= 0) /* output necessary for death */ |
191 |
+ |
XPixSet(gwind,0,0,1,1,BlackPixel); |
192 |
+ |
while (XPending() > 0) |
193 |
+ |
getevent(); |
194 |
+ |
|
195 |
+ |
} |
196 |
+ |
|
197 |
+ |
|
198 |
+ |
static |
199 |
+ |
x_comin(inp, prompt) /* read in a command line */ |
200 |
+ |
char *inp, *prompt; |
201 |
+ |
{ |
202 |
|
int x_getc(), x_comout(); |
203 |
|
|
204 |
< |
if (fromcombuf(inp, &x_driver)) |
205 |
< |
return; |
204 |
> |
if (prompt != NULL) |
205 |
> |
if (fromcombuf(inp, &x_driver)) |
206 |
> |
return; |
207 |
> |
else |
208 |
> |
xt_puts(prompt, comline); |
209 |
|
xt_cursor(comline, TBLKCURS); |
210 |
|
editline(inp, x_getc, x_comout); |
211 |
|
xt_cursor(comline, TNOCURS); |
282 |
|
{ |
283 |
|
int planes; |
284 |
|
|
285 |
< |
freepixels(); |
285 |
> |
if (ncolors > 0) |
286 |
> |
return(ncolors); |
287 |
|
for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){ |
288 |
|
pixval = (int *)malloc(ncolors*sizeof(int)); |
289 |
|
if (pixval == NULL) |
352 |
|
return; |
353 |
|
} |
354 |
|
/* check for change in size */ |
355 |
< |
if (eexp->width != gwidth || eexp->height != gheight+COMHEIGHT) { |
356 |
< |
x_driver.xsiz = eexp->width; |
357 |
< |
x_driver.ysiz = eexp->height; |
355 |
> |
if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) { |
356 |
> |
gwidth = eexp->width; |
357 |
> |
gheight = eexp->height-COMHEIGHT; |
358 |
> |
x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
359 |
> |
x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
360 |
|
strcpy(getcombuf(&x_driver), "new\n"); |
361 |
|
return; |
362 |
|
} |
363 |
|
/* remap colors */ |
364 |
< |
if (ncolors == 0 && getpixels() == 0) { |
364 |
> |
if (getpixels() == 0) { |
365 |
|
stderr_v("cannot allocate colors\n"); |
366 |
|
return; |
367 |
|
} |
379 |
|
register char *str; |
380 |
|
|
381 |
|
str = XLookupMapping(ekey, &n); |
382 |
< |
while (n-- > 0 && c_last < sizeof(c_queue)) |
382 |
> |
while (n-- > 0 && c_last < sizeof(c_queue)) { |
383 |
|
c_queue[c_last++] = *str++; |
384 |
< |
x_driver.inpready = c_last - c_first; |
384 |
> |
x_driver.inpready++; |
385 |
> |
} |
386 |
|
} |
387 |
|
|
388 |
|
|