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.4 by greg, Thu Feb 22 10:22:01 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 36 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
39   #define WFLUSH          30              /* flush after this many rays */
40   #endif
41  
42 + #define  ourscreen      DefaultScreen(ourdisplay)
43 + #define  ourroot        RootWindow(ourdisplay,ourscreen)
44 + #define  ourwhite       WhitePixel(ourdisplay,ourscreen)
45 + #define  ourblack       BlackPixel(ourdisplay,ourscreen)
46 +
47   #define  checkinp()     while (XPending(ourdisplay) > 0) getevent()
48  
49 < #define  levptr(etype)  ((etype *)&thisevent)
49 > #define  levptr(etype)  ((etype *)&currentevent)
50  
51 < static char  *clientname;               /* calling client's name */
51 > static XEvent  currentevent;            /* current event */
52  
45 static XEvent  thisevent;               /* current event */
46
53   static int  ncolors = 0;                /* color table size */
54   static int  *pixval = NULL;             /* allocated pixels */
55  
# Line 53 | Line 59 | static Window  gwind = 0;              /* our graphics window */
59  
60   static Cursor  pickcursor = 0;          /* cursor used for picking */
61  
62 < static int  gwidth = 0;                 /* graphics window width */
57 < static int  gheight = 0;                /* graphics window height */
62 > static int  gwidth, gheight;            /* graphics window size */
63  
64   static TEXTWIND  *comline = NULL;       /* our command line */
65  
# Line 81 | Line 86 | struct driver *
86   x11_init(name, id)              /* initialize driver */
87   char  *name, *id;
88   {
89 +        XWMHints  ourxwmhints;
90          Pixmap  bmCursorSrc, bmCursorMsk;
91  
92          ourdisplay = XOpenDisplay(NULL);
# Line 88 | Line 94 | char  *name, *id;
94                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
95                  return(NULL);
96          }
97 <        if (DisplayPlanes(ourdisplay, DefaultScreen(ourdisplay)) < 4) {
97 >        if (DisplayPlanes(ourdisplay, ourscreen) < 4) {
98                  stderr_v("not enough colors\n");
99                  return(NULL);
100          }
101 <        ourmap = DefaultColormap(ourdisplay,DefaultScreen(ourdisplay));
101 >        ourmap = DefaultColormap(ourdisplay,ourscreen);
102          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        */
103          /* create a cursor */
104          pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross);
105 <        /*  new */
106 <        clientname = id;
107 <        x11_driver.xsiz = DisplayWidth(ourdisplay,DefaultScreen(ourdisplay))
108 <                        - 2*BORWIDTH;
109 <        x11_driver.ysiz = DisplayHeight(ourdisplay,DefaultScreen(ourdisplay))
110 <                        - (COMHEIGHT + 2*BORWIDTH);
105 >        /* open window */
106 >        gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0,
107 >                DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
108 >                DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
109 >                BORWIDTH, ourblack, ourwhite);
110 >        if (gwind == 0) {
111 >                stderr_v("cannot create window\n");
112 >                return(NULL);
113 >        }
114 >        XStoreName(ourdisplay, gwind, id);
115 >        ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
116 >        ourxwmhints.flags = InputHint;
117 >        ourxwmhints.input = True;
118 >        XSetWMHints(ourdisplay, gwind, &ourxwmhints);
119 >        XSelectInput(ourdisplay, gwind, ExposureMask);
120 >        XMapWindow(ourdisplay, gwind);
121 >        XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent));
122 >        gwidth = levptr(XExposeEvent)->width;
123 >        gheight = levptr(XExposeEvent)->height - COMHEIGHT;
124 >        x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
125 >        x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
126          x11_driver.inpready = 0;
127          cmdvec = x11_comout;                    /* set error vectors */
128          if (wrnvec != NULL)
# Line 144 | Line 147 | x11_close()                    /* close our display */
147                  XFreeGC(ourdisplay, ourgc);
148                  XDestroyWindow(ourdisplay, gwind);
149                  gwind = 0;
147                gwidth = gheight = 0;
150                  ourgc = 0;
151          }
152          XFreeCursor(ourdisplay, pickcursor);
# Line 158 | Line 160 | static
160   x11_clear(xres, yres)                   /* clear our display */
161   int  xres, yres;
162   {
161        XWMHints  ourxwmhints;
162        XSetWindowAttributes ourwindowattr;
163
163          if (xres != gwidth || yres != gheight) {        /* change window */
164                  if (comline != NULL)
165                          xt_close(comline);
166 <                if (gwind == 0) {                       /* new window */
167 <                        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);
166 >                XSelectInput(ourdisplay, gwind, 0);
167 >                XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
168                  comline = xt_open(ourdisplay,
169 <                                DefaultGC(ourdisplay,DefaultScreen(ourdisplay)),
169 >                                DefaultGC(ourdisplay,ourscreen),
170                                  gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
171 <                if (comline == NULL)
172 <                        goto fail;
171 >                if (comline == NULL) {
172 >                        stderr_v("Cannot open command line window\n");
173 >                        quit(1);
174 >                }
175 >                XSelectInput(ourdisplay, comline->w, ExposureMask);
176                  gwidth = xres;
177                  gheight = yres;
178 <        } else                                          /* just clear */
179 <                XClearWindow(ourdisplay, gwind);
178 >                XSync(ourdisplay, 1);           /* discard input */
179 >                sleep(2);                       /* wait for window manager */
180 >        }
181 >        XClearWindow(ourdisplay, gwind);
182                                                  /* reinitialize color table */
183 <        if (ncolors == 0 && getpixels() == 0)
183 >        if (getpixels() == 0)
184                  stderr_v("cannot allocate colors\n");
185          else
186                  new_ctab(ncolors);
187 <        return;
188 < fail:
189 <        stderr_v("Failure opening window in x11_clear\n");
209 <        quit(1);
187 >
188 >        XSelectInput(ourdisplay, gwind,
189 >                StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
190   }
191  
192  
# Line 242 | Line 222 | char  *inp, *prompt;
222          int  x11_getc(), x11_comout();
223  
224          if (prompt != NULL)
225 <                xt_puts(prompt, comline);
225 >                if (fromcombuf(inp, &x11_driver))
226 >                        return;
227 >                else
228 >                        xt_puts(prompt, comline);
229          xt_cursor(comline, TBLKCURS);
230          editline(inp, x11_getc, x11_comout);
231          xt_cursor(comline, TNOCURS);
# Line 319 | Line 302 | int  r, g, b;
302   static int
303   getpixels()                             /* get the color map */
304   {
305 <        Visual  *ourvis = DefaultVisual(ourdisplay,DefaultScreen(ourdisplay));
305 >        Visual  *ourvis = DefaultVisual(ourdisplay,ourscreen);
306  
307 <        freepixels();
307 >        if (ncolors > 0)
308 >                return(ncolors);
309          for (ncolors=(ourvis->map_entries)-3; ncolors>12; ncolors=ncolors*.937){
310                  pixval = (int *)malloc(ncolors*sizeof(int));
311                  if (pixval == NULL)
# Line 362 | Line 346 | getevent()                     /* get next event */
346   {
347          XNextEvent(ourdisplay, levptr(XEvent));
348          switch (levptr(XEvent)->type) {
349 +        case ConfigureNotify:
350 +                resizewindow(levptr(XConfigureEvent));
351 +                break;
352 +        case UnmapNotify:
353 +                freepixels();
354 +                break;
355 +        case MapNotify:
356 +                if (getpixels() == 0)
357 +                        stderr_v("Cannot allocate colors\n");
358 +                else
359 +                        new_ctab(ncolors);
360 +                break;
361 +        case Expose:
362 +                fixwindow(levptr(XExposeEvent));
363 +                break;
364          case KeyPress:
365                  getkey(levptr(XKeyPressedEvent));
366                  break;
# Line 381 | Line 380 | register XKeyPressedEvent  *ekey;
380   }
381  
382  
384 #ifdef notdef
383   static
384   fixwindow(eexp)                         /* repair damage to window */
385   register XExposeEvent  *eexp;
386   {
387 <        if (eexp->subwindow == 0)
388 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
387 >        if (eexp->window == gwind) {
388 >                sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n",
389 >                        eexp->x, gheight - eexp->y - eexp->height,
390                          eexp->x + eexp->width, gheight - eexp->y);
391 <        else if (eexp->subwindow == comline->w)
392 <                xt_redraw(comline);
391 >        } else if (eexp->window == comline->w) {
392 >                if (eexp->count == 0)
393 >                        xt_redraw(comline);
394 >        }
395   }
396 < #endif
396 >
397 >
398 > static
399 > resizewindow(ersz)                      /* resize window */
400 > register XConfigureEvent  *ersz;
401 > {
402 >        if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight)
403 >                return;
404 >
405 >        gwidth = ersz->width;
406 >        gheight = ersz->height-COMHEIGHT;
407 >        x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
408 >        x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
409 >
410 >        strcpy(getcombuf(&x11_driver), "new\n");
411 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines