---
I was surprised that setting value for color-{16..255} has no effects
x.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/x.c b/x.c
index 0422421..57e246a 100644
--- a/x.c
+++ b/x.c
_AT_@ -152,6 +152,7 @@ static void xsetenv(void);
static void xseturgency(int);
static int evcol(XEvent *);
static int evrow(XEvent *);
+static int colornamelen(void);
static void expose(XEvent *);
static void visibility(XEvent *);
_AT_@ -702,13 +703,24 @@ sixd_to_16bit(int x)
return x == 0 ? 0 : 0x3737 + 0x2828 * x;
}
+int
+colornamelen(void)
+{
+ int c = 0;
+ for (size_t i = 0; i < sizeof colorname; i += sizeof colorname[c])
+ c++;
+ return c;
+}
+
int
xloadcolor(int i, const char *name, Color *ncolor)
{
XRenderColor color = { .alpha = 0xffff };
if (!name) {
- if (BETWEEN(i, 16, 255)) { /* 256 color */
+ if (i < colornamelen() && colorname[i]) {
+ name = colorname[i];
+ } else if (BETWEEN(i, 16, 255)) { /* 256 color */
if (i < 6*6*6+16) { /* same colors as xterm */
color.red = sixd_to_16bit( ((i-16)/36)%6 );
color.green = sixd_to_16bit( ((i-16)/6) %6 );
_AT_@ -720,7 +732,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
return XftColorAllocValue(xw.dpy, xw.vis,
xw.cmap, &color, ncolor);
} else
- name = colorname[i];
+ die("Cannot load color number: %d\n", i);
}
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
_AT_@ -737,7 +749,7 @@ xloadcols(void)
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
} else {
- dc.collen = MAX(LEN(colorname), 256);
+ dc.collen = MAX(colornamelen(), 256);
dc.col = xmalloc(dc.collen * sizeof(Color));
}
--
2.20.1.352.g40155ab247
Received on Mon Jan 21 2019 - 05:53:20 CET
This archive was generated by hypermail 2.3.0 : Mon Jan 21 2019 - 06:00:22 CET