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 1.3 by greg, Tue Jan 30 11:37:54 1990 UTC vs.
Revision 1.5 by greg, Thu Feb 22 11:46:26 1990 UTC

# Line 5 | Line 5 | static char SCCSid[] = "$SunId$ LBL";
5   /* Copyright (c) 1989 Regents of the University of California */
6  
7   /*
8 < *  x11.c - driver for X-windows version 10.4
8 > *  x11.c - driver for X-windows version 11.3
9   *
10 < *     1989
10 > *     Jan 1990
11   */
12  
13   #include  <stdio.h>
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include  <sys/ioctl.h>
16  
17   #include  <X11/Xlib.h>
18 < #include <X11/cursorfont.h>
19 < #include <X11/Xutil.h>
18 > #include  <X11/cursorfont.h>
19 > #include  <X11/Xutil.h>
20  
21   #include  "color.h"
22   #include  "driver.h"
# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24  
25   #define GAMMA           2.2             /* exponent for color correction */
26  
27 + #define MINWIDTH        (4*COMCW)       /* minimum graphics window width */
28 + #define MINHEIGHT       16              /* minimum graphics window height */
29 +
30   #define BORWIDTH        5               /* border width */
31   #define COMHEIGHT       (COMLH*COMCH)   /* command line height (pixels) */
32  
# Line 32 | Line 35 | static char SCCSid[] = "$SunId$ LBL";
35   #define COMCW           8               /* approx. character width (pixels) */
36   #define COMCH           14              /* approx. character height (pixels) */
37  
38 < #ifndef WFLUSH
39 < #define WFLUSH          30              /* flush after this many rays */
40 < #endif
38 > #define  ourscreen      DefaultScreen(ourdisplay)
39 > #define  ourroot        RootWindow(ourdisplay,ourscreen)
40 > #define  ourwhite       WhitePixel(ourdisplay,ourscreen)
41 > #define  ourblack       BlackPixel(ourdisplay,ourscreen)
42  
43 < #define  checkinp()     while (XPending(ourdisplay) > 0) getevent()
43 > #define  levptr(etype)  ((etype *)&currentevent)
44  
45 < #define  levptr(etype)  ((etype *)&thisevent)
45 > static XEvent  currentevent;            /* current event */
46  
43 static char  *clientname;               /* calling client's name */
44
45 static XEvent  thisevent;               /* current event */
46
47   static int  ncolors = 0;                /* color table size */
48   static int  *pixval = NULL;             /* allocated pixels */
49  
# Line 53 | Line 53 | static Window  gwind = 0;              /* our graphics window */
53  
54   static Cursor  pickcursor = 0;          /* cursor used for picking */
55  
56 < static int  gwidth = 0;                 /* graphics window width */
57 < static int  gheight = 0;                /* graphics window height */
56 > static int  gwidth, gheight;            /* graphics window size */
57  
58   static TEXTWIND  *comline = NULL;       /* our command line */
59  
# Line 69 | Line 68 | static Colormap ourmap;                        /* our color map */
68   extern char  *malloc();
69  
70   int  x11_close(), x11_clear(), x11_paintr(), x11_errout(),
71 <                x11_getcur(), x11_comout(), x11_comin();
71 >                x11_getcur(), x11_comout(), x11_comin(), x11_flush();
72  
73   static struct driver  x11_driver = {
74          x11_close, x11_clear, x11_paintr, x11_getcur,
75 <        x11_comout, x11_comin, 1.0
75 >        x11_comout, x11_comin, x11_flush, 1.0
76   };
77  
78  
# Line 81 | Line 80 | struct driver *
80   x11_init(name, id)              /* initialize driver */
81   char  *name, *id;
82   {
83 +        XWMHints  ourxwmhints;
84          Pixmap  bmCursorSrc, bmCursorMsk;
85  
86          ourdisplay = XOpenDisplay(NULL);
# Line 88 | Line 88 | char  *name, *id;
88                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
89                  return(NULL);
90          }
91 <        if (DisplayPlanes(ourdisplay, DefaultScreen(ourdisplay)) < 4) {
91 >        if (DisplayPlanes(ourdisplay, ourscreen) < 4) {
92                  stderr_v("not enough colors\n");
93                  return(NULL);
94          }
95 <        ourmap = DefaultColormap(ourdisplay,DefaultScreen(ourdisplay));
95 >        ourmap = DefaultColormap(ourdisplay,ourscreen);
96          make_gmap(GAMMA);                       /* make color map */
97        /*
98        bmCursorSrc = XCreateBitmapFromData(ourdisplay,
99                        gwind, bcross_bits,
100                        bcross_width, bcross_height);
101        bmCursorMsk = XCreateBitmapFromData(ourdisplay,
102                        gwind, bcross_mask_bits,
103                        bcross_width, bcross_height);
104
105        pickcursor = XCreatePixmapCursor(ourdisplay,
106                        bmCursorSrc, bmCursorMsk,
107                        BlackPixel(ourdisplay,
108                        DefaultScreen(ourdisplay)),
109                        WhitePixel(ourdisplay,
110                        DefaultScreen(ourdisplay)),
111                        bcross_x_hot, bcross_y_hot);
112        XFreePixmap(ourdisplay, bmCursorSrc);
113        XFreePixmap(ourdisplay, bmCursorMsk);
114        */
97          /* create a cursor */
98          pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross);
99 <        /*  new */
100 <        clientname = id;
101 <        x11_driver.xsiz = DisplayWidth(ourdisplay,DefaultScreen(ourdisplay))
102 <                        - 2*BORWIDTH;
103 <        x11_driver.ysiz = DisplayHeight(ourdisplay,DefaultScreen(ourdisplay))
104 <                        - (COMHEIGHT + 2*BORWIDTH);
99 >        /* open window */
100 >        gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0,
101 >                DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
102 >                DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
103 >                BORWIDTH, ourblack, ourwhite);
104 >        if (gwind == 0) {
105 >                stderr_v("cannot create window\n");
106 >                return(NULL);
107 >        }
108 >        XStoreName(ourdisplay, gwind, id);
109 >        ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
110 >        ourxwmhints.flags = InputHint;
111 >        ourxwmhints.input = True;
112 >        XSetWMHints(ourdisplay, gwind, &ourxwmhints);
113 >        XSelectInput(ourdisplay, gwind, ExposureMask);
114 >        XMapWindow(ourdisplay, gwind);
115 >        XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent));
116 >        gwidth = levptr(XExposeEvent)->width;
117 >        gheight = levptr(XExposeEvent)->height - COMHEIGHT;
118 >        x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
119 >        x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
120          x11_driver.inpready = 0;
121          cmdvec = x11_comout;                    /* set error vectors */
122          if (wrnvec != NULL)
# Line 144 | Line 141 | x11_close()                    /* close our display */
141                  XFreeGC(ourdisplay, ourgc);
142                  XDestroyWindow(ourdisplay, gwind);
143                  gwind = 0;
147                gwidth = gheight = 0;
144                  ourgc = 0;
145          }
146          XFreeCursor(ourdisplay, pickcursor);
# Line 158 | Line 154 | static
154   x11_clear(xres, yres)                   /* clear our display */
155   int  xres, yres;
156   {
161        XWMHints  ourxwmhints;
162        XSetWindowAttributes ourwindowattr;
163
157          if (xres != gwidth || yres != gheight) {        /* change window */
158                  if (comline != NULL)
159                          xt_close(comline);
160 <                if (gwind == 0) {                       /* new window */
161 <                        ourwindowattr.backing_store = Always;
169 <                        ourwindowattr.background_pixel =
170 <                        WhitePixel(ourdisplay, DefaultScreen(ourdisplay));
171 <                        ourwindowattr.border_pixel =
172 <                        BlackPixel(ourdisplay, DefaultScreen(ourdisplay));
173 <                        gwind = XCreateWindow(ourdisplay,
174 <                                RootWindow(ourdisplay,
175 <                                DefaultScreen(ourdisplay)),
176 <                                0, 0, xres, yres+COMHEIGHT, BORWIDTH,
177 <                                0, InputOutput, CopyFromParent,
178 <                                CWBackingStore|CWBackPixel|CWBorderPixel,
179 <                                &ourwindowattr);
180 <                        if (gwind == 0)
181 <                                goto fail;
182 <                        XStoreName(ourdisplay, gwind, clientname);
183 <                        ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
184 <                        ourxwmhints.flags = InputHint;
185 <                        ourxwmhints.input = True;
186 <                        XSetWMHints(ourdisplay, gwind, &ourxwmhints);
187 <                        XSelectInput(ourdisplay, gwind,
188 <                                     KeyPressMask|ButtonPressMask);
189 <                        XMapWindow(ourdisplay, gwind);
190 <                } else                                  /* resize window */
191 <                        XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
160 >                XSelectInput(ourdisplay, gwind, 0);
161 >                XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
162                  comline = xt_open(ourdisplay,
163 <                                DefaultGC(ourdisplay,DefaultScreen(ourdisplay)),
163 >                                DefaultGC(ourdisplay,ourscreen),
164                                  gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
165 <                if (comline == NULL)
166 <                        goto fail;
165 >                if (comline == NULL) {
166 >                        stderr_v("Cannot open command line window\n");
167 >                        quit(1);
168 >                }
169 >                XSelectInput(ourdisplay, comline->w, ExposureMask);
170                  gwidth = xres;
171                  gheight = yres;
172 <        } else                                          /* just clear */
173 <                XClearWindow(ourdisplay, gwind);
172 >                XSync(ourdisplay, 1);           /* discard input */
173 >                sleep(2);                       /* wait for window manager */
174 >        }
175 >        XClearWindow(ourdisplay, gwind);
176                                                  /* reinitialize color table */
177 <        if (ncolors == 0 && getpixels() == 0)
177 >        if (getpixels() == 0)
178                  stderr_v("cannot allocate colors\n");
179          else
180                  new_ctab(ncolors);
181 <        return;
182 < fail:
183 <        stderr_v("Failure opening window in x11_clear\n");
209 <        quit(1);
181 >
182 >        XSelectInput(ourdisplay, gwind,
183 >                StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
184   }
185  
186  
# Line 215 | Line 189 | x11_paintr(col, xmin, ymin, xmax, ymax)                /* fill a rec
189   COLOR  col;
190   int  xmin, ymin, xmax, ymax;
191   {
218        extern long  nrays;             /* global ray count */
192          extern int  xnewcolr();         /* pixel assignment routine */
220        static long  lastflush = 0;     /* ray count at last flush */
193  
194          if (ncolors > 0) {
195                  XSetForeground(ourdisplay, ourgc,
# Line 225 | Line 197 | int  xmin, ymin, xmax, ymax;
197                  XFillRectangle(ourdisplay, gwind,
198                          ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin);
199          }
228        if (nrays - lastflush >= WFLUSH) {
229                if (ncolors <= 0)       /* output necessary for death */
230                        XFillRectangle(ourdisplay, gwind,
231                                        ourgc, 0, 0, 1 ,1);
232                checkinp();
233                lastflush = nrays;
234        }
200   }
201  
202  
203   static
204 + x11_flush()                     /* flush output */
205 + {
206 +        if (ncolors <= 0)       /* output necessary for death */
207 +                XFillRectangle(ourdisplay, gwind, ourgc, 0, 0, 1 ,1);
208 +        while (XPending(ourdisplay) > 0)
209 +                getevent();
210 + }
211 +
212 +
213 + static
214   x11_comin(inp, prompt)          /* read in a command line */
215   char  *inp, *prompt;
216   {
217          int  x11_getc(), x11_comout();
218  
219          if (prompt != NULL)
220 <                xt_puts(prompt, comline);
220 >                if (fromcombuf(inp, &x11_driver))
221 >                        return;
222 >                else
223 >                        xt_puts(prompt, comline);
224          xt_cursor(comline, TBLKCURS);
225          editline(inp, x11_getc, x11_comout);
226          xt_cursor(comline, TNOCURS);
# Line 319 | Line 297 | int  r, g, b;
297   static int
298   getpixels()                             /* get the color map */
299   {
300 <        Visual  *ourvis = DefaultVisual(ourdisplay,DefaultScreen(ourdisplay));
300 >        Visual  *ourvis = DefaultVisual(ourdisplay,ourscreen);
301  
302 <        freepixels();
302 >        if (ncolors > 0)
303 >                return(ncolors);
304          for (ncolors=(ourvis->map_entries)-3; ncolors>12; ncolors=ncolors*.937){
305                  pixval = (int *)malloc(ncolors*sizeof(int));
306                  if (pixval == NULL)
# Line 362 | Line 341 | getevent()                     /* get next event */
341   {
342          XNextEvent(ourdisplay, levptr(XEvent));
343          switch (levptr(XEvent)->type) {
344 +        case ConfigureNotify:
345 +                resizewindow(levptr(XConfigureEvent));
346 +                break;
347 +        case UnmapNotify:
348 +                freepixels();
349 +                break;
350 +        case MapNotify:
351 +                if (getpixels() == 0)
352 +                        stderr_v("Cannot allocate colors\n");
353 +                else
354 +                        new_ctab(ncolors);
355 +                break;
356 +        case Expose:
357 +                fixwindow(levptr(XExposeEvent));
358 +                break;
359          case KeyPress:
360                  getkey(levptr(XKeyPressedEvent));
361                  break;
# Line 381 | Line 375 | register XKeyPressedEvent  *ekey;
375   }
376  
377  
384 #ifdef notdef
378   static
379   fixwindow(eexp)                         /* repair damage to window */
380   register XExposeEvent  *eexp;
381   {
382 <        if (eexp->subwindow == 0)
383 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
382 >        if (eexp->window == gwind) {
383 >                sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n",
384 >                        eexp->x, gheight - eexp->y - eexp->height,
385                          eexp->x + eexp->width, gheight - eexp->y);
386 <        else if (eexp->subwindow == comline->w)
387 <                xt_redraw(comline);
386 >        } else if (eexp->window == comline->w) {
387 >                if (eexp->count == 0)
388 >                        xt_redraw(comline);
389 >        }
390   }
391 < #endif
391 >
392 >
393 > static
394 > resizewindow(ersz)                      /* resize window */
395 > register XConfigureEvent  *ersz;
396 > {
397 >        if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight)
398 >                return;
399 >
400 >        gwidth = ersz->width;
401 >        gheight = ersz->height-COMHEIGHT;
402 >        x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
403 >        x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
404 >
405 >        strcpy(getcombuf(&x11_driver), "new\n");
406 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines