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 11R4 |
8 |
> |
* x11.c - driver for X-windows version 11 |
9 |
|
* |
10 |
< |
* 1989 |
10 |
> |
* Jan 1990 |
11 |
|
*/ |
12 |
|
|
13 |
|
#include <stdio.h> |
15 |
|
#include <sys/ioctl.h> |
16 |
|
|
17 |
|
#include <X11/Xlib.h> |
18 |
< |
#include <X11/cursorfont.h> |
19 |
< |
#include <X11/Xutil.h> |
20 |
< |
#ifdef notdef |
21 |
< |
#include "bcross.cursor" |
22 |
< |
#include "bcross_mask.cu" |
23 |
< |
#endif |
18 |
> |
#include <X11/cursorfont.h> |
19 |
> |
#include <X11/Xutil.h> |
20 |
|
|
21 |
|
#include "color.h" |
26 |
– |
|
22 |
|
#include "driver.h" |
28 |
– |
|
23 |
|
#include "x11twind.h" |
24 |
+ |
#include "x11icon.h" |
25 |
|
|
26 |
|
#define GAMMA 2.2 /* exponent for color correction */ |
27 |
|
|
28 |
+ |
#define MINWIDTH (32*COMCW) /* minimum graphics window width */ |
29 |
+ |
#define MINHEIGHT MINWIDTH /* minimum graphics window height */ |
30 |
+ |
|
31 |
|
#define BORWIDTH 5 /* border width */ |
34 |
– |
#define BARHEIGHT 25 /* menu bar size */ |
32 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
33 |
|
|
34 |
|
#define COMFN "8x13" /* command line font name */ |
36 |
|
#define COMCW 8 /* approx. character width (pixels) */ |
37 |
|
#define COMCH 14 /* approx. character height (pixels) */ |
38 |
|
|
39 |
< |
#ifndef WFLUSH |
40 |
< |
#define WFLUSH 30 /* flush after this many rays */ |
44 |
< |
#endif |
39 |
> |
#define ourscreen DefaultScreen(ourdisplay) |
40 |
> |
#define ourroot RootWindow(ourdisplay,ourscreen) |
41 |
|
|
42 |
< |
#define checkinp() while (XPending(ourdisplay) > 0) getevent() |
42 |
> |
#define levptr(etype) ((etype *)¤tevent) |
43 |
|
|
44 |
< |
#define levptr(etype) ((etype *)&thisevent) |
44 |
> |
static XEvent currentevent; /* current event */ |
45 |
|
|
50 |
– |
static char *clientname; /* calling client's name */ |
51 |
– |
|
52 |
– |
static XEvent thisevent; /* current event */ |
53 |
– |
|
46 |
|
static int ncolors = 0; /* color table size */ |
47 |
< |
static int *pixval = NULL; /* allocated pixels */ |
47 |
> |
static unsigned long *pixval = NULL; /* allocated pixels */ |
48 |
> |
static unsigned long ourblack=0, ourwhite=1; |
49 |
|
|
50 |
|
static Display *ourdisplay = NULL; /* our display */ |
51 |
|
|
52 |
+ |
static XVisualInfo ourvinfo; /* our visual information */ |
53 |
+ |
|
54 |
|
static Window gwind = 0; /* our graphics window */ |
55 |
|
|
56 |
|
static Cursor pickcursor = 0; /* cursor used for picking */ |
57 |
|
|
58 |
< |
static int gwidth = 0; /* graphics window width */ |
64 |
< |
static int gheight = 0; /* graphics window height */ |
58 |
> |
static int gwidth, gheight; /* graphics window size */ |
59 |
|
|
60 |
|
static TEXTWIND *comline = NULL; /* our command line */ |
61 |
|
|
65 |
|
|
66 |
|
static GC ourgc = 0; /* our graphics context for drawing */ |
67 |
|
|
68 |
< |
static Colormap ourmap; /* our color map */ |
68 |
> |
static Colormap ourmap = 0; /* our color map */ |
69 |
|
|
70 |
< |
extern char *malloc(); |
70 |
> |
extern char *malloc(), *getcombuf(); |
71 |
|
|
72 |
< |
int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
73 |
< |
x11_getcur(), x11_comout(), x11_comin(); |
72 |
> |
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
73 |
> |
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
74 |
|
|
75 |
|
static struct driver x11_driver = { |
76 |
|
x11_close, x11_clear, x11_paintr, x11_getcur, |
77 |
< |
x11_comout, x11_comin, |
84 |
< |
MAXRES, MAXRES |
77 |
> |
x11_comout, x11_comin, x11_flush, 1.0 |
78 |
|
}; |
79 |
|
|
80 |
|
|
82 |
|
x11_init(name, id) /* initialize driver */ |
83 |
|
char *name, *id; |
84 |
|
{ |
85 |
< |
Pixmap bmCursorSrc, bmCursorMsk; |
85 |
> |
int nplanes; |
86 |
> |
XSetWindowAttributes ourwinattr; |
87 |
> |
XWMHints ourxwmhints; |
88 |
> |
XSizeHints oursizhints; |
89 |
|
|
90 |
|
ourdisplay = XOpenDisplay(NULL); |
91 |
|
if (ourdisplay == NULL) { |
92 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
93 |
|
return(NULL); |
94 |
|
} |
95 |
< |
if (DisplayPlanes(ourdisplay, DefaultScreen(ourdisplay)) < 4) { |
96 |
< |
stderr_v("not enough colors\n"); |
95 |
> |
/* find a usable visual */ |
96 |
> |
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
97 |
> |
if (XMatchVisualInfo(ourdisplay,ourscreen, |
98 |
> |
24,TrueColor,&ourvinfo) || |
99 |
> |
XMatchVisualInfo(ourdisplay,ourscreen, |
100 |
> |
24,DirectColor,&ourvinfo)) { |
101 |
> |
ourblack = 0; |
102 |
> |
ourwhite = ourvinfo.red_mask | |
103 |
> |
ourvinfo.green_mask | |
104 |
> |
ourvinfo.blue_mask ; |
105 |
> |
} else { |
106 |
> |
if (nplanes < 4) { |
107 |
> |
stderr_v("not enough colors\n"); |
108 |
> |
return(NULL); |
109 |
> |
} |
110 |
> |
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
111 |
> |
nplanes,PseudoColor,&ourvinfo) && |
112 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
113 |
> |
nplanes,GrayScale,&ourvinfo)) { |
114 |
> |
stderr_v("unsupported visual type\n"); |
115 |
> |
return(NULL); |
116 |
> |
} |
117 |
> |
ourblack = BlackPixel(ourdisplay,ourscreen); |
118 |
> |
ourwhite = WhitePixel(ourdisplay,ourscreen); |
119 |
> |
} |
120 |
> |
make_gmap(GAMMA); |
121 |
> |
/* open window */ |
122 |
> |
ourwinattr.background_pixel = ourblack; |
123 |
> |
ourwinattr.border_pixel = ourblack; |
124 |
> |
/* this is stupid */ |
125 |
> |
ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, |
126 |
> |
ourvinfo.visual, AllocNone); |
127 |
> |
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
128 |
> |
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
129 |
> |
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
130 |
> |
BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, |
131 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
132 |
> |
if (gwind == 0) { |
133 |
> |
stderr_v("cannot create window\n"); |
134 |
|
return(NULL); |
135 |
|
} |
136 |
< |
ourmap = DefaultColormap(ourdisplay,DefaultScreen(ourdisplay)); |
104 |
< |
make_gmap(GAMMA); /* make color map */ |
105 |
< |
/* |
106 |
< |
bmCursorSrc = XCreateBitmapFromData(ourdisplay, |
107 |
< |
gwind, bcross_bits, |
108 |
< |
bcross_width, bcross_height); |
109 |
< |
bmCursorMsk = XCreateBitmapFromData(ourdisplay, |
110 |
< |
gwind, bcross_mask_bits, |
111 |
< |
bcross_width, bcross_height); |
112 |
< |
|
113 |
< |
pickcursor = XCreatePixmapCursor(ourdisplay, |
114 |
< |
bmCursorSrc, bmCursorMsk, |
115 |
< |
BlackPixel(ourdisplay, |
116 |
< |
DefaultScreen(ourdisplay)), |
117 |
< |
WhitePixel(ourdisplay, |
118 |
< |
DefaultScreen(ourdisplay)), |
119 |
< |
bcross_x_hot, bcross_y_hot); |
120 |
< |
XFreePixmap(ourdisplay, bmCursorSrc); |
121 |
< |
XFreePixmap(ourdisplay, bmCursorMsk); |
122 |
< |
*/ |
136 |
> |
XStoreName(ourdisplay, gwind, id); |
137 |
|
/* create a cursor */ |
138 |
< |
pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); |
139 |
< |
/* new */ |
140 |
< |
clientname = id; |
138 |
> |
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
139 |
> |
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
140 |
> |
ourxwmhints.flags = InputHint|IconPixmapHint; |
141 |
> |
ourxwmhints.input = True; |
142 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
143 |
> |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
144 |
> |
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
145 |
> |
oursizhints.min_width = MINWIDTH; |
146 |
> |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
147 |
> |
oursizhints.flags = PMinSize; |
148 |
> |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
149 |
> |
XSelectInput(ourdisplay, gwind, ExposureMask); |
150 |
> |
XMapWindow(ourdisplay, gwind); |
151 |
> |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
152 |
> |
gwidth = levptr(XExposeEvent)->width; |
153 |
> |
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
154 |
> |
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
155 |
> |
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
156 |
|
x11_driver.inpready = 0; |
157 |
|
cmdvec = x11_comout; /* set error vectors */ |
158 |
|
if (wrnvec != NULL) |
173 |
|
xt_close(comline); |
174 |
|
comline = NULL; |
175 |
|
} |
147 |
– |
if (gwind != 0) { |
148 |
– |
XFreeGC(ourdisplay, ourgc); |
149 |
– |
XDestroyWindow(ourdisplay, gwind); |
150 |
– |
gwind = 0; |
151 |
– |
gwidth = gheight = 0; |
152 |
– |
ourgc = 0; |
153 |
– |
} |
154 |
– |
XFreeCursor(ourdisplay, pickcursor); |
176 |
|
freepixels(); |
177 |
+ |
XFreeGC(ourdisplay, ourgc); |
178 |
+ |
XDestroyWindow(ourdisplay, gwind); |
179 |
+ |
gwind = 0; |
180 |
+ |
ourgc = 0; |
181 |
+ |
XFreeCursor(ourdisplay, pickcursor); |
182 |
|
XCloseDisplay(ourdisplay); |
183 |
|
ourdisplay = NULL; |
184 |
|
} |
188 |
|
x11_clear(xres, yres) /* clear our display */ |
189 |
|
int xres, yres; |
190 |
|
{ |
191 |
< |
XWMHints ourxwmhints; |
192 |
< |
XSetWindowAttributes ourwindowattr; |
193 |
< |
|
194 |
< |
if (xres != gwidth || yres != gheight) { /* change window */ |
195 |
< |
if (comline != NULL) |
196 |
< |
xt_close(comline); |
197 |
< |
if (gwind == 0) { /* new window */ |
198 |
< |
ourwindowattr.backing_store = Always; |
199 |
< |
ourwindowattr.background_pixel = |
174 |
< |
WhitePixel(ourdisplay, DefaultScreen(ourdisplay)); |
175 |
< |
ourwindowattr.border_pixel = |
176 |
< |
BlackPixel(ourdisplay, DefaultScreen(ourdisplay)); |
177 |
< |
gwind = XCreateWindow(ourdisplay, |
178 |
< |
RootWindow(ourdisplay, |
179 |
< |
DefaultScreen(ourdisplay)), |
180 |
< |
0, 0, xres, yres+COMHEIGHT, BORWIDTH, |
181 |
< |
0, InputOutput, CopyFromParent, |
182 |
< |
CWBackingStore|CWBackPixel|CWBorderPixel, |
183 |
< |
&ourwindowattr); |
184 |
< |
if (gwind == 0) |
185 |
< |
goto fail; |
186 |
< |
XStoreName(ourdisplay, gwind, clientname); |
187 |
< |
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
188 |
< |
ourxwmhints.flags = InputHint; |
189 |
< |
ourxwmhints.input = True; |
190 |
< |
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
191 |
< |
XSelectInput(ourdisplay, gwind, |
192 |
< |
KeyPressMask|ButtonPressMask); |
193 |
< |
XMapWindow(ourdisplay, gwind); |
194 |
< |
} else /* resize window */ |
195 |
< |
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
196 |
< |
comline = xt_open(ourdisplay, |
197 |
< |
DefaultGC(ourdisplay,DefaultScreen(ourdisplay)), |
198 |
< |
gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
199 |
< |
if (comline == NULL) |
200 |
< |
goto fail; |
191 |
> |
/* check limits */ |
192 |
> |
if (xres < MINWIDTH) |
193 |
> |
xres = MINWIDTH; |
194 |
> |
if (yres < MINHEIGHT) |
195 |
> |
yres = MINHEIGHT; |
196 |
> |
/* resize window */ |
197 |
> |
if (xres != gwidth || yres != gheight) { |
198 |
> |
XSelectInput(ourdisplay, gwind, 0); |
199 |
> |
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
200 |
|
gwidth = xres; |
201 |
|
gheight = yres; |
202 |
|
XFlush(ourdisplay); |
203 |
< |
sleep(10); |
204 |
< |
} else /* just clear */ |
205 |
< |
XClearWindow(ourdisplay, gwind); |
203 |
> |
sleep(2); /* wait for window manager */ |
204 |
> |
XSync(ourdisplay, 1); /* discard input */ |
205 |
> |
} |
206 |
> |
XClearWindow(ourdisplay, gwind); |
207 |
|
/* reinitialize color table */ |
208 |
< |
if (ncolors == 0 && getpixels() == 0) |
209 |
< |
stderr_v("cannot allocate colors\n"); |
210 |
< |
else |
211 |
< |
new_ctab(ncolors); |
212 |
< |
return; |
213 |
< |
fail: |
214 |
< |
stderr_v("Failure opening window in x11_clear\n"); |
215 |
< |
quit(1); |
208 |
> |
if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) |
209 |
> |
if (getpixels() == 0) |
210 |
> |
stderr_v("cannot allocate colors\n"); |
211 |
> |
else |
212 |
> |
new_ctab(ncolors); |
213 |
> |
/* get new command line */ |
214 |
> |
if (comline != NULL) |
215 |
> |
xt_close(comline); |
216 |
> |
comline = xt_open(ourdisplay, gwind, 0, gheight, |
217 |
> |
gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN); |
218 |
> |
if (comline == NULL) { |
219 |
> |
stderr_v("Cannot open command line window\n"); |
220 |
> |
quit(1); |
221 |
> |
} |
222 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
223 |
> |
/* remove earmuffs */ |
224 |
> |
XSelectInput(ourdisplay, gwind, |
225 |
> |
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
226 |
|
} |
227 |
|
|
228 |
|
|
231 |
|
COLOR col; |
232 |
|
int xmin, ymin, xmax, ymax; |
233 |
|
{ |
224 |
– |
extern long nrays; /* global ray count */ |
234 |
|
extern int xnewcolr(); /* pixel assignment routine */ |
235 |
< |
static long lastflush = 0; /* ray count at last flush */ |
235 |
> |
extern unsigned long true_pixel(); |
236 |
> |
unsigned long pixel; |
237 |
|
|
238 |
< |
if (ncolors > 0) { |
239 |
< |
XSetForeground(ourdisplay, ourgc, |
240 |
< |
pixval[get_pixel(col, xnewcolr)]); |
241 |
< |
XFillRectangle(ourdisplay, gwind, |
242 |
< |
ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); |
243 |
< |
} |
244 |
< |
if (nrays - lastflush >= WFLUSH) { |
245 |
< |
if (ncolors <= 0) /* output necessary for death */ |
246 |
< |
XFillRectangle(ourdisplay, gwind, |
237 |
< |
ourgc, 0, 0, 1 ,1); |
238 |
< |
checkinp(); |
239 |
< |
lastflush = nrays; |
240 |
< |
} |
238 |
> |
if (ncolors > 0) |
239 |
> |
pixel = pixval[get_pixel(col, xnewcolr)]; |
240 |
> |
else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor) |
241 |
> |
pixel = true_pixel(col); |
242 |
> |
else |
243 |
> |
return; |
244 |
> |
XSetForeground(ourdisplay, ourgc, pixel); |
245 |
> |
XFillRectangle(ourdisplay, gwind, |
246 |
> |
ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
static |
251 |
< |
x11_comin(inp) /* read in a command line */ |
246 |
< |
char *inp; |
251 |
> |
x11_flush() /* flush output */ |
252 |
|
{ |
253 |
< |
int x11_getc(), x11_comout(); |
253 |
> |
XNoOp(ourdisplay); |
254 |
> |
while (XPending(ourdisplay) > 0) |
255 |
> |
getevent(); |
256 |
> |
} |
257 |
|
|
258 |
+ |
|
259 |
+ |
static |
260 |
+ |
x11_comin(inp, prompt) /* read in a command line */ |
261 |
+ |
char *inp, *prompt; |
262 |
+ |
{ |
263 |
+ |
extern int x11_getc(); |
264 |
+ |
|
265 |
+ |
if (prompt != NULL) |
266 |
+ |
if (fromcombuf(inp, &x11_driver)) |
267 |
+ |
return; |
268 |
+ |
else |
269 |
+ |
xt_puts(prompt, comline); |
270 |
|
xt_cursor(comline, TBLKCURS); |
271 |
|
editline(inp, x11_getc, x11_comout); |
272 |
|
xt_cursor(comline, TNOCURS); |
277 |
|
x11_comout(out) /* output a string to command line */ |
278 |
|
char *out; |
279 |
|
{ |
280 |
< |
if (comline != NULL) |
281 |
< |
xt_puts(out, comline); |
282 |
< |
XFlush(ourdisplay); |
280 |
> |
if (comline == NULL) |
281 |
> |
return; |
282 |
> |
xt_puts(out, comline); |
283 |
> |
if (out[strlen(out)-1] == '\n') |
284 |
> |
XFlush(ourdisplay); |
285 |
|
} |
286 |
|
|
287 |
|
|
289 |
|
x11_errout(msg) /* output an error message */ |
290 |
|
char *msg; |
291 |
|
{ |
270 |
– |
x11_comout(msg); |
292 |
|
stderr_v(msg); /* send to stderr also! */ |
293 |
+ |
x11_comout(msg); |
294 |
|
} |
295 |
|
|
296 |
|
|
345 |
|
static int |
346 |
|
getpixels() /* get the color map */ |
347 |
|
{ |
348 |
< |
Visual *ourvis = DefaultVisual(ourdisplay,DefaultScreen(ourdisplay)); |
348 |
> |
XColor thiscolor; |
349 |
> |
register int i, j; |
350 |
|
|
351 |
< |
freepixels(); |
352 |
< |
for (ncolors=(ourvis->map_entries)-3; ncolors>12; ncolors=ncolors*.937){ |
353 |
< |
pixval = (int *)malloc(ncolors*sizeof(int)); |
351 |
> |
if (ncolors > 0) |
352 |
> |
return(ncolors); |
353 |
> |
if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) { |
354 |
> |
ourmap = DefaultColormap(ourdisplay,ourscreen); |
355 |
> |
goto loop; |
356 |
> |
} |
357 |
> |
newmap: |
358 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone); |
359 |
> |
loop: |
360 |
> |
for (ncolors = ourvinfo.colormap_size; |
361 |
> |
ncolors > ourvinfo.colormap_size/3; |
362 |
> |
ncolors = ncolors*.937) { |
363 |
> |
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
364 |
|
if (pixval == NULL) |
365 |
< |
break; |
365 |
> |
return(ncolors = 0); |
366 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
367 |
|
pixval,ncolors) != 0) |
368 |
< |
return(ncolors); |
368 |
> |
break; |
369 |
|
free((char *)pixval); |
370 |
+ |
pixval = NULL; |
371 |
|
} |
372 |
< |
return(ncolors = 0); |
372 |
> |
if (pixval == NULL) { |
373 |
> |
if (ourmap == DefaultColormap(ourdisplay,ourscreen)) |
374 |
> |
goto newmap; /* try it with our map */ |
375 |
> |
else |
376 |
> |
return(ncolors = 0); /* failed */ |
377 |
> |
} |
378 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
379 |
> |
for (i = 0; i < ncolors; i++) { /* reset black and white */ |
380 |
> |
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
381 |
> |
continue; |
382 |
> |
thiscolor.pixel = pixval[i]; |
383 |
> |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
384 |
> |
XQueryColor(ourdisplay, |
385 |
> |
DefaultColormap(ourdisplay,ourscreen), |
386 |
> |
&thiscolor); |
387 |
> |
XStoreColor(ourdisplay, ourmap, &thiscolor); |
388 |
> |
for (j = i; j+1 < ncolors; j++) |
389 |
> |
pixval[j] = pixval[j+1]; |
390 |
> |
ncolors--; |
391 |
> |
i--; |
392 |
> |
} |
393 |
> |
XSetWindowColormap(ourdisplay, gwind, ourmap); |
394 |
> |
return(ncolors); |
395 |
|
} |
396 |
|
|
397 |
|
|
402 |
|
return; |
403 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
404 |
|
ncolors = 0; |
405 |
+ |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
406 |
+ |
XFreeColormap(ourdisplay, ourmap); |
407 |
+ |
ourmap = 0; |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
+ |
static unsigned long |
412 |
+ |
true_pixel(col) /* return true pixel value for color */ |
413 |
+ |
COLOR col; |
414 |
+ |
{ |
415 |
+ |
unsigned long rval; |
416 |
+ |
BYTE rgb[3]; |
417 |
+ |
|
418 |
+ |
map_color(rgb, col); |
419 |
+ |
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
420 |
+ |
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
421 |
+ |
rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask; |
422 |
+ |
return(rval); |
423 |
+ |
} |
424 |
+ |
|
425 |
+ |
|
426 |
|
static int |
427 |
|
x11_getc() /* get a command character */ |
428 |
|
{ |
440 |
|
{ |
441 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
442 |
|
switch (levptr(XEvent)->type) { |
443 |
+ |
case ConfigureNotify: |
444 |
+ |
resizewindow(levptr(XConfigureEvent)); |
445 |
+ |
break; |
446 |
+ |
case UnmapNotify: |
447 |
+ |
freepixels(); |
448 |
+ |
break; |
449 |
+ |
case MapNotify: |
450 |
+ |
if (ourvinfo.class == PseudoColor || |
451 |
+ |
ourvinfo.class == GrayScale) |
452 |
+ |
if (getpixels() == 0) |
453 |
+ |
stderr_v("Cannot allocate colors\n"); |
454 |
+ |
else |
455 |
+ |
new_ctab(ncolors); |
456 |
+ |
break; |
457 |
+ |
case Expose: |
458 |
+ |
fixwindow(levptr(XExposeEvent)); |
459 |
+ |
break; |
460 |
|
case KeyPress: |
461 |
|
getkey(levptr(XKeyPressedEvent)); |
462 |
|
break; |
470 |
|
getkey(ekey) /* get input key */ |
471 |
|
register XKeyPressedEvent *ekey; |
472 |
|
{ |
473 |
< |
c_last += XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, |
473 |
> |
register int n; |
474 |
> |
|
475 |
> |
n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, |
476 |
|
NULL, NULL); |
477 |
< |
x11_driver.inpready = c_last-c_first; |
477 |
> |
c_last += n; |
478 |
> |
x11_driver.inpready += n; |
479 |
|
} |
480 |
|
|
481 |
|
|
388 |
– |
#ifdef notdef |
482 |
|
static |
483 |
|
fixwindow(eexp) /* repair damage to window */ |
484 |
|
register XExposeEvent *eexp; |
485 |
|
{ |
486 |
< |
if (eexp->subwindow == 0) |
487 |
< |
repaint(eexp->x, gheight - eexp->y - eexp->height, |
486 |
> |
if (eexp->window == gwind) { |
487 |
> |
sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n", |
488 |
> |
eexp->x, gheight - eexp->y - eexp->height, |
489 |
|
eexp->x + eexp->width, gheight - eexp->y); |
490 |
< |
else if (eexp->subwindow == comline->w) |
491 |
< |
xt_redraw(comline); |
490 |
> |
} else if (eexp->window == comline->w) { |
491 |
> |
if (eexp->count == 0) |
492 |
> |
xt_redraw(comline); |
493 |
> |
} |
494 |
|
} |
495 |
< |
#endif |
495 |
> |
|
496 |
> |
|
497 |
> |
static |
498 |
> |
resizewindow(ersz) /* resize window */ |
499 |
> |
register XConfigureEvent *ersz; |
500 |
> |
{ |
501 |
> |
if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight) |
502 |
> |
return; |
503 |
> |
|
504 |
> |
gwidth = ersz->width; |
505 |
> |
gheight = ersz->height-COMHEIGHT; |
506 |
> |
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
507 |
> |
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
508 |
> |
|
509 |
> |
strcpy(getcombuf(&x11_driver), "new\n"); |
510 |
> |
} |