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.3 |
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 |
|
|
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 */ |
34 |
– |
#define BARHEIGHT 25 /* menu bar size */ |
31 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
32 |
|
|
33 |
|
#define COMFN "8x13" /* command line font name */ |
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 *)¤tevent) |
50 |
|
|
51 |
< |
static char *clientname; /* calling client's name */ |
51 |
> |
static XEvent currentevent; /* current event */ |
52 |
|
|
52 |
– |
static XEvent thisevent; /* current event */ |
53 |
– |
|
53 |
|
static int ncolors = 0; /* color table size */ |
54 |
|
static int *pixval = NULL; /* allocated pixels */ |
55 |
|
|
59 |
|
|
60 |
|
static Cursor pickcursor = 0; /* cursor used for picking */ |
61 |
|
|
62 |
< |
static int gwidth = 0; /* graphics window width */ |
64 |
< |
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 |
|
|
78 |
|
|
79 |
|
static struct driver x11_driver = { |
80 |
|
x11_close, x11_clear, x11_paintr, x11_getcur, |
81 |
< |
x11_comout, x11_comin, |
84 |
< |
MAXRES, MAXRES |
81 |
> |
x11_comout, x11_comin, 1.0 |
82 |
|
}; |
83 |
|
|
84 |
|
|
86 |
|
x11_init(name, id) /* initialize driver */ |
87 |
|
char *name, *id; |
88 |
|
{ |
89 |
+ |
XWMHints ourxwmhints; |
90 |
|
Pixmap bmCursorSrc, bmCursorMsk; |
91 |
|
|
92 |
|
ourdisplay = XOpenDisplay(NULL); |
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 */ |
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 |
– |
*/ |
103 |
|
/* create a cursor */ |
104 |
|
pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); |
105 |
< |
/* new */ |
106 |
< |
clientname = id; |
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) |
147 |
|
XFreeGC(ourdisplay, ourgc); |
148 |
|
XDestroyWindow(ourdisplay, gwind); |
149 |
|
gwind = 0; |
151 |
– |
gwidth = gheight = 0; |
150 |
|
ourgc = 0; |
151 |
|
} |
152 |
|
XFreeCursor(ourdisplay, pickcursor); |
160 |
|
x11_clear(xres, yres) /* clear our display */ |
161 |
|
int xres, yres; |
162 |
|
{ |
165 |
– |
XWMHints ourxwmhints; |
166 |
– |
XSetWindowAttributes ourwindowattr; |
167 |
– |
|
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; |
173 |
< |
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); |
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 |
< |
XFlush(ourdisplay); |
179 |
< |
sleep(10); |
180 |
< |
} else /* just clear */ |
181 |
< |
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"); |
215 |
< |
quit(1); |
187 |
> |
|
188 |
> |
XSelectInput(ourdisplay, gwind, |
189 |
> |
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
190 |
|
} |
191 |
|
|
192 |
|
|
216 |
|
|
217 |
|
|
218 |
|
static |
219 |
< |
x11_comin(inp) /* read in a command line */ |
220 |
< |
char *inp; |
219 |
> |
x11_comin(inp, prompt) /* read in a command line */ |
220 |
> |
char *inp, *prompt; |
221 |
|
{ |
222 |
|
int x11_getc(), x11_comout(); |
223 |
|
|
224 |
+ |
if (prompt != NULL) |
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); |
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) |
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; |
380 |
|
} |
381 |
|
|
382 |
|
|
388 |
– |
#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 |
> |
} |