ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/x11.c
Revision: 2.31
Committed: Mon Jul 21 22:30:19 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.30: +5 -3 lines
Log Message:
Eliminated copystruct() macro, which is unnecessary in ANSI.
Reduced ambiguity warnings for nested if/if/else clauses.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.31 static const char RCSid[] = "$Id: x11.c,v 2.30 2003/02/25 02:47:23 greg Exp $";
3 greg 1.1 #endif
4     /*
5 greg 2.4 * x11.c - driver for X-windows version 11
6 greg 2.29 */
7    
8 greg 2.30 #include "copyright.h"
9 greg 1.1
10 gregl 2.27 #include "standard.h"
11 greg 1.1 #include <sys/ioctl.h>
12 greg 2.23 #ifdef sparc
13     #include <sys/conf.h>
14     #include <sys/file.h>
15     #include <sys/filio.h>
16     #endif
17 greg 2.25 #if !defined(FNDELAY) && defined(O_NONBLOCK)
18     #define FNDELAY O_NONBLOCK
19     #endif
20 greg 1.1
21     #include <X11/Xlib.h>
22 greg 1.4 #include <X11/cursorfont.h>
23     #include <X11/Xutil.h>
24 greg 1.1
25     #include "color.h"
26     #include "driver.h"
27     #include "x11twind.h"
28 greg 1.18 #include "x11icon.h"
29 greg 1.1
30 greg 2.6 #define GAMMA 2.2 /* default exponent correction */
31 greg 1.1
32 greg 1.6 #define MINWIDTH (32*COMCW) /* minimum graphics window width */
33 greg 2.9 #define MINHEIGHT (MINWIDTH/2) /* minimum graphics window height */
34 greg 1.4
35 greg 1.1 #define BORWIDTH 5 /* border width */
36     #define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */
37    
38     #define COMFN "8x13" /* command line font name */
39     #define COMLH 3 /* number of command lines */
40     #define COMCW 8 /* approx. character width (pixels) */
41     #define COMCH 14 /* approx. character height (pixels) */
42    
43 greg 1.4 #define ourscreen DefaultScreen(ourdisplay)
44     #define ourroot RootWindow(ourdisplay,ourscreen)
45    
46     #define levptr(etype) ((etype *)&currentevent)
47 greg 1.1
48 greg 1.4 static XEvent currentevent; /* current event */
49 greg 1.1
50     static int ncolors = 0; /* color table size */
51 greg 2.8 static int mapped = 0; /* window is mapped? */
52 greg 1.17 static unsigned long *pixval = NULL; /* allocated pixels */
53 greg 2.3 static unsigned long ourblack=0, ourwhite=1;
54 greg 1.1
55     static Display *ourdisplay = NULL; /* our display */
56    
57 greg 2.2 static XVisualInfo ourvinfo; /* our visual information */
58 greg 1.6
59 greg 1.1 static Window gwind = 0; /* our graphics window */
60    
61     static Cursor pickcursor = 0; /* cursor used for picking */
62    
63 greg 1.4 static int gwidth, gheight; /* graphics window size */
64 greg 1.1
65 greg 2.17 static int comheight; /* desired comline height */
66 greg 1.1 static TEXTWIND *comline = NULL; /* our command line */
67    
68     static char c_queue[64]; /* input queue */
69     static int c_first = 0; /* first character in queue */
70     static int c_last = 0; /* last character in queue */
71    
72     static GC ourgc = 0; /* our graphics context for drawing */
73    
74 greg 1.6 static Colormap ourmap = 0; /* our color map */
75 greg 1.1
76 greg 2.19 #define IC_X11 0
77     #define IC_IOCTL 1
78     #define IC_READ 2
79    
80     static int inpcheck; /* whence to check input */
81    
82 greg 2.29 static int x11_getcur();
83 greg 1.1
84 greg 2.29 static void x11_close(), x11_clear(), x11_paintr(), x11_errout(),
85     x11_comout(), x11_comin(), x11_flush();
86 greg 1.1
87 greg 2.29 static void std_comin(), std_comout();
88 greg 2.17
89 greg 1.1 static struct driver x11_driver = {
90     x11_close, x11_clear, x11_paintr, x11_getcur,
91 greg 2.17 NULL, NULL, x11_flush, 1.0
92 greg 1.1 };
93    
94 greg 2.29 static int getpixels(), x11_getc();
95     static void xnewcolr(), freepixels(), resizewindow(),
96     getevent(), getkey(), fixwindow();
97 greg 2.11 static unsigned long true_pixel();
98 greg 1.1
99 greg 2.11
100 greg 1.1 struct driver *
101     x11_init(name, id) /* initialize driver */
102     char *name, *id;
103     {
104 greg 2.6 char *gv;
105 greg 1.6 int nplanes;
106 greg 1.10 XSetWindowAttributes ourwinattr;
107 greg 1.4 XWMHints ourxwmhints;
108 greg 1.12 XSizeHints oursizhints;
109 greg 2.17 /* open display server */
110 greg 1.1 ourdisplay = XOpenDisplay(NULL);
111     if (ourdisplay == NULL) {
112 gregl 2.27 eputs("cannot open X-windows; DISPLAY variable set?\n");
113 greg 1.1 return(NULL);
114     }
115 greg 2.2 /* find a usable visual */
116 greg 1.6 nplanes = DisplayPlanes(ourdisplay, ourscreen);
117 greg 2.4 if (XMatchVisualInfo(ourdisplay,ourscreen,
118 greg 2.26 nplanes>12?nplanes:24,TrueColor,&ourvinfo) ||
119 greg 2.4 XMatchVisualInfo(ourdisplay,ourscreen,
120 greg 2.26 nplanes>12?nplanes:24,DirectColor,&ourvinfo)) {
121 greg 2.4 ourblack = 0;
122     ourwhite = ourvinfo.red_mask |
123     ourvinfo.green_mask |
124     ourvinfo.blue_mask ;
125     } else {
126 greg 2.2 if (nplanes < 4) {
127 gregl 2.27 eputs("not enough colors\n");
128 greg 1.6 return(NULL);
129 greg 2.4 }
130     if (!XMatchVisualInfo(ourdisplay,ourscreen,
131 greg 2.2 nplanes,PseudoColor,&ourvinfo) &&
132     !XMatchVisualInfo(ourdisplay,ourscreen,
133     nplanes,GrayScale,&ourvinfo)) {
134 gregl 2.27 eputs("unsupported visual type\n");
135 greg 2.2 return(NULL);
136 greg 1.6 }
137 greg 2.3 ourblack = BlackPixel(ourdisplay,ourscreen);
138     ourwhite = WhitePixel(ourdisplay,ourscreen);
139     }
140 greg 2.6 /* set gamma */
141 greg 2.14 if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
142 greg 2.18 || (gv = getenv("DISPLAY_GAMMA")) != NULL)
143 greg 2.6 make_gmap(atof(gv));
144     else
145     make_gmap(GAMMA);
146 greg 2.17 /* X11 command line or no? */
147     if (!strcmp(name, "x11"))
148     comheight = COMHEIGHT;
149 greg 2.25 else /* "x11d" */ {
150 greg 2.17 comheight = 0;
151 greg 2.25 #ifndef FNDELAY
152 gregl 2.27 eputs("warning: x11d driver not fully functional on this machine\n");
153 greg 2.25 #endif
154     }
155 greg 2.6 /* open window */
156 greg 1.12 ourwinattr.background_pixel = ourblack;
157 greg 1.10 ourwinattr.border_pixel = ourblack;
158 greg 2.4 /* this is stupid */
159 greg 2.2 ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
160     ourvinfo.visual, AllocNone);
161 greg 1.10 gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
162 greg 1.4 DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
163     DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
164 greg 2.2 BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
165     CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
166 greg 1.4 if (gwind == 0) {
167 gregl 2.27 eputs("cannot create window\n");
168 greg 1.4 return(NULL);
169     }
170 greg 2.4 XStoreName(ourdisplay, gwind, id);
171 greg 1.10 /* create a cursor */
172     pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross);
173 greg 1.4 ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
174 greg 1.18 ourxwmhints.flags = InputHint|IconPixmapHint;
175 greg 1.4 ourxwmhints.input = True;
176 greg 1.18 ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
177     gwind, x11icon_bits, x11icon_width, x11icon_height);
178 greg 1.4 XSetWMHints(ourdisplay, gwind, &ourxwmhints);
179 greg 1.12 oursizhints.min_width = MINWIDTH;
180 greg 2.17 oursizhints.min_height = MINHEIGHT+comheight;
181 greg 1.12 oursizhints.flags = PMinSize;
182     XSetNormalHints(ourdisplay, gwind, &oursizhints);
183 greg 1.4 XSelectInput(ourdisplay, gwind, ExposureMask);
184     XMapWindow(ourdisplay, gwind);
185 greg 1.17 XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent));
186 greg 1.4 gwidth = levptr(XExposeEvent)->width;
187 greg 2.17 gheight = levptr(XExposeEvent)->height - comheight;
188 greg 1.4 x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
189     x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
190 greg 1.1 x11_driver.inpready = 0;
191 greg 2.8 mapped = 1;
192 greg 2.17 /* set i/o vectors */
193     if (comheight) {
194     x11_driver.comin = x11_comin;
195     x11_driver.comout = x11_comout;
196 gregl 2.27 erract[COMMAND].pf = x11_comout;
197     if (erract[WARNING].pf != NULL)
198     erract[WARNING].pf = x11_errout;
199 greg 2.19 inpcheck = IC_X11;
200 greg 2.17 } else {
201     x11_driver.comin = std_comin;
202     x11_driver.comout = std_comout;
203 gregl 2.27 erract[COMMAND].pf = std_comout;
204 greg 2.19 inpcheck = IC_IOCTL;
205 greg 2.17 }
206 greg 1.1 return(&x11_driver);
207     }
208    
209    
210 greg 2.29 static void
211 greg 1.1 x11_close() /* close our display */
212     {
213 gregl 2.27 erract[COMMAND].pf = NULL; /* reset error vectors */
214     if (erract[WARNING].pf != NULL)
215     erract[WARNING].pf = wputs;
216 greg 1.1 if (ourdisplay == NULL)
217     return;
218     if (comline != NULL) {
219     xt_close(comline);
220     comline = NULL;
221     }
222 greg 1.8 freepixels();
223     XFreeGC(ourdisplay, ourgc);
224     XDestroyWindow(ourdisplay, gwind);
225     gwind = 0;
226     ourgc = 0;
227 greg 1.1 XFreeCursor(ourdisplay, pickcursor);
228     XCloseDisplay(ourdisplay);
229     ourdisplay = NULL;
230     }
231    
232    
233 greg 2.29 static void
234 greg 1.1 x11_clear(xres, yres) /* clear our display */
235     int xres, yres;
236     {
237 greg 1.12 /* check limits */
238     if (xres < MINWIDTH)
239     xres = MINWIDTH;
240     if (yres < MINHEIGHT)
241     yres = MINHEIGHT;
242     /* resize window */
243     if (xres != gwidth || yres != gheight) {
244 greg 1.4 XSelectInput(ourdisplay, gwind, 0);
245 greg 2.17 XResizeWindow(ourdisplay, gwind, xres, yres+comheight);
246 greg 1.1 gwidth = xres;
247     gheight = yres;
248 greg 1.8 XFlush(ourdisplay);
249     sleep(2); /* wait for window manager */
250 greg 1.4 XSync(ourdisplay, 1); /* discard input */
251     }
252 greg 1.13 XClearWindow(ourdisplay, gwind);
253     /* reinitialize color table */
254 schorsch 2.31 if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) {
255 greg 1.13 if (getpixels() == 0)
256 gregl 2.27 eputs("cannot allocate colors\n");
257 greg 1.13 else
258     new_ctab(ncolors);
259 schorsch 2.31 }
260 greg 1.12 /* get new command line */
261 greg 1.13 if (comline != NULL)
262     xt_close(comline);
263 greg 2.17 if (comheight) {
264     comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth,
265     comheight, 0, ourblack, ourwhite, COMFN);
266     if (comline == NULL) {
267 gregl 2.27 eputs("cannot open command line window\n");
268 greg 2.17 quit(1);
269     }
270     XSelectInput(ourdisplay, comline->w, ExposureMask);
271 greg 1.12 /* remove earmuffs */
272 greg 2.17 XSelectInput(ourdisplay, gwind,
273 greg 1.4 StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask);
274 greg 2.17 } else /* remove earmuffs */
275     XSelectInput(ourdisplay, gwind,
276     StructureNotifyMask|ExposureMask|ButtonPressMask);
277 greg 1.1 }
278    
279    
280 greg 2.29 static void
281 greg 1.1 x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */
282     COLOR col;
283     int xmin, ymin, xmax, ymax;
284     {
285 greg 1.6 unsigned long pixel;
286 greg 1.1
287 greg 2.8 if (!mapped)
288     return;
289 greg 1.6 if (ncolors > 0)
290     pixel = pixval[get_pixel(col, xnewcolr)];
291 greg 2.8 else
292 greg 1.6 pixel = true_pixel(col);
293     XSetForeground(ourdisplay, ourgc, pixel);
294     XFillRectangle(ourdisplay, gwind,
295     ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin);
296 greg 1.5 }
297    
298    
299 greg 2.29 static void
300 greg 1.5 x11_flush() /* flush output */
301     {
302 greg 2.19 char buf[256];
303 greg 2.15 int n;
304 greg 2.16 /* check for input */
305 greg 1.10 XNoOp(ourdisplay);
306 greg 2.16 n = XPending(ourdisplay); /* from X server */
307     while (n-- > 0)
308 greg 1.5 getevent();
309 greg 2.22 #ifdef FNDELAY
310 greg 2.19 if (inpcheck == IC_IOCTL) { /* from stdin */
311 greg 2.22 #ifdef FIONREAD
312 greg 2.17 if (ioctl(fileno(stdin), FIONREAD, &n) < 0) {
313 greg 2.22 #else
314     if (1) {
315     #endif
316 greg 2.19 if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) {
317 gregl 2.27 eputs("cannot change input mode\n");
318 greg 2.19 quit(1);
319     }
320     inpcheck = IC_READ;
321     } else
322     x11_driver.inpready += n;
323     }
324     if (inpcheck == IC_READ) {
325     n = read(fileno(stdin), buf, sizeof(buf)-1);
326     if (n > 0) {
327     buf[n] = '\0';
328 greg 2.21 tocombuf(buf, &x11_driver);
329 greg 2.17 }
330 greg 2.15 }
331 greg 2.22 #endif
332 greg 1.1 }
333    
334    
335 greg 2.29 static void
336 greg 1.3 x11_comin(inp, prompt) /* read in a command line */
337     char *inp, *prompt;
338 greg 1.1 {
339 greg 2.15 if (prompt != NULL) {
340     x11_flush(); /* make sure we get everything */
341 greg 1.4 if (fromcombuf(inp, &x11_driver))
342     return;
343 greg 2.15 xt_puts(prompt, comline);
344     }
345 greg 1.1 xt_cursor(comline, TBLKCURS);
346     editline(inp, x11_getc, x11_comout);
347     xt_cursor(comline, TNOCURS);
348     }
349    
350    
351 greg 2.29 static void
352 greg 2.17 x11_comout(outp) /* output a string to command line */
353     char *outp;
354 greg 1.1 {
355 gregl 2.28 if (comline == NULL || outp == NULL || !outp[0])
356 greg 1.11 return;
357 greg 2.17 xt_puts(outp, comline);
358     if (outp[strlen(outp)-1] == '\n')
359 greg 1.11 XFlush(ourdisplay);
360 greg 1.1 }
361    
362    
363 greg 2.29 static void
364 greg 1.1 x11_errout(msg) /* output an error message */
365     char *msg;
366     {
367 gregl 2.27 eputs(msg); /* send to stderr also! */
368 greg 1.1 x11_comout(msg);
369     }
370    
371    
372 greg 2.29 static void
373 greg 2.17 std_comin(inp, prompt) /* read in command line from stdin */
374     char *inp, *prompt;
375     {
376     if (prompt != NULL) {
377     if (fromcombuf(inp, &x11_driver))
378     return;
379     if (!x11_driver.inpready)
380 greg 2.25 std_comout(prompt);
381 greg 2.17 }
382 greg 2.24 #ifdef FNDELAY
383     if (inpcheck == IC_READ) { /* turn off FNDELAY */
384     if (fcntl(fileno(stdin), F_SETFL, 0) < 0) {
385 gregl 2.27 eputs("cannot change input mode\n");
386 greg 2.24 quit(1);
387     }
388     inpcheck = IC_IOCTL;
389     }
390     #endif
391 greg 2.17 if (gets(inp) == NULL) {
392     strcpy(inp, "quit");
393     return;
394     }
395     x11_driver.inpready -= strlen(inp) + 1;
396     if (x11_driver.inpready < 0)
397     x11_driver.inpready = 0;
398     }
399    
400    
401 greg 2.29 static void
402 greg 2.17 std_comout(outp) /* write out string to stdout */
403     char *outp;
404     {
405     fputs(outp, stdout);
406 greg 2.20 fflush(stdout);
407 greg 2.17 }
408    
409    
410 greg 1.1 static int
411     x11_getcur(xp, yp) /* get cursor position */
412     int *xp, *yp;
413     {
414     while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask,
415     GrabModeAsync, GrabModeAsync, None, pickcursor,
416     CurrentTime) != GrabSuccess)
417     sleep(2);
418    
419     do
420     getevent();
421     while (c_last <= c_first && levptr(XEvent)->type != ButtonPress);
422     *xp = levptr(XButtonPressedEvent)->x;
423     *yp = gheight-1 - levptr(XButtonPressedEvent)->y;
424     XUngrabPointer(ourdisplay, CurrentTime);
425     XFlush(ourdisplay); /* insure release */
426     if (c_last > c_first) /* key pressed */
427     return(x11_getc());
428     /* button pressed */
429 greg 2.10 if (levptr(XButtonPressedEvent)->button == Button1)
430 greg 1.1 return(MB1);
431 greg 2.10 if (levptr(XButtonPressedEvent)->button == Button2)
432 greg 1.1 return(MB2);
433 greg 2.10 if (levptr(XButtonPressedEvent)->button == Button3)
434 greg 1.1 return(MB3);
435     return(ABORT);
436     }
437    
438    
439 greg 2.29 static void
440 greg 1.1 xnewcolr(ndx, r, g, b) /* enter a color into hardware table */
441     int ndx;
442     int r, g, b;
443     {
444     XColor xcolor;
445    
446     xcolor.pixel = pixval[ndx];
447     xcolor.red = r << 8;
448     xcolor.green = g << 8;
449     xcolor.blue = b << 8;
450     xcolor.flags = DoRed|DoGreen|DoBlue;
451    
452     XStoreColor(ourdisplay, ourmap, &xcolor);
453     }
454    
455    
456     static int
457     getpixels() /* get the color map */
458     {
459 greg 1.16 XColor thiscolor;
460     register int i, j;
461    
462 greg 1.4 if (ncolors > 0)
463 greg 2.2 return(ncolors);
464     if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
465 greg 1.6 ourmap = DefaultColormap(ourdisplay,ourscreen);
466     goto loop;
467     }
468     newmap:
469 greg 2.2 ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
470 greg 1.6 loop:
471 greg 2.2 for (ncolors = ourvinfo.colormap_size;
472     ncolors > ourvinfo.colormap_size/3;
473 greg 1.6 ncolors = ncolors*.937) {
474 greg 1.17 pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
475 greg 1.1 if (pixval == NULL)
476 greg 1.6 return(ncolors = 0);
477 greg 2.8 if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors))
478 greg 1.6 break;
479 greg 2.29 free((void *)pixval);
480 greg 1.6 pixval = NULL;
481 greg 1.1 }
482 greg 1.6 if (pixval == NULL) {
483     if (ourmap == DefaultColormap(ourdisplay,ourscreen))
484     goto newmap; /* try it with our map */
485     else
486     return(ncolors = 0); /* failed */
487     }
488 greg 1.16 if (ourmap != DefaultColormap(ourdisplay,ourscreen))
489     for (i = 0; i < ncolors; i++) { /* reset black and white */
490 greg 1.6 if (pixval[i] != ourblack && pixval[i] != ourwhite)
491     continue;
492     thiscolor.pixel = pixval[i];
493     thiscolor.flags = DoRed|DoGreen|DoBlue;
494     XQueryColor(ourdisplay,
495     DefaultColormap(ourdisplay,ourscreen),
496     &thiscolor);
497     XStoreColor(ourdisplay, ourmap, &thiscolor);
498     for (j = i; j+1 < ncolors; j++)
499     pixval[j] = pixval[j+1];
500     ncolors--;
501     i--;
502     }
503 greg 1.16 XSetWindowColormap(ourdisplay, gwind, ourmap);
504 greg 1.6 return(ncolors);
505 greg 1.1 }
506    
507    
508 greg 2.29 static void
509 greg 1.1 freepixels() /* free our pixels */
510     {
511     if (ncolors == 0)
512     return;
513     XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L);
514 greg 2.29 free((void *)pixval);
515 greg 2.7 pixval = NULL;
516 greg 1.1 ncolors = 0;
517 greg 1.8 if (ourmap != DefaultColormap(ourdisplay,ourscreen))
518 greg 1.6 XFreeColormap(ourdisplay, ourmap);
519     ourmap = 0;
520 greg 1.1 }
521    
522    
523 greg 1.6 static unsigned long
524     true_pixel(col) /* return true pixel value for color */
525     COLOR col;
526     {
527     unsigned long rval;
528     BYTE rgb[3];
529    
530     map_color(rgb, col);
531 greg 2.2 rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
532     rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
533     rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
534 greg 1.6 return(rval);
535     }
536    
537    
538 greg 1.1 static int
539     x11_getc() /* get a command character */
540     {
541     while (c_last <= c_first) {
542     c_first = c_last = 0; /* reset */
543     getevent(); /* wait for key */
544     }
545     x11_driver.inpready--;
546     return(c_queue[c_first++]);
547     }
548    
549    
550 greg 2.29 static void
551 greg 1.1 getevent() /* get next event */
552     {
553     XNextEvent(ourdisplay, levptr(XEvent));
554     switch (levptr(XEvent)->type) {
555 greg 1.4 case ConfigureNotify:
556     resizewindow(levptr(XConfigureEvent));
557     break;
558     case UnmapNotify:
559 greg 2.8 mapped = 0;
560 greg 1.4 freepixels();
561     break;
562     case MapNotify:
563 greg 2.2 if (ourvinfo.class == PseudoColor ||
564 schorsch 2.31 ourvinfo.class == GrayScale) {
565 greg 1.6 if (getpixels() == 0)
566 gregl 2.27 eputs("cannot allocate colors\n");
567 greg 1.6 else
568     new_ctab(ncolors);
569 schorsch 2.31 }
570 greg 2.8 mapped = 1;
571 greg 1.4 break;
572     case Expose:
573     fixwindow(levptr(XExposeEvent));
574     break;
575 greg 1.1 case KeyPress:
576     getkey(levptr(XKeyPressedEvent));
577     break;
578     case ButtonPress:
579     break;
580     }
581     }
582    
583    
584 greg 2.29 static void
585 greg 1.1 getkey(ekey) /* get input key */
586     register XKeyPressedEvent *ekey;
587     {
588 greg 1.8 register int n;
589 greg 1.7
590     n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last,
591 greg 1.1 NULL, NULL);
592 greg 1.7 c_last += n;
593     x11_driver.inpready += n;
594 greg 1.1 }
595    
596    
597 greg 2.29 static void
598 greg 1.1 fixwindow(eexp) /* repair damage to window */
599     register XExposeEvent *eexp;
600     {
601 greg 2.21 char buf[80];
602    
603 greg 1.4 if (eexp->window == gwind) {
604 greg 2.21 sprintf(buf, "repaint %d %d %d %d\n",
605 greg 1.4 eexp->x, gheight - eexp->y - eexp->height,
606 greg 1.1 eexp->x + eexp->width, gheight - eexp->y);
607 greg 2.21 tocombuf(buf, &x11_driver);
608 greg 1.4 } else if (eexp->window == comline->w) {
609     if (eexp->count == 0)
610     xt_redraw(comline);
611     }
612 greg 1.1 }
613 greg 1.4
614    
615 greg 2.29 static void
616 greg 1.4 resizewindow(ersz) /* resize window */
617     register XConfigureEvent *ersz;
618     {
619 greg 2.17 if (ersz->width == gwidth && ersz->height-comheight == gheight)
620 greg 1.4 return;
621    
622     gwidth = ersz->width;
623 greg 2.17 gheight = ersz->height-comheight;
624 greg 1.4 x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
625     x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
626    
627 greg 2.21 tocombuf("new\n", &x11_driver);
628 greg 1.4 }