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.8 by greg, Wed Sep 16 16:15:42 1992 UTC vs.
Revision 2.23 by greg, Mon Dec 12 16:47:29 1994 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
12  
13   #include  <stdio.h>
14 <
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  
23   #include  <X11/Xlib.h>
24   #include  <X11/cursorfont.h>
# Line 26 | Line 32 | static char SCCSid[] = "$SunId$ LBL";
32   #define GAMMA           2.2             /* default exponent correction */
33  
34   #define MINWIDTH        (32*COMCW)      /* minimum graphics window width */
35 < #define MINHEIGHT       MINWIDTH        /* minimum graphics window height */
35 > #define MINHEIGHT       (MINWIDTH/2)    /* minimum graphics window height */
36  
37   #define BORWIDTH        5               /* border width */
38   #define COMHEIGHT       (COMLH*COMCH)   /* command line height (pixels) */
# Line 58 | Line 64 | static Cursor  pickcursor = 0;         /* cursor used for pic
64  
65   static int  gwidth, gheight;            /* graphics window size */
66  
67 + static int  comheight;                  /* desired comline height */
68   static TEXTWIND  *comline = NULL;       /* our command line */
69  
70   static char  c_queue[64];               /* input queue */
# Line 68 | Line 75 | static GC  ourgc = 0;                  /* our graphics context for dr
75  
76   static Colormap ourmap = 0;             /* our color map */
77  
78 < extern char  *malloc(), *getcombuf();
78 > #define IC_X11          0
79 > #define IC_IOCTL        1
80 > #define IC_READ         2
81  
82 + static int  inpcheck;                   /* whence to check input */
83 +
84 + extern char  *malloc();
85 +
86   static int  x11_close(), x11_clear(), x11_paintr(), x11_errout(),
87                  x11_getcur(), x11_comout(), x11_comin(), x11_flush();
88  
89 + static int  std_comin(), std_comout();
90 +
91   static struct driver  x11_driver = {
92          x11_close, x11_clear, x11_paintr, x11_getcur,
93 <        x11_comout, x11_comin, x11_flush, 1.0
93 >        NULL, NULL, x11_flush, 1.0
94   };
95  
96 + static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
97 +                getevent(), getkey(), fixwindow(), x11_getc();
98 + static unsigned long  true_pixel();
99  
100 +
101   struct driver *
102   x11_init(name, id)              /* initialize driver */
103   char  *name, *id;
# Line 89 | Line 108 | char  *name, *id;
108          XSetWindowAttributes    ourwinattr;
109          XWMHints  ourxwmhints;
110          XSizeHints      oursizhints;
111 <
111 >                                        /* open display server */
112          ourdisplay = XOpenDisplay(NULL);
113          if (ourdisplay == NULL) {
114                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 121 | Line 140 | char  *name, *id;
140                  ourwhite = WhitePixel(ourdisplay,ourscreen);
141          }
142                                          /* set gamma */
143 <        if ((gv = getenv("GAMMA")) != NULL)
143 >        if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
144 >                        || (gv = getenv("DISPLAY_GAMMA")) != NULL)
145                  make_gmap(atof(gv));
146          else
147                  make_gmap(GAMMA);
148 +                                        /* X11 command line or no? */
149 +        if (!strcmp(name, "x11"))
150 +                comheight = COMHEIGHT;
151 +        else /* "x11d" */
152 +                comheight = 0;
153                                          /* open window */
154          ourwinattr.background_pixel = ourblack;
155          ourwinattr.border_pixel = ourblack;
# Line 150 | Line 175 | char  *name, *id;
175                          gwind, x11icon_bits, x11icon_width, x11icon_height);
176          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
177          oursizhints.min_width = MINWIDTH;
178 <        oursizhints.min_height = MINHEIGHT+COMHEIGHT;
178 >        oursizhints.min_height = MINHEIGHT+comheight;
179          oursizhints.flags = PMinSize;
180          XSetNormalHints(ourdisplay, gwind, &oursizhints);
181          XSelectInput(ourdisplay, gwind, ExposureMask);
182          XMapWindow(ourdisplay, gwind);
183          XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent));
184          gwidth = levptr(XExposeEvent)->width;
185 <        gheight = levptr(XExposeEvent)->height - COMHEIGHT;
185 >        gheight = levptr(XExposeEvent)->height - comheight;
186          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
187          x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
188          x11_driver.inpready = 0;
189          mapped = 1;
190 <        cmdvec = x11_comout;                    /* set error vectors */
191 <        if (wrnvec != NULL)
192 <                wrnvec = x11_errout;
190 >                                        /* set i/o vectors */
191 >        if (comheight) {
192 >                x11_driver.comin = x11_comin;
193 >                x11_driver.comout = x11_comout;
194 >                cmdvec = x11_comout;
195 >                if (wrnvec != NULL)
196 >                        wrnvec = x11_errout;
197 >                inpcheck = IC_X11;
198 >        } else {
199 >                x11_driver.comin = std_comin;
200 >                x11_driver.comout = std_comout;
201 >                cmdvec = std_comout;
202 >                inpcheck = IC_IOCTL;
203 >        }
204          return(&x11_driver);
205   }
206  
# Line 204 | Line 240 | int  xres, yres;
240                                                  /* resize window */
241          if (xres != gwidth || yres != gheight) {
242                  XSelectInput(ourdisplay, gwind, 0);
243 <                XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
243 >                XResizeWindow(ourdisplay, gwind, xres, yres+comheight);
244                  gwidth = xres;
245                  gheight = yres;
246                  XFlush(ourdisplay);
# Line 221 | Line 257 | int  xres, yres;
257                                                  /* get new command line */
258          if (comline != NULL)
259                  xt_close(comline);
260 <        comline = xt_open(ourdisplay, gwind, 0, gheight,
261 <                        gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN);
262 <        if (comline == NULL) {
263 <                stderr_v("Cannot open command line window\n");
264 <                quit(1);
265 <        }
266 <        XSelectInput(ourdisplay, comline->w, ExposureMask);
260 >        if (comheight) {
261 >                comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth,
262 >                                comheight, 0, ourblack, ourwhite, COMFN);
263 >                if (comline == NULL) {
264 >                        stderr_v("Cannot open command line window\n");
265 >                        quit(1);
266 >                }
267 >                XSelectInput(ourdisplay, comline->w, ExposureMask);
268                                                  /* remove earmuffs */
269 <        XSelectInput(ourdisplay, gwind,
269 >                XSelectInput(ourdisplay, gwind,
270                  StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
271 +        } else                                  /* remove earmuffs */
272 +                XSelectInput(ourdisplay, gwind,
273 +                        StructureNotifyMask|ExposureMask|ButtonPressMask);
274   }
275  
276  
# Line 239 | Line 279 | x11_paintr(col, xmin, ymin, xmax, ymax)                /* fill a rec
279   COLOR  col;
280   int  xmin, ymin, xmax, ymax;
281   {
242        extern int  xnewcolr();         /* pixel assignment routine */
243        extern unsigned long  true_pixel();
282          unsigned long  pixel;
283  
284          if (!mapped)
# Line 258 | Line 296 | int  xmin, ymin, xmax, ymax;
296   static
297   x11_flush()                     /* flush output */
298   {
299 +        char    buf[256];
300 +        int     n;
301 +                                                /* check for input */
302          XNoOp(ourdisplay);
303 <        while (XPending(ourdisplay) > 0)
303 >        n = XPending(ourdisplay);                       /* from X server */
304 >        while (n-- > 0)
305                  getevent();
306 + #ifdef FNDELAY
307 +        if (inpcheck == IC_IOCTL) {                     /* from stdin */
308 + #ifdef FIONREAD
309 +                if (ioctl(fileno(stdin), FIONREAD, &n) < 0) {
310 + #else
311 +                if (1) {
312 + #endif
313 +                        if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) {
314 +                                stderr_v("Cannot change input mode\n");
315 +                                quit(1);
316 +                        }
317 +                        inpcheck = IC_READ;
318 +                } else
319 +                        x11_driver.inpready += n;
320 +        }
321 +        if (inpcheck == IC_READ) {
322 +                n = read(fileno(stdin), buf, sizeof(buf)-1);
323 +                if (n > 0) {
324 +                        buf[n] = '\0';
325 +                        tocombuf(buf, &x11_driver);
326 +                }
327 +        }
328 + #endif
329   }
330  
331  
# Line 268 | Line 333 | static
333   x11_comin(inp, prompt)          /* read in a command line */
334   char  *inp, *prompt;
335   {
336 <        extern int  x11_getc();
337 <
273 <        if (prompt != NULL)
336 >        if (prompt != NULL) {
337 >                x11_flush();            /* make sure we get everything */
338                  if (fromcombuf(inp, &x11_driver))
339                          return;
340 <                else
341 <                        xt_puts(prompt, comline);
340 >                xt_puts(prompt, comline);
341 >        }
342          xt_cursor(comline, TBLKCURS);
343          editline(inp, x11_getc, x11_comout);
344          xt_cursor(comline, TNOCURS);
# Line 282 | Line 346 | char  *inp, *prompt;
346  
347  
348   static
349 < x11_comout(out)                 /* output a string to command line */
350 < char  *out;
349 > x11_comout(outp)                /* output a string to command line */
350 > char  *outp;
351   {
352          if (comline == NULL)
353                  return;
354 <        xt_puts(out, comline);
355 <        if (out[strlen(out)-1] == '\n')
354 >        xt_puts(outp, comline);
355 >        if (outp[strlen(outp)-1] == '\n')
356                  XFlush(ourdisplay);
357   }
358  
# Line 302 | Line 366 | char  *msg;
366   }
367  
368  
369 + static
370 + std_comin(inp, prompt)          /* read in command line from stdin */
371 + char  *inp, *prompt;
372 + {
373 +        extern char     *gets();
374 +
375 +        if (prompt != NULL) {
376 +                if (fromcombuf(inp, &x11_driver))
377 +                        return;
378 +                if (!x11_driver.inpready)
379 +                        fputs(prompt, stdout);
380 +        }
381 +        if (gets(inp) == NULL) {
382 +                strcpy(inp, "quit");
383 +                return;
384 +        }
385 +        x11_driver.inpready -= strlen(inp) + 1;
386 +        if (x11_driver.inpready < 0)
387 +                x11_driver.inpready = 0;
388 + }
389 +
390 +
391 + static
392 + std_comout(outp)                /* write out string to stdout */
393 + char    *outp;
394 + {
395 +        fputs(outp, stdout);
396 +        fflush(stdout);
397 + }
398 +
399 +
400   static int
401   x11_getcur(xp, yp)              /* get cursor position */
402   int  *xp, *yp;
# Line 321 | Line 416 | int  *xp, *yp;
416          if (c_last > c_first)                   /* key pressed */
417                  return(x11_getc());
418                                                  /* button pressed */
419 <        if (levptr(XButtonPressedEvent)->button & Button1)
419 >        if (levptr(XButtonPressedEvent)->button == Button1)
420                  return(MB1);
421 <        if (levptr(XButtonPressedEvent)->button & Button2)
421 >        if (levptr(XButtonPressedEvent)->button == Button2)
422                  return(MB2);
423 <        if (levptr(XButtonPressedEvent)->button & Button3)
423 >        if (levptr(XButtonPressedEvent)->button == Button3)
424                  return(MB3);
330        if (levptr(XButtonPressedEvent)->button & (Button4|Button5))
331                return(MB1);
425          return(ABORT);
426   }
427  
# Line 494 | Line 587 | static
587   fixwindow(eexp)                         /* repair damage to window */
588   register XExposeEvent  *eexp;
589   {
590 +        char  buf[80];
591 +
592          if (eexp->window == gwind) {
593 <                sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n",
593 >                sprintf(buf, "repaint %d %d %d %d\n",
594                          eexp->x, gheight - eexp->y - eexp->height,
595                          eexp->x + eexp->width, gheight - eexp->y);
596 +                tocombuf(buf, &x11_driver);
597          } else if (eexp->window == comline->w) {
598                  if (eexp->count == 0)
599                          xt_redraw(comline);
# Line 509 | Line 605 | static
605   resizewindow(ersz)                      /* resize window */
606   register XConfigureEvent  *ersz;
607   {
608 <        if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight)
608 >        if (ersz->width == gwidth && ersz->height-comheight == gheight)
609                  return;
610  
611          gwidth = ersz->width;
612 <        gheight = ersz->height-COMHEIGHT;
612 >        gheight = ersz->height-comheight;
613          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
614          x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
615  
616 <        strcpy(getcombuf(&x11_driver), "new\n");
616 >        tocombuf("new\n", &x11_driver);
617   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines