ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/x11.c
(Generate patch)

Comparing ray/src/rt/x11.c (file contents):
Revision 2.12 by greg, Fri Jun 4 14:48:52 1993 UTC vs.
Revision 2.26 by greg, Tue Dec 5 10:54:39 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ LBL";
13   #include  <stdio.h>
14   #include  <math.h>
15   #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
22 + #if  !defined(FNDELAY) && defined(O_NONBLOCK)
23 + #define  FNDELAY  O_NONBLOCK
24 + #endif
25  
26   #include  <X11/Xlib.h>
27   #include  <X11/cursorfont.h>
# Line 58 | Line 67 | static Cursor  pickcursor = 0;         /* cursor used for pic
67  
68   static int  gwidth, gheight;            /* graphics window size */
69  
70 + static int  comheight;                  /* desired comline height */
71   static TEXTWIND  *comline = NULL;       /* our command line */
72  
73   static char  c_queue[64];               /* input queue */
# Line 68 | Line 78 | static GC  ourgc = 0;                  /* our graphics context for dr
78  
79   static Colormap ourmap = 0;             /* our color map */
80  
81 < extern char  *malloc(), *getcombuf();
81 > #define IC_X11          0
82 > #define IC_IOCTL        1
83 > #define IC_READ         2
84  
85 + static int  inpcheck;                   /* whence to check input */
86 +
87 + extern char  *malloc();
88 +
89   static int  x11_close(), x11_clear(), x11_paintr(), x11_errout(),
90                  x11_getcur(), x11_comout(), x11_comin(), x11_flush();
91  
92 + static int  std_comin(), std_comout();
93 +
94   static struct driver  x11_driver = {
95          x11_close, x11_clear, x11_paintr, x11_getcur,
96 <        x11_comout, x11_comin, x11_flush, 1.0
96 >        NULL, NULL, x11_flush, 1.0
97   };
98  
99 < static int  getpixels(), xnewcolr(), freepixels(),
100 <                getevent(), getkey(), fixwindow();
99 > static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
100 >                getevent(), getkey(), fixwindow(), x11_getc();
101   static unsigned long  true_pixel();
102  
103  
# Line 93 | Line 111 | char  *name, *id;
111          XSetWindowAttributes    ourwinattr;
112          XWMHints  ourxwmhints;
113          XSizeHints      oursizhints;
114 <
114 >                                        /* open display server */
115          ourdisplay = XOpenDisplay(NULL);
116          if (ourdisplay == NULL) {
117                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 102 | Line 120 | char  *name, *id;
120                                          /* find a usable visual */
121          nplanes = DisplayPlanes(ourdisplay, ourscreen);
122          if (XMatchVisualInfo(ourdisplay,ourscreen,
123 <                                24,TrueColor,&ourvinfo) ||
123 >                                nplanes>12?nplanes:24,TrueColor,&ourvinfo) ||
124                          XMatchVisualInfo(ourdisplay,ourscreen,
125 <                                24,DirectColor,&ourvinfo)) {
125 >                                nplanes>12?nplanes:24,DirectColor,&ourvinfo)) {
126                  ourblack = 0;
127                  ourwhite = ourvinfo.red_mask |
128                                  ourvinfo.green_mask |
# Line 125 | Line 143 | char  *name, *id;
143                  ourwhite = WhitePixel(ourdisplay,ourscreen);
144          }
145                                          /* set gamma */
146 <        if ((gv = getenv("GAMMA")) != NULL)
146 >        if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
147 >                        || (gv = getenv("DISPLAY_GAMMA")) != NULL)
148                  make_gmap(atof(gv));
149          else
150                  make_gmap(GAMMA);
151 +                                        /* X11 command line or no? */
152 +        if (!strcmp(name, "x11"))
153 +                comheight = COMHEIGHT;
154 +        else /* "x11d" */ {
155 +                comheight = 0;
156 + #ifndef  FNDELAY
157 +                stderr_v("warning: x11d driver not fully functional on this machine\n");
158 + #endif
159 +        }
160                                          /* open window */
161          ourwinattr.background_pixel = ourblack;
162          ourwinattr.border_pixel = ourblack;
# Line 154 | Line 182 | char  *name, *id;
182                          gwind, x11icon_bits, x11icon_width, x11icon_height);
183          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
184          oursizhints.min_width = MINWIDTH;
185 <        oursizhints.min_height = MINHEIGHT+COMHEIGHT;
185 >        oursizhints.min_height = MINHEIGHT+comheight;
186          oursizhints.flags = PMinSize;
187          XSetNormalHints(ourdisplay, gwind, &oursizhints);
188          XSelectInput(ourdisplay, gwind, ExposureMask);
189          XMapWindow(ourdisplay, gwind);
190          XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent));
191          gwidth = levptr(XExposeEvent)->width;
192 <        gheight = levptr(XExposeEvent)->height - COMHEIGHT;
192 >        gheight = levptr(XExposeEvent)->height - comheight;
193          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
194          x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
195          x11_driver.inpready = 0;
196          mapped = 1;
197 <        cmdvec = x11_comout;                    /* set error vectors */
198 <        if (wrnvec != NULL)
199 <                wrnvec = x11_errout;
197 >                                        /* set i/o vectors */
198 >        if (comheight) {
199 >                x11_driver.comin = x11_comin;
200 >                x11_driver.comout = x11_comout;
201 >                cmdvec = x11_comout;
202 >                if (wrnvec != NULL)
203 >                        wrnvec = x11_errout;
204 >                inpcheck = IC_X11;
205 >        } else {
206 >                x11_driver.comin = std_comin;
207 >                x11_driver.comout = std_comout;
208 >                cmdvec = std_comout;
209 >                inpcheck = IC_IOCTL;
210 >        }
211          return(&x11_driver);
212   }
213  
# Line 208 | Line 247 | int  xres, yres;
247                                                  /* resize window */
248          if (xres != gwidth || yres != gheight) {
249                  XSelectInput(ourdisplay, gwind, 0);
250 <                XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
250 >                XResizeWindow(ourdisplay, gwind, xres, yres+comheight);
251                  gwidth = xres;
252                  gheight = yres;
253                  XFlush(ourdisplay);
# Line 225 | Line 264 | int  xres, yres;
264                                                  /* get new command line */
265          if (comline != NULL)
266                  xt_close(comline);
267 <        comline = xt_open(ourdisplay, gwind, 0, gheight,
268 <                        gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN);
269 <        if (comline == NULL) {
270 <                stderr_v("Cannot open command line window\n");
271 <                quit(1);
272 <        }
273 <        XSelectInput(ourdisplay, comline->w, ExposureMask);
267 >        if (comheight) {
268 >                comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth,
269 >                                comheight, 0, ourblack, ourwhite, COMFN);
270 >                if (comline == NULL) {
271 >                        stderr_v("cannot open command line window\n");
272 >                        quit(1);
273 >                }
274 >                XSelectInput(ourdisplay, comline->w, ExposureMask);
275                                                  /* remove earmuffs */
276 <        XSelectInput(ourdisplay, gwind,
276 >                XSelectInput(ourdisplay, gwind,
277                  StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
278 +        } else                                  /* remove earmuffs */
279 +                XSelectInput(ourdisplay, gwind,
280 +                        StructureNotifyMask|ExposureMask|ButtonPressMask);
281   }
282  
283  
# Line 260 | Line 303 | int  xmin, ymin, xmax, ymax;
303   static
304   x11_flush()                     /* flush output */
305   {
306 +        char    buf[256];
307 +        int     n;
308 +                                                /* check for input */
309          XNoOp(ourdisplay);
310 <        while (XPending(ourdisplay) > 0)
310 >        n = XPending(ourdisplay);                       /* from X server */
311 >        while (n-- > 0)
312                  getevent();
313 + #ifdef FNDELAY
314 +        if (inpcheck == IC_IOCTL) {                     /* from stdin */
315 + #ifdef FIONREAD
316 +                if (ioctl(fileno(stdin), FIONREAD, &n) < 0) {
317 + #else
318 +                if (1) {
319 + #endif
320 +                        if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) {
321 +                                stderr_v("cannot change input mode\n");
322 +                                quit(1);
323 +                        }
324 +                        inpcheck = IC_READ;
325 +                } else
326 +                        x11_driver.inpready += n;
327 +        }
328 +        if (inpcheck == IC_READ) {
329 +                n = read(fileno(stdin), buf, sizeof(buf)-1);
330 +                if (n > 0) {
331 +                        buf[n] = '\0';
332 +                        tocombuf(buf, &x11_driver);
333 +                }
334 +        }
335 + #endif
336   }
337  
338  
# Line 270 | Line 340 | static
340   x11_comin(inp, prompt)          /* read in a command line */
341   char  *inp, *prompt;
342   {
343 <        extern int  x11_getc();
344 <
275 <        if (prompt != NULL)
343 >        if (prompt != NULL) {
344 >                x11_flush();            /* make sure we get everything */
345                  if (fromcombuf(inp, &x11_driver))
346                          return;
347 <                else
348 <                        xt_puts(prompt, comline);
347 >                xt_puts(prompt, comline);
348 >        }
349          xt_cursor(comline, TBLKCURS);
350          editline(inp, x11_getc, x11_comout);
351          xt_cursor(comline, TNOCURS);
# Line 284 | Line 353 | char  *inp, *prompt;
353  
354  
355   static
356 < x11_comout(out)                 /* output a string to command line */
357 < char  *out;
356 > x11_comout(outp)                /* output a string to command line */
357 > char  *outp;
358   {
359          if (comline == NULL)
360                  return;
361 <        xt_puts(out, comline);
362 <        if (out[strlen(out)-1] == '\n')
361 >        xt_puts(outp, comline);
362 >        if (outp[strlen(outp)-1] == '\n')
363                  XFlush(ourdisplay);
364   }
365  
# Line 304 | Line 373 | char  *msg;
373   }
374  
375  
376 + static
377 + std_comin(inp, prompt)          /* read in command line from stdin */
378 + char  *inp, *prompt;
379 + {
380 +        extern char     *gets();
381 +
382 +        if (prompt != NULL) {
383 +                if (fromcombuf(inp, &x11_driver))
384 +                        return;
385 +                if (!x11_driver.inpready)
386 +                        std_comout(prompt);
387 +        }
388 + #ifdef FNDELAY
389 +        if (inpcheck == IC_READ) {      /* turn off FNDELAY */
390 +                if (fcntl(fileno(stdin), F_SETFL, 0) < 0) {
391 +                        stderr_v("cannot change input mode\n");
392 +                        quit(1);
393 +                }
394 +                inpcheck = IC_IOCTL;
395 +        }
396 + #endif
397 +        if (gets(inp) == NULL) {
398 +                strcpy(inp, "quit");
399 +                return;
400 +        }
401 +        x11_driver.inpready -= strlen(inp) + 1;
402 +        if (x11_driver.inpready < 0)
403 +                x11_driver.inpready = 0;
404 + }
405 +
406 +
407 + static
408 + std_comout(outp)                /* write out string to stdout */
409 + char    *outp;
410 + {
411 +        fputs(outp, stdout);
412 +        fflush(stdout);
413 + }
414 +
415 +
416   static int
417   x11_getcur(xp, yp)              /* get cursor position */
418   int  *xp, *yp;
# Line 460 | Line 569 | getevent()                     /* get next event */
569                  if (ourvinfo.class == PseudoColor ||
570                                  ourvinfo.class == GrayScale)
571                          if (getpixels() == 0)
572 <                                stderr_v("Cannot allocate colors\n");
572 >                                stderr_v("cannot allocate colors\n");
573                          else
574                                  new_ctab(ncolors);
575                  mapped = 1;
# Line 494 | Line 603 | static
603   fixwindow(eexp)                         /* repair damage to window */
604   register XExposeEvent  *eexp;
605   {
606 +        char  buf[80];
607 +
608          if (eexp->window == gwind) {
609 <                sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n",
609 >                sprintf(buf, "repaint %d %d %d %d\n",
610                          eexp->x, gheight - eexp->y - eexp->height,
611                          eexp->x + eexp->width, gheight - eexp->y);
612 +                tocombuf(buf, &x11_driver);
613          } else if (eexp->window == comline->w) {
614                  if (eexp->count == 0)
615                          xt_redraw(comline);
# Line 509 | Line 621 | static
621   resizewindow(ersz)                      /* resize window */
622   register XConfigureEvent  *ersz;
623   {
624 <        if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight)
624 >        if (ersz->width == gwidth && ersz->height-comheight == gheight)
625                  return;
626  
627          gwidth = ersz->width;
628 <        gheight = ersz->height-COMHEIGHT;
628 >        gheight = ersz->height-comheight;
629          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
630          x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
631  
632 <        strcpy(getcombuf(&x11_driver), "new\n");
632 >        tocombuf("new\n", &x11_driver);
633   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines