From 44206a27f3c91eddd458ddc9d12514cbb65e19c3 Mon Sep 17 00:00:00 2001 From: Jakub Date: Fri, 24 May 2024 20:43:21 -0400 Subject: [PATCH] add tag reo-organiuzation to resetlayout --- dwm.c | 30 ++++++++++ patches/behavior/dwm-reorganizetags-6.2.diff | 58 ++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 patches/behavior/dwm-reorganizetags-6.2.diff diff --git a/dwm.c b/dwm.c index df20470..7f2e260 100644 --- a/dwm.c +++ b/dwm.c @@ -224,6 +224,7 @@ static void pop(Client *c); static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); +static void reorganizetags(const Arg *arg); static void resetlayout(const Arg *arg); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); @@ -1797,6 +1798,35 @@ resetlayout(const Arg *arg) selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = nmaster; arrange(selmon); + + reorganizetags(0); +} + +void +reorganizetags(const Arg *arg) { + Client *c; + unsigned int occ, unocc, i; + unsigned int tagdest[LENGTH(tags)]; + + occ = 0; + for (c = selmon->clients; c; c = c->next) + occ |= (1 << (ffs(c->tags)-1)); + unocc = 0; + for (i = 0; i < LENGTH(tags); ++i) { + while (unocc < i && (occ & (1 << unocc))) + unocc++; + if (occ & (1 << i)) { + tagdest[i] = unocc; + occ &= ~(1 << i); + occ |= 1 << unocc; + } + } + + for (c = selmon->clients; c; c = c->next) + c->tags = 1 << tagdest[ffs(c->tags)-1]; + if (selmon->sel) + selmon->tagset[selmon->seltags] = selmon->sel->tags; + arrange(selmon); } void diff --git a/patches/behavior/dwm-reorganizetags-6.2.diff b/patches/behavior/dwm-reorganizetags-6.2.diff new file mode 100644 index 0000000..23d4e3a --- /dev/null +++ b/patches/behavior/dwm-reorganizetags-6.2.diff @@ -0,0 +1,58 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..961a189 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -70,6 +70,7 @@ static Key keys[] = { + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, ++ { MODKEY, XK_r, reorganizetags, {0} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, +diff --git a/dwm.c b/dwm.c +index 4465af1..723d675 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -188,6 +188,7 @@ static void pop(Client *); + static void propertynotify(XEvent *e); + static void quit(const Arg *arg); + static Monitor *recttomon(int x, int y, int w, int h); ++static void reorganizetags(const Arg *arg); + static void resize(Client *c, int x, int y, int w, int h, int interact); + static void resizeclient(Client *c, int x, int y, int w, int h); + static void resizemouse(const Arg *arg); +@@ -1265,6 +1266,33 @@ recttomon(int x, int y, int w, int h) + return r; + } + ++void ++reorganizetags(const Arg *arg) { ++ Client *c; ++ unsigned int occ, unocc, i; ++ unsigned int tagdest[LENGTH(tags)]; ++ ++ occ = 0; ++ for (c = selmon->clients; c; c = c->next) ++ occ |= (1 << (ffs(c->tags)-1)); ++ unocc = 0; ++ for (i = 0; i < LENGTH(tags); ++i) { ++ while (unocc < i && (occ & (1 << unocc))) ++ unocc++; ++ if (occ & (1 << i)) { ++ tagdest[i] = unocc; ++ occ &= ~(1 << i); ++ occ |= 1 << unocc; ++ } ++ } ++ ++ for (c = selmon->clients; c; c = c->next) ++ c->tags = 1 << tagdest[ffs(c->tags)-1]; ++ if (selmon->sel) ++ selmon->tagset[selmon->seltags] = selmon->sel->tags; ++ arrange(selmon); ++} ++ + void + resize(Client *c, int x, int y, int w, int h, int interact) + {