5 |
|
* x11.c - driver for X-windows version 11 |
6 |
|
*/ |
7 |
|
|
8 |
< |
/* ==================================================================== |
9 |
< |
* The Radiance Software License, Version 1.0 |
10 |
< |
* |
11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
< |
* |
14 |
< |
* Redistribution and use in source and binary forms, with or without |
15 |
< |
* modification, are permitted provided that the following conditions |
16 |
< |
* are met: |
17 |
< |
* |
18 |
< |
* 1. Redistributions of source code must retain the above copyright |
19 |
< |
* notice, this list of conditions and the following disclaimer. |
20 |
< |
* |
21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
< |
* notice, this list of conditions and the following disclaimer in |
23 |
< |
* the documentation and/or other materials provided with the |
24 |
< |
* distribution. |
25 |
< |
* |
26 |
< |
* 3. The end-user documentation included with the redistribution, |
27 |
< |
* if any, must include the following acknowledgment: |
28 |
< |
* "This product includes Radiance software |
29 |
< |
* (http://radsite.lbl.gov/) |
30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
31 |
< |
* (http://www.lbl.gov/)." |
32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
34 |
< |
* |
35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
< |
* and "The Regents of the University of California" must |
37 |
< |
* not be used to endorse or promote products derived from this |
38 |
< |
* software without prior written permission. For written |
39 |
< |
* permission, please contact [email protected]. |
40 |
< |
* |
41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
42 |
< |
* nor may "Radiance" appear in their name, without prior written |
43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
44 |
< |
* |
45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
< |
* SUCH DAMAGE. |
57 |
< |
* ==================================================================== |
58 |
< |
* |
59 |
< |
* This software consists of voluntary contributions made by many |
60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
< |
* <http://www.lbl.gov/>. |
63 |
< |
*/ |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
|
#include "standard.h" |
11 |
|
#include <sys/ioctl.h> |
67 |
– |
#ifdef sparc |
68 |
– |
#include <sys/conf.h> |
69 |
– |
#include <sys/file.h> |
70 |
– |
#include <sys/filio.h> |
71 |
– |
#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(); |
150 |
< |
static void xnewcolr(), freepixels(), resizewindow(), |
151 |
< |
getevent(), getkey(), fixwindow(); |
152 |
< |
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; |
206 |
|
x11_driver.comin = x11_comin; |
207 |
|
x11_driver.comout = x11_comout; |
208 |
|
erract[COMMAND].pf = x11_comout; |
209 |
+ |
/* doesn't work with raypcalls.c |
210 |
|
if (erract[WARNING].pf != NULL) |
211 |
|
erract[WARNING].pf = x11_errout; |
212 |
+ |
*/ |
213 |
|
inpcheck = IC_X11; |
214 |
|
} else { |
215 |
|
x11_driver.comin = std_comin; |
222 |
|
|
223 |
|
|
224 |
|
static void |
225 |
< |
x11_close() /* close our display */ |
225 |
> |
x11_close(void) /* close our display */ |
226 |
|
{ |
227 |
|
erract[COMMAND].pf = NULL; /* reset error vectors */ |
228 |
|
if (erract[WARNING].pf != NULL) |
245 |
|
|
246 |
|
|
247 |
|
static void |
248 |
< |
x11_clear(xres, yres) /* clear our display */ |
249 |
< |
int xres, yres; |
248 |
> |
x11_clear( /* clear our display */ |
249 |
> |
int xres, |
250 |
> |
int yres |
251 |
> |
) |
252 |
|
{ |
253 |
|
/* check limits */ |
254 |
|
if (xres < MINWIDTH) |
267 |
|
} |
268 |
|
XClearWindow(ourdisplay, gwind); |
269 |
|
/* reinitialize color table */ |
270 |
< |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
270 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) { |
271 |
|
if (getpixels() == 0) |
272 |
|
eputs("cannot allocate colors\n"); |
273 |
|
else |
274 |
|
new_ctab(ncolors); |
275 |
+ |
} |
276 |
|
/* get new command line */ |
277 |
|
if (comline != NULL) |
278 |
|
xt_close(comline); |
294 |
|
|
295 |
|
|
296 |
|
static void |
297 |
< |
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
298 |
< |
COLOR col; |
299 |
< |
int xmin, ymin, xmax, ymax; |
297 |
> |
x11_paintr( /* fill a rectangle */ |
298 |
> |
COLOR col, |
299 |
> |
int xmin, |
300 |
> |
int ymin, |
301 |
> |
int xmax, |
302 |
> |
int ymax |
303 |
> |
) |
304 |
|
{ |
305 |
|
unsigned long pixel; |
306 |
|
|
317 |
|
|
318 |
|
|
319 |
|
static void |
320 |
< |
x11_flush() /* flush output */ |
320 |
> |
x11_flush(void) /* flush output */ |
321 |
|
{ |
322 |
|
char buf[256]; |
323 |
|
int n; |
353 |
|
|
354 |
|
|
355 |
|
static void |
356 |
< |
x11_comin(inp, prompt) /* read in a command line */ |
357 |
< |
char *inp, *prompt; |
356 |
> |
x11_comin( /* read in a command line */ |
357 |
> |
char *inp, |
358 |
> |
char *prompt |
359 |
> |
) |
360 |
|
{ |
361 |
|
if (prompt != NULL) { |
362 |
|
x11_flush(); /* make sure we get everything */ |
371 |
|
|
372 |
|
|
373 |
|
static void |
374 |
< |
x11_comout(outp) /* output a string to command line */ |
375 |
< |
char *outp; |
374 |
> |
x11_comout( /* output a string to command line */ |
375 |
> |
const char *outp |
376 |
> |
) |
377 |
|
{ |
378 |
|
if (comline == NULL || outp == NULL || !outp[0]) |
379 |
|
return; |
384 |
|
|
385 |
|
|
386 |
|
static void |
387 |
< |
x11_errout(msg) /* output an error message */ |
388 |
< |
char *msg; |
387 |
> |
x11_errout( /* output an error message */ |
388 |
> |
char *msg |
389 |
> |
) |
390 |
|
{ |
391 |
|
eputs(msg); /* send to stderr also! */ |
392 |
|
x11_comout(msg); |
394 |
|
|
395 |
|
|
396 |
|
static void |
397 |
< |
std_comin(inp, prompt) /* read in command line from stdin */ |
398 |
< |
char *inp, *prompt; |
397 |
> |
std_comin( /* read in command line from stdin */ |
398 |
> |
char *inp, |
399 |
> |
char *prompt |
400 |
> |
) |
401 |
|
{ |
402 |
+ |
int n, c; |
403 |
+ |
|
404 |
|
if (prompt != NULL) { |
405 |
|
if (fromcombuf(inp, &x11_driver)) |
406 |
|
return; |
416 |
|
inpcheck = IC_IOCTL; |
417 |
|
} |
418 |
|
#endif |
419 |
< |
if (gets(inp) == NULL) { |
419 |
> |
n = 0; /* gets() no longer exists... */ |
420 |
> |
while ((c = getchar()) != EOF && c != '\n') |
421 |
> |
inp[n++] = c; |
422 |
> |
|
423 |
> |
if (!n & (c == EOF)) { |
424 |
|
strcpy(inp, "quit"); |
425 |
|
return; |
426 |
|
} |
427 |
< |
x11_driver.inpready -= strlen(inp) + 1; |
428 |
< |
if (x11_driver.inpready < 0) |
429 |
< |
x11_driver.inpready = 0; |
427 |
> |
inp[n] = '\0'; |
428 |
> |
x11_driver.inpready -= n + 1; |
429 |
> |
x11_driver.inpready *= (x11_driver.inpready > 0); |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
|
static void |
434 |
< |
std_comout(outp) /* write out string to stdout */ |
435 |
< |
char *outp; |
434 |
> |
std_comout( /* write out string to stdout */ |
435 |
> |
const char *outp |
436 |
> |
) |
437 |
|
{ |
438 |
|
fputs(outp, stdout); |
439 |
|
fflush(stdout); |
441 |
|
|
442 |
|
|
443 |
|
static int |
444 |
< |
x11_getcur(xp, yp) /* get cursor position */ |
445 |
< |
int *xp, *yp; |
444 |
> |
x11_getcur( /* get cursor position */ |
445 |
> |
int *xp, |
446 |
> |
int *yp |
447 |
> |
) |
448 |
|
{ |
449 |
|
while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask, |
450 |
|
GrabModeAsync, GrabModeAsync, None, pickcursor, |
472 |
|
|
473 |
|
|
474 |
|
static void |
475 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
476 |
< |
int ndx; |
477 |
< |
int r, g, b; |
475 |
> |
xnewcolr( /* enter a color into hardware table */ |
476 |
> |
int ndx, |
477 |
> |
int r, |
478 |
> |
int g, |
479 |
> |
int b |
480 |
> |
) |
481 |
|
{ |
482 |
|
XColor xcolor; |
483 |
|
|
492 |
|
|
493 |
|
|
494 |
|
static int |
495 |
< |
getpixels() /* get the color map */ |
495 |
> |
getpixels(void) /* get the color map */ |
496 |
|
{ |
497 |
|
XColor thiscolor; |
498 |
|
register int i, j; |
544 |
|
|
545 |
|
|
546 |
|
static void |
547 |
< |
freepixels() /* free our pixels */ |
547 |
> |
freepixels(void) /* free our pixels */ |
548 |
|
{ |
549 |
|
if (ncolors == 0) |
550 |
|
return; |
559 |
|
|
560 |
|
|
561 |
|
static unsigned long |
562 |
< |
true_pixel(col) /* return true pixel value for color */ |
563 |
< |
COLOR col; |
562 |
> |
true_pixel( /* return true pixel value for color */ |
563 |
> |
COLOR col |
564 |
> |
) |
565 |
|
{ |
566 |
|
unsigned long rval; |
567 |
< |
BYTE rgb[3]; |
567 |
> |
uby8 rgb[3]; |
568 |
|
|
569 |
|
map_color(rgb, col); |
570 |
|
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
575 |
|
|
576 |
|
|
577 |
|
static int |
578 |
< |
x11_getc() /* get a command character */ |
578 |
> |
x11_getc(void) /* get a command character */ |
579 |
|
{ |
580 |
|
while (c_last <= c_first) { |
581 |
|
c_first = c_last = 0; /* reset */ |
587 |
|
|
588 |
|
|
589 |
|
static void |
590 |
< |
getevent() /* get next event */ |
590 |
> |
getevent(void) /* get next event */ |
591 |
|
{ |
592 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
593 |
|
switch (levptr(XEvent)->type) { |
600 |
|
break; |
601 |
|
case MapNotify: |
602 |
|
if (ourvinfo.class == PseudoColor || |
603 |
< |
ourvinfo.class == GrayScale) |
603 |
> |
ourvinfo.class == GrayScale) { |
604 |
|
if (getpixels() == 0) |
605 |
|
eputs("cannot allocate colors\n"); |
606 |
|
else |
607 |
|
new_ctab(ncolors); |
608 |
+ |
} |
609 |
|
mapped = 1; |
610 |
|
break; |
611 |
|
case Expose: |
621 |
|
|
622 |
|
|
623 |
|
static void |
624 |
< |
getkey(ekey) /* get input key */ |
625 |
< |
register XKeyPressedEvent *ekey; |
624 |
> |
getkey( /* get input key */ |
625 |
> |
register XKeyPressedEvent *ekey |
626 |
> |
) |
627 |
|
{ |
628 |
|
register int n; |
629 |
|
|
635 |
|
|
636 |
|
|
637 |
|
static void |
638 |
< |
fixwindow(eexp) /* repair damage to window */ |
639 |
< |
register XExposeEvent *eexp; |
638 |
> |
fixwindow( /* repair damage to window */ |
639 |
> |
register XExposeEvent *eexp |
640 |
> |
) |
641 |
|
{ |
642 |
|
char buf[80]; |
643 |
|
|
654 |
|
|
655 |
|
|
656 |
|
static void |
657 |
< |
resizewindow(ersz) /* resize window */ |
658 |
< |
register XConfigureEvent *ersz; |
657 |
> |
resizewindow( /* resize window */ |
658 |
> |
register XConfigureEvent *ersz |
659 |
> |
) |
660 |
|
{ |
661 |
|
if (ersz->width == gwidth && ersz->height-comheight == gheight) |
662 |
|
return; |