13 |
|
#include <stdio.h> |
14 |
|
#include <math.h> |
15 |
|
#include <sys/ioctl.h> |
16 |
+ |
#include <fcntl.h> |
17 |
|
|
18 |
|
#include <X11/Xlib.h> |
19 |
|
#include <X11/cursorfont.h> |
70 |
|
|
71 |
|
static Colormap ourmap = 0; /* our color map */ |
72 |
|
|
73 |
< |
extern char *malloc(), *getcombuf(); |
73 |
> |
#define IC_X11 0 |
74 |
> |
#define IC_IOCTL 1 |
75 |
> |
#define IC_READ 2 |
76 |
|
|
77 |
+ |
static int inpcheck; /* whence to check input */ |
78 |
+ |
|
79 |
+ |
extern char *malloc(); |
80 |
+ |
|
81 |
|
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
82 |
|
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
83 |
|
|
136 |
|
} |
137 |
|
/* set gamma */ |
138 |
|
if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
139 |
< |
|| (gv = getenv("GAMMA")) != NULL) |
139 |
> |
|| (gv = getenv("DISPLAY_GAMMA")) != NULL) |
140 |
|
make_gmap(atof(gv)); |
141 |
|
else |
142 |
|
make_gmap(GAMMA); |
189 |
|
cmdvec = x11_comout; |
190 |
|
if (wrnvec != NULL) |
191 |
|
wrnvec = x11_errout; |
192 |
+ |
inpcheck = IC_X11; |
193 |
|
} else { |
194 |
|
x11_driver.comin = std_comin; |
195 |
|
x11_driver.comout = std_comout; |
196 |
|
cmdvec = std_comout; |
197 |
+ |
inpcheck = IC_IOCTL; |
198 |
|
} |
199 |
|
return(&x11_driver); |
200 |
|
} |
291 |
|
static |
292 |
|
x11_flush() /* flush output */ |
293 |
|
{ |
294 |
+ |
char buf[256]; |
295 |
|
int n; |
296 |
|
/* check for input */ |
297 |
|
XNoOp(ourdisplay); |
298 |
|
n = XPending(ourdisplay); /* from X server */ |
299 |
|
while (n-- > 0) |
300 |
|
getevent(); |
301 |
< |
if (x11_driver.comin == std_comin) { /* from stdin */ |
301 |
> |
if (inpcheck == IC_IOCTL) { /* from stdin */ |
302 |
|
if (ioctl(fileno(stdin), FIONREAD, &n) < 0) { |
303 |
< |
stderr_v("ioctl error on stdin\n"); |
304 |
< |
quit(1); |
303 |
> |
if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) { |
304 |
> |
stderr_v("Cannot change input mode\n"); |
305 |
> |
quit(1); |
306 |
> |
} |
307 |
> |
inpcheck = IC_READ; |
308 |
> |
} else |
309 |
> |
x11_driver.inpready += n; |
310 |
> |
} |
311 |
> |
if (inpcheck == IC_READ) { |
312 |
> |
n = read(fileno(stdin), buf, sizeof(buf)-1); |
313 |
> |
if (n > 0) { |
314 |
> |
buf[n] = '\0'; |
315 |
> |
tocombuf(buf, &x11_driver); |
316 |
|
} |
296 |
– |
x11_driver.inpready += n; |
317 |
|
} |
318 |
|
} |
319 |
|
|
382 |
|
char *outp; |
383 |
|
{ |
384 |
|
fputs(outp, stdout); |
385 |
+ |
fflush(stdout); |
386 |
|
} |
387 |
|
|
388 |
|
|
576 |
|
fixwindow(eexp) /* repair damage to window */ |
577 |
|
register XExposeEvent *eexp; |
578 |
|
{ |
579 |
+ |
char buf[80]; |
580 |
+ |
|
581 |
|
if (eexp->window == gwind) { |
582 |
< |
sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n", |
582 |
> |
sprintf(buf, "repaint %d %d %d %d\n", |
583 |
|
eexp->x, gheight - eexp->y - eexp->height, |
584 |
|
eexp->x + eexp->width, gheight - eexp->y); |
585 |
+ |
tocombuf(buf, &x11_driver); |
586 |
|
} else if (eexp->window == comline->w) { |
587 |
|
if (eexp->count == 0) |
588 |
|
xt_redraw(comline); |
602 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
603 |
|
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
604 |
|
|
605 |
< |
strcpy(getcombuf(&x11_driver), "new\n"); |
605 |
> |
tocombuf("new\n", &x11_driver); |
606 |
|
} |