2
* General Device dependent code for xli.
4
* Author; Graeme W. Gill
10
static int saParseXColor(DisplayInfo *dinfo, char *spec, XColor *xcolor);
12
/* Initialise a display info structure to default values */
13
void xliDefaultDispinfo(DisplayInfo *dinfo)
22
/* open up a display and screen, and stick the info away */
23
/* Return FALSE on failure */
24
boolean xliOpenDisplay(DisplayInfo *dinfo, char *name)
28
if (!(disp = XOpenDisplay(globals.dname)))
29
return FALSE; /* failed */
30
scrn = DefaultScreen(disp);
33
dinfo->colormap = DefaultColormap(disp, scrn);
34
dinfo->width = DisplayWidth(disp, scrn);
35
dinfo->height = DisplayHeight(disp, scrn);
36
XSetErrorHandler(errorHandler);
41
/* report display name when connection fails */
42
char *xliDisplayName(char *name)
44
return XDisplayName(name);
47
void xliCloseDisplay(DisplayInfo *dinfo)
49
XCloseDisplay(dinfo->disp);
53
simple X11 error handler. this provides us with some kind of error recovery.
56
int errorHandler(Display * disp, XErrorEvent * error)
58
char errortext[BUFSIZ];
60
XGetErrorText(disp, error->error_code, errortext, BUFSIZ);
61
fprintf(stderr, "xli: X Error: %s on 0x%lx\n",
62
errortext, error->resourceid);
69
/* Return the default visual class */
70
int xliDefaultVisual(void)
72
return (DefaultVisual(globals.dinfo.disp, globals.dinfo.scrn)->class);
75
/* return the default depth of the default visual */
76
int xliDefaultDepth(void)
78
return DefaultDepth(globals.dinfo.disp, globals.dinfo.scrn);
81
/* Print some information about the display */
82
void tellAboutDisplay(DisplayInfo * dinfo)
87
screen = ScreenOfDisplay(dinfo->disp, dinfo->scrn);
88
printf("Server: %s Version %d\n", ServerVendor(dinfo->disp), VendorRelease(dinfo->disp));
89
printf("Depths and visuals supported:\n");
90
for (a = 0; a < screen->ndepths; a++) {
91
printf("%2d:", screen->depths[a].depth);
92
for (b = 0; b < screen->depths[a].nvisuals; b++)
93
printf(" %s", nameOfVisualClass(screen->depths[a].visuals[b].class));
97
printf("[No information on server; error occurred before connection]\n");
101
/* A standalone color name to RGB lookup routine */
108
} xliXColorTableEntry;
110
#include "rgbtab.h" /* Equivalent of an X color table */
112
/* parse an X like color. */
113
int xliParseXColor(DisplayInfo *dinfo, char *spec, XColor *xcolor)
118
stat = XParseColor(globals.dinfo.disp, globals.dinfo.colormap,
121
stat = saParseXColor(dinfo, spec, xcolor);
127
static int saParseXColor(DisplayInfo *dinfo, char *spec, XColor *xcolor)
130
xliXColorTableEntry *tp;
137
for (i = 0; i < n; i++) {
138
if (isupper(spec[i]))
139
spec[i] = tolower(spec[i]);
141
if (spec[0] == '#') {
144
r = hstoi(spec + 1, 1);
145
g = hstoi(spec + 2, 1);
146
b = hstoi(spec + 3, 1);
147
if (r >= 0 && g >= 0 && b >= 0) {
148
xcolor->red = r * 0x1111;
149
xcolor->green = g * 0x1111;
150
xcolor->blue = b * 0x1111;
156
r = hstoi(spec + 1, 2);
157
g = hstoi(spec + 3, 2);
158
b = hstoi(spec + 5, 2);
159
if (r >= 0 && g >= 0 && b >= 0) {
160
xcolor->red = r * 0x101;
161
xcolor->green = g * 0x101;
162
xcolor->blue = b * 0x101;
168
r = hstoi(spec + 1, 3);
169
g = hstoi(spec + 4, 3);
170
b = hstoi(spec + 7, 3);
171
if (r >= 0 && g >= 0 && b >= 0) {
172
xcolor->red = (r * 65535) / 4095;
173
xcolor->green = (g * 65535) / 4095;
174
xcolor->blue = (b * 65535) / 4095;
180
r = hstoi(spec + 1, 4);
181
g = hstoi(spec + 5, 4);
182
b = hstoi(spec + 9, 4);
183
if (r >= 0 && g >= 0 && b >= 0) {
194
else its a color name. Do a linear search for it
195
(binary search would be better)
197
for (n = 0, tp = &xliXColorTable[0]; tp->name[0]; tp++) {
198
if (strcmp(spec, tp->name) == 0) {
199
xcolor->red = tp->red * 0x101;
200
xcolor->green = tp->green * 0x101;
201
xcolor->blue = tp->blue * 0x101;
209
/* default - return black */
218
/* gamma correct an XColor */
219
void xliGammaCorrectXColor(XColor * xlicolor, double gamma)
221
xlicolor->red = (int) (0.5 + 65535.0 * pow((double) xlicolor->red / 65535.0, gamma));
222
xlicolor->green = (int) (0.5 + 65535.0 * pow((double) xlicolor->green / 65535.0, gamma));
223
xlicolor->blue = (int) (0.5 + 65535.0 * pow((double) xlicolor->blue / 65535.0, gamma));