changeset: 2261:ae4cc5595a32
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Jan 25 14:38:19 2008 -0500
summary: +/regex/ to add matching tags, -/regex/ to remove them. Higher level list processing.
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/_util.c
--- a/cmd/wmii/_util.c Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/_util.c Fri Jan 25 14:38:19 2008 -0500
@@ -37,8 +37,10 @@ reinit(Regex *r, char *regx) {
refree(r);
- r->regex = estrdup(regx);
- r->regc = regcomp(regx);
+ if(regx[0] != '\0') {
+ r->regex = estrdup(regx);
+ r->regc = regcomp(regx);
+ }
}
void
@@ -67,8 +69,7 @@ comm(int cols, char **toka, char **tokb)
comm(int cols, char **toka, char **tokb) {
Vector_ptr vec;
char **ret;
- char *p;
- int cmp, len, i;
+ int cmp, len;
len = 0;
vector_pinit(&vec);
@@ -100,16 +101,45 @@ comm(int cols, char **toka, char **tokb)
tokb++;
}
}
- ret = emalloc((vec.n+1) * sizeof(char*) + len);
- ret[vec.n] = nil;
- p = (char*)&ret[vec.n+1];
- for(i=0; i < vec.n; i++) {
- len = strlen(vec.ary[i]) + 1;
- memcpy(p, vec.ary[i], len);
- ret[i] = p;
- p += len;
- }
+ ret = strlistdup((char**)vec.ary, vec.n);
free(vec.ary);
return ret;
}
+char**
+grep(char **list, Reprog *re, int flags) {
+ Vector_ptr vec;
+ char **p;
+ int res;
+
+ vector_pinit(&vec);
+ for(p=list; *p; p++) {
+ res = 0;
+ if(re)
+ res = regexec(re, *p, nil, 0);
+ if(res && !(flags & GInvert)
+ || !res && (flags & GInvert))
+ vector_ppush(&vec, *p);
+ }
+ p = strlistdup((char**)vec.ary, vec.n);
+ free(vec.ary);
+ return p;
+}
+
+char*
+join(char **list, char *sep) {
+ Fmt f;
+ char **p;
+
+ if(fmtstrinit(&f) < 0)
+ abort();
+
+ for(p=list; *p; p++) {
+ if(p != list)
+ fmtstrcpy(&f, sep);
+ fmtstrcpy(&f, *p);
+ }
+
+ return fmtstrflush(&f);
+}
+
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/client.c
--- a/cmd/wmii/client.c Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/client.c Fri Jan 25 14:38:19 2008 -0500
@@ -246,6 +246,7 @@ client_destroy(Client *c) {
client_setviews(c, &none);
sethandler(&c->w, nil);
refree(&c->tagre);
+ refree(&c->tagvre);
free(c->retags);
if(hide)
@@ -914,6 +915,7 @@ client_setviews(Client *c, char **tags)
c->sel = f;
kludge = c;
view_attach(f->view, f);
+ kludge = nil;
f->cnext = *fp;
*fp = f;
}
@@ -947,13 +949,12 @@ static char *badtags[] = {
void
apply_tags(Client *c, const char *tags) {
- View *v;
uint i, j, k, n;
bool add;
char buf[512], last;
- char *toks[32], *vtags[32];
- char **p;
- char *cur;
+ char *toks[32];
+ char **p, **q;
+ char *cur, *s;
buf[0] = 0;
@@ -962,17 +963,16 @@ apply_tags(Client *c, const char *tags)
break;
if(tags[n] == '+' || tags[n] == '-')
- utflcpy(buf, c->tags, sizeof(c->tags));
-
- strlcat(buf, &tags[n], sizeof(buf));
+ utflcpy(buf, c->tags, sizeof c->tags);
+ strlcat(buf, &tags[n], sizeof buf);
n = 0;
- add = True;
+ add = true;
if(buf[0] == '+')
n++;
else if(buf[0] == '-') {
n++;
- add = False;
+ add = false;
}
j = 0;
@@ -992,7 +992,7 @@ apply_tags(Client *c, const char *tags)
if(add)
reinit(&c->tagre, buf+n+1);
else
- refree(&c->tagre);
+ reinit(&c->tagvre, buf+n+1);
last = buf[i];
buf[i] = '\0';
goto next;
@@ -1018,7 +1018,6 @@ apply_tags(Client *c, const char *tags)
if(!Mbsearch(buf+n, badtags, bsstrcmp))
cur = buf+n;
- n = i + 1;
if(cur && j < nelem(toks)-1) {
if(add)
toks[j++] = cur;
@@ -1031,10 +1030,11 @@ apply_tags(Client *c, const char *tags)
}
next:
+ n = i + 1;
if(last == '+')
- add = True;
+ add = true;
if(last == '-')
- add = False;
+ add = false;
if(last == '\0')
buf[n] = '\0';
}
@@ -1042,32 +1042,24 @@ apply_tags(Client *c, const char *tags)
toks[j] = nil;
qsort(toks, j, sizeof *toks, strpcmp);
uniq(toks);
- c->tags[0] = '\0';
- for(p=toks; *p; p++) {
- if(p > toks)
- strlcat(c->tags, "+", sizeof c->tags);
- strlcat(c->tags, *p, sizeof c->tags);
- }
-
- i = 0;
- if(c->tagre.regex)
- for(v=view; v; v=v->next)
- if(regexec(c->tagre.regc, v->name, nil, 0))
- if(i < nelem(vtags)-1)
- vtags[i++] = v->name;
- vtags[i] = nil;
+
+ s = join(toks, "+");
+ utflcpy(c->tags, s, sizeof c->tags);
+ free(s);
free(c->retags);
- c->retags = comm(CRight, toks, vtags);
-
- for(p=vtags; *p; p++)
- if(j < nelem(toks)-1)
- toks[j++] = *p;
- toks[j] = nil;
- qsort(toks, j, sizeof *toks, strpcmp);
- uniq(toks);
-
- client_setviews(c, toks);
+
+ p = view_names();
+ q = grep(p, c->tagre.regc, 0);
+ free(p);
+ p = grep(q, c->tagvre.regc, GInvert);
+ free(q);
+ c->retags = comm(CRight, toks, p);
+ free(p);
+
+ p = comm(~0, c->retags, toks);
+ client_setviews(c, p);
+ free(p);
changeprop_string(&c->w, "_WMII_TAGS", c->tags);
}
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/dat.h Fri Jan 25 14:38:19 2008 -0500
@@ -29,6 +29,10 @@ enum {
CLeft = 1<<0,
CCenter = 1<<1,
CRight = 1<<2,
+};
+
+enum {
+ GInvert = 1<<0,
};
enum {
@@ -144,6 +148,7 @@ struct Client {
Window* framewin;
XWindow trans;
Regex tagre;
+ Regex tagvre;
Group* group;
Strut* strut;
Cursor cursor;
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/ewmh.c
--- a/cmd/wmii/ewmh.c Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/ewmh.c Fri Jan 25 14:38:19 2008 -0500
@@ -70,18 +70,14 @@ ewmh_init(void) {
void
ewmh_updateclientlist(void) {
+ Vector_long vec;
Client *c;
- long *list;
- int i;
-
- i = 0;
+
+ vector_linit(&vec);
for(c=client; c; c=c->next)
- i++;
- list = emalloc(i * sizeof *list);
- i = 0;
- for(c=client; c; c=c->next)
- list[i++] = c->w.w;
- changeprop_long(&scr.root, Net("CLIENT_LIST"), "WINDOW", list, i);
+ vector_lpush(&vec, c->w.w);
+ changeprop_long(&scr.root, Net("CLIENT_LIST"), "WINDOW", vec.ary, vec.n);
+ free(vec.ary);
}
void
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/fns.h Fri Jan 25 14:38:19 2008 -0500
@@ -207,6 +207,7 @@ void view_focus(WMScreen*, View*);
void view_focus(WMScreen*, View*);
bool view_fullscreen_p(View*);
char* view_index(View*);
+char** view_names(void);
uint view_newcolw(View*, int i);
void view_restack(View*);
void view_scale(View*, int w);
@@ -217,9 +218,11 @@ Rectangle* view_rects(View*, uint *num,
Rectangle* view_rects(View*, uint *num, Frame *ignore);
/* util.c */
+char** comm(int, char**, char**);
+char** grep(char**, Reprog*, int);
+char* join(char**, char*);
void refree(Regex*);
void reinit(Regex*, char*);
-char** comm(int, char**, char**);
void uniq(char**);
/* utf.c */
diff -r 487d96a8c4d2 -r ae4cc5595a32 cmd/wmii/view.c
--- a/cmd/wmii/view.c Thu Jan 24 22:55:45 2008 -0500
+++ b/cmd/wmii/view.c Fri Jan 25 14:38:19 2008 -0500
@@ -5,6 +5,10 @@
#include "dat.h"
#include "fns.h"
+#define foreach_frame(v, a, f) \
+ for((a)=(v)->area; (a); (a)=(a)->next) \
+ for((f)=(a)->frame; (f); (f)=(f)->anext)
+
static bool
empty_p(View *v) {
Frame *f;
@@ -12,19 +16,18 @@ empty_p(View *v) {
char **p;
int cmp;
- for(a=v->area; a; a=a->next)
- for(f=a->frame; f; f=f->anext) {
- for(p=f->client->retags; *p; p++) {
- cmp = strcmp(*p, v->name);
- if(cmp == 0)
- goto nextframe;
- if(cmp > 0)
- return false;
- }
- return false;
- nextframe:
- continue;
- }
+ foreach_frame(v, a, f) {
+ for(p=f->client->retags; *p; p++) {
+ cmp = strcmp(*p, v->name);
+ if(cmp == 0)
+ goto nextframe;
+ if(cmp > 0)
+ return false;
+ }
+ return false;
+ nextframe:
+ continue;
+ }
return true;
}
@@ -65,10 +68,6 @@ view_create(const char *name) {
if(!strcmp(name, v->name))
return v;
- print("xviews:\n");
- for(View *q=view; q; q=q->next)
- print("view: %d %s\n", !strcmp(name, q->name), q->name);
-
v = emallocz(sizeof(View));
v->id = id++;
v->r = screen->r;
@@ -104,18 +103,22 @@ void
void
view_destroy(View *v) {
View **vp;
- Frame *f;
+ Frame *f, *fn;
View *tv;
- Area *a;
+ Area *a, *an;
for(vp=&view; *vp; vp=&(*vp)->next)
if(*vp == v) break;
*vp = v->next;
/* FIXME: Can do better */
- for(a=v->area; a; a=a->next)
- for(f=a->frame; f; f=f->anext)
+ for(a=v->area; a; a=an) {
+ an = a->next;
+ for(f=a->frame; f; f=fn) {
+ fn = f->anext;
apply_tags(f->client, f->client->tags);
+ }
+ }
while((a = v->area->next))
area_destroy(a);
@@ -150,9 +153,8 @@ update_frame_selectors(View *v) {
Area *a;
Frame *f;
- for(a=v->area; a; a=a->next)
- for(f=a->frame; f; f=f->anext)
- f->client->sel = f;
+ foreach_frame(v, a, f)
+ f->client->sel = f;
}
void
@@ -297,6 +299,18 @@ view_attach(View *v, Frame *f) {
c->sel = f;
}
+char**
+view_names(void) {
+ Vector_ptr vec;
+ View *v;
+
+ vector_pinit(&vec);
+ for(v=view; v; v=v->next)
+ vector_ppush(&vec, v->name);
+ vector_ppush(&vec, nil);
+ return erealloc(vec.ary, vec.n * sizeof *vec.ary);
+}
+
void
view_restack(View *v) {
static Vector_long wins;
@@ -484,7 +498,7 @@ view_index(View *v) {
int i;
bufclear();
- for((a=v->area), (i=0); a; (a=a->next), i++) {
+ for(a=v->area, i=0; a; a=a->next, i++) {
if(a->floating)
bufprint("# ~ %d %d\n", Dx(a->r), Dy(a->r));
else
Received on Fri Jan 25 2008 - 20:41:30 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:10 UTC