mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
src/theme.c: support inline alpha encoding like #aabbccff
.. and mark the current `#rrggbb aaa` encoding as deprecated.
This commit is contained in:
parent
45c60de263
commit
2c2341530b
2 changed files with 25 additions and 9 deletions
|
|
@ -34,7 +34,11 @@ labwc-config(5).
|
||||||
*color*
|
*color*
|
||||||
Colors can be specified by either of the following:
|
Colors can be specified by either of the following:
|
||||||
- #rrggbb (hexadecimal RGB values)
|
- #rrggbb (hexadecimal RGB values)
|
||||||
- #rrggbb aaa (same but with decimal alpha value)
|
- #rrggbb aaa (same but with decimal alpha value percentage)
|
||||||
|
- #rrggbbaa (same but with inline alpha value in hex encoding)
|
||||||
|
|
||||||
|
Note: the #rrggbb aaa notation is deprecated starting from
|
||||||
|
labwc 0.7.2 and may be removed in future releases.
|
||||||
|
|
||||||
*justification*
|
*justification*
|
||||||
Justification determines the horizontal alignment of text.
|
Justification determines the horizontal alignment of text.
|
||||||
|
|
|
||||||
28
src/theme.c
28
src/theme.c
|
|
@ -404,15 +404,27 @@ parse_hexstr(const char *hex, float *rgba)
|
||||||
rgba[0] = (hex_to_dec(hex[1]) * 16 + hex_to_dec(hex[2])) / 255.0;
|
rgba[0] = (hex_to_dec(hex[1]) * 16 + hex_to_dec(hex[2])) / 255.0;
|
||||||
rgba[1] = (hex_to_dec(hex[3]) * 16 + hex_to_dec(hex[4])) / 255.0;
|
rgba[1] = (hex_to_dec(hex[3]) * 16 + hex_to_dec(hex[4])) / 255.0;
|
||||||
rgba[2] = (hex_to_dec(hex[5]) * 16 + hex_to_dec(hex[6])) / 255.0;
|
rgba[2] = (hex_to_dec(hex[5]) * 16 + hex_to_dec(hex[6])) / 255.0;
|
||||||
if (strlen(hex) > 7) {
|
rgba[3] = 1.0;
|
||||||
rgba[3] = atoi(hex + 7) / 100.0;
|
|
||||||
/* Pre-multiply everything as expected by wlr_scene */
|
size_t len = strlen(hex);
|
||||||
rgba[0] *= rgba[3];
|
if (len >= 9 && hex[7] == ' ') {
|
||||||
rgba[1] *= rgba[3];
|
/* Deprecated #aabbcc 100 alpha encoding to support openbox themes */
|
||||||
rgba[2] *= rgba[3];
|
rgba[3] = atoi(hex + 8) / 100.0;
|
||||||
} else {
|
wlr_log(WLR_ERROR,
|
||||||
rgba[3] = 1.0;
|
"The theme uses deprecated alpha notation %s, please convert to "
|
||||||
|
"#rrggbbaa to ensure your config works on newer labwc releases", hex);
|
||||||
|
} else if (len == 9) {
|
||||||
|
/* Inline alpha encoding like #aabbccff */
|
||||||
|
rgba[3] = (hex_to_dec(hex[7]) * 16 + hex_to_dec(hex[8])) / 255.0;
|
||||||
|
} else if (len > 7) {
|
||||||
|
/* More than just #aabbcc */
|
||||||
|
wlr_log(WLR_ERROR, "invalid alpha color encoding: '%s'", hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pre-multiply everything as expected by wlr_scene */
|
||||||
|
rgba[0] *= rgba[3];
|
||||||
|
rgba[1] *= rgba[3];
|
||||||
|
rgba[2] *= rgba[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum lab_justification
|
static enum lab_justification
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue