[hackers] [wmii] Allow colors to be specified in any form recognized by X, including rgba. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Fri, 18 Jun 2010 14:57:55 +0000 (UTC)

changeset: 2734:b3140b29583c
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Fri Jun 18 10:57:42 2010 -0400
files: cmd/wmii/client.c cmd/wmii/main.c cmd/wmii/message.c cmd/x11/wmii9menu.c include/stuff/x11.h lib/libstuff/client_readconfig.c lib/libstuff/util/stokenize.c lib/libstuff/x11/colors/loadcolor.c
description:
Allow colors to be specified in any form recognized by X, including rgba.

diff -r 45371d69c278 -r b3140b29583c cmd/wmii/client.c
--- a/cmd/wmii/client.c Fri Jun 18 10:17:25 2010 -0400
+++ b/cmd/wmii/client.c Fri Jun 18 10:57:42 2010 -0400
@@ -129,7 +129,7 @@
         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 -r 45371d69c278 -r b3140b29583c cmd/wmii/main.c
--- a/cmd/wmii/main.c Fri Jun 18 10:17:25 2010 -0400
+++ b/cmd/wmii/main.c Fri Jun 18 10:57:42 2010 -0400
@@ -417,8 +417,8 @@
         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 -r 45371d69c278 -r b3140b29583c cmd/wmii/message.c
--- a/cmd/wmii/message.c Fri Jun 18 10:17:25 2010 -0400
+++ b/cmd/wmii/message.c Fri Jun 18 10:57:42 2010 -0400
@@ -876,34 +876,13 @@
 void
 msg_parsecolors(IxpMsg *m, CTuple *col) {
         static char Ebad[] = "bad color string";
- Rune r;
- char c, *p;
- int i, j;
+ char n;
 
- /* '#%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);
+ n = loadcolor(col, m->pos, m->end);
+ if(n == 0)
+ error(Ebad);
 
- chartorune(&r, p);
- if(i < 2) {
- if(r != ' ')
- error(Ebad);
- p++;
- }else if(*p != '\0' && !isspacerune(r))
- error(Ebad);
- }
-
- c = *p;
- *p = '\0';
- loadcolor(col, m->pos);
- *p = c;
-
- m->pos = p;
+ m->pos += n;
         msg_eatrunes(m, isspacerune, true);
 }
 
diff -r 45371d69c278 -r b3140b29583c cmd/x11/wmii9menu.c
--- a/cmd/x11/wmii9menu.c Fri Jun 18 10:17:25 2010 -0400
+++ b/cmd/x11/wmii9menu.c Fri Jun 18 10:57:42 2010 -0400
@@ -155,8 +155,8 @@
         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 -r 45371d69c278 -r b3140b29583c include/stuff/x11.h
--- a/include/stuff/x11.h Fri Jun 18 10:17:25 2010 -0400
+++ b/include/stuff/x11.h Fri Jun 18 10:57:42 2010 -0400
@@ -62,7 +62,7 @@
         Color bg;
         Color fg;
         Color border;
- char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
+ char colstr[64];
 };
 
 struct ErrorCode {
@@ -267,7 +267,7 @@
 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 -r 45371d69c278 -r b3140b29583c lib/libstuff/client_readconfig.c
--- a/lib/libstuff/client_readconfig.c Fri Jun 18 10:17:25 2010 -0400
+++ b/lib/libstuff/client_readconfig.c Fri Jun 18 10:57:42 2010 -0400
@@ -11,9 +11,9 @@
 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 -r 45371d69c278 -r b3140b29583c lib/libstuff/util/stokenize.c
--- a/lib/libstuff/util/stokenize.c Fri Jun 18 10:17:25 2010 -0400
+++ b/lib/libstuff/util/stokenize.c Fri Jun 18 10:57:42 2010 -0400
@@ -11,7 +11,7 @@
         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 -r 45371d69c278 -r b3140b29583c lib/libstuff/x11/colors/loadcolor.c
--- a/lib/libstuff/x11/colors/loadcolor.c Fri Jun 18 10:17:25 2010 -0400
+++ b/lib/libstuff/x11/colors/loadcolor.c Fri Jun 18 10:57:42 2010 -0400
@@ -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;
 }
Received on Fri Jun 18 2010 - 14:57:55 UTC

This archive was generated by hypermail 2.2.0 : Fri Jun 18 2010 - 15:00:08 UTC