- c = xcb_alloc_named_color(conn, cmap, strlen(colorname), colorname);
- r = xcb_alloc_named_color_reply(conn, c, NULL);
- if (!r) {
- strlcat(cname, colorname + 2, sizeof cname - 1);
- c = xcb_alloc_named_color(conn, cmap, strlen(cname),
- cname);
- r = xcb_alloc_named_color_reply(conn, c, NULL);
+ /* color is in format rgb://rr/gg/bb */
+ if (strncmp(colorname, "rgb:", 4) == 0) {
+ if (parse_rgb(colorname, &rr, &gg, &bb) == -1)
+ warnx("could not parse rgb %s", colorname);
+ else {
+ cr = xcb_alloc_color_reply(conn,
+ xcb_alloc_color(conn, cmap, rr, gg, bb),
+ NULL);
+ if (cr) {
+ result = cr->pixel;
+ free(cr);
+ } else
+ warnx("color '%s' not found", colorname);
+ }
+ } else {
+ nr = xcb_alloc_named_color_reply(conn,
+ xcb_alloc_named_color(conn, cmap, strlen(colorname),
+ colorname),
+ NULL);
+ if (!nr) {
+ strlcat(cname, colorname + 2, sizeof cname - 1);
+ nr = xcb_alloc_named_color_reply(conn,
+ xcb_alloc_named_color(conn, cmap, strlen(cname),
+ cname),
+ NULL);
+ }
+ if (nr) {
+ result = nr->pixel;
+ free(nr);
+ } else
+ warnx("color '%s' not found", colorname);