1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* x11.c - driver for X-windows version 11 |
9 |
– |
* |
10 |
– |
* Jan 1990 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
9 |
< |
#include <math.h> |
8 |
> |
#include "copyright.h" |
9 |
> |
|
10 |
> |
#include "standard.h" |
11 |
|
#include <sys/ioctl.h> |
16 |
– |
#include <fcntl.h> |
17 |
– |
#ifdef sparc |
18 |
– |
#include <sys/conf.h> |
19 |
– |
#include <sys/file.h> |
20 |
– |
#include <sys/filio.h> |
21 |
– |
#endif |
12 |
|
#if !defined(FNDELAY) && defined(O_NONBLOCK) |
13 |
|
#define FNDELAY O_NONBLOCK |
14 |
|
#endif |
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" |
75 |
|
|
76 |
|
static int inpcheck; /* whence to check input */ |
77 |
|
|
78 |
< |
extern char *malloc(); |
78 |
> |
static void x11_errout(char *msg); |
79 |
|
|
80 |
< |
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
81 |
< |
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
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 int std_comin(), std_comout(); |
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 |
|
NULL, NULL, x11_flush, 1.0 |
94 |
|
}; |
95 |
|
|
96 |
< |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), |
100 |
< |
getevent(), getkey(), fixwindow(), x11_getc(); |
101 |
< |
static unsigned long true_pixel(); |
96 |
> |
static dr_getchf_t x11_getc; |
97 |
|
|
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 |
< |
struct driver * |
108 |
< |
x11_init(name, id) /* initialize driver */ |
109 |
< |
char *name, *id; |
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 |
|
{ |
108 |
– |
extern char *getenv(); |
116 |
|
char *gv; |
117 |
|
int nplanes; |
118 |
|
XSetWindowAttributes ourwinattr; |
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 */ |
136 |
|
ourvinfo.blue_mask ; |
137 |
|
} else { |
138 |
|
if (nplanes < 4) { |
139 |
< |
stderr_v("not enough colors\n"); |
139 |
> |
eputs("not enough colors\n"); |
140 |
|
return(NULL); |
141 |
|
} |
142 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
143 |
|
nplanes,PseudoColor,&ourvinfo) && |
144 |
|
!XMatchVisualInfo(ourdisplay,ourscreen, |
145 |
|
nplanes,GrayScale,&ourvinfo)) { |
146 |
< |
stderr_v("unsupported visual type\n"); |
146 |
> |
eputs("unsupported visual type\n"); |
147 |
|
return(NULL); |
148 |
|
} |
149 |
|
ourblack = BlackPixel(ourdisplay,ourscreen); |
161 |
|
else /* "x11d" */ { |
162 |
|
comheight = 0; |
163 |
|
#ifndef FNDELAY |
164 |
< |
stderr_v("warning: x11d driver not fully functional on this machine\n"); |
164 |
> |
eputs("warning: x11d driver not fully functional on this machine\n"); |
165 |
|
#endif |
166 |
|
} |
167 |
|
/* open window */ |
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); |
205 |
|
if (comheight) { |
206 |
|
x11_driver.comin = x11_comin; |
207 |
|
x11_driver.comout = x11_comout; |
208 |
< |
cmdvec = x11_comout; |
209 |
< |
if (wrnvec != NULL) |
210 |
< |
wrnvec = x11_errout; |
208 |
> |
erract[COMMAND].pf = x11_comout; |
209 |
> |
if (erract[WARNING].pf != NULL) |
210 |
> |
erract[WARNING].pf = x11_errout; |
211 |
|
inpcheck = IC_X11; |
212 |
|
} else { |
213 |
|
x11_driver.comin = std_comin; |
214 |
|
x11_driver.comout = std_comout; |
215 |
< |
cmdvec = std_comout; |
215 |
> |
erract[COMMAND].pf = std_comout; |
216 |
|
inpcheck = IC_IOCTL; |
217 |
|
} |
218 |
|
return(&x11_driver); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
static |
223 |
< |
x11_close() /* close our display */ |
222 |
> |
static void |
223 |
> |
x11_close(void) /* close our display */ |
224 |
|
{ |
225 |
< |
cmdvec = NULL; /* reset error vectors */ |
226 |
< |
if (wrnvec != NULL) |
227 |
< |
wrnvec = stderr_v; |
225 |
> |
erract[COMMAND].pf = NULL; /* reset error vectors */ |
226 |
> |
if (erract[WARNING].pf != NULL) |
227 |
> |
erract[WARNING].pf = wputs; |
228 |
|
if (ourdisplay == NULL) |
229 |
|
return; |
230 |
|
if (comline != NULL) { |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
< |
static |
246 |
< |
x11_clear(xres, yres) /* clear our display */ |
247 |
< |
int xres, yres; |
245 |
> |
static void |
246 |
> |
x11_clear( /* clear our display */ |
247 |
> |
int xres, |
248 |
> |
int yres |
249 |
> |
) |
250 |
|
{ |
251 |
|
/* check limits */ |
252 |
|
if (xres < MINWIDTH) |
265 |
|
} |
266 |
|
XClearWindow(ourdisplay, gwind); |
267 |
|
/* reinitialize color table */ |
268 |
< |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
268 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) { |
269 |
|
if (getpixels() == 0) |
270 |
< |
stderr_v("cannot allocate colors\n"); |
270 |
> |
eputs("cannot allocate colors\n"); |
271 |
|
else |
272 |
|
new_ctab(ncolors); |
273 |
+ |
} |
274 |
|
/* get new command line */ |
275 |
|
if (comline != NULL) |
276 |
|
xt_close(comline); |
278 |
|
comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth, |
279 |
|
comheight, 0, ourblack, ourwhite, COMFN); |
280 |
|
if (comline == NULL) { |
281 |
< |
stderr_v("cannot open command line window\n"); |
281 |
> |
eputs("cannot open command line window\n"); |
282 |
|
quit(1); |
283 |
|
} |
284 |
|
XSelectInput(ourdisplay, comline->w, ExposureMask); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
< |
static |
295 |
< |
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
296 |
< |
COLOR col; |
297 |
< |
int xmin, ymin, xmax, ymax; |
294 |
> |
static void |
295 |
> |
x11_paintr( /* fill a rectangle */ |
296 |
> |
COLOR col, |
297 |
> |
int xmin, |
298 |
> |
int ymin, |
299 |
> |
int xmax, |
300 |
> |
int ymax |
301 |
> |
) |
302 |
|
{ |
303 |
|
unsigned long pixel; |
304 |
|
|
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
< |
static |
318 |
< |
x11_flush() /* flush output */ |
317 |
> |
static void |
318 |
> |
x11_flush(void) /* flush output */ |
319 |
|
{ |
320 |
|
char buf[256]; |
321 |
|
int n; |
332 |
|
if (1) { |
333 |
|
#endif |
334 |
|
if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) { |
335 |
< |
stderr_v("cannot change input mode\n"); |
335 |
> |
eputs("cannot change input mode\n"); |
336 |
|
quit(1); |
337 |
|
} |
338 |
|
inpcheck = IC_READ; |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
< |
static |
354 |
< |
x11_comin(inp, prompt) /* read in a command line */ |
355 |
< |
char *inp, *prompt; |
353 |
> |
static void |
354 |
> |
x11_comin( /* read in a command line */ |
355 |
> |
char *inp, |
356 |
> |
char *prompt |
357 |
> |
) |
358 |
|
{ |
359 |
|
if (prompt != NULL) { |
360 |
|
x11_flush(); /* make sure we get everything */ |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
< |
static |
372 |
< |
x11_comout(outp) /* output a string to command line */ |
373 |
< |
char *outp; |
371 |
> |
static void |
372 |
> |
x11_comout( /* output a string to command line */ |
373 |
> |
char *outp |
374 |
> |
) |
375 |
|
{ |
376 |
< |
if (comline == NULL) |
376 |
> |
if (comline == NULL || outp == NULL || !outp[0]) |
377 |
|
return; |
378 |
|
xt_puts(outp, comline); |
379 |
|
if (outp[strlen(outp)-1] == '\n') |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
< |
static |
385 |
< |
x11_errout(msg) /* output an error message */ |
386 |
< |
char *msg; |
384 |
> |
static void |
385 |
> |
x11_errout( /* output an error message */ |
386 |
> |
char *msg |
387 |
> |
) |
388 |
|
{ |
389 |
< |
stderr_v(msg); /* send to stderr also! */ |
389 |
> |
eputs(msg); /* send to stderr also! */ |
390 |
|
x11_comout(msg); |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
< |
static |
395 |
< |
std_comin(inp, prompt) /* read in command line from stdin */ |
396 |
< |
char *inp, *prompt; |
394 |
> |
static void |
395 |
> |
std_comin( /* read in command line from stdin */ |
396 |
> |
char *inp, |
397 |
> |
char *prompt |
398 |
> |
) |
399 |
|
{ |
380 |
– |
extern char *gets(); |
381 |
– |
|
400 |
|
if (prompt != NULL) { |
401 |
|
if (fromcombuf(inp, &x11_driver)) |
402 |
|
return; |
406 |
|
#ifdef FNDELAY |
407 |
|
if (inpcheck == IC_READ) { /* turn off FNDELAY */ |
408 |
|
if (fcntl(fileno(stdin), F_SETFL, 0) < 0) { |
409 |
< |
stderr_v("cannot change input mode\n"); |
409 |
> |
eputs("cannot change input mode\n"); |
410 |
|
quit(1); |
411 |
|
} |
412 |
|
inpcheck = IC_IOCTL; |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
< |
static |
426 |
< |
std_comout(outp) /* write out string to stdout */ |
427 |
< |
char *outp; |
425 |
> |
static void |
426 |
> |
std_comout( /* write out string to stdout */ |
427 |
> |
char *outp |
428 |
> |
) |
429 |
|
{ |
430 |
|
fputs(outp, stdout); |
431 |
|
fflush(stdout); |
433 |
|
|
434 |
|
|
435 |
|
static int |
436 |
< |
x11_getcur(xp, yp) /* get cursor position */ |
437 |
< |
int *xp, *yp; |
436 |
> |
x11_getcur( /* get cursor position */ |
437 |
> |
int *xp, |
438 |
> |
int *yp |
439 |
> |
) |
440 |
|
{ |
441 |
|
while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask, |
442 |
|
GrabModeAsync, GrabModeAsync, None, pickcursor, |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
< |
static |
467 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
468 |
< |
int ndx; |
469 |
< |
int r, g, b; |
466 |
> |
static void |
467 |
> |
xnewcolr( /* enter a color into hardware table */ |
468 |
> |
int ndx, |
469 |
> |
int r, |
470 |
> |
int g, |
471 |
> |
int b |
472 |
> |
) |
473 |
|
{ |
474 |
|
XColor xcolor; |
475 |
|
|
484 |
|
|
485 |
|
|
486 |
|
static int |
487 |
< |
getpixels() /* get the color map */ |
487 |
> |
getpixels(void) /* get the color map */ |
488 |
|
{ |
489 |
|
XColor thiscolor; |
490 |
|
register int i, j; |
506 |
|
return(ncolors = 0); |
507 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) |
508 |
|
break; |
509 |
< |
free((char *)pixval); |
509 |
> |
free((void *)pixval); |
510 |
|
pixval = NULL; |
511 |
|
} |
512 |
|
if (pixval == NULL) { |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
< |
static |
539 |
< |
freepixels() /* free our pixels */ |
538 |
> |
static void |
539 |
> |
freepixels(void) /* free our pixels */ |
540 |
|
{ |
541 |
|
if (ncolors == 0) |
542 |
|
return; |
543 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
544 |
< |
free((char *)pixval); |
544 |
> |
free((void *)pixval); |
545 |
|
pixval = NULL; |
546 |
|
ncolors = 0; |
547 |
|
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
551 |
|
|
552 |
|
|
553 |
|
static unsigned long |
554 |
< |
true_pixel(col) /* return true pixel value for color */ |
555 |
< |
COLOR col; |
554 |
> |
true_pixel( /* return true pixel value for color */ |
555 |
> |
COLOR col |
556 |
> |
) |
557 |
|
{ |
558 |
|
unsigned long rval; |
559 |
|
BYTE rgb[3]; |
567 |
|
|
568 |
|
|
569 |
|
static int |
570 |
< |
x11_getc() /* get a command character */ |
570 |
> |
x11_getc(void) /* get a command character */ |
571 |
|
{ |
572 |
|
while (c_last <= c_first) { |
573 |
|
c_first = c_last = 0; /* reset */ |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
< |
static |
582 |
< |
getevent() /* get next event */ |
581 |
> |
static void |
582 |
> |
getevent(void) /* get next event */ |
583 |
|
{ |
584 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
585 |
|
switch (levptr(XEvent)->type) { |
592 |
|
break; |
593 |
|
case MapNotify: |
594 |
|
if (ourvinfo.class == PseudoColor || |
595 |
< |
ourvinfo.class == GrayScale) |
595 |
> |
ourvinfo.class == GrayScale) { |
596 |
|
if (getpixels() == 0) |
597 |
< |
stderr_v("cannot allocate colors\n"); |
597 |
> |
eputs("cannot allocate colors\n"); |
598 |
|
else |
599 |
|
new_ctab(ncolors); |
600 |
+ |
} |
601 |
|
mapped = 1; |
602 |
|
break; |
603 |
|
case Expose: |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
< |
static |
616 |
< |
getkey(ekey) /* get input key */ |
617 |
< |
register XKeyPressedEvent *ekey; |
615 |
> |
static void |
616 |
> |
getkey( /* get input key */ |
617 |
> |
register XKeyPressedEvent *ekey |
618 |
> |
) |
619 |
|
{ |
620 |
|
register int n; |
621 |
|
|
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
< |
static |
630 |
< |
fixwindow(eexp) /* repair damage to window */ |
631 |
< |
register XExposeEvent *eexp; |
629 |
> |
static void |
630 |
> |
fixwindow( /* repair damage to window */ |
631 |
> |
register XExposeEvent *eexp |
632 |
> |
) |
633 |
|
{ |
634 |
|
char buf[80]; |
635 |
|
|
645 |
|
} |
646 |
|
|
647 |
|
|
648 |
< |
static |
649 |
< |
resizewindow(ersz) /* resize window */ |
650 |
< |
register XConfigureEvent *ersz; |
648 |
> |
static void |
649 |
> |
resizewindow( /* resize window */ |
650 |
> |
register XConfigureEvent *ersz |
651 |
> |
) |
652 |
|
{ |
653 |
|
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
654 |
|
return; |