JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
code polishing, removed unnecessary newlines
[dwm.git] / tag.c
diff --git a/tag.c b/tag.c
index 7bc4da0..70a1553 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -1,5 +1,4 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
+/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 #include "dwm.h"
@@ -33,22 +32,19 @@ static unsigned int len = 0;
 /* extern */
 
 Client *
-getnext(Client *c)
-{
+getnext(Client *c) {
        for(; c && !isvisible(c); c = c->next);
        return c;
 }
 
 Client *
-getprev(Client *c)
-{
+getprev(Client *c) {
        for(; c && !isvisible(c); c = c->prev);
        return c;
 }
 
 void
-initrregs()
-{
+initrregs(void) {
        unsigned int i;
        regex_t *reg;
 
@@ -56,7 +52,6 @@ initrregs()
                return;
        len = sizeof(rule) / sizeof(rule[0]);
        rreg = emallocz(len * sizeof(RReg));
-
        for(i = 0; i < len; i++) {
                if(rule[i].clpattern) {
                        reg = emallocz(sizeof(regex_t));
@@ -76,15 +71,18 @@ initrregs()
 }
 
 void
-settags(Client *c)
-{
+settags(Client *c, Client *trans) {
        char prop[512];
        unsigned int i, j;
        regmatch_t tmp;
-       Bool matched = False;
+       Bool matched = trans != NULL;
        XClassHint ch;
 
-       if(XGetClassHint(dpy, c->win, &ch)) {
+       if(matched) {
+               for(i = 0; i < ntags; i++)
+                       c->tags[i] = trans->tags[i];
+       }
+       else if(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);
@@ -106,45 +104,32 @@ settags(Client *c)
        if(!matched)
                for(i = 0; i < ntags; i++)
                        c->tags[i] = seltag[i];
+       for(c->weight = 0; c->weight < ntags && !c->tags[c->weight]; c->weight++);
 }
 
 void
-tag(Arg *arg)
-{
+tag(Arg *arg) {
        unsigned int i;
 
        if(!sel)
                return;
-
        for(i = 0; i < ntags; i++)
                sel->tags[i] = False;
        sel->tags[arg->i] = True;
-       settitle(sel);
-       detach(sel);
-       attach(sel);
-       if(!isvisible(sel))
-               arrange(NULL);
-       else
-               drawstatus();
+       sel->weight = arg->i;
+       arrange(NULL);
 }
 
 void
-toggletag(Arg *arg)
-{
+toggletag(Arg *arg) {
        unsigned int i;
 
        if(!sel)
                return;
-
        sel->tags[arg->i] = !sel->tags[arg->i];
        for(i = 0; i < ntags && !sel->tags[i]; i++);
        if(i == ntags)
                sel->tags[arg->i] = True;
-       settitle(sel);
-       detach(sel);
-       attach(sel);
-       if(!isvisible(sel))
-               arrange(NULL);
-       else
-               drawstatus();
+       sel->weight = (i == ntags) ? arg->i : i;
+       arrange(NULL);
 }