summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann2014-06-01 16:52:19 +0200
committerChristoph Lohmann2014-06-01 16:52:19 +0200
commit8b4cfcea73a37ab6d67c06c69e9af3de304185e3 (patch)
tree85264ab3c7c376dd6cb6da2709e329ae5aac606a
parenta32c5f5726f514b49bd396f27aab0e78c40126d3 (diff)
downloadst-8b4cfcea73a37ab6d67c06c69e9af3de304185e3.tar.gz
st-8b4cfcea73a37ab6d67c06c69e9af3de304185e3.tar.xz
st-8b4cfcea73a37ab6d67c06c69e9af3de304185e3.zip
Revert "Refactor xsetcolorname()"
This reverts commit a32c5f5726f514b49bd396f27aab0e78c40126d3.
-rw-r--r--st.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/st.c b/st.c
index beae9bc..79a4e0a 100644
--- a/st.c
+++ b/st.c
@@ -2757,28 +2757,32 @@ xloadcols(void) {
int
xsetcolorname(int x, const char *name) {
XRenderColor color = { .alpha = 0xffff };
-
+ Colour colour;
if(!BETWEEN(x, 0, LEN(colorname)))
return -1;
if(!name) {
- if(BETWEEN(x, 16, 6*6*6+16)) { /* 256 colour */
- color.red = sixd_to_16bit( ((x-16)/36)%6 );
- color.green = sixd_to_16bit( ((x-16)/6) %6 );
- color.blue = sixd_to_16bit( ((x-16)/1) %6 );
- if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[x]))
- die("Could not allocate color %d\n", x);
+ if(BETWEEN(x, 16, 16 + 215)) {
+ int r = (x - 16) / 36, g = ((x - 16) % 36) / 6, b = (x - 16) % 6;
+ color.red = sixd_to_16bit(r);
+ color.green = sixd_to_16bit(g);
+ color.blue = sixd_to_16bit(b);
+ if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &colour))
+ return 0; /* something went wrong */
+ dc.col[x] = colour;
return 1;
- } else if(BETWEEN(x, 6*6*6+16, 255)) { /* grayscale */
- color.red = color.green = color.blue = 0x0808 + 0x0a0a * (x-(6*6*6+16));
- if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[x]))
- die("Could not allocate color %d\n", x);
+ } else if(BETWEEN(x, 16 + 216, 255)) {
+ color.red = color.green = color.blue = 0x0808 + 0x0a0a * (x - (16 + 216));
+ if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &colour))
+ return 0; /* something went wrong */
+ dc.col[x] = colour;
return 1;
- } else { /* system colours */
+ } else {
name = colorname[x];
}
}
- if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &dc.col[x]))
- return 0; /* invalid name */
+ if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &colour))
+ return 0;
+ dc.col[x] = colour;
return 1;
}