diff options
Diffstat (limited to 'libi3/get_colorpixel.c')
-rw-r--r-- | libi3/get_colorpixel.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libi3/get_colorpixel.c b/libi3/get_colorpixel.c index 32ef34cd..45e47725 100644 --- a/libi3/get_colorpixel.c +++ b/libi3/get_colorpixel.c @@ -30,17 +30,27 @@ SLIST_HEAD(colorpixel_head, Colorpixel) colorpixels; * */ uint32_t get_colorpixel(const char *hex) { - char strgroups[3][3] = { + char alpha[2]; + if (strlen(hex) == strlen("#rrggbbaa")) { + alpha[0] = hex[7]; + alpha[1] = hex[8]; + } else { + alpha[0] = alpha[1] = 'F'; + } + + char strgroups[4][3] = { {hex[1], hex[2], '\0'}, {hex[3], hex[4], '\0'}, - {hex[5], hex[6], '\0'}}; + {hex[5], hex[6], '\0'}, + {alpha[0], alpha[1], '\0'}}; uint8_t r = strtol(strgroups[0], NULL, 16); uint8_t g = strtol(strgroups[1], NULL, 16); uint8_t b = strtol(strgroups[2], NULL, 16); + uint8_t a = strtol(strgroups[3], NULL, 16); /* Shortcut: if our screen is true color, no need to do a roundtrip to X11 */ if (root_screen == NULL || root_screen->root_depth == 24 || root_screen->root_depth == 32) { - return (0xFFUL << 24) | (r << 16 | g << 8 | b); + return (a << 24) | (r << 16 | g << 8 | b); } /* Lookup this colorpixel in the cache */ |