commit a33719f9d4d65532b09985ed4ece5da58d996897
parent 87f46f44bb3f555526a9f8ddca90190242275895
Author: Kris Maglione <kris@suckless.org>
Date: Fri, 18 Jun 2010 10:57:42 -0400
Allow colors to be specified in any form recognized by X, including rgba.
Diffstat:
8 files changed, 29 insertions(+), 45 deletions(-)
diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c
@@ -129,7 +129,7 @@ client_create(XWindow w, XWindowAttributes *wa) {
freestringlist(host);
free(pid);
- if(render_argb_p(wa->visual)) {
+ if(have_render) { /* render_argb_p(wa->visual) */
depth = 32;
vis = scr.visual32;
c->ibuf = &ibuf32;
diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c
@@ -417,8 +417,8 @@ main(int argc, char *argv[]) {
def.mod = Mod1Mask;
strcpy(def.grabmod, "Mod1");
- loadcolor(&def.focuscolor, FOCUSCOLORS);
- loadcolor(&def.normcolor, NORMCOLORS);
+ loadcolor(&def.focuscolor, FOCUSCOLORS, nil);
+ loadcolor(&def.normcolor, NORMCOLORS, nil);
disp.sel = pointerscreen();
diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c
@@ -876,34 +876,13 @@ msg_nudge(View *v, IxpMsg *m) {
void
msg_parsecolors(IxpMsg *m, CTuple *col) {
static char Ebad[] = "bad color string";
- Rune r;
- char c, *p;
- int i, j;
-
- /* '#%6x #%6x #%6x' */
- p = m->pos;
- for(i = 0; i < 3 && p < m->end; i++) {
- if(*p++ != '#')
- error(Ebad);
- for(j = 0; j < 6; j++)
- if(p >= m->end || !isxdigit(*p++))
- error(Ebad);
-
- chartorune(&r, p);
- if(i < 2) {
- if(r != ' ')
- error(Ebad);
- p++;
- }else if(*p != '\0' && !isspacerune(r))
- error(Ebad);
- }
+ char n;
- c = *p;
- *p = '\0';
- loadcolor(col, m->pos);
- *p = c;
+ n = loadcolor(col, m->pos, m->end);
+ if(n == 0)
+ error(Ebad);
- m->pos = p;
+ m->pos += n;
msg_eatrunes(m, isspacerune, true);
}
diff --git a/cmd/x11/wmii9menu.c b/cmd/x11/wmii9menu.c
@@ -155,8 +155,8 @@ main(int argc, char **argv)
client_init(address);
wborder = strtol(readctl("border "), nil, 10);
- loadcolor(&cnorm, readctl("normcolors "));
- loadcolor(&csel, readctl("focuscolors "));
+ loadcolor(&cnorm, readctl("normcolors "), nil);
+ loadcolor(&csel, readctl("focuscolors "), nil);
font = loadfont(readctl("font "));
if(!font)
fatal("Can't load font");
diff --git a/include/stuff/x11.h b/include/stuff/x11.h
@@ -62,7 +62,7 @@ struct CTuple {
Color bg;
Color fg;
Color border;
- char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
+ char colstr[64];
};
struct ErrorCode {
@@ -267,7 +267,7 @@ bool havexft(void);
void initdisplay(void);
KeyCode keycode(const char*);
uint labelh(Font*);
-bool loadcolor(CTuple*, const char*);
+int loadcolor(CTuple*, const char*, const char*);
Font* loadfont(const char*);
void lowerwin(Window*);
int mapwin(Window*);
diff --git a/lib/libstuff/client_readconfig.c b/lib/libstuff/client_readconfig.c
@@ -11,9 +11,9 @@ void
client_readconfig(CTuple *norm, CTuple *focus, Font **font) {
if(norm)
- loadcolor(norm, readctl("normcolors "));
+ loadcolor(norm, readctl("normcolors "), nil);
if(focus)
- loadcolor(focus, readctl("focuscolors "));
+ loadcolor(focus, readctl("focuscolors "), nil);
*font = loadfont(readctl("font "));
if(!*font)
fatal("Can't load font %q", readctl("font "));
diff --git a/lib/libstuff/util/stokenize.c b/lib/libstuff/util/stokenize.c
@@ -11,7 +11,7 @@ stokenize(char *res[], uint reslen, char *str, char *delim) {
i = 0;
s = str;
while(i < reslen && *s) {
- while(strchr(delim, *s))
+ while(*s && strchr(delim, *s))
*(s++) = '\0';
if(*s)
res[i++] = s;
diff --git a/lib/libstuff/x11/colors/loadcolor.c b/lib/libstuff/x11/colors/loadcolor.c
@@ -4,15 +4,20 @@
#include <string.h>
#include "../x11.h"
-bool
-loadcolor(CTuple *c, const char *str) {
- char buf[24];
+int
+loadcolor(CTuple *c, const char *str, const char *end) {
+ char buf[128];
+ char *toks[4];
- utflcpy(buf, str, sizeof buf);
- memcpy(c->colstr, str, sizeof c->colstr);
+ utflcpy(buf, str, end ? min(end - str + 1, sizeof buf) : sizeof buf);
+ if(3 > stokenize(toks, nelem(toks), buf, " \t\r\n"))
+ return 0;
- buf[7] = buf[15] = buf[23] = '\0';
- return parsecolor(buf, &c->fg)
- && parsecolor(buf+8, &c->bg)
- && parsecolor(buf+16, &c->border);
+ if(!(parsecolor(toks[0], &c->fg)
+ && parsecolor(toks[1], &c->bg)
+ && parsecolor(toks[2], &c->border)))
+ return 0;
+
+ snprint(c->colstr, sizeof c->colstr, "%s %s %s", toks[0], toks[1], toks[2]);
+ return toks[2] + strlen(toks[2]) - buf;
}