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" garbeam@75: garbeam@75: #include garbeam@75: #include garbeam@75: garbeam@84: /* static */ garbeam@76: garbeam@84: /* CUSTOMIZE */ garbeam@84: static Rule rule[] = { garbeam@84: /* class instance tags isfloat */ garbeam@84: { "Firefox-bin", "Gecko", { [Twww] = "www" }, False }, garbeam@84: }; garbeam@84: garbeam@84: /* extern */ garbeam@84: garbeam@84: /* CUSTOMIZE */ garbeam@76: char *tags[TLast] = { garbeam@76: [Tscratch] = "scratch", garbeam@76: [Tdev] = "dev", garbeam@76: [Twww] = "www", garbeam@76: [Twork] = "work", garbeam@76: }; garbeam@75: void (*arrange)(Arg *) = dotile; garbeam@75: garbeam@76: void garbeam@76: appendtag(Arg *arg) garbeam@75: { garbeam@76: if(!sel) garbeam@76: return; garbeam@75: garbeam@76: sel->tags[arg->i] = tags[arg->i]; garbeam@75: arrange(NULL); garbeam@75: } garbeam@75: garbeam@75: void garbeam@75: dofloat(Arg *arg) garbeam@75: { garbeam@75: Client *c; garbeam@75: garbeam@75: arrange = dofloat; garbeam@75: for(c = clients; c; c = c->next) { garbeam@75: if(c->tags[tsel]) garbeam@75: resize(c, True); garbeam@75: else garbeam@75: ban(c); garbeam@75: } garbeam@75: if(sel && !sel->tags[tsel]) { garbeam@93: if((sel = getnext(clients, tsel))) { garbeam@75: higher(sel); garbeam@75: focus(sel); garbeam@75: } garbeam@75: } garbeam@75: drawall(); garbeam@75: } garbeam@75: garbeam@75: void garbeam@75: dotile(Arg *arg) garbeam@75: { garbeam@75: Client *c; garbeam@75: int n, i, w, h; garbeam@75: garbeam@75: w = sw - mw; garbeam@75: arrange = dotile; garbeam@75: for(n = 0, c = clients; c; c = c->next) garbeam@80: if(c->tags[tsel] && !c->isfloat) garbeam@75: n++; garbeam@75: garbeam@75: if(n > 1) garbeam@75: h = (sh - bh) / (n - 1); garbeam@75: else garbeam@75: h = sh - bh; garbeam@75: garbeam@75: for(i = 0, c = clients; c; c = c->next) { garbeam@75: if(c->tags[tsel]) { garbeam@80: if(c->isfloat) { garbeam@75: higher(c); garbeam@75: resize(c, True); garbeam@75: continue; garbeam@75: } garbeam@75: if(n == 1) { garbeam@75: c->x = sx; garbeam@75: c->y = sy + bh; garbeam@75: c->w = sw - 2 * c->border; garbeam@75: c->h = sh - 2 * c->border - bh; garbeam@75: } garbeam@75: else if(i == 0) { garbeam@75: c->x = sx; garbeam@75: c->y = sy + bh; garbeam@75: c->w = mw - 2 * c->border; garbeam@75: c->h = sh - 2 * c->border - bh; garbeam@75: } garbeam@75: else { garbeam@75: c->x = sx + mw; garbeam@75: c->y = sy + (i - 1) * h + bh; garbeam@75: c->w = w - 2 * c->border; garbeam@75: c->h = h - 2 * c->border; garbeam@75: } garbeam@75: resize(c, False); garbeam@75: i++; garbeam@75: } garbeam@75: else garbeam@75: ban(c); garbeam@75: } garbeam@75: if(!sel || (sel && !sel->tags[tsel])) { garbeam@93: if((sel = getnext(clients, tsel))) { garbeam@75: higher(sel); garbeam@75: focus(sel); garbeam@75: } garbeam@75: } garbeam@75: drawall(); garbeam@75: } garbeam@75: garbeam@76: Client * garbeam@93: getnext(Client *c, unsigned int t) garbeam@75: { garbeam@93: for(; c && !c->tags[t]; c = c->next); garbeam@76: return c; garbeam@75: } garbeam@75: garbeam@75: void garbeam@93: heretag(Arg *arg) garbeam@93: { garbeam@93: int i; garbeam@93: Client *c; garbeam@93: garbeam@93: if(arg->i == tsel) garbeam@93: return; garbeam@93: garbeam@93: if(!(c = getnext(clients, arg->i))) garbeam@93: return; garbeam@93: garbeam@93: for(i = 0; i < TLast; i++) garbeam@93: c->tags[i] = NULL; garbeam@93: c->tags[tsel] = tags[tsel]; garbeam@93: arrange(NULL); garbeam@93: focus(c); garbeam@93: } garbeam@93: garbeam@93: void garbeam@75: replacetag(Arg *arg) garbeam@75: { garbeam@75: int i; garbeam@75: if(!sel) garbeam@75: return; garbeam@75: garbeam@75: for(i = 0; i < TLast; i++) garbeam@75: sel->tags[i] = NULL; garbeam@75: appendtag(arg); garbeam@75: } garbeam@75: garbeam@76: void garbeam@76: settags(Client *c) garbeam@76: { garbeam@76: XClassHint ch; garbeam@76: static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0; garbeam@76: unsigned int i, j; garbeam@76: Bool matched = False; garbeam@76: garbeam@76: if(!len) { garbeam@76: c->tags[tsel] = tags[tsel]; garbeam@76: return; garbeam@76: } garbeam@76: garbeam@76: if(XGetClassHint(dpy, c->win, &ch)) { garbeam@76: if(ch.res_class && ch.res_name) { garbeam@76: for(i = 0; i < len; i++) garbeam@76: if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class)) garbeam@76: && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance))) garbeam@76: { garbeam@76: for(j = 0; j < TLast; j++) garbeam@76: c->tags[j] = rule[i].tags[j]; garbeam@80: c->isfloat = rule[i].isfloat; garbeam@76: matched = True; garbeam@76: break; garbeam@76: } garbeam@76: } 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: garbeam@76: if(!matched) garbeam@76: c->tags[tsel] = tags[tsel]; garbeam@76: } garbeam@76: garbeam@76: void garbeam@76: view(Arg *arg) garbeam@76: { garbeam@76: tsel = arg->i; garbeam@76: arrange(NULL); garbeam@76: drawall(); garbeam@76: }