wl_backend: add X11 rgb.txt color name lookup
The named color table only had basic colors (black, white, red, etc.) but Window Maker backgrounds use extended X11 color names like deepskyblue4, tomato4, blue4. Now falls back to parsing /usr/share/X11/rgb.txt for any unrecognized color name. Fixes Sunset and other multi-color gradient backgrounds that use X11 named colors.
This commit is contained in:
parent
a62a05bbb7
commit
07022840ac
|
|
@ -8767,6 +8767,42 @@ static int wl_get_color_for_colormap(unsigned long colormap,
|
|||
}
|
||||
}
|
||||
|
||||
/* Look up in X11 rgb.txt database */
|
||||
{
|
||||
static const char *rgb_paths[] = {
|
||||
"/usr/share/X11/rgb.txt",
|
||||
"/usr/lib/X11/rgb.txt",
|
||||
"/etc/X11/rgb.txt",
|
||||
NULL
|
||||
};
|
||||
FILE *f = NULL;
|
||||
for (int i = 0; rgb_paths[i] && !f; i++)
|
||||
f = fopen(rgb_paths[i], "r");
|
||||
if (f) {
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
unsigned int rv, gv, bv;
|
||||
char name[128];
|
||||
if (line[0] == '!' || line[0] == '#')
|
||||
continue;
|
||||
if (sscanf(line, "%u %u %u %127[^\n]", &rv, &gv, &bv, name) == 4) {
|
||||
/* Trim leading whitespace/tabs from name */
|
||||
char *n = name;
|
||||
while (*n == ' ' || *n == '\t') n++;
|
||||
if (strcasecmp(n, color_name) == 0) {
|
||||
color->red = rv << 8 | rv;
|
||||
color->green = gv << 8 | gv;
|
||||
color->blue = bv << 8 | bv;
|
||||
color->pixel = (0xFF << 24) | (rv << 16) | (gv << 8) | bv;
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
wwarning(_("could not parse color \"%s\" (Wayland)"), color_name);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue