| 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> |
| 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" |
| 24 |
|
|
| 25 |
|
#define GAMMA 2.2 /* exponent for color correction */ |
| 26 |
|
|
| 27 |
+ |
#define MINWIDTH (32*COMCW) /* minimum graphics window width */ |
| 28 |
+ |
#define MINHEIGHT MINWIDTH /* minimum graphics window height */ |
| 29 |
+ |
|
| 30 |
|
#define BORWIDTH 5 /* border width */ |
| 31 |
|
#define COMHEIGHT (COMLH*COMCH) /* command line height (pixels) */ |
| 32 |
|
|
| 35 |
|
#define COMCW 8 /* approx. character width (pixels) */ |
| 36 |
|
#define COMCH 14 /* approx. character height (pixels) */ |
| 37 |
|
|
| 38 |
< |
#ifndef WFLUSH |
| 39 |
< |
#define WFLUSH 30 /* flush after this many rays */ |
| 40 |
< |
#endif |
| 38 |
> |
#define ourscreen DefaultScreen(ourdisplay) |
| 39 |
> |
#define ourroot RootWindow(ourdisplay,ourscreen) |
| 40 |
> |
#define ourwhite WhitePixel(ourdisplay,ourscreen) |
| 41 |
> |
#define ourblack BlackPixel(ourdisplay,ourscreen) |
| 42 |
|
|
| 43 |
< |
#define checkinp() while (XPending(ourdisplay) > 0) getevent() |
| 43 |
> |
#define levptr(etype) ((etype *)¤tevent) |
| 44 |
|
|
| 45 |
< |
#define levptr(etype) ((etype *)&thisevent) |
| 45 |
> |
static XEvent currentevent; /* current event */ |
| 46 |
|
|
| 43 |
– |
static char *clientname; /* calling client's name */ |
| 44 |
– |
|
| 45 |
– |
static XEvent thisevent; /* current event */ |
| 46 |
– |
|
| 47 |
|
static int ncolors = 0; /* color table size */ |
| 48 |
|
static int *pixval = NULL; /* allocated pixels */ |
| 49 |
|
|
| 50 |
|
static Display *ourdisplay = NULL; /* our display */ |
| 51 |
|
|
| 52 |
+ |
static Visual *ourvisual; /* our visual structure */ |
| 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 */ |
| 57 |
< |
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, 1.0 |
| 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 |
> |
XVisualInfo ourvinfo; |
| 87 |
> |
XSetWindowAttributes ourwinattr; |
| 88 |
> |
XWMHints ourxwmhints; |
| 89 |
> |
XSizeHints oursizhints; |
| 90 |
|
|
| 91 |
|
ourdisplay = XOpenDisplay(NULL); |
| 92 |
|
if (ourdisplay == NULL) { |
| 93 |
|
stderr_v("cannot open X-windows; DISPLAY variable set?\n"); |
| 94 |
|
return(NULL); |
| 95 |
|
} |
| 96 |
< |
if (DisplayPlanes(ourdisplay, DefaultScreen(ourdisplay)) < 4) { |
| 96 |
> |
nplanes = DisplayPlanes(ourdisplay, ourscreen); |
| 97 |
> |
if (nplanes < 4) { |
| 98 |
|
stderr_v("not enough colors\n"); |
| 99 |
|
return(NULL); |
| 100 |
+ |
} else if (nplanes <= 12) { |
| 101 |
+ |
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 102 |
+ |
nplanes,PseudoColor,&ourvinfo)) { |
| 103 |
+ |
stderr_v("PseudoColor server required\n"); |
| 104 |
+ |
return(NULL); |
| 105 |
+ |
} |
| 106 |
+ |
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 107 |
+ |
nplanes,TrueColor,&ourvinfo) && |
| 108 |
+ |
/* kludge for DirectColor */ |
| 109 |
+ |
!XMatchVisualInfo(ourdisplay,ourscreen, |
| 110 |
+ |
nplanes,DirectColor,&ourvinfo)) { |
| 111 |
+ |
stderr_v("TrueColor server required\n"); |
| 112 |
+ |
return(NULL); |
| 113 |
|
} |
| 114 |
< |
ourmap = DefaultColormap(ourdisplay,DefaultScreen(ourdisplay)); |
| 115 |
< |
make_gmap(GAMMA); /* make color map */ |
| 116 |
< |
/* |
| 117 |
< |
bmCursorSrc = XCreateBitmapFromData(ourdisplay, |
| 118 |
< |
gwind, bcross_bits, |
| 119 |
< |
bcross_width, bcross_height); |
| 120 |
< |
bmCursorMsk = XCreateBitmapFromData(ourdisplay, |
| 121 |
< |
gwind, bcross_mask_bits, |
| 122 |
< |
bcross_width, bcross_height); |
| 123 |
< |
|
| 124 |
< |
pickcursor = XCreatePixmapCursor(ourdisplay, |
| 125 |
< |
bmCursorSrc, bmCursorMsk, |
| 126 |
< |
BlackPixel(ourdisplay, |
| 127 |
< |
DefaultScreen(ourdisplay)), |
| 128 |
< |
WhitePixel(ourdisplay, |
| 110 |
< |
DefaultScreen(ourdisplay)), |
| 111 |
< |
bcross_x_hot, bcross_y_hot); |
| 112 |
< |
XFreePixmap(ourdisplay, bmCursorSrc); |
| 113 |
< |
XFreePixmap(ourdisplay, bmCursorMsk); |
| 114 |
< |
*/ |
| 114 |
> |
ourvisual = ourvinfo.visual; |
| 115 |
> |
make_gmap(GAMMA); |
| 116 |
> |
/* open window */ |
| 117 |
> |
ourwinattr.background_pixel = ourblack; |
| 118 |
> |
ourwinattr.border_pixel = ourblack; |
| 119 |
> |
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
| 120 |
> |
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
| 121 |
> |
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
| 122 |
> |
BORWIDTH, nplanes, InputOutput, ourvisual, |
| 123 |
> |
CWBackPixel|CWBorderPixel, &ourwinattr); |
| 124 |
> |
if (gwind == 0) { |
| 125 |
> |
stderr_v("cannot create window\n"); |
| 126 |
> |
return(NULL); |
| 127 |
> |
} |
| 128 |
> |
XStoreName(ourdisplay, gwind, id); |
| 129 |
|
/* create a cursor */ |
| 130 |
< |
pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); |
| 131 |
< |
/* new */ |
| 132 |
< |
clientname = id; |
| 133 |
< |
x11_driver.xsiz = DisplayWidth(ourdisplay,DefaultScreen(ourdisplay)) |
| 134 |
< |
- 2*BORWIDTH; |
| 135 |
< |
x11_driver.ysiz = DisplayHeight(ourdisplay,DefaultScreen(ourdisplay)) |
| 136 |
< |
- (COMHEIGHT + 2*BORWIDTH); |
| 130 |
> |
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
| 131 |
> |
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
| 132 |
> |
ourxwmhints.flags = InputHint; |
| 133 |
> |
ourxwmhints.input = True; |
| 134 |
> |
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 135 |
> |
oursizhints.min_width = MINWIDTH; |
| 136 |
> |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
| 137 |
> |
oursizhints.flags = PMinSize; |
| 138 |
> |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 139 |
> |
XSelectInput(ourdisplay, gwind, ExposureMask); |
| 140 |
> |
XMapWindow(ourdisplay, gwind); |
| 141 |
> |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); |
| 142 |
> |
gwidth = levptr(XExposeEvent)->width; |
| 143 |
> |
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
| 144 |
> |
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 145 |
> |
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
| 146 |
|
x11_driver.inpready = 0; |
| 147 |
|
cmdvec = x11_comout; /* set error vectors */ |
| 148 |
|
if (wrnvec != NULL) |
| 163 |
|
xt_close(comline); |
| 164 |
|
comline = NULL; |
| 165 |
|
} |
| 143 |
– |
if (gwind != 0) { |
| 144 |
– |
XFreeGC(ourdisplay, ourgc); |
| 145 |
– |
XDestroyWindow(ourdisplay, gwind); |
| 146 |
– |
gwind = 0; |
| 147 |
– |
gwidth = gheight = 0; |
| 148 |
– |
ourgc = 0; |
| 149 |
– |
} |
| 150 |
– |
XFreeCursor(ourdisplay, pickcursor); |
| 166 |
|
freepixels(); |
| 167 |
+ |
XFreeGC(ourdisplay, ourgc); |
| 168 |
+ |
XDestroyWindow(ourdisplay, gwind); |
| 169 |
+ |
gwind = 0; |
| 170 |
+ |
ourgc = 0; |
| 171 |
+ |
XFreeCursor(ourdisplay, pickcursor); |
| 172 |
|
XCloseDisplay(ourdisplay); |
| 173 |
|
ourdisplay = NULL; |
| 174 |
|
} |
| 178 |
|
x11_clear(xres, yres) /* clear our display */ |
| 179 |
|
int xres, yres; |
| 180 |
|
{ |
| 181 |
< |
XWMHints ourxwmhints; |
| 182 |
< |
XSetWindowAttributes ourwindowattr; |
| 183 |
< |
|
| 184 |
< |
if (xres != gwidth || yres != gheight) { /* change window */ |
| 185 |
< |
if (comline != NULL) |
| 186 |
< |
xt_close(comline); |
| 187 |
< |
if (gwind == 0) { /* new window */ |
| 188 |
< |
ourwindowattr.backing_store = Always; |
| 189 |
< |
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); |
| 192 |
< |
comline = xt_open(ourdisplay, |
| 193 |
< |
DefaultGC(ourdisplay,DefaultScreen(ourdisplay)), |
| 194 |
< |
gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
| 195 |
< |
if (comline == NULL) |
| 196 |
< |
goto fail; |
| 181 |
> |
/* check limits */ |
| 182 |
> |
if (xres < MINWIDTH) |
| 183 |
> |
xres = MINWIDTH; |
| 184 |
> |
if (yres < MINHEIGHT) |
| 185 |
> |
yres = MINHEIGHT; |
| 186 |
> |
/* resize window */ |
| 187 |
> |
if (xres != gwidth || yres != gheight) { |
| 188 |
> |
XSelectInput(ourdisplay, gwind, 0); |
| 189 |
> |
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
| 190 |
|
gwidth = xres; |
| 191 |
|
gheight = yres; |
| 192 |
< |
} else /* just clear */ |
| 193 |
< |
XClearWindow(ourdisplay, gwind); |
| 192 |
> |
XFlush(ourdisplay); |
| 193 |
> |
sleep(2); /* wait for window manager */ |
| 194 |
> |
XSync(ourdisplay, 1); /* discard input */ |
| 195 |
> |
} |
| 196 |
> |
XClearWindow(ourdisplay, gwind); |
| 197 |
|
/* reinitialize color table */ |
| 198 |
< |
if (ncolors == 0 && getpixels() == 0) |
| 199 |
< |
stderr_v("cannot allocate colors\n"); |
| 200 |
< |
else |
| 201 |
< |
new_ctab(ncolors); |
| 202 |
< |
return; |
| 203 |
< |
fail: |
| 204 |
< |
stderr_v("Failure opening window in x11_clear\n"); |
| 205 |
< |
quit(1); |
| 198 |
> |
if (ourvisual->class == PseudoColor) |
| 199 |
> |
if (getpixels() == 0) |
| 200 |
> |
stderr_v("cannot allocate colors\n"); |
| 201 |
> |
else |
| 202 |
> |
new_ctab(ncolors); |
| 203 |
> |
/* get new command line */ |
| 204 |
> |
if (comline != NULL) |
| 205 |
> |
xt_close(comline); |
| 206 |
> |
comline = xt_open(ourdisplay, |
| 207 |
> |
DefaultGC(ourdisplay,ourscreen), |
| 208 |
> |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
| 209 |
> |
if (comline == NULL) { |
| 210 |
> |
stderr_v("Cannot open command line window\n"); |
| 211 |
> |
quit(1); |
| 212 |
> |
} |
| 213 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
| 214 |
> |
/* remove earmuffs */ |
| 215 |
> |
XSelectInput(ourdisplay, gwind, |
| 216 |
> |
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 222 |
|
COLOR col; |
| 223 |
|
int xmin, ymin, xmax, ymax; |
| 224 |
|
{ |
| 218 |
– |
extern long nrays; /* global ray count */ |
| 225 |
|
extern int xnewcolr(); /* pixel assignment routine */ |
| 226 |
< |
static long lastflush = 0; /* ray count at last flush */ |
| 226 |
> |
extern unsigned long true_pixel(); |
| 227 |
> |
unsigned long pixel; |
| 228 |
|
|
| 229 |
< |
if (ncolors > 0) { |
| 230 |
< |
XSetForeground(ourdisplay, ourgc, |
| 231 |
< |
pixval[get_pixel(col, xnewcolr)]); |
| 232 |
< |
XFillRectangle(ourdisplay, gwind, |
| 233 |
< |
ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); |
| 234 |
< |
} |
| 235 |
< |
if (nrays - lastflush >= WFLUSH) { |
| 236 |
< |
if (ncolors <= 0) /* output necessary for death */ |
| 237 |
< |
XFillRectangle(ourdisplay, gwind, |
| 231 |
< |
ourgc, 0, 0, 1 ,1); |
| 232 |
< |
checkinp(); |
| 233 |
< |
lastflush = nrays; |
| 234 |
< |
} |
| 229 |
> |
if (ncolors > 0) |
| 230 |
> |
pixel = pixval[get_pixel(col, xnewcolr)]; |
| 231 |
> |
else if (ourvisual->class != PseudoColor) |
| 232 |
> |
pixel = true_pixel(col); |
| 233 |
> |
else |
| 234 |
> |
return; |
| 235 |
> |
XSetForeground(ourdisplay, ourgc, pixel); |
| 236 |
> |
XFillRectangle(ourdisplay, gwind, |
| 237 |
> |
ourgc, xmin, gheight-ymax, xmax-xmin, ymax-ymin); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
static |
| 242 |
< |
x11_comin(inp) /* read in a command line */ |
| 240 |
< |
char *inp; |
| 242 |
> |
x11_flush() /* flush output */ |
| 243 |
|
{ |
| 244 |
< |
int x11_getc(), x11_comout(); |
| 244 |
> |
XNoOp(ourdisplay); |
| 245 |
> |
while (XPending(ourdisplay) > 0) |
| 246 |
> |
getevent(); |
| 247 |
> |
} |
| 248 |
|
|
| 249 |
+ |
|
| 250 |
+ |
static |
| 251 |
+ |
x11_comin(inp, prompt) /* read in a command line */ |
| 252 |
+ |
char *inp, *prompt; |
| 253 |
+ |
{ |
| 254 |
+ |
extern int x11_getc(); |
| 255 |
+ |
|
| 256 |
+ |
if (prompt != NULL) |
| 257 |
+ |
if (fromcombuf(inp, &x11_driver)) |
| 258 |
+ |
return; |
| 259 |
+ |
else |
| 260 |
+ |
xt_puts(prompt, comline); |
| 261 |
|
xt_cursor(comline, TBLKCURS); |
| 262 |
|
editline(inp, x11_getc, x11_comout); |
| 263 |
|
xt_cursor(comline, TNOCURS); |
| 268 |
|
x11_comout(out) /* output a string to command line */ |
| 269 |
|
char *out; |
| 270 |
|
{ |
| 271 |
< |
if (comline != NULL) |
| 272 |
< |
xt_puts(out, comline); |
| 273 |
< |
XFlush(ourdisplay); |
| 271 |
> |
if (comline == NULL) |
| 272 |
> |
return; |
| 273 |
> |
xt_puts(out, comline); |
| 274 |
> |
if (out[strlen(out)-1] == '\n') |
| 275 |
> |
XFlush(ourdisplay); |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
|
| 280 |
|
x11_errout(msg) /* output an error message */ |
| 281 |
|
char *msg; |
| 282 |
|
{ |
| 264 |
– |
x11_comout(msg); |
| 283 |
|
stderr_v(msg); /* send to stderr also! */ |
| 284 |
+ |
x11_comout(msg); |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 336 |
|
static int |
| 337 |
|
getpixels() /* get the color map */ |
| 338 |
|
{ |
| 339 |
< |
Visual *ourvis = DefaultVisual(ourdisplay,DefaultScreen(ourdisplay)); |
| 340 |
< |
|
| 341 |
< |
freepixels(); |
| 342 |
< |
for (ncolors=(ourvis->map_entries)-3; ncolors>12; ncolors=ncolors*.937){ |
| 339 |
> |
if (ncolors > 0) |
| 340 |
> |
return(ncolors); |
| 341 |
> |
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
| 342 |
> |
ourmap = DefaultColormap(ourdisplay,ourscreen); |
| 343 |
> |
goto loop; |
| 344 |
> |
} |
| 345 |
> |
newmap: |
| 346 |
> |
ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone); |
| 347 |
> |
loop: |
| 348 |
> |
for (ncolors = ourvisual->map_entries; |
| 349 |
> |
ncolors > ourvisual->map_entries/3; |
| 350 |
> |
ncolors = ncolors*.937) { |
| 351 |
|
pixval = (int *)malloc(ncolors*sizeof(int)); |
| 352 |
|
if (pixval == NULL) |
| 353 |
< |
break; |
| 353 |
> |
return(ncolors = 0); |
| 354 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
| 355 |
|
pixval,ncolors) != 0) |
| 356 |
< |
return(ncolors); |
| 356 |
> |
break; |
| 357 |
|
free((char *)pixval); |
| 358 |
+ |
pixval = NULL; |
| 359 |
|
} |
| 360 |
< |
return(ncolors = 0); |
| 360 |
> |
if (pixval == NULL) { |
| 361 |
> |
if (ourmap == DefaultColormap(ourdisplay,ourscreen)) |
| 362 |
> |
goto newmap; /* try it with our map */ |
| 363 |
> |
else |
| 364 |
> |
return(ncolors = 0); /* failed */ |
| 365 |
> |
} |
| 366 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { |
| 367 |
> |
XColor thiscolor; |
| 368 |
> |
register int i, j; |
| 369 |
> |
/* reset black and white */ |
| 370 |
> |
for (i = 0; i < ncolors; i++) { |
| 371 |
> |
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
| 372 |
> |
continue; |
| 373 |
> |
thiscolor.pixel = pixval[i]; |
| 374 |
> |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
| 375 |
> |
XQueryColor(ourdisplay, |
| 376 |
> |
DefaultColormap(ourdisplay,ourscreen), |
| 377 |
> |
&thiscolor); |
| 378 |
> |
XStoreColor(ourdisplay, ourmap, &thiscolor); |
| 379 |
> |
for (j = i; j+1 < ncolors; j++) |
| 380 |
> |
pixval[j] = pixval[j+1]; |
| 381 |
> |
ncolors--; |
| 382 |
> |
i--; |
| 383 |
> |
} |
| 384 |
> |
} |
| 385 |
> |
XSetWindowColormap(ourdisplay, gwind, ourmap); |
| 386 |
> |
return(ncolors); |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
|
| 394 |
|
return; |
| 395 |
|
XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); |
| 396 |
|
ncolors = 0; |
| 397 |
+ |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
| 398 |
+ |
XFreeColormap(ourdisplay, ourmap); |
| 399 |
+ |
ourmap = 0; |
| 400 |
|
} |
| 401 |
|
|
| 402 |
|
|
| 403 |
+ |
static unsigned long |
| 404 |
+ |
true_pixel(col) /* return true pixel value for color */ |
| 405 |
+ |
COLOR col; |
| 406 |
+ |
{ |
| 407 |
+ |
unsigned long rval; |
| 408 |
+ |
BYTE rgb[3]; |
| 409 |
+ |
|
| 410 |
+ |
map_color(rgb, col); |
| 411 |
+ |
rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask; |
| 412 |
+ |
rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask; |
| 413 |
+ |
rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask; |
| 414 |
+ |
return(rval); |
| 415 |
+ |
} |
| 416 |
+ |
|
| 417 |
+ |
|
| 418 |
|
static int |
| 419 |
|
x11_getc() /* get a command character */ |
| 420 |
|
{ |
| 432 |
|
{ |
| 433 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
| 434 |
|
switch (levptr(XEvent)->type) { |
| 435 |
+ |
case ConfigureNotify: |
| 436 |
+ |
resizewindow(levptr(XConfigureEvent)); |
| 437 |
+ |
break; |
| 438 |
+ |
case UnmapNotify: |
| 439 |
+ |
freepixels(); |
| 440 |
+ |
break; |
| 441 |
+ |
case MapNotify: |
| 442 |
+ |
if (ourvisual->class == PseudoColor) |
| 443 |
+ |
if (getpixels() == 0) |
| 444 |
+ |
stderr_v("Cannot allocate colors\n"); |
| 445 |
+ |
else |
| 446 |
+ |
new_ctab(ncolors); |
| 447 |
+ |
break; |
| 448 |
+ |
case Expose: |
| 449 |
+ |
fixwindow(levptr(XExposeEvent)); |
| 450 |
+ |
break; |
| 451 |
|
case KeyPress: |
| 452 |
|
getkey(levptr(XKeyPressedEvent)); |
| 453 |
|
break; |
| 461 |
|
getkey(ekey) /* get input key */ |
| 462 |
|
register XKeyPressedEvent *ekey; |
| 463 |
|
{ |
| 464 |
< |
c_last += XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, |
| 464 |
> |
register int n; |
| 465 |
> |
|
| 466 |
> |
n = XLookupString(ekey, c_queue+c_last, sizeof(c_queue)-c_last, |
| 467 |
|
NULL, NULL); |
| 468 |
< |
x11_driver.inpready = c_last-c_first; |
| 468 |
> |
c_last += n; |
| 469 |
> |
x11_driver.inpready += n; |
| 470 |
|
} |
| 471 |
|
|
| 472 |
|
|
| 382 |
– |
#ifdef notdef |
| 473 |
|
static |
| 474 |
|
fixwindow(eexp) /* repair damage to window */ |
| 475 |
|
register XExposeEvent *eexp; |
| 476 |
|
{ |
| 477 |
< |
if (eexp->subwindow == 0) |
| 478 |
< |
repaint(eexp->x, gheight - eexp->y - eexp->height, |
| 477 |
> |
if (eexp->window == gwind) { |
| 478 |
> |
sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n", |
| 479 |
> |
eexp->x, gheight - eexp->y - eexp->height, |
| 480 |
|
eexp->x + eexp->width, gheight - eexp->y); |
| 481 |
< |
else if (eexp->subwindow == comline->w) |
| 482 |
< |
xt_redraw(comline); |
| 481 |
> |
} else if (eexp->window == comline->w) { |
| 482 |
> |
if (eexp->count == 0) |
| 483 |
> |
xt_redraw(comline); |
| 484 |
> |
} |
| 485 |
|
} |
| 486 |
< |
#endif |
| 486 |
> |
|
| 487 |
> |
|
| 488 |
> |
static |
| 489 |
> |
resizewindow(ersz) /* resize window */ |
| 490 |
> |
register XConfigureEvent *ersz; |
| 491 |
> |
{ |
| 492 |
> |
if (ersz->width == gwidth && ersz->height-COMHEIGHT == gheight) |
| 493 |
> |
return; |
| 494 |
> |
|
| 495 |
> |
gwidth = ersz->width; |
| 496 |
> |
gheight = ersz->height-COMHEIGHT; |
| 497 |
> |
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 498 |
> |
x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; |
| 499 |
> |
|
| 500 |
> |
strcpy(getcombuf(&x11_driver), "new\n"); |
| 501 |
> |
} |