| 21 |
|
#include "color.h" |
| 22 |
|
#include "driver.h" |
| 23 |
|
#include "x11twind.h" |
| 24 |
+ |
#include "x11icon.h" |
| 25 |
|
|
| 26 |
|
#define GAMMA 2.2 /* exponent for color correction */ |
| 27 |
|
|
| 46 |
|
static XEvent currentevent; /* current event */ |
| 47 |
|
|
| 48 |
|
static int ncolors = 0; /* color table size */ |
| 49 |
< |
static int *pixval = NULL; /* allocated pixels */ |
| 49 |
> |
static unsigned long *pixval = NULL; /* allocated pixels */ |
| 50 |
|
|
| 51 |
|
static Display *ourdisplay = NULL; /* our display */ |
| 52 |
|
|
| 68 |
|
|
| 69 |
|
static Colormap ourmap = 0; /* our color map */ |
| 70 |
|
|
| 71 |
< |
extern char *malloc(); |
| 71 |
> |
extern char *malloc(), *getcombuf(); |
| 72 |
|
|
| 73 |
< |
int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
| 73 |
> |
static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), |
| 74 |
|
x11_getcur(), x11_comout(), x11_comin(), x11_flush(); |
| 75 |
|
|
| 76 |
|
static struct driver x11_driver = { |
| 85 |
|
{ |
| 86 |
|
int nplanes; |
| 87 |
|
XVisualInfo ourvinfo; |
| 88 |
+ |
XSetWindowAttributes ourwinattr; |
| 89 |
|
XWMHints ourxwmhints; |
| 90 |
+ |
XSizeHints oursizhints; |
| 91 |
|
|
| 92 |
|
ourdisplay = XOpenDisplay(NULL); |
| 93 |
|
if (ourdisplay == NULL) { |
| 101 |
|
} else if (nplanes <= 12) { |
| 102 |
|
if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 103 |
|
nplanes,PseudoColor,&ourvinfo)) { |
| 104 |
< |
stderr_v("PseudoColor not supported\n"); |
| 104 |
> |
stderr_v("PseudoColor server required\n"); |
| 105 |
|
return(NULL); |
| 106 |
|
} |
| 107 |
|
} else if (!XMatchVisualInfo(ourdisplay,ourscreen, |
| 108 |
< |
nplanes,TrueColor,&ourvinfo)) { |
| 109 |
< |
stderr_v("TrueColor not supported\n"); |
| 108 |
> |
nplanes,TrueColor,&ourvinfo) && |
| 109 |
> |
/* kludge for DirectColor */ |
| 110 |
> |
!XMatchVisualInfo(ourdisplay,ourscreen, |
| 111 |
> |
nplanes,DirectColor,&ourvinfo)) { |
| 112 |
> |
stderr_v("TrueColor server required\n"); |
| 113 |
|
return(NULL); |
| 114 |
|
} |
| 115 |
|
ourvisual = ourvinfo.visual; |
| 116 |
|
make_gmap(GAMMA); |
| 111 |
– |
/* create a cursor */ |
| 112 |
– |
pickcursor = XCreateFontCursor (ourdisplay, XC_diamond_cross); |
| 117 |
|
/* open window */ |
| 118 |
< |
gwind = XCreateSimpleWindow(ourdisplay, ourroot, 0, 0, |
| 118 |
> |
ourwinattr.background_pixel = ourblack; |
| 119 |
> |
ourwinattr.border_pixel = ourblack; |
| 120 |
> |
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
| 121 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
| 122 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
| 123 |
< |
BORWIDTH, ourblack, ourwhite); |
| 123 |
> |
BORWIDTH, nplanes, InputOutput, ourvisual, |
| 124 |
> |
CWBackPixel|CWBorderPixel, &ourwinattr); |
| 125 |
|
if (gwind == 0) { |
| 126 |
|
stderr_v("cannot create window\n"); |
| 127 |
|
return(NULL); |
| 128 |
|
} |
| 129 |
|
XStoreName(ourdisplay, gwind, id); |
| 130 |
+ |
/* create a cursor */ |
| 131 |
+ |
pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross); |
| 132 |
|
ourgc = XCreateGC(ourdisplay, gwind, 0, NULL); |
| 133 |
< |
ourxwmhints.flags = InputHint; |
| 133 |
> |
ourxwmhints.flags = InputHint|IconPixmapHint; |
| 134 |
|
ourxwmhints.input = True; |
| 135 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
| 136 |
+ |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
| 137 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
| 138 |
+ |
oursizhints.min_width = MINWIDTH; |
| 139 |
+ |
oursizhints.min_height = MINHEIGHT+COMHEIGHT; |
| 140 |
+ |
oursizhints.flags = PMinSize; |
| 141 |
+ |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 142 |
|
XSelectInput(ourdisplay, gwind, ExposureMask); |
| 143 |
|
XMapWindow(ourdisplay, gwind); |
| 144 |
< |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent)); |
| 144 |
> |
XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent)); |
| 145 |
|
gwidth = levptr(XExposeEvent)->width; |
| 146 |
|
gheight = levptr(XExposeEvent)->height - COMHEIGHT; |
| 147 |
|
x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; |
| 181 |
|
x11_clear(xres, yres) /* clear our display */ |
| 182 |
|
int xres, yres; |
| 183 |
|
{ |
| 184 |
< |
if (xres != gwidth || yres != gheight) { /* change window */ |
| 185 |
< |
if (comline != NULL) |
| 186 |
< |
xt_close(comline); |
| 184 |
> |
/* check limits */ |
| 185 |
> |
if (xres < MINWIDTH) |
| 186 |
> |
xres = MINWIDTH; |
| 187 |
> |
if (yres < MINHEIGHT) |
| 188 |
> |
yres = MINHEIGHT; |
| 189 |
> |
/* resize window */ |
| 190 |
> |
if (xres != gwidth || yres != gheight) { |
| 191 |
|
XSelectInput(ourdisplay, gwind, 0); |
| 192 |
|
XResizeWindow(ourdisplay, gwind, xres, yres+COMHEIGHT); |
| 174 |
– |
comline = xt_open(ourdisplay, |
| 175 |
– |
DefaultGC(ourdisplay,ourscreen), |
| 176 |
– |
gwind, 0, yres, xres, COMHEIGHT, 0, COMFN); |
| 177 |
– |
if (comline == NULL) { |
| 178 |
– |
stderr_v("Cannot open command line window\n"); |
| 179 |
– |
quit(1); |
| 180 |
– |
} |
| 181 |
– |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
| 193 |
|
gwidth = xres; |
| 194 |
|
gheight = yres; |
| 195 |
|
XFlush(ourdisplay); |
| 197 |
|
XSync(ourdisplay, 1); /* discard input */ |
| 198 |
|
} |
| 199 |
|
XClearWindow(ourdisplay, gwind); |
| 200 |
< |
if (ourvisual->class == PseudoColor) /* reinitialize color table */ |
| 200 |
> |
/* reinitialize color table */ |
| 201 |
> |
if (ourvisual->class == PseudoColor) |
| 202 |
|
if (getpixels() == 0) |
| 203 |
|
stderr_v("cannot allocate colors\n"); |
| 204 |
|
else |
| 205 |
|
new_ctab(ncolors); |
| 206 |
< |
|
| 206 |
> |
/* get new command line */ |
| 207 |
> |
if (comline != NULL) |
| 208 |
> |
xt_close(comline); |
| 209 |
> |
comline = xt_open(ourdisplay, |
| 210 |
> |
DefaultGC(ourdisplay,ourscreen), |
| 211 |
> |
gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN); |
| 212 |
> |
if (comline == NULL) { |
| 213 |
> |
stderr_v("Cannot open command line window\n"); |
| 214 |
> |
quit(1); |
| 215 |
> |
} |
| 216 |
> |
XSelectInput(ourdisplay, comline->w, ExposureMask); |
| 217 |
> |
/* remove earmuffs */ |
| 218 |
|
XSelectInput(ourdisplay, gwind, |
| 219 |
|
StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask); |
| 220 |
|
} |
| 231 |
|
|
| 232 |
|
if (ncolors > 0) |
| 233 |
|
pixel = pixval[get_pixel(col, xnewcolr)]; |
| 234 |
< |
else if (ourvisual->class == TrueColor) |
| 234 |
> |
else if (ourvisual->class != PseudoColor) |
| 235 |
|
pixel = true_pixel(col); |
| 236 |
|
else |
| 237 |
|
return; |
| 244 |
|
static |
| 245 |
|
x11_flush() /* flush output */ |
| 246 |
|
{ |
| 247 |
< |
if (ncolors <= 0 && ourvisual->class != TrueColor) /* dummy */ |
| 225 |
< |
XFillRectangle(ourdisplay, gwind, ourgc, 0, 0, 1 ,1); |
| 247 |
> |
XNoOp(ourdisplay); |
| 248 |
|
while (XPending(ourdisplay) > 0) |
| 249 |
|
getevent(); |
| 250 |
|
} |
| 254 |
|
x11_comin(inp, prompt) /* read in a command line */ |
| 255 |
|
char *inp, *prompt; |
| 256 |
|
{ |
| 257 |
< |
int x11_getc(), x11_comout(); |
| 257 |
> |
extern int x11_getc(); |
| 258 |
|
|
| 259 |
|
if (prompt != NULL) |
| 260 |
|
if (fromcombuf(inp, &x11_driver)) |
| 271 |
|
x11_comout(out) /* output a string to command line */ |
| 272 |
|
char *out; |
| 273 |
|
{ |
| 274 |
< |
if (comline != NULL) |
| 275 |
< |
xt_puts(out, comline); |
| 274 |
> |
if (comline == NULL) |
| 275 |
> |
return; |
| 276 |
> |
xt_puts(out, comline); |
| 277 |
> |
if (out[strlen(out)-1] == '\n') |
| 278 |
> |
XFlush(ourdisplay); |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
|
| 283 |
|
x11_errout(msg) /* output an error message */ |
| 284 |
|
char *msg; |
| 285 |
|
{ |
| 261 |
– |
x11_comout(msg); |
| 286 |
|
stderr_v(msg); /* send to stderr also! */ |
| 287 |
+ |
x11_comout(msg); |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
|
| 339 |
|
static int |
| 340 |
|
getpixels() /* get the color map */ |
| 341 |
|
{ |
| 342 |
+ |
XColor thiscolor; |
| 343 |
+ |
register int i, j; |
| 344 |
+ |
|
| 345 |
|
if (ncolors > 0) |
| 346 |
< |
return(ncolors); |
| 346 |
> |
goto donecolors; |
| 347 |
|
if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) { |
| 348 |
|
ourmap = DefaultColormap(ourdisplay,ourscreen); |
| 349 |
|
goto loop; |
| 354 |
|
for (ncolors = ourvisual->map_entries; |
| 355 |
|
ncolors > ourvisual->map_entries/3; |
| 356 |
|
ncolors = ncolors*.937) { |
| 357 |
< |
pixval = (int *)malloc(ncolors*sizeof(int)); |
| 357 |
> |
pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long)); |
| 358 |
|
if (pixval == NULL) |
| 359 |
|
return(ncolors = 0); |
| 360 |
|
if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0, |
| 369 |
|
else |
| 370 |
|
return(ncolors = 0); /* failed */ |
| 371 |
|
} |
| 372 |
< |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) { |
| 373 |
< |
XColor thiscolor; |
| 346 |
< |
register int i, j; |
| 347 |
< |
/* reset black and white */ |
| 348 |
< |
for (i = 0; i < ncolors; i++) { |
| 372 |
> |
if (ourmap != DefaultColormap(ourdisplay,ourscreen)) |
| 373 |
> |
for (i = 0; i < ncolors; i++) { /* reset black and white */ |
| 374 |
|
if (pixval[i] != ourblack && pixval[i] != ourwhite) |
| 375 |
|
continue; |
| 376 |
|
thiscolor.pixel = pixval[i]; |
| 384 |
|
ncolors--; |
| 385 |
|
i--; |
| 386 |
|
} |
| 362 |
– |
} |
| 387 |
|
XSetWindowColormap(ourdisplay, gwind, ourmap); |
| 388 |
+ |
donecolors: |
| 389 |
+ |
#ifdef DEBUG |
| 390 |
+ |
thiscolor.flags = DoRed|DoGreen|DoBlue; |
| 391 |
+ |
thiscolor.red = thiscolor.green = thiscolor.blue = 0; |
| 392 |
+ |
for (i = 0; i < ncolors; i++) { |
| 393 |
+ |
thiscolor.pixel = pixval[i]; |
| 394 |
+ |
XStoreColor(ourdisplay, ourmap, &thiscolor); |
| 395 |
+ |
} |
| 396 |
+ |
#endif |
| 397 |
|
return(ncolors); |
| 398 |
|
} |
| 399 |
|
|