wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 75a2951be17677df1ea89a20e3aafb49d492b2c6
parent 391c14baac4cf859b0cfcf51f2bfbe45daadf2de
Author: Kris Maglione <jg@suckless.org>
Date:   Sat, 31 Mar 2007 17:22:30 -0400

Write /ctl before the second sourcing of rc.wmii.local

Diffstat:
cmd/wmii/draw.c | 40+++++++++++++++++++++++-----------------
cmd/wmii/rule.c | 33+++++++++++++++++----------------
rc/rc.wmii.rc | 6+++---
3 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/cmd/wmii/draw.c b/cmd/wmii/draw.c @@ -1,6 +1,7 @@ /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ +#include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -34,12 +35,9 @@ loadfont(Blitz *blitz, BlitzFont *font) { font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); if(missing) { fprintf(stderr, "%s: missing fontset%s for '%s':", argv0, - n > 1 ? "s": "", - fontname); + (n > 1 ? "s":""), fontname); for(i = 0; i < n; i++) - fprintf(stderr, "%s %s", - i ? ",": "", - missing[i]); + fprintf(stderr, "%s %s", (i ? ",":""), missing[i]); fprintf(stderr, "\n"); XFreeStringList(missing); } @@ -59,10 +57,10 @@ loadfont(Blitz *blitz, BlitzFont *font) { XFreeFont(blitz->dpy, font->xfont); font->xfont = nil; font->xfont = XLoadQueryFont(blitz->dpy, fontname); - if (!font->xfont) { - if(!strncmp(fontname, BLITZ_FONT, sizeof(BLITZ_FONT))) - fatal("cannot load font: %s", - BLITZ_FONT); + fprintf(stderr, "%s: cannot load font: %s\n", argv0, fontname); + if(!font->xfont) { + if(!strcmp(fontname, BLITZ_FONT)) + fatal("cannot load font: %s", BLITZ_FONT); free(font->fontstr); font->fontstr = estrdup(BLITZ_FONT); loadfont(blitz, font); @@ -129,9 +127,8 @@ draw_label(BlitzBrush *b, char *text) { buf[len - 1] = '.'; } - if(b->font->set) { + if(b->font->set) XmbTextExtents(b->font->set, text, len, &r, nil); - } switch (b->align) { case EAST: @@ -219,15 +216,24 @@ loadcolor(Blitz *blitz, BlitzColor *c) { char * parse_colors(char **buf, int *buflen, BlitzColor *col) { - uint i; - if(*buflen < 23 || 3 != sscanf(*buf, "#%06x #%06x #%06x", &i,&i,&i)) + static regex_t reg; + static Bool compiled; + + if(!compiled) { + compiled = 1; + regcomp(&reg, "^#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}", + REG_EXTENDED|REG_NOSUB|REG_ICASE); + } + + if(*buflen < 23 || regexec(&reg, *buf, 0, 0, 0)) return "bad value"; - (*buflen) -= 23; - bcopy(*buf, col->colstr, 23); + + memcpy(col->colstr, *buf, 23); loadcolor(&blz, col); - (*buf) += 23; - if(**buf == '\n' || **buf == ' ') { + *buf += 23; + *buflen -= 23; + if(isspace(**buf)) { (*buf)++; (*buflen)--; } diff --git a/cmd/wmii/rule.c b/cmd/wmii/rule.c @@ -3,6 +3,7 @@ * See LICENSE file for license details. */ +#include <assert.h> #include <string.h> #include <stdlib.h> #include <util.h> @@ -33,9 +34,11 @@ trim(char *str, const char *chars) { void update_rules(Rule **rule, const char *data) { - int mode = IGNORE; + int state = IGNORE; Rule *rul; - char *p, *r = nil, *v = nil, regex[256], value[256]; + char regex[256], value[256]; + char *r, *v; + const char *p; if(!data || !strlen(data)) return; @@ -44,28 +47,26 @@ update_rules(Rule **rule, const char *data) { regfree(&rul->regex); free(rul); } - for(p = (char *)data; *p; p++) - switch(mode) { + for(p = data; *p; p++) + switch(state) { case IGNORE: if(*p == '/') { - mode = REGEX; r = regex; + state = REGEX; } else if(*p == '>') { - mode = VALUE; value[0] = 0; v = value; + state = VALUE; } break; case REGEX: if(*p == '/') { - mode = IGNORE; *r = 0; + state = IGNORE; } - else { - *r = *p; - r++; - } + else + *r++ = *p; break; case VALUE: if(*p == '\n' || *p == 0) { @@ -77,12 +78,12 @@ update_rules(Rule **rule, const char *data) { rule = &(*rule)->next; } else free(*rule); - mode = IGNORE; - } - else { - *v = *p; - v++; + state = IGNORE; } + else + *v++ = *p; break; + default: /* can't happen */ + assert(!"invalid state"); } } diff --git a/rc/rc.wmii.rc b/rc/rc.wmii.rc @@ -196,9 +196,6 @@ fn run_command { } } -# Source Overrides -. <{awk '/^# Overrides/, 0' $local </dev/null} - # WM Configuration wmiir write /ctl <<! grabmod $MODKEY @@ -208,6 +205,9 @@ focuscolors $WMII_FOCUSCOLORS normcolors $WMII_NORMCOLORS ! +# Source Overrides +. <{awk '/^# Overrides/, 0' $local </dev/null} + # Misc Setup xsetroot -solid $WMII_BACKGROUND Action status &