tRefactor xsetcolorname() - st - [fork] customized build of st, the simple term… | |
git clone git://src.adamsgaard.dk/st | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a32c5f5726f514b49bd396f27aab0e78c40126d3 | |
parent ba36d1394b3add5b9d4c174f1443cc312bcc7e09 | |
Author: FRIGN <[email protected]> | |
Date: Sun, 25 May 2014 12:13:22 +0200 | |
Refactor xsetcolorname() | |
I mainly improved the slightly off algorithm used to load colours in the 256-co… | |
removed unnecessary local values (r,g,b,colour). | |
"colour" is not necessary as a punchbag for XftColorAlloc[Value,Name], as they … | |
tthe result-adress until they are absolutely sure everything worked out[0]. | |
Being at it, I changed the error-returns for AllocValue to dies (just like in x… | |
a failure is most likely an OOM-situation you better catch early. | |
In case of an invalid name everything stays the same. | |
t[0]: http://www.opensource.apple.com/source/X11libs/X11libs-40/libXft/libXft-2… | |
Signed-off-by: Christoph Lohmann <[email protected]> | |
Diffstat: | |
M st.c | 32 ++++++++++++++---------------… | |
1 file changed, 14 insertions(+), 18 deletions(-) | |
--- | |
diff --git a/st.c b/st.c | |
t@@ -2757,32 +2757,28 @@ 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, 16 + 215)) { | |
- int r = (x - 16) / 36, g = ((x - 16) % 36) / 6, b = (x… | |
- 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… | |
- return 0; /* something went wrong */ | |
- dc.col[x] = colour; | |
+ 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… | |
+ die("Could not allocate color %d\n", x); | |
return 1; | |
- } else if(BETWEEN(x, 16 + 216, 255)) { | |
- color.red = color.green = color.blue = 0x0808 + 0x0a0a… | |
- if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color… | |
- return 0; /* something went wrong */ | |
- dc.col[x] = colour; | |
+ } else if(BETWEEN(x, 6*6*6+16, 255)) { /* grayscale */ | |
+ color.red = color.green = color.blue = 0x0808 + 0x0a0a… | |
+ if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color… | |
+ die("Could not allocate color %d\n", x); | |
return 1; | |
- } else { | |
+ } else { /* system colours */ | |
name = colorname[x]; | |
} | |
} | |
- if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &colour)) | |
- return 0; | |
- dc.col[x] = colour; | |
+ if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &dc.col[x])) | |
+ return 0; /* invalid name */ | |
return 1; | |
} | |