Forget the other one.

2009/12/2 markus schnalke <[email protected]>

> [2009-12-02 13:02] =?ISO-8859-1?Q?M=2E_Huil=E9n_Abed_Moure?= <
> [email protected]>
> >
> > This is a patch [...]
>
> Please use
>
>        diff -u ...
>
> next time.
>
>
> meillo
>
>
--- dwm-5.7.2/dwm.c     2009-09-27 16:20:23.000000000 -0300
+++ dwm.cc      2009-12-04 23:08:27.098638635 -0300
@@ -212,6 +212,7 @@
 static void showhide(Client *c);
 static void sigchld(int unused);
 static void spawn(const Arg *arg);
+static void switchtag(const Arg *arg);
 static void tag(const Arg *arg);
 static void tagmon(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
@@ -231,6 +232,7 @@
 static void updatestatus(void);
 static void updatetitle(Client *c);
 static void updatewmhints(Client *c);
+static void refreshtagcache(int tagmask);
 static void view(const Arg *arg);
 static Client *wintoclient(Window w);
 static Monitor *wintomon(Window w);
@@ -298,6 +300,7 @@
                        {
                                c->isfloating = r->isfloating;
                                c->tags |= r->tags;
+                               refreshtagcache(c->tags);
                                for(m = mons; m && m->num != r->monitor; m = 
m->next);
                                if(m)
                                        c->mon = m;
@@ -1519,7 +1522,8 @@
        wa.cursor = cursor[CurNormal];
        wa.event_mask = 
SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
                        |EnterWindowMask|LeaveWindowMask|StructureNotifyMask
-                       |PropertyChangeMask;
+                       |PropertyChangeMask
+                       |KeyReleaseMask;
        XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
        XSelectInput(dpy, root, wa.event_mask);
        grabkeys();
@@ -1563,10 +1567,36 @@
 }
 
 void
+switchtag(const Arg *arg) {
+       Client *c;
+       unsigned int i = 0;
+       Client *selclient = selmon->sel;
+       const XEvent ev = {.type = 0};
+
+       if (selmon->clients == NULL) return;
+       XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, 
CurrentTime);
+       do {
+               if (ev.type == KeyRelease) continue;
+               do {
+                       if (++i >= LENGTH(tagcache) || tagcache[i] == -1) i = 0;
+                       for (c = selmon->clients; c != NULL && !(c->tags & 
tagcache[i]); c = c->next);
+               } while (c == NULL);
+               if ((arg->ui == 1)) selclient->tags = tagcache[i];
+               selmon->tagset[selmon->seltags] = tagcache[i];
+               arrange(selmon);
+       } while (!XMaskEvent(dpy, KeyReleaseMask|KeyPressMask, (XEvent*)&ev) &&
+                       ((XKeycodeToKeysym(dpy, (KeyCode)ev.xkey.keycode, 0) == 
SWITCHTAGKEY)));
+       XUngrabKeyboard(dpy, CurrentTime);
+       refreshtagcache(selmon->tagset[selmon->seltags]);
+}
+
+void
 tag(const Arg *arg) {
        if(selmon->sel && arg->ui & TAGMASK) {
                selmon->sel->tags = arg->ui & TAGMASK;
                arrange(selmon);
+               refreshtagcache(arg->ui & TAGMASK);
+               refreshtagcache(selmon->tagset[selmon->seltags]);
        }
 }
 
@@ -1657,6 +1687,7 @@
        if(newtagset) {
                selmon->tagset[selmon->seltags] = newtagset;
                arrange(selmon);
+               refreshtagcache(selmon->tagset[selmon->seltags]);
        }
 }
 
@@ -1911,6 +1942,16 @@
 }
 
 void
+refreshtagcache(int tagmask) {
+       unsigned int i;
+       if((tagcache[0] == tagmask)) return;
+       for (i = 1; i <= LENGTH(tagcache)-1 && tagcache[i] != tagmask; i++);
+       if (i == LENGTH(tagcache)) i = LENGTH(tagcache) - 1;
+       for (; i > 0; i--) tagcache[i] = tagcache[i-1];
+       tagcache[0] = tagmask;
+}
+
+void
 view(const Arg *arg) {
        if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
                return;
@@ -1918,6 +1959,7 @@
        if(arg->ui & TAGMASK)
                selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
        arrange(selmon);
+       refreshtagcache(selmon->tagset[selmon->seltags]);
 }
 
 Client *
17a18
> static int tagcache[] = {1, -1, -1, -1, -1, -1, -1, -1, -1};
37a39
> #define SWITCHTAGKEY XK_Tab
61c63,64
<       { MODKEY,                       XK_Tab,    view,           {0} },
---
>       { MODKEY,                       SWITCHTAGKEY,    switchtag,      {.ui = 
> 0} },
>       { MODKEY|ShiftMask,             SWITCHTAGKEY,    switchtag,      {.ui = 
> 1} },

Reply via email to