Allow text drawing to use the alpha channel. (#5246)
This is the last remaining diff from the i3-gaps tree. related to https://github.com/i3/i3/issues/3724 Tested using the following config with picom: bar { i3bar_command i3bar -t status_command i3status colors { # fully transparent text on opaque background: statusline #ffffff00 background #000000ff } }
This commit is contained in:
committed by
GitHub
parent
c8fd8eff21
commit
9e3a9e8225
@ -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 */
|
||||
|
Reference in New Issue
Block a user