dwm-reorganizetags-6.2.diff (1898B)
1 diff --git a/config.def.h b/config.def.h 2 index 1c0b587..961a189 100644 3 --- a/config.def.h 4 +++ b/config.def.h 5 @@ -70,6 +70,7 @@ static Key keys[] = { 6 { MODKEY, XK_d, incnmaster, {.i = -1 } }, 7 { MODKEY, XK_h, setmfact, {.f = -0.05} }, 8 { MODKEY, XK_l, setmfact, {.f = +0.05} }, 9 + { MODKEY, XK_r, reorganizetags, {0} }, 10 { MODKEY, XK_Return, zoom, {0} }, 11 { MODKEY, XK_Tab, view, {0} }, 12 { MODKEY|ShiftMask, XK_c, killclient, {0} }, 13 diff --git a/dwm.c b/dwm.c 14 index 4465af1..723d675 100644 15 --- a/dwm.c 16 +++ b/dwm.c 17 @@ -188,6 +188,7 @@ static void pop(Client *); 18 static void propertynotify(XEvent *e); 19 static void quit(const Arg *arg); 20 static Monitor *recttomon(int x, int y, int w, int h); 21 +static void reorganizetags(const Arg *arg); 22 static void resize(Client *c, int x, int y, int w, int h, int interact); 23 static void resizeclient(Client *c, int x, int y, int w, int h); 24 static void resizemouse(const Arg *arg); 25 @@ -1265,6 +1266,33 @@ recttomon(int x, int y, int w, int h) 26 return r; 27 } 28 29 +void 30 +reorganizetags(const Arg *arg) { 31 + Client *c; 32 + unsigned int occ, unocc, i; 33 + unsigned int tagdest[LENGTH(tags)]; 34 + 35 + occ = 0; 36 + for (c = selmon->clients; c; c = c->next) 37 + occ |= (1 << (ffs(c->tags)-1)); 38 + unocc = 0; 39 + for (i = 0; i < LENGTH(tags); ++i) { 40 + while (unocc < i && (occ & (1 << unocc))) 41 + unocc++; 42 + if (occ & (1 << i)) { 43 + tagdest[i] = unocc; 44 + occ &= ~(1 << i); 45 + occ |= 1 << unocc; 46 + } 47 + } 48 + 49 + for (c = selmon->clients; c; c = c->next) 50 + c->tags = 1 << tagdest[ffs(c->tags)-1]; 51 + if (selmon->sel) 52 + selmon->tagset[selmon->seltags] = selmon->sel->tags; 53 + arrange(selmon); 54 +} 55 + 56 void 57 resize(Client *c, int x, int y, int w, int h, int interact) 58 {