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 |
|
|
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; |
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; |
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; |
368 |
< |
register int i, j; |
369 |
< |
/* reset black and white */ |
370 |
< |
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 |
|
} |
384 |
– |
} |
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 |
|
|