| 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 */ |
| 74 |
|
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
| 75 |
|
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
| 76 |
|
|
| 77 |
+ |
static int std_comin(), std_comout(); |
| 78 |
+ |
|
| 79 |
|
static struct driver x11_driver = { |
| 80 |
|
x11_close, x11_clear, x11_paintr, x11_getcur, |
| 81 |
< |
x11_comout, x11_comin, x11_flush, 1.0 |
| 81 |
> |
NULL, NULL, x11_flush, 1.0 |
| 82 |
|
}; |
| 83 |
|
|
| 84 |
|
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), |
| 96 |
|
XSetWindowAttributes ourwinattr; |
| 97 |
|
XWMHints ourxwmhints; |
| 98 |
|
XSizeHints oursizhints; |
| 99 |
< |
|
| 99 |
> |
/* open display server */ |
| 100 |
|
ourdisplay = XOpenDisplay(NULL); |
| 101 |
|
if (ourdisplay == NULL) { |
| 102 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
| 133 |
|
make_gmap(atof(gv)); |
| 134 |
|
else |
| 135 |
|
make_gmap(GAMMA); |
| 136 |
+ |
/* X11 command line or no? */ |
| 137 |
+ |
if (!strcmp(name, "x11")) |
| 138 |
+ |
comheight = COMHEIGHT; |
| 139 |
+ |
else /* "x11d" */ |
| 140 |
+ |
comheight = 0; |
| 141 |
|
/* open window */ |
| 142 |
|
ourwinattr.background_pixel = ourblack; |
| 143 |
|
ourwinattr.border_pixel = ourblack; |
| 163 |
|
gwind, x11icon_bits, x11icon_width, x11icon_height); |
| 164 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 165 |
|
oursizhints.min_width = MINWIDTH; |
| 166 |
< |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
| 166 |
> |
oursizhints.min_height = MINHEIGHT+comheight; |
| 167 |
|
oursizhints.flags = PMinSize; |
| 168 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 169 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
| 170 |
|
XMapWindow(ourdisplay, gwind); |
| 171 |
|
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
| 172 |
|
gwidth = levptr(XExposeEvent)->width; |
| 173 |
< |
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
| 173 |
> |
gheight = levptr(XExposeEvent)->height - comheight; |
| 174 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 175 |
|
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
| 176 |
|
x11_driver.inpready = 0; |
| 177 |
|
mapped = 1; |
| 178 |
< |
cmdvec = x11_comout; /* set error vectors */ |
| 179 |
< |
if (wrnvec != NULL) |
| 180 |
< |
wrnvec = x11_errout; |
| 178 |
> |
/* set i/o vectors */ |
| 179 |
> |
if (comheight) { |
| 180 |
> |
x11_driver.comin = x11_comin; |
| 181 |
> |
x11_driver.comout = x11_comout; |
| 182 |
> |
cmdvec = x11_comout; |
| 183 |
> |
if (wrnvec != NULL) |
| 184 |
> |
wrnvec = x11_errout; |
| 185 |
> |
} else { |
| 186 |
> |
x11_driver.comin = std_comin; |
| 187 |
> |
x11_driver.comout = std_comout; |
| 188 |
> |
cmdvec = std_comout; |
| 189 |
> |
} |
| 190 |
|
return(&x11_driver); |
| 191 |
|
} |
| 192 |
|
|
| 226 |
|
/* resize window */ |
| 227 |
|
if (xres != gwidth || yres != gheight) { |
| 228 |
|
XSelectInput(ourdisplay, gwind, 0); |
| 229 |
< |
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
| 229 |
> |
XResizeWindow(ourdisplay, gwind, xres, yres+comheight); |
| 230 |
|
gwidth = xres; |
| 231 |
|
gheight = yres; |
| 232 |
|
XFlush(ourdisplay); |
| 243 |
|
/* get new command line */ |
| 244 |
|
if (comline != NULL) |
| 245 |
|
xt_close(comline); |
| 246 |
< |
comline = xt_open(ourdisplay, gwind, 0, gheight, |
| 247 |
< |
gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN); |
| 248 |
< |
if (comline == NULL) { |
| 249 |
< |
stderr_v("Cannot open command line window\n"); |
| 250 |
< |
quit(1); |
| 251 |
< |
} |
| 252 |
< |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
| 246 |
> |
if (comheight) { |
| 247 |
> |
comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth, |
| 248 |
> |
comheight, 0, ourblack, ourwhite, COMFN); |
| 249 |
> |
if (comline == NULL) { |
| 250 |
> |
stderr_v("Cannot open command line window\n"); |
| 251 |
> |
quit(1); |
| 252 |
> |
} |
| 253 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
| 254 |
|
/* remove earmuffs */ |
| 255 |
< |
XSelectInput(ourdisplay, gwind, |
| 255 |
> |
XSelectInput(ourdisplay, gwind, |
| 256 |
|
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
| 257 |
+ |
} else /* remove earmuffs */ |
| 258 |
+ |
XSelectInput(ourdisplay, gwind, |
| 259 |
+ |
StructureNotifyMask|ExposureMask|ButtonPressMask); |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
|
| 283 |
|
x11_flush() /* flush output */ |
| 284 |
|
{ |
| 285 |
|
int n; |
| 265 |
– |
char *buf; |
| 286 |
|
/* check for input */ |
| 287 |
|
XNoOp(ourdisplay); |
| 288 |
|
n = XPending(ourdisplay); /* from X server */ |
| 289 |
|
while (n-- > 0) |
| 290 |
|
getevent(); |
| 291 |
< |
if (ioctl(0, FIONREAD, &n) == 0 && n > 0) { /* from stdin */ |
| 292 |
< |
buf = getcombuf(&x11_driver); |
| 293 |
< |
n = read(0, buf, n); |
| 294 |
< |
if (n > 0) |
| 295 |
< |
buf[n] = '\0'; |
| 291 |
> |
if (x11_driver.comin == std_comin) { /* from stdin */ |
| 292 |
> |
if (ioctl(fileno(stdin), FIONREAD, &n) < 0) { |
| 293 |
> |
stderr_v("ioctl error on stdin\n"); |
| 294 |
> |
quit(1); |
| 295 |
> |
} |
| 296 |
> |
x11_driver.inpready += n; |
| 297 |
|
} |
| 298 |
|
} |
| 299 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
static |
| 318 |
< |
x11_comout(out) /* output a string to command line */ |
| 319 |
< |
char *out; |
| 318 |
> |
x11_comout(outp) /* output a string to command line */ |
| 319 |
> |
char *outp; |
| 320 |
|
{ |
| 321 |
|
if (comline == NULL) |
| 322 |
|
return; |
| 323 |
< |
xt_puts(out, comline); |
| 324 |
< |
if (out[strlen(out)-1] == '\n') |
| 323 |
> |
xt_puts(outp, comline); |
| 324 |
> |
if (outp[strlen(outp)-1] == '\n') |
| 325 |
|
XFlush(ourdisplay); |
| 326 |
|
} |
| 327 |
|
|
| 335 |
|
} |
| 336 |
|
|
| 337 |
|
|
| 338 |
+ |
static |
| 339 |
+ |
std_comin(inp, prompt) /* read in command line from stdin */ |
| 340 |
+ |
char *inp, *prompt; |
| 341 |
+ |
{ |
| 342 |
+ |
extern char *gets(); |
| 343 |
+ |
|
| 344 |
+ |
if (prompt != NULL) { |
| 345 |
+ |
if (fromcombuf(inp, &x11_driver)) |
| 346 |
+ |
return; |
| 347 |
+ |
if (!x11_driver.inpready) |
| 348 |
+ |
fputs(prompt, stdout); |
| 349 |
+ |
} |
| 350 |
+ |
if (gets(inp) == NULL) { |
| 351 |
+ |
strcpy(inp, "quit"); |
| 352 |
+ |
return; |
| 353 |
+ |
} |
| 354 |
+ |
x11_driver.inpready -= strlen(inp) + 1; |
| 355 |
+ |
if (x11_driver.inpready < 0) |
| 356 |
+ |
x11_driver.inpready = 0; |
| 357 |
+ |
} |
| 358 |
+ |
|
| 359 |
+ |
|
| 360 |
+ |
static |
| 361 |
+ |
std_comout(outp) /* write out string to stdout */ |
| 362 |
+ |
char *outp; |
| 363 |
+ |
{ |
| 364 |
+ |
fputs(outp, stdout); |
| 365 |
+ |
} |
| 366 |
+ |
|
| 367 |
+ |
|
| 368 |
|
static int |
| 369 |
|
x11_getcur(xp, yp) /* get cursor position */ |
| 370 |
|
int *xp, *yp; |
| 570 |
|
resizewindow(ersz) /* resize window */ |
| 571 |
|
register XConfigureEvent *ersz; |
| 572 |
|
{ |
| 573 |
< |
if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight) |
| 573 |
> |
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
| 574 |
|
return; |
| 575 |
|
|
| 576 |
|
gwidth = ersz->width; |
| 577 |
< |
gheight = ersz->height-COMHEIGHT; |
| 577 |
> |
gheight = ersz->height-comheight; |
| 578 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 579 |
|
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
| 580 |
|
|