diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index 35ceada..43d34aa 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -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; }