garbeam@75: /* garbeam@75: * (C)opyright MMVI Anselm R. Garbe garbeam@75: * See LICENSE file for license details. garbeam@75: */ garbeam@76: #include "dwm.h" arg@114: #include arg@114: #include arg@191: #include garbeam@75: #include arg@114: #include garbeam@75: #include garbeam@75: garbeam@76: arg@114: typedef struct { arg@191: const char *clpattern; arg@191: const char *tpattern; arg@114: Bool isfloat; arg@114: } Rule; arg@114: arg@191: typedef struct { arg@191: regex_t *clregex; arg@191: regex_t *tregex; arg@191: } RReg; arg@191: arg@191: /* static */ arg@191: arg@146: TAGS arg@146: RULES garbeam@84: arg@191: static RReg *rreg = NULL; arg@191: static unsigned int len = 0; arg@191: arg@383: static void arg@384: commit() arg@383: { arg@383: /* asserts sel != NULL */ arg@383: settitle(sel); arg@383: if(!isvisible(sel)) arg@383: arrange(NULL); arg@383: else arg@383: drawstatus(); arg@383: } arg@383: arg@125: /* extern */ arg@125: garbeam@76: Client * arg@142: getnext(Client *c) garbeam@75: { arg@261: for(; c && !isvisible(c); c = c->next); garbeam@76: return c; garbeam@75: } garbeam@75: arg@127: Client * arg@127: getprev(Client *c) arg@127: { arg@261: for(; c && !isvisible(c); c = c->prev); arg@127: return c; arg@127: } arg@127: garbeam@75: void arg@191: initrregs() arg@191: { arg@191: unsigned int i; arg@191: regex_t *reg; arg@191: arg@191: if(rreg) arg@191: return; arg@191: len = sizeof(rule) / sizeof(rule[0]); arg@191: rreg = emallocz(len * sizeof(RReg)); arg@191: arg@191: for(i = 0; i < len; i++) { arg@191: if(rule[i].clpattern) { arg@191: reg = emallocz(sizeof(regex_t)); arg@191: if(regcomp(reg, rule[i].clpattern, 0)) arg@191: free(reg); arg@191: else arg@191: rreg[i].clregex = reg; arg@191: } arg@191: if(rule[i].tpattern) { arg@191: reg = emallocz(sizeof(regex_t)); arg@191: if(regcomp(reg, rule[i].tpattern, 0)) arg@191: free(reg); arg@191: else arg@191: rreg[i].tregex = reg; arg@191: } arg@191: } arg@191: } arg@191: arg@270: void garbeam@76: settags(Client *c) garbeam@76: { arg@336: char prop[512]; arg@191: unsigned int i, j; arg@114: regmatch_t tmp; garbeam@76: Bool matched = False; arg@114: XClassHint ch; garbeam@76: garbeam@76: if(XGetClassHint(dpy, c->win, &ch)) { arg@336: snprintf(prop, sizeof(prop), "%s:%s:%s", arg@114: ch.res_class ? ch.res_class : "", arg@336: ch.res_name ? ch.res_name : "", c->name); arg@191: for(i = 0; !matched && i < len; i++) arg@336: if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { arg@191: c->isfloat = rule[i].isfloat; arg@191: for(j = 0; rreg[i].tregex && j < ntags; j++) { arg@191: if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { arg@191: matched = True; arg@191: c->tags[j] = True; arg@191: } garbeam@76: } arg@114: } garbeam@76: if(ch.res_class) garbeam@76: XFree(ch.res_class); garbeam@76: if(ch.res_name) garbeam@76: XFree(ch.res_name); garbeam@76: } garbeam@76: if(!matched) arg@261: for(i = 0; i < ntags; i++) arg@262: c->tags[i] = seltag[i]; arg@381: for(i = 0; i < ntags && !c->tags[i]; i++); arg@381: c->weight = i; garbeam@76: } garbeam@76: garbeam@76: void arg@284: tag(Arg *arg) arg@284: { arg@284: unsigned int i; arg@284: arg@284: if(!sel) arg@284: return; arg@284: arg@284: for(i = 0; i < ntags; i++) arg@284: sel->tags[i] = False; arg@284: sel->tags[arg->i] = True; arg@384: commit(); arg@284: } arg@284: arg@284: void arg@284: toggletag(Arg *arg) arg@284: { arg@284: unsigned int i; arg@284: arg@284: if(!sel) arg@284: return; arg@284: arg@284: sel->tags[arg->i] = !sel->tags[arg->i]; arg@284: for(i = 0; i < ntags && !sel->tags[i]; i++); arg@284: if(i == ntags) arg@284: sel->tags[arg->i] = True; arg@384: commit(); arg@284: }