From 6413a4d6f816832f4d78254508c3d8dd60476889 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Tue, 26 May 2020 22:28:05 +0500 Subject: [PATCH] Revert "Support arbitrary hex color formats (16/32bits per component)" This reverts commit 1e36a6b4ac569527981e06db429f3e6cd8ac99b8. --- src/draw.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/draw.c b/src/draw.c index e5f1ada..8bce3c9 100644 --- a/src/draw.c +++ b/src/draw.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "dunst.h" #include "icon.h" @@ -45,7 +44,7 @@ void draw_setup(void) pango_fdesc = pango_font_description_from_string(settings.font); } -static struct color hex_to_color(uintmax_t hexValue, int dpc) +static struct color hex_to_color(uint32_t hexValue, int dpc) { const int bpc = 4 * dpc; const unsigned single_max = UINT_MAX_N(bpc); @@ -61,38 +60,20 @@ static struct color hex_to_color(uintmax_t hexValue, int dpc) static struct color string_to_color(const char *str) { - uintmax_t val; - unsigned clen; - { - int cn; - - /* accept 3 or 4 equal components */ { - char *end; - val = strtoumax(str+1, &end, 16); - if (errno == ERANGE || (end[0] != '\0' && end[1] != '\0')) - goto err; - - const int len = (end - (str+1)); - if (len % 3 == 0) cn = 3; - else if (len % 4 == 0) cn = 4; - else goto err; - clen = len / cn; - } - /* component length must be 2^n */ { - unsigned mask = 1; - while(mask < clen) mask <<= 1; - if (mask != clen) goto err; - } - /* turn 3-component to opaque 4-components */ { - const unsigned csize = clen * 4; - if (cn == 3) - val = (val << csize) | UINT_MAX_N(csize); - } + char *end; + uint32_t val = strtoul(str+1, &end, 16); + if (*end != '\0' && *(end+1) != '\0') { + LOG_W("Invalid color string: '%s'", str); + } + + switch (strlen(str+1)) { + case 3: return hex_to_color((val << 4) | 0xF, 1); + case 6: return hex_to_color((val << 8) | 0xFF, 2); + case 4: return hex_to_color(val, 1); + case 8: return hex_to_color(val, 2); } - return hex_to_color(val, clen); /* return black on error */ - err: LOG_W("Invalid color string: '%s'", str); return hex_to_color(0xF, 1); }