Added ability to deselect ALL tags, removing all windows from view.
[dwm] / dwm.c
diff --git a/dwm.c b/dwm.c
index a507385..14fe6cc 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -235,6 +235,11 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
 
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
 
+static void keyrelease(XEvent *e);
+static void combotag(const Arg *arg);
+static void comboview(const Arg *arg);
+
+
 /* variables */
 static const char broken[] = "broken";
 static char stext[256];
 /* variables */
 static const char broken[] = "broken";
 static char stext[256];
@@ -246,6 +251,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
 static unsigned int numlockmask = 0;
 static void (*handler[LASTEvent]) (XEvent *) = {
        [ButtonPress] = buttonpress,
 static unsigned int numlockmask = 0;
 static void (*handler[LASTEvent]) (XEvent *) = {
        [ButtonPress] = buttonpress,
+       [ButtonRelease] = keyrelease,
        [ClientMessage] = clientmessage,
        [ConfigureRequest] = configurerequest,
        [ConfigureNotify] = configurenotify,
        [ClientMessage] = clientmessage,
        [ConfigureRequest] = configurerequest,
        [ConfigureNotify] = configurenotify,
@@ -253,6 +259,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
        [EnterNotify] = enternotify,
        [Expose] = expose,
        [FocusIn] = focusin,
        [EnterNotify] = enternotify,
        [Expose] = expose,
        [FocusIn] = focusin,
+       [KeyRelease] = keyrelease,
        [KeyPress] = keypress,
        [MappingNotify] = mappingnotify,
        [MapRequest] = maprequest,
        [KeyPress] = keypress,
        [MappingNotify] = mappingnotify,
        [MapRequest] = maprequest,
@@ -276,6 +283,42 @@ static Window root, wmcheckwin;
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
 /* function implementations */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
 /* function implementations */
+static int combo = 0;
+
+void
+keyrelease(XEvent *e) {
+       combo = 0;
+}
+
+void
+combotag(const Arg *arg) {
+       if(selmon->sel && arg->ui & TAGMASK) {
+               if (combo) {
+                       selmon->sel->tags |= arg->ui & TAGMASK;
+               } else {
+                       combo = 1;
+                       selmon->sel->tags = arg->ui & TAGMASK;
+               }
+               focus(NULL);
+               arrange(selmon);
+       }
+}
+
+void
+comboview(const Arg *arg) {
+       unsigned newtags = arg->ui & TAGMASK;
+       if (combo) {
+               selmon->tagset[selmon->seltags] |= newtags;
+       } else {
+               selmon->seltags ^= 1;   /*toggle tagset*/
+               combo = 1;
+               if (newtags)
+                       selmon->tagset[selmon->seltags] = newtags;
+       }
+       focus(NULL);
+       arrange(selmon);
+}
+
 void
 applyrules(Client *c)
 {
 void
 applyrules(Client *c)
 {
@@ -309,7 +352,9 @@ applyrules(Client *c)
                XFree(ch.res_class);
        if (ch.res_name)
                XFree(ch.res_name);
                XFree(ch.res_class);
        if (ch.res_name)
                XFree(ch.res_name);
-       c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
+       if(c->tags & TAGMASK)                    c->tags = c->tags & TAGMASK;
+       else if(c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags];
+       else                                     c->tags = 1;
 }
 
 int
 }
 
 int
@@ -637,7 +682,7 @@ createmon(void)
        Monitor *m;
 
        m = ecalloc(1, sizeof(Monitor));
        Monitor *m;
 
        m = ecalloc(1, sizeof(Monitor));
-       m->tagset[0] = m->tagset[1] = 1;
+       m->tagset[0] = m->tagset[1] = startontag ? 1 : 0;
        m->mfact = mfact;
        m->nmaster = nmaster;
        m->showbar = showbar;
        m->mfact = mfact;
        m->nmaster = nmaster;
        m->showbar = showbar;
@@ -1421,7 +1466,7 @@ sendmon(Client *c, Monitor *m)
        detach(c);
        detachstack(c);
        c->mon = m;
        detach(c);
        detachstack(c);
        c->mon = m;
-       c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+       c->tags = (m->tagset[m->seltags] ? m->tagset[m->seltags] : 1);
        attach(c);
        attachstack(c);
        focus(NULL);
        attach(c);
        attachstack(c);
        focus(NULL);
@@ -1741,11 +1786,9 @@ toggleview(const Arg *arg)
 {
        unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
 
 {
        unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
 
-       if (newtagset) {
-               selmon->tagset[selmon->seltags] = newtagset;
-               focus(NULL);
-               arrange(selmon);
-       }
+       selmon->tagset[selmon->seltags] = newtagset;
+       focus(NULL);
+       arrange(selmon);
 }
 
 void
 }
 
 void
@@ -2039,7 +2082,7 @@ updatewmhints(Client *c)
 void
 view(const Arg *arg)
 {
 void
 view(const Arg *arg)
 {
-       if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+       if(arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
                return;
        selmon->seltags ^= 1; /* toggle sel tagset */
        if (arg->ui & TAGMASK)
                return;
        selmon->seltags ^= 1; /* toggle sel tagset */
        if (arg->ui & TAGMASK)