summaryrefslogtreecommitdiff
path: root/xprop.c
diff options
context:
space:
mode:
authorPierre-Loup A. Griffais <git@plagman.net>2020-06-06 15:19:10 -0700
committerPierre-Loup A. Griffais <git@plagman.net>2020-11-01 13:45:27 -0800
commitd41b28bfa8f5bf5155082167fb004e3c709b52ae (patch)
treeed92694f4147fbe89db372b692559c01ada23c44 /xprop.c
parente25ae1d9b03a84c3ca825745156af2a7045f04e5 (diff)
Support true color output for icons if the terminal advertises it.
Diffstat (limited to 'xprop.c')
-rw-r--r--xprop.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/xprop.c b/xprop.c
index 52ed662..f13660f 100644
--- a/xprop.c
+++ b/xprop.c
@@ -751,6 +751,17 @@ is_utf8_locale (void)
#endif
}
+static int
+is_truecolor_term (void)
+{
+ char *colorterm = getenv( "COLORTERM" );
+
+ if (colorterm && !strcmp(colorterm,"truecolor"))
+ return 1;
+
+ return 0;
+}
+
static const char *
Format_Icons (const unsigned long *icon, int len)
{
@@ -779,13 +790,15 @@ Format_Icons (const unsigned long *icon, int len)
icon_pixel_bytes = 1;
if (is_utf8_locale())
icon_pixel_bytes = 3; /* Up to 3 bytes per character in that mode. */
+ if (is_utf8_locale())
+ icon_pixel_bytes = 25; /* 16 control characters, and up to 9 chars of RGB. */
/* Initial tab, pixels, and newline. */
icon_line_bytes = 8 + display_width * icon_pixel_bytes + 1;
offset = (tail - result);
- alloced += 80; /* For the header */
+ alloced += 80; /* For the header, final newline, color reset */
alloced += icon_line_bytes * height; /* For the rows */
result = realloc (result, alloced);
@@ -825,7 +838,17 @@ Format_Icons (const unsigned long *icon, int len)
(587 * (g / 255.0)) +
(114 * (b / 255.0))));
- if (is_utf8_locale())
+ if (is_truecolor_term())
+ {
+ float opacity = a / 255.0;
+
+ r = r * opacity;
+ g = g * opacity;
+ b = b * opacity;
+
+ tail += sprintf (tail, "\033[38;2;%d;%d;%dm\342\226\210\342\226\210", r, g, b );
+ }
+ else if (is_utf8_locale())
{
static const char palette[][4] =
{
@@ -857,6 +880,10 @@ Format_Icons (const unsigned long *icon, int len)
tail += sprintf (tail, "\n");
}
+ /* Reset colors. */
+ if (is_truecolor_term())
+ tail += sprintf (tail, "\033[0m");
+
tail += sprintf (tail, "\n");
}