Hi there,

This is a patch for dwm 5.7.2 to switch tags with the algorithm LRU
(Least Recently Used). Just like the known alt+tab from other systems.
It also allows to switch the focused client tag with alt+shift+tab.

Authors: (*) Sherekan and (*) Bardamu.

Hope it will be useful.
214a215
> static void switchtag(const Arg *arg);
233a235
> static void refreshtagcache(int tagmask);
1522c1524,1525
<                       |PropertyChangeMask;
---
>                       |PropertyChangeMask
>                       |KeyReleaseMask;
1565a1569,1592
> 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
1569a1597,1598
>               refreshtagcache(arg->ui & TAGMASK);
>               refreshtagcache(selmon->tagset[selmon->seltags]);
1659a1689
>               refreshtagcache(selmon->tagset[selmon->seltags]);
1913a1944,1953
> 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
1920a1961
>       refreshtagcache(selmon->tagset[selmon->seltags]);
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