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.5 by greg, Thu Feb 22 11:46:26 1990 UTC vs.
Revision 2.24 by greg, Tue Mar 7 14:18:34 1995 UTC

# Line 1 | Line 1
1 + /* Copyright (c) 1992 Regents of the University of California */
2 +
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
5 /* Copyright (c) 1989 Regents of the University of California */
6
7   /*
8 < *  x11.c - driver for X-windows version 11.3
8 > *  x11.c - driver for X-windows version 11
9   *
10   *     Jan 1990
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 21 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   #include  "color.h"
28   #include  "driver.h"
29   #include  "x11twind.h"
30 + #include  "x11icon.h"
31  
32 < #define GAMMA           2.2             /* exponent for color correction */
32 > #define GAMMA           2.2             /* default exponent correction */
33  
34 < #define MINWIDTH        (4*COMCW)       /* minimum graphics window width */
35 < #define MINHEIGHT       16              /* minimum graphics window height */
34 > #define MINWIDTH        (32*COMCW)      /* minimum graphics window width */
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 37 | Line 44 | static char SCCSid[] = "$SunId$ LBL";
44  
45   #define  ourscreen      DefaultScreen(ourdisplay)
46   #define  ourroot        RootWindow(ourdisplay,ourscreen)
40 #define  ourwhite       WhitePixel(ourdisplay,ourscreen)
41 #define  ourblack       BlackPixel(ourdisplay,ourscreen)
47  
48   #define  levptr(etype)  ((etype *)&currentevent)
49  
50   static XEvent  currentevent;            /* current event */
51  
52   static int  ncolors = 0;                /* color table size */
53 < static int  *pixval = NULL;             /* allocated pixels */
53 > static int  mapped = 0;                 /* window is mapped? */
54 > static unsigned long  *pixval = NULL;   /* allocated pixels */
55 > static unsigned long  ourblack=0, ourwhite=1;
56  
57   static Display  *ourdisplay = NULL;     /* our display */
58  
59 + static XVisualInfo  ourvinfo;           /* our visual information */
60 +
61   static Window  gwind = 0;               /* our graphics window */
62  
63   static Cursor  pickcursor = 0;          /* cursor used for picking */
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 63 | Line 73 | static int  c_last = 0;                        /* last character in queue *
73  
74   static GC  ourgc = 0;                   /* our graphics context for drawing */
75  
76 < static Colormap ourmap;                 /* our color map */
76 > static Colormap ourmap = 0;             /* our color map */
77  
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 < int  x11_close(), x11_clear(), x11_paintr(), x11_errout(),
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;
104   {
105 +        extern char  *getenv();
106 +        char  *gv;
107 +        int  nplanes;
108 +        XSetWindowAttributes    ourwinattr;
109          XWMHints  ourxwmhints;
110 <        Pixmap  bmCursorSrc, bmCursorMsk;
111 <
110 >        XSizeHints      oursizhints;
111 >                                        /* open display server */
112          ourdisplay = XOpenDisplay(NULL);
113          if (ourdisplay == NULL) {
114                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
115                  return(NULL);
116          }
117 <        if (DisplayPlanes(ourdisplay, ourscreen) < 4) {
118 <                stderr_v("not enough colors\n");
119 <                return(NULL);
117 >                                        /* find a usable visual */
118 >        nplanes = DisplayPlanes(ourdisplay, ourscreen);
119 >        if (XMatchVisualInfo(ourdisplay,ourscreen,
120 >                                24,TrueColor,&ourvinfo) ||
121 >                        XMatchVisualInfo(ourdisplay,ourscreen,
122 >                                24,DirectColor,&ourvinfo)) {
123 >                ourblack = 0;
124 >                ourwhite = ourvinfo.red_mask |
125 >                                ourvinfo.green_mask |
126 >                                ourvinfo.blue_mask ;
127 >        } else {
128 >                if (nplanes < 4) {
129 >                        stderr_v("not enough colors\n");
130 >                        return(NULL);
131 >                }
132 >                if (!XMatchVisualInfo(ourdisplay,ourscreen,
133 >                                        nplanes,PseudoColor,&ourvinfo) &&
134 >                                !XMatchVisualInfo(ourdisplay,ourscreen,
135 >                                        nplanes,GrayScale,&ourvinfo)) {
136 >                        stderr_v("unsupported visual type\n");
137 >                        return(NULL);
138 >                }
139 >                ourblack = BlackPixel(ourdisplay,ourscreen);
140 >                ourwhite = WhitePixel(ourdisplay,ourscreen);
141          }
142 <        ourmap = DefaultColormap(ourdisplay,ourscreen);
143 <        make_gmap(GAMMA);                       /* make color map */
144 <        /* create a cursor */
145 <        pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross);
146 <        /* open window */
147 <        gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0,
142 >                                        /* set gamma */
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;
156 >                                        /* this is stupid */
157 >        ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
158 >                                ourvinfo.visual, AllocNone);
159 >        gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
160                  DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
161                  DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
162 <                BORWIDTH, ourblack, ourwhite);
162 >                BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
163 >                CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
164          if (gwind == 0) {
165                  stderr_v("cannot create window\n");
166                  return(NULL);
167          }
168 <        XStoreName(ourdisplay, gwind, id);
168 >        XStoreName(ourdisplay, gwind, id);
169 >        /* create a cursor */
170 >        pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross);
171          ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
172 <        ourxwmhints.flags = InputHint;
172 >        ourxwmhints.flags = InputHint|IconPixmapHint;
173          ourxwmhints.input = True;
174 +        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
175 +                        gwind, x11icon_bits, x11icon_width, x11icon_height);
176          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
177 +        oursizhints.min_width = MINWIDTH;
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(XExposeEvent));
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 <        cmdvec = x11_comout;                    /* set error vectors */
190 <        if (wrnvec != NULL)
191 <                wrnvec = x11_errout;
189 >        mapped = 1;
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 137 | Line 217 | x11_close()                    /* close our display */
217                  xt_close(comline);
218                  comline = NULL;
219          }
140        if (gwind != 0) {
141                XFreeGC(ourdisplay, ourgc);
142                XDestroyWindow(ourdisplay, gwind);
143                gwind = 0;
144                ourgc = 0;
145        }
146        XFreeCursor(ourdisplay, pickcursor);
220          freepixels();
221 +        XFreeGC(ourdisplay, ourgc);
222 +        XDestroyWindow(ourdisplay, gwind);
223 +        gwind = 0;
224 +        ourgc = 0;
225 +        XFreeCursor(ourdisplay, pickcursor);
226          XCloseDisplay(ourdisplay);
227          ourdisplay = NULL;
228   }
# Line 154 | Line 232 | static
232   x11_clear(xres, yres)                   /* clear our display */
233   int  xres, yres;
234   {
235 <        if (xres != gwidth || yres != gheight) {        /* change window */
236 <                if (comline != NULL)
237 <                        xt_close(comline);
235 >                                                /* check limits */
236 >        if (xres < MINWIDTH)
237 >                xres = MINWIDTH;
238 >        if (yres < MINHEIGHT)
239 >                yres = MINHEIGHT;
240 >                                                /* resize window */
241 >        if (xres != gwidth || yres != gheight) {
242                  XSelectInput(ourdisplay, gwind, 0);
243 <                XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT);
162 <                comline = xt_open(ourdisplay,
163 <                                DefaultGC(ourdisplay,ourscreen),
164 <                                gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
165 <                if (comline == NULL) {
166 <                        stderr_v("Cannot open command line window\n");
167 <                        quit(1);
168 <                }
169 <                XSelectInput(ourdisplay, comline->w, ExposureMask);
243 >                XResizeWindow(ourdisplay, gwind, xres, yres+comheight);
244                  gwidth = xres;
245                  gheight = yres;
246 <                XSync(ourdisplay, 1);           /* discard input */
246 >                XFlush(ourdisplay);
247                  sleep(2);                       /* wait for window manager */
248 +                XSync(ourdisplay, 1);           /* discard input */
249          }
250          XClearWindow(ourdisplay, gwind);
251                                                  /* reinitialize color table */
252 <        if (getpixels() == 0)
253 <                stderr_v("cannot allocate colors\n");
254 <        else
255 <                new_ctab(ncolors);
256 <
257 <        XSelectInput(ourdisplay, gwind,
252 >        if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale)
253 >                if (getpixels() == 0)
254 >                        stderr_v("cannot allocate colors\n");
255 >                else
256 >                        new_ctab(ncolors);
257 >                                                /* get new command line */
258 >        if (comline != NULL)
259 >                xt_close(comline);
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,
270                  StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
271 +        } else                                  /* remove earmuffs */
272 +                XSelectInput(ourdisplay, gwind,
273 +                        StructureNotifyMask|ExposureMask|ButtonPressMask);
274   }
275  
276  
# Line 189 | Line 279 | x11_paintr(col, xmin, ymin, xmax, ymax)                /* fill a rec
279   COLOR  col;
280   int  xmin, ymin, xmax, ymax;
281   {
282 <        extern int  xnewcolr();         /* pixel assignment routine */
282 >        unsigned long  pixel;
283  
284 <        if (ncolors > 0) {
285 <                XSetForeground(ourdisplay, ourgc,
286 <                                pixval[get_pixel(col, xnewcolr)]);
287 <                XFillRectangle(ourdisplay, gwind,
288 <                        ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin);
289 <        }
284 >        if (!mapped)
285 >                return;
286 >        if (ncolors > 0)
287 >                pixel = pixval[get_pixel(col, xnewcolr)];
288 >        else
289 >                pixel = true_pixel(col);
290 >        XSetForeground(ourdisplay, ourgc, pixel);
291 >        XFillRectangle(ourdisplay, gwind,
292 >                ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin);
293   }
294  
295  
296   static
297   x11_flush()                     /* flush output */
298   {
299 <        if (ncolors <= 0)       /* output necessary for death */
300 <                XFillRectangle(ourdisplay, gwind, ourgc, 0, 0, 1 ,1);
301 <        while (XPending(ourdisplay) > 0)
299 >        char    buf[256];
300 >        int     n;
301 >                                                /* check for input */
302 >        XNoOp(ourdisplay);
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 214 | Line 333 | static
333   x11_comin(inp, prompt)          /* read in a command line */
334   char  *inp, *prompt;
335   {
336 <        int  x11_getc(), x11_comout();
337 <
219 <        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 228 | 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 <                xt_puts(out, comline);
354 <        XFlush(ourdisplay);
352 >        if (comline == NULL)
353 >                return;
354 >        xt_puts(outp, comline);
355 >        if (outp[strlen(outp)-1] == '\n')
356 >                XFlush(ourdisplay);
357   }
358  
359  
# Line 241 | Line 361 | static
361   x11_errout(msg)                 /* output an error message */
362   char  *msg;
363   {
244        x11_comout(msg);
364          stderr_v(msg);          /* send to stderr also! */
365 +        x11_comout(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 + #ifdef FNDELAY
382 +        if (inpcheck == IC_READ) {      /* turn off FNDELAY */
383 +                if (fcntl(fileno(stdin), F_SETFL, 0) < 0) {
384 +                        stderr_v("Cannot change input mode\n");
385 +                        quit(1);
386 +                }
387 +                inpcheck = IC_IOCTL;
388 +        }
389 + #endif
390 +        if (gets(inp) == NULL) {
391 +                strcpy(inp, "quit");
392 +                return;
393 +        }
394 +        x11_driver.inpready -= strlen(inp) + 1;
395 +        if (x11_driver.inpready < 0)
396 +                x11_driver.inpready = 0;
397 + }
398 +
399 +
400 + static
401 + std_comout(outp)                /* write out string to stdout */
402 + char    *outp;
403 + {
404 +        fputs(outp, stdout);
405 +        fflush(stdout);
406 + }
407 +
408 +
409   static int
410   x11_getcur(xp, yp)              /* get cursor position */
411   int  *xp, *yp;
# Line 265 | Line 425 | int  *xp, *yp;
425          if (c_last > c_first)                   /* key pressed */
426                  return(x11_getc());
427                                                  /* button pressed */
428 <        if (levptr(XButtonPressedEvent)->button & Button1)
428 >        if (levptr(XButtonPressedEvent)->button == Button1)
429                  return(MB1);
430 <        if (levptr(XButtonPressedEvent)->button & Button2)
430 >        if (levptr(XButtonPressedEvent)->button == Button2)
431                  return(MB2);
432 <        if (levptr(XButtonPressedEvent)->button & Button3)
432 >        if (levptr(XButtonPressedEvent)->button == Button3)
433                  return(MB3);
274        if (levptr(XButtonPressedEvent)->button & (Button4|Button5))
275                return(MB1);
434          return(ABORT);
435   }
436  
# Line 297 | Line 455 | int  r, g, b;
455   static int
456   getpixels()                             /* get the color map */
457   {
458 <        Visual  *ourvis = DefaultVisual(ourdisplay,ourscreen);
458 >        XColor  thiscolor;
459 >        register int  i, j;
460  
461          if (ncolors > 0)
462                  return(ncolors);
463 <        for (ncolors=(ourvis->map_entries)-3; ncolors>12; ncolors=ncolors*.937){
464 <                pixval = (int *)malloc(ncolors*sizeof(int));
463 >        if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
464 >                ourmap = DefaultColormap(ourdisplay,ourscreen);
465 >                goto loop;
466 >        }
467 > newmap:
468 >        ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
469 > loop:
470 >        for (ncolors = ourvinfo.colormap_size;
471 >                        ncolors > ourvinfo.colormap_size/3;
472 >                        ncolors = ncolors*.937) {
473 >                pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
474                  if (pixval == NULL)
475 +                        return(ncolors = 0);
476 +                if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors))
477                          break;
308                if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,
309                                pixval,ncolors) != 0)
310                        return(ncolors);
478                  free((char *)pixval);
479 +                pixval = NULL;
480          }
481 <        return(ncolors = 0);
481 >        if (pixval == NULL) {
482 >                if (ourmap == DefaultColormap(ourdisplay,ourscreen))
483 >                        goto newmap;            /* try it with our map */
484 >                else
485 >                        return(ncolors = 0);    /* failed */
486 >        }
487 >        if (ourmap != DefaultColormap(ourdisplay,ourscreen))
488 >                for (i = 0; i < ncolors; i++) { /* reset black and white */
489 >                        if (pixval[i] != ourblack && pixval[i] != ourwhite)
490 >                                continue;
491 >                        thiscolor.pixel = pixval[i];
492 >                        thiscolor.flags = DoRed|DoGreen|DoBlue;
493 >                        XQueryColor(ourdisplay,
494 >                                        DefaultColormap(ourdisplay,ourscreen),
495 >                                        &thiscolor);
496 >                        XStoreColor(ourdisplay, ourmap, &thiscolor);
497 >                        for (j = i; j+1 < ncolors; j++)
498 >                                pixval[j] = pixval[j+1];
499 >                        ncolors--;
500 >                        i--;
501 >                }
502 >        XSetWindowColormap(ourdisplay, gwind, ourmap);
503 >        return(ncolors);
504   }
505  
506  
# Line 320 | Line 510 | freepixels()                           /* free our pixels */
510          if (ncolors == 0)
511                  return;
512          XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L);
513 +        free((char *)pixval);
514 +        pixval = NULL;
515          ncolors = 0;
516 +        if (ourmap != DefaultColormap(ourdisplay,ourscreen))
517 +                XFreeColormap(ourdisplay, ourmap);
518 +        ourmap = 0;
519   }
520  
521  
522 + static unsigned long
523 + true_pixel(col)                 /* return true pixel value for color */
524 + COLOR  col;
525 + {
526 +        unsigned long  rval;
527 +        BYTE  rgb[3];
528 +
529 +        map_color(rgb, col);
530 +        rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
531 +        rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
532 +        rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
533 +        return(rval);
534 + }
535 +
536 +
537   static int
538   x11_getc()                      /* get a command character */
539   {
# Line 345 | Line 555 | getevent()                     /* get next event */
555                  resizewindow(levptr(XConfigureEvent));
556                  break;
557          case UnmapNotify:
558 +                mapped = 0;
559                  freepixels();
560                  break;
561          case MapNotify:
562 <                if (getpixels() == 0)
563 <                        stderr_v("Cannot allocate colors\n");
564 <                else
565 <                        new_ctab(ncolors);
562 >                if (ourvinfo.class == PseudoColor ||
563 >                                ourvinfo.class == GrayScale)
564 >                        if (getpixels() == 0)
565 >                                stderr_v("Cannot allocate colors\n");
566 >                        else
567 >                                new_ctab(ncolors);
568 >                mapped = 1;
569                  break;
570          case Expose:
571                  fixwindow(levptr(XExposeEvent));
# Line 369 | Line 583 | static
583   getkey(ekey)                            /* get input key */
584   register XKeyPressedEvent  *ekey;
585   {
586 <        c_last += XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last,
586 >        register int  n;
587 >
588 >        n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last,
589                                  NULL, NULL);
590 <        x11_driver.inpready = c_last-c_first;
590 >        c_last += n;
591 >        x11_driver.inpready += n;
592   }
593  
594  
# Line 379 | Line 596 | static
596   fixwindow(eexp)                         /* repair damage to window */
597   register XExposeEvent  *eexp;
598   {
599 +        char  buf[80];
600 +
601          if (eexp->window == gwind) {
602 <                sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n",
602 >                sprintf(buf, "repaint %d %d %d %d\n",
603                          eexp->x, gheight - eexp->y - eexp->height,
604                          eexp->x + eexp->width, gheight - eexp->y);
605 +                tocombuf(buf, &x11_driver);
606          } else if (eexp->window == comline->w) {
607                  if (eexp->count == 0)
608                          xt_redraw(comline);
# Line 394 | Line 614 | static
614   resizewindow(ersz)                      /* resize window */
615   register XConfigureEvent  *ersz;
616   {
617 <        if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight)
617 >        if (ersz->width == gwidth && ersz->height-comheight == gheight)
618                  return;
619  
620          gwidth = ersz->width;
621 <        gheight = ersz->height-COMHEIGHT;
621 >        gheight = ersz->height-comheight;
622          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
623          x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
624  
625 <        strcpy(getcombuf(&x11_driver), "new\n");
625 >        tocombuf("new\n", &x11_driver);
626   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines