mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-19 05:33:44 -04:00
osc: parse_legacy_color(): the alpha component is not a floating point number
When using the urxvt extension of the XParseColor format, the alpha component is not a floating point number, but a decimal number in the range 0-100.
This commit is contained in:
parent
8adb52e63a
commit
7fc3b18586
1 changed files with 7 additions and 8 deletions
15
osc.c
15
osc.c
|
|
@ -268,19 +268,18 @@ parse_legacy_color(const char *string, uint32_t *color, bool *_have_alpha,
|
||||||
uint16_t alpha = 0xffff;
|
uint16_t alpha = 0xffff;
|
||||||
|
|
||||||
if (string[0] == '[') {
|
if (string[0] == '[') {
|
||||||
/* e.g. \E]11;[0.5]#00ff00 */
|
/* e.g. \E]11;[50]#00ff00 */
|
||||||
const char *start = &string[1];
|
const char *start = &string[1];
|
||||||
const char *end = strchr(string, ']');
|
|
||||||
if (end == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char *_end;
|
errno = 0;
|
||||||
double percent = strtod(start, &_end);
|
char *end;
|
||||||
if (_end != end)
|
unsigned long percent = strtoul(start, &end, 10);
|
||||||
|
|
||||||
|
if (errno != 0 || *end != ']')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
have_alpha = true;
|
have_alpha = true;
|
||||||
alpha = 0xffff * percent;
|
alpha = (0xffff * min(percent, 100) + 50) / 100;
|
||||||
|
|
||||||
string = end + 1;
|
string = end + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue