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:
Michael Stapelberg 2022-11-06 12:43:37 +01:00 committed by GitHub
parent c8fd8eff21
commit 9e3a9e8225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View File

@ -1144,7 +1144,8 @@ client.background::
which do not cover the whole area of this window expose the color. Note which do not cover the whole area of this window expose the color. Note
that this colorclass only takes a single color. that this colorclass only takes a single color.
Colors are in HTML hex format (#rrggbb), see the following example: Colors are in HTML hex format (#rrggbb, optionally #rrggbbaa), see the following
example:
*Examples (default colors)*: *Examples (default colors)*:
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -1996,8 +1997,8 @@ bar {
=== Colors === Colors
As with i3, colors are in HTML hex format (#rrggbb). The following colors can As with i3, colors are in HTML hex format (#rrggbb, optionally #rrggbbaa). The
be configured at the moment: following colors can be configured at the moment:
background:: background::
Background color of the bar. Background color of the bar.

View File

@ -21,6 +21,7 @@ static xcb_visualtype_t *root_visual_type;
static double pango_font_red; static double pango_font_red;
static double pango_font_green; static double pango_font_green;
static double pango_font_blue; static double pango_font_blue;
static double pango_font_alpha;
static PangoLayout *create_layout_with_dpi(cairo_t *cr) { static PangoLayout *create_layout_with_dpi(cairo_t *cr) {
PangoLayout *layout; PangoLayout *layout;
@ -102,7 +103,7 @@ static void draw_text_pango(const char *text, size_t text_len,
/* Do the drawing */ /* Do the drawing */
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue); cairo_set_source_rgba(cr, pango_font_red, pango_font_green, pango_font_blue, pango_font_alpha);
pango_cairo_update_layout(cr, layout); pango_cairo_update_layout(cr, layout);
pango_layout_get_pixel_size(layout, NULL, &height); pango_layout_get_pixel_size(layout, NULL, &height);
/* Center the piece of text vertically. */ /* Center the piece of text vertically. */
@ -303,6 +304,7 @@ void set_font_colors(xcb_gcontext_t gc, color_t foreground, color_t background)
pango_font_red = foreground.red; pango_font_red = foreground.red;
pango_font_green = foreground.green; pango_font_green = foreground.green;
pango_font_blue = foreground.blue; pango_font_blue = foreground.blue;
pango_font_alpha = foreground.alpha;
break; break;
} }
} }

View File

@ -30,17 +30,27 @@ SLIST_HEAD(colorpixel_head, Colorpixel) colorpixels;
* *
*/ */
uint32_t get_colorpixel(const char *hex) { 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[1], hex[2], '\0'},
{hex[3], hex[4], '\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 r = strtol(strgroups[0], NULL, 16);
uint8_t g = strtol(strgroups[1], NULL, 16); uint8_t g = strtol(strgroups[1], NULL, 16);
uint8_t b = strtol(strgroups[2], 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 */ /* 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) { 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 */ /* Lookup this colorpixel in the cache */

View File

@ -0,0 +1 @@
colors now support an optional alpha value at the end (#rrggbbaa)