X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=tag.c;h=aecf048760a116dc5ae0b06dcfc9ab653d2337ad;hp=d29a179863ee7bcc89e1745a480aaed989858cc3;hb=d934296476be7345842fec1a2630d1752c704078;hpb=58f2fe3f6af3d6f8c925125c721a2d1800d750dc diff --git a/tag.c b/tag.c index d29a179..aecf048 100644 --- a/tag.c +++ b/tag.c @@ -1,200 +1,157 @@ -/* - * (C)opyright MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ +/* © 2006-2007 Anselm R. Garbe + * © 2006-2007 Sander van Dijk + * © 2006-2007 Jukka Salmi + * © 2007 Premysl Hruby + * © 2007 Szabolcs Nagy + * See LICENSE file for license details. */ #include "dwm.h" - -#include +#include +#include +#include #include /* static */ -/* CUSTOMIZE */ -static Rule rule[] = { - /* class instance tags isfloat */ - { "Firefox-bin", "Gecko", { [Twww] = "www" }, False }, -}; +typedef struct { + const char *prop; + const char *tags; + Bool isfloating; +} Rule; -/* extern */ +typedef struct { + regex_t *propregex; + regex_t *tagregex; +} Regs; -/* CUSTOMIZE */ -char *tags[TLast] = { - [Tscratch] = "scratch", - [Tdev] = "dev", - [Twww] = "www", - [Twork] = "work", -}; -void (*arrange)(Arg *) = dotile; +TAGS +RULES -void -appendtag(Arg *arg) -{ - if(!sel) - return; +static Regs *regs = NULL; +static unsigned int nrules = 0; - sel->tags[arg->i] = tags[arg->i]; - arrange(NULL); -} +/* extern */ void -dofloat(Arg *arg) -{ - Client *c; - - arrange = dofloat; - for(c = clients; c; c = c->next) { - setgeom(c); - if(c->tags[tsel]) { - resize(c, True); +compileregs(void) { + unsigned int i; + regex_t *reg; + + if(regs) + return; + nrules = sizeof rule / sizeof rule[0]; + regs = emallocz(nrules * sizeof(Regs)); + for(i = 0; i < nrules; i++) { + if(rule[i].prop) { + reg = emallocz(sizeof(regex_t)); + if(regcomp(reg, rule[i].prop, REG_EXTENDED)) + free(reg); + else + regs[i].propregex = reg; } - else - ban(c); - } - if(sel && !sel->tags[tsel]) { - if((sel = getnext(clients, tsel))) { - higher(sel); - focus(sel); + if(rule[i].tags) { + reg = emallocz(sizeof(regex_t)); + if(regcomp(reg, rule[i].tags, REG_EXTENDED)) + free(reg); + else + regs[i].tagregex = reg; } } - drawall(); +} + +Bool +isvisible(Client *c) { + unsigned int i; + + for(i = 0; i < ntags; i++) + if(c->tags[i] && seltag[i]) + return True; + return False; } void -dotile(Arg *arg) -{ - Client *c; - int n, i, w, h; - - w = sw - mw; - arrange = dotile; - for(n = 0, c = clients; c; c = c->next) - if(c->tags[tsel] && !c->isfloat) - n++; - - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; - - for(i = 0, c = clients; c; c = c->next) { - setgeom(c); - if(c->tags[tsel]) { - if(c->isfloat) { - higher(c); - resize(c, True); - continue; - } - if(n == 1) { - *c->x = sx; - *c->y = sy + bh; - *c->w = sw - 2 * c->border; - *c->h = sh - 2 * c->border - bh; - } - else if(i == 0) { - *c->x = sx; - *c->y = sy + bh; - *c->w = mw - 2 * c->border; - *c->h = sh - 2 * c->border - bh; - } - else { - *c->x = sx + mw; - *c->y = sy + (i - 1) * h + bh; - *c->w = w - 2 * c->border; - *c->h = h - 2 * c->border; +settags(Client *c, Client *trans) { + char prop[512]; + unsigned int i, j; + regmatch_t tmp; + Bool matched = trans != NULL; + XClassHint ch = { 0 }; + + if(matched) + for(i = 0; i < ntags; i++) + c->tags[i] = trans->tags[i]; + else { + XGetClassHint(dpy, c->win, &ch); + snprintf(prop, sizeof prop, "%s:%s:%s", + ch.res_class ? ch.res_class : "", + ch.res_name ? ch.res_name : "", c->name); + for(i = 0; i < nrules; i++) + if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) { + c->isfloating = rule[i].isfloating; + for(j = 0; regs[i].tagregex && j < ntags; j++) { + if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { + matched = True; + c->tags[j] = True; + } + } } - resize(c, False); - i++; - } - else - ban(c); - } - if(!sel || (sel && !sel->tags[tsel])) { - if((sel = getnext(clients, tsel))) { - higher(sel); - focus(sel); - } + if(ch.res_class) + XFree(ch.res_class); + if(ch.res_name) + XFree(ch.res_name); } - drawall(); -} - -Client * -getnext(Client *c, unsigned int t) -{ - for(; c && !c->tags[t]; c = c->next); - return c; + if(!matched) + for(i = 0; i < ntags; i++) + c->tags[i] = seltag[i]; } void -heretag(Arg *arg) -{ +tag(const char *arg) { int i; - Client *c; - - if(arg->i == tsel) - return; - if(!(c = getnext(clients, arg->i))) + if(!sel) return; - - for(i = 0; i < TLast; i++) - c->tags[i] = NULL; - c->tags[tsel] = tags[tsel]; - pop(c); - focus(c); + for(i = 0; i < ntags; i++) + sel->tags[i] = arg == NULL; + i = arg ? atoi(arg) : 0; + if(i >= 0 && i < ntags) + sel->tags[i] = True; + lt->arrange(); } void -replacetag(Arg *arg) -{ - int i; +toggletag(const char *arg) { + int i, j; + if(!sel) return; - - for(i = 0; i < TLast; i++) - sel->tags[i] = NULL; - appendtag(arg); + i = arg ? atoi(arg) : 0; + sel->tags[i] = !sel->tags[i]; + for(j = 0; j < ntags && !sel->tags[j]; j++); + if(j == ntags) + sel->tags[i] = True; + lt->arrange(); } void -settags(Client *c) -{ - XClassHint ch; - static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0; - unsigned int i, j; - Bool matched = False; - - if(!len) { - c->tags[tsel] = tags[tsel]; - return; - } - - if(XGetClassHint(dpy, c->win, &ch)) { - if(ch.res_class && ch.res_name) { - for(i = 0; i < len; i++) - if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class)) - && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance))) - { - for(j = 0; j < TLast; j++) - c->tags[j] = rule[i].tags[j]; - c->isfloat = rule[i].isfloat; - matched = True; - break; - } - } - if(ch.res_class) - XFree(ch.res_class); - if(ch.res_name) - XFree(ch.res_name); - } - - if(!matched) - c->tags[tsel] = tags[tsel]; +toggleview(const char *arg) { + int i, j; + + i = arg ? atoi(arg) : 0; + seltag[i] = !seltag[i]; + for(j = 0; j < ntags && !seltag[j]; j++); + if(j == ntags) + seltag[i] = True; /* cannot toggle last view */ + lt->arrange(); } void -view(Arg *arg) -{ - tsel = arg->i; - arrange(NULL); - drawall(); +view(const char *arg) { + int i; + + for(i = 0; i < ntags; i++) + seltag[i] = arg == NULL; + i = arg ? atoi(arg) : 0; + if(i >= 0 && i < ntags) + seltag[i] = True; + lt->arrange(); }