| 22 |
|
#include <X11/cursorfont.h> |
| 23 |
|
#include <X11/Xutil.h> |
| 24 |
|
|
| 25 |
+ |
#include "platform.h" |
| 26 |
|
#include "color.h" |
| 27 |
|
#include "driver.h" |
| 28 |
|
#include "x11twind.h" |
| 80 |
|
|
| 81 |
|
static int inpcheck; /* whence to check input */ |
| 82 |
|
|
| 83 |
< |
static int x11_getcur(); |
| 83 |
> |
static void x11_errout(char *msg); |
| 84 |
|
|
| 85 |
< |
static void x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
| 86 |
< |
x11_comout(), x11_comin(), x11_flush(); |
| 85 |
> |
static dr_closef_t x11_close; |
| 86 |
> |
static dr_clearf_t x11_clear; |
| 87 |
> |
static dr_paintrf_t x11_paintr; |
| 88 |
> |
static dr_getcurf_t x11_getcur; |
| 89 |
> |
static dr_comoutf_t x11_comout; |
| 90 |
> |
static dr_cominf_t x11_comin; |
| 91 |
> |
static dr_flushf_t x11_flush; |
| 92 |
|
|
| 93 |
< |
static void std_comin(), std_comout(); |
| 93 |
> |
static dr_cominf_t std_comin; |
| 94 |
> |
static dr_comoutf_t std_comout; |
| 95 |
|
|
| 96 |
|
static struct driver x11_driver = { |
| 97 |
|
x11_close, x11_clear, x11_paintr, x11_getcur, |
| 98 |
|
NULL, NULL, x11_flush, 1.0 |
| 99 |
|
}; |
| 100 |
|
|
| 101 |
< |
static int getpixels(), x11_getc(); |
| 95 |
< |
static void xnewcolr(), freepixels(), resizewindow(), |
| 96 |
< |
getevent(), getkey(), fixwindow(); |
| 97 |
< |
static unsigned long true_pixel(); |
| 101 |
> |
static dr_getchf_t x11_getc; |
| 102 |
|
|
| 103 |
+ |
static void freepixels(void); |
| 104 |
+ |
static int getpixels(void); |
| 105 |
+ |
static dr_newcolrf_t xnewcolr; |
| 106 |
+ |
static unsigned long true_pixel(COLOR col); |
| 107 |
+ |
static void getevent(void); |
| 108 |
+ |
static void getkey(XKeyPressedEvent *ekey); |
| 109 |
+ |
static void fixwindow(XExposeEvent *eexp); |
| 110 |
+ |
static void resizewindow(XConfigureEvent *ersz); |
| 111 |
|
|
| 112 |
< |
struct driver * |
| 113 |
< |
x11_init(name, id) /* initialize driver */ |
| 114 |
< |
char *name, *id; |
| 112 |
> |
extern dr_initf_t x11_init; /* XXX this should be in a seperate header file */ |
| 113 |
> |
|
| 114 |
> |
|
| 115 |
> |
extern struct driver * |
| 116 |
> |
x11_init( /* initialize driver */ |
| 117 |
> |
char *name, |
| 118 |
> |
char *id |
| 119 |
> |
) |
| 120 |
|
{ |
| 121 |
|
char *gv; |
| 122 |
|
int nplanes; |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
static void |
| 228 |
< |
x11_close() /* close our display */ |
| 228 |
> |
x11_close(void) /* close our display */ |
| 229 |
|
{ |
| 230 |
|
erract[COMMAND].pf = NULL; /* reset error vectors */ |
| 231 |
|
if (erract[WARNING].pf != NULL) |
| 248 |
|
|
| 249 |
|
|
| 250 |
|
static void |
| 251 |
< |
x11_clear(xres, yres) /* clear our display */ |
| 252 |
< |
int xres, yres; |
| 251 |
> |
x11_clear( /* clear our display */ |
| 252 |
> |
int xres, |
| 253 |
> |
int yres |
| 254 |
> |
) |
| 255 |
|
{ |
| 256 |
|
/* check limits */ |
| 257 |
|
if (xres < MINWIDTH) |
| 270 |
|
} |
| 271 |
|
XClearWindow(ourdisplay, gwind); |
| 272 |
|
/* reinitialize color table */ |
| 273 |
< |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
| 273 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) { |
| 274 |
|
if (getpixels() == 0) |
| 275 |
|
eputs("cannot allocate colors\n"); |
| 276 |
|
else |
| 277 |
|
new_ctab(ncolors); |
| 278 |
+ |
} |
| 279 |
|
/* get new command line */ |
| 280 |
|
if (comline != NULL) |
| 281 |
|
xt_close(comline); |
| 297 |
|
|
| 298 |
|
|
| 299 |
|
static void |
| 300 |
< |
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
| 301 |
< |
COLOR col; |
| 302 |
< |
int xmin, ymin, xmax, ymax; |
| 300 |
> |
x11_paintr( /* fill a rectangle */ |
| 301 |
> |
COLOR col, |
| 302 |
> |
int xmin, |
| 303 |
> |
int ymin, |
| 304 |
> |
int xmax, |
| 305 |
> |
int ymax |
| 306 |
> |
) |
| 307 |
|
{ |
| 308 |
|
unsigned long pixel; |
| 309 |
|
|
| 320 |
|
|
| 321 |
|
|
| 322 |
|
static void |
| 323 |
< |
x11_flush() /* flush output */ |
| 323 |
> |
x11_flush(void) /* flush output */ |
| 324 |
|
{ |
| 325 |
|
char buf[256]; |
| 326 |
|
int n; |
| 356 |
|
|
| 357 |
|
|
| 358 |
|
static void |
| 359 |
< |
x11_comin(inp, prompt) /* read in a command line */ |
| 360 |
< |
char *inp, *prompt; |
| 359 |
> |
x11_comin( /* read in a command line */ |
| 360 |
> |
char *inp, |
| 361 |
> |
char *prompt |
| 362 |
> |
) |
| 363 |
|
{ |
| 364 |
|
if (prompt != NULL) { |
| 365 |
|
x11_flush(); /* make sure we get everything */ |
| 374 |
|
|
| 375 |
|
|
| 376 |
|
static void |
| 377 |
< |
x11_comout(outp) /* output a string to command line */ |
| 378 |
< |
char *outp; |
| 377 |
> |
x11_comout( /* output a string to command line */ |
| 378 |
> |
char *outp |
| 379 |
> |
) |
| 380 |
|
{ |
| 381 |
|
if (comline == NULL || outp == NULL || !outp[0]) |
| 382 |
|
return; |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
static void |
| 390 |
< |
x11_errout(msg) /* output an error message */ |
| 391 |
< |
char *msg; |
| 390 |
> |
x11_errout( /* output an error message */ |
| 391 |
> |
char *msg |
| 392 |
> |
) |
| 393 |
|
{ |
| 394 |
|
eputs(msg); /* send to stderr also! */ |
| 395 |
|
x11_comout(msg); |
| 397 |
|
|
| 398 |
|
|
| 399 |
|
static void |
| 400 |
< |
std_comin(inp, prompt) /* read in command line from stdin */ |
| 401 |
< |
char *inp, *prompt; |
| 400 |
> |
std_comin( /* read in command line from stdin */ |
| 401 |
> |
char *inp, |
| 402 |
> |
char *prompt |
| 403 |
> |
) |
| 404 |
|
{ |
| 405 |
|
if (prompt != NULL) { |
| 406 |
|
if (fromcombuf(inp, &x11_driver)) |
| 428 |
|
|
| 429 |
|
|
| 430 |
|
static void |
| 431 |
< |
std_comout(outp) /* write out string to stdout */ |
| 432 |
< |
char *outp; |
| 431 |
> |
std_comout( /* write out string to stdout */ |
| 432 |
> |
char *outp |
| 433 |
> |
) |
| 434 |
|
{ |
| 435 |
|
fputs(outp, stdout); |
| 436 |
|
fflush(stdout); |
| 438 |
|
|
| 439 |
|
|
| 440 |
|
static int |
| 441 |
< |
x11_getcur(xp, yp) /* get cursor position */ |
| 442 |
< |
int *xp, *yp; |
| 441 |
> |
x11_getcur( /* get cursor position */ |
| 442 |
> |
int *xp, |
| 443 |
> |
int *yp |
| 444 |
> |
) |
| 445 |
|
{ |
| 446 |
|
while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask, |
| 447 |
|
GrabModeAsync, GrabModeAsync, None, pickcursor, |
| 469 |
|
|
| 470 |
|
|
| 471 |
|
static void |
| 472 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
| 473 |
< |
int ndx; |
| 474 |
< |
int r, g, b; |
| 472 |
> |
xnewcolr( /* enter a color into hardware table */ |
| 473 |
> |
int ndx, |
| 474 |
> |
int r, |
| 475 |
> |
int g, |
| 476 |
> |
int b |
| 477 |
> |
) |
| 478 |
|
{ |
| 479 |
|
XColor xcolor; |
| 480 |
|
|
| 489 |
|
|
| 490 |
|
|
| 491 |
|
static int |
| 492 |
< |
getpixels() /* get the color map */ |
| 492 |
> |
getpixels(void) /* get the color map */ |
| 493 |
|
{ |
| 494 |
|
XColor thiscolor; |
| 495 |
|
register int i, j; |
| 541 |
|
|
| 542 |
|
|
| 543 |
|
static void |
| 544 |
< |
freepixels() /* free our pixels */ |
| 544 |
> |
freepixels(void) /* free our pixels */ |
| 545 |
|
{ |
| 546 |
|
if (ncolors == 0) |
| 547 |
|
return; |
| 556 |
|
|
| 557 |
|
|
| 558 |
|
static unsigned long |
| 559 |
< |
true_pixel(col) /* return true pixel value for color */ |
| 560 |
< |
COLOR col; |
| 559 |
> |
true_pixel( /* return true pixel value for color */ |
| 560 |
> |
COLOR col |
| 561 |
> |
) |
| 562 |
|
{ |
| 563 |
|
unsigned long rval; |
| 564 |
|
BYTE rgb[3]; |
| 572 |
|
|
| 573 |
|
|
| 574 |
|
static int |
| 575 |
< |
x11_getc() /* get a command character */ |
| 575 |
> |
x11_getc(void) /* get a command character */ |
| 576 |
|
{ |
| 577 |
|
while (c_last <= c_first) { |
| 578 |
|
c_first = c_last = 0; /* reset */ |
| 584 |
|
|
| 585 |
|
|
| 586 |
|
static void |
| 587 |
< |
getevent() /* get next event */ |
| 587 |
> |
getevent(void) /* get next event */ |
| 588 |
|
{ |
| 589 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
| 590 |
|
switch (levptr(XEvent)->type) { |
| 597 |
|
break; |
| 598 |
|
case MapNotify: |
| 599 |
|
if (ourvinfo.class == PseudoColor || |
| 600 |
< |
ourvinfo.class == GrayScale) |
| 600 |
> |
ourvinfo.class == GrayScale) { |
| 601 |
|
if (getpixels() == 0) |
| 602 |
|
eputs("cannot allocate colors\n"); |
| 603 |
|
else |
| 604 |
|
new_ctab(ncolors); |
| 605 |
+ |
} |
| 606 |
|
mapped = 1; |
| 607 |
|
break; |
| 608 |
|
case Expose: |
| 618 |
|
|
| 619 |
|
|
| 620 |
|
static void |
| 621 |
< |
getkey(ekey) /* get input key */ |
| 622 |
< |
register XKeyPressedEvent *ekey; |
| 621 |
> |
getkey( /* get input key */ |
| 622 |
> |
register XKeyPressedEvent *ekey |
| 623 |
> |
) |
| 624 |
|
{ |
| 625 |
|
register int n; |
| 626 |
|
|
| 632 |
|
|
| 633 |
|
|
| 634 |
|
static void |
| 635 |
< |
fixwindow(eexp) /* repair damage to window */ |
| 636 |
< |
register XExposeEvent *eexp; |
| 635 |
> |
fixwindow( /* repair damage to window */ |
| 636 |
> |
register XExposeEvent *eexp |
| 637 |
> |
) |
| 638 |
|
{ |
| 639 |
|
char buf[80]; |
| 640 |
|
|
| 651 |
|
|
| 652 |
|
|
| 653 |
|
static void |
| 654 |
< |
resizewindow(ersz) /* resize window */ |
| 655 |
< |
register XConfigureEvent *ersz; |
| 654 |
> |
resizewindow( /* resize window */ |
| 655 |
> |
register XConfigureEvent *ersz |
| 656 |
> |
) |
| 657 |
|
{ |
| 658 |
|
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
| 659 |
|
return; |