| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 11 |
|
#include <sys/ioctl.h> |
| 12 |
– |
#ifdef sparc |
| 13 |
– |
#include <sys/conf.h> |
| 14 |
– |
#include <sys/file.h> |
| 15 |
– |
#include <sys/filio.h> |
| 16 |
– |
#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 |
< |
static int x11_getcur(); |
| 78 |
> |
static void x11_errout(char *msg); |
| 79 |
|
|
| 80 |
< |
static void x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
| 81 |
< |
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 void 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(), x11_getc(); |
| 95 |
< |
static void xnewcolr(), freepixels(), resizewindow(), |
| 96 |
< |
getevent(), getkey(), fixwindow(); |
| 97 |
< |
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 |
|
{ |
| 116 |
|
char *gv; |
| 117 |
|
int nplanes; |
| 220 |
|
|
| 221 |
|
|
| 222 |
|
static void |
| 223 |
< |
x11_close() /* close our display */ |
| 223 |
> |
x11_close(void) /* close our display */ |
| 224 |
|
{ |
| 225 |
|
erract[COMMAND].pf = NULL; /* reset error vectors */ |
| 226 |
|
if (erract[WARNING].pf != NULL) |
| 243 |
|
|
| 244 |
|
|
| 245 |
|
static void |
| 246 |
< |
x11_clear(xres, yres) /* clear our display */ |
| 247 |
< |
int xres, yres; |
| 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 |
|
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); |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
static void |
| 295 |
< |
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
| 296 |
< |
COLOR col; |
| 297 |
< |
int xmin, ymin, xmax, ymax; |
| 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 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
static void |
| 318 |
< |
x11_flush() /* flush output */ |
| 318 |
> |
x11_flush(void) /* flush output */ |
| 319 |
|
{ |
| 320 |
|
char buf[256]; |
| 321 |
|
int n; |
| 351 |
|
|
| 352 |
|
|
| 353 |
|
static void |
| 354 |
< |
x11_comin(inp, prompt) /* read in a command line */ |
| 355 |
< |
char *inp, *prompt; |
| 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 */ |
| 369 |
|
|
| 370 |
|
|
| 371 |
|
static void |
| 372 |
< |
x11_comout(outp) /* output a string to command line */ |
| 373 |
< |
char *outp; |
| 372 |
> |
x11_comout( /* output a string to command line */ |
| 373 |
> |
char *outp |
| 374 |
> |
) |
| 375 |
|
{ |
| 376 |
|
if (comline == NULL || outp == NULL || !outp[0]) |
| 377 |
|
return; |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
static void |
| 385 |
< |
x11_errout(msg) /* output an error message */ |
| 386 |
< |
char *msg; |
| 385 |
> |
x11_errout( /* output an error message */ |
| 386 |
> |
char *msg |
| 387 |
> |
) |
| 388 |
|
{ |
| 389 |
|
eputs(msg); /* send to stderr also! */ |
| 390 |
|
x11_comout(msg); |
| 392 |
|
|
| 393 |
|
|
| 394 |
|
static void |
| 395 |
< |
std_comin(inp, prompt) /* read in command line from stdin */ |
| 396 |
< |
char *inp, *prompt; |
| 395 |
> |
std_comin( /* read in command line from stdin */ |
| 396 |
> |
char *inp, |
| 397 |
> |
char *prompt |
| 398 |
> |
) |
| 399 |
|
{ |
| 400 |
|
if (prompt != NULL) { |
| 401 |
|
if (fromcombuf(inp, &x11_driver)) |
| 423 |
|
|
| 424 |
|
|
| 425 |
|
static void |
| 426 |
< |
std_comout(outp) /* write out string to stdout */ |
| 427 |
< |
char *outp; |
| 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, |
| 464 |
|
|
| 465 |
|
|
| 466 |
|
static void |
| 467 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
| 468 |
< |
int ndx; |
| 469 |
< |
int r, g, b; |
| 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; |
| 536 |
|
|
| 537 |
|
|
| 538 |
|
static void |
| 539 |
< |
freepixels() /* free our pixels */ |
| 539 |
> |
freepixels(void) /* free our pixels */ |
| 540 |
|
{ |
| 541 |
|
if (ncolors == 0) |
| 542 |
|
return; |
| 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 */ |
| 579 |
|
|
| 580 |
|
|
| 581 |
|
static void |
| 582 |
< |
getevent() /* get next event */ |
| 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 |
|
eputs("cannot allocate colors\n"); |
| 598 |
|
else |
| 599 |
|
new_ctab(ncolors); |
| 600 |
+ |
} |
| 601 |
|
mapped = 1; |
| 602 |
|
break; |
| 603 |
|
case Expose: |
| 613 |
|
|
| 614 |
|
|
| 615 |
|
static void |
| 616 |
< |
getkey(ekey) /* get input key */ |
| 617 |
< |
register XKeyPressedEvent *ekey; |
| 616 |
> |
getkey( /* get input key */ |
| 617 |
> |
register XKeyPressedEvent *ekey |
| 618 |
> |
) |
| 619 |
|
{ |
| 620 |
|
register int n; |
| 621 |
|
|
| 627 |
|
|
| 628 |
|
|
| 629 |
|
static void |
| 630 |
< |
fixwindow(eexp) /* repair damage to window */ |
| 631 |
< |
register XExposeEvent *eexp; |
| 630 |
> |
fixwindow( /* repair damage to window */ |
| 631 |
> |
register XExposeEvent *eexp |
| 632 |
> |
) |
| 633 |
|
{ |
| 634 |
|
char buf[80]; |
| 635 |
|
|
| 646 |
|
|
| 647 |
|
|
| 648 |
|
static void |
| 649 |
< |
resizewindow(ersz) /* resize window */ |
| 650 |
< |
register XConfigureEvent *ersz; |
| 649 |
> |
resizewindow( /* resize window */ |
| 650 |
> |
register XConfigureEvent *ersz |
| 651 |
> |
) |
| 652 |
|
{ |
| 653 |
|
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
| 654 |
|
return; |