reorganize tags patch; squashing two commits to fix patching error and whitespace complaint

This commit is contained in:
zoigmant 2026-03-29 18:29:36 -07:00
parent 998808b303
commit 87be65900d
3 changed files with 222 additions and 0 deletions

View File

@ -0,0 +1,37 @@
### Reorganize Tags
Implements the functionality of the reorganize tags patch in the dwm patch.
From the dwm patch:
> Shifts all clients per tag to leftmost unoccupied tags.
> For example, if clients A, B, C are tagged on tags 1, 5, 9 respectively, when
> this function is called, they will now be on 1, 2, and 3. The focused client
> will also remain focused.
> Clients on multiple tags will be treated as if they only were only on their
> leftmost tag, and will be reduced to one tag after the operation is complete.
#### Distribute Tags
> This provides an additional feature to distribute the clients through
> the tags as evenly as possible.
> (The tags are filled left-to-right, looping back if necessary.)
> Eg, if there are 9 clients and 9 tags then each tag will have one
> client. If there are 19 clients, then 3 will be tagged onto tag 1, and
> 2 will be tagged onto each of tags 2 to 9.
### Download
- [main 2026-03-25](/dwl/dwl-patches/raw/branch/rmain/patches/reorganizetags/reorganizetags.patch)
- [with bar patch](/dwl/dwl-patches/raw/branch/rmain/patches/reorganizetags/reorganizetags-bar.patch)
With the bar patch, it will be necessary to replace `TAGCOUNT` with `LENGTH(tags)`. This is done in a separate patch.
### Authors
- [zoigmant](codeberg.org/zoigmant)
### Credits (Authors of the dwm patch)
- [Paul Baldaray](paulbaldaray@gmail.com)
- [kleinbottle4](kleinbottle4@gmail.com)

View File

@ -0,0 +1,93 @@
From ec0ff716f4096e8552c0d142e41a36468c65ed1d Mon Sep 17 00:00:00 2001
From: zoigmant <zoigmant@noreply.codeberg.org>
Date: Sun, 29 Mar 2026 18:08:04 -0700
Subject: [PATCH] [PATCH] reorganize tags patch. Mostly imported from dwm.
Allows the users to move occupied tags as far left as possible. Patched to
accomodate the bar patch
---
config.def.h | 1 +
dwl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/config.def.h b/config.def.h
index 7da50d2..70c36dd 100644
--- a/config.def.h
+++ b/config.def.h
@@ -136,6 +136,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
+ { MODKEY, XKB_KEY_r, reorganizetags, {0} },
{ MODKEY, XKB_KEY_Return, zoom, {0} },
{ MODKEY, XKB_KEY_Tab, view, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c, killclient, {0} },
diff --git a/dwl.c b/dwl.c
index 7b2abf5..4d80bd6 100644
--- a/dwl.c
+++ b/dwl.c
@@ -346,6 +346,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
+static void reorganizetags(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
@@ -2405,6 +2406,53 @@ requestmonstate(struct wl_listener *listener, void *data)
updatemons(NULL, NULL);
}
+void
+reorganizetags(const Arg *arg) {
+ Client *c;
+ unsigned int occ, unocc, i;
+ unsigned int tagdest[LENGTH(tags)];
+ for (i = 0; i < LENGTH(tags); i++)
+ tagdest[i] = 0; /* so no uninitialized memory warning */
+
+ occ = 0;
+ wl_list_for_each(c, &clients, link) {
+ if ((c->mon == selmon) && c->tags) {
+ for(i = 0;; i++) { /* because no ffs() in this C standard */
+ if ((c->tags) & (1 << i)) {
+ occ |= (1 << i);
+ break;
+ }
+ }
+ }
+ }
+ 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;
+ }
+ }
+
+ wl_list_for_each(c, &clients, link) {
+ if ((c->mon == selmon) && c->tags) {
+ for(i = 0;; i++) {
+ if ((c->tags) & (1 << i)) {
+ c->tags = 1 << tagdest[i];
+ break;
+ }
+ }
+ }
+ }
+ if (focustop(selmon))
+ selmon->tagset[selmon->seltags] = focustop(selmon)->tags;
+ focusclient(focustop(selmon), 1);
+ drawbars();
+ arrange(selmon);
+}
+
void
resize(Client *c, struct wlr_box geo, int interact)
{
--
2.52.0

View File

@ -0,0 +1,92 @@
From c7efef1814c12b8f10de1c32568eaf9241e8518d Mon Sep 17 00:00:00 2001
From: zoigmant <zoigmant@noreply.codeberg.org>
Date: Wed, 25 Mar 2026 15:10:30 -0700
Subject: [PATCH] [PATCH] reorganizetags patch. Mostly imported from dwm.
Allows the users to move occupied tags over so as to remove empty tags
inbetween occupied tags. It preserves the order of the tags.
---
config.def.h | 1 +
dwl.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..12f6d92 100644
--- a/config.def.h
+++ b/config.def.h
@@ -129,6 +129,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
+ { MODKEY, XKB_KEY_r, reorganizetags, {0} },
{ MODKEY, XKB_KEY_Return, zoom, {0} },
{ MODKEY, XKB_KEY_Tab, view, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c, killclient, {0} },
diff --git a/dwl.c b/dwl.c
index 44f3ad9..8ea1345 100644
--- a/dwl.c
+++ b/dwl.c
@@ -313,6 +313,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
+static void reorganizetags(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
@@ -2202,6 +2203,52 @@ requestmonstate(struct wl_listener *listener, void *data)
updatemons(NULL, NULL);
}
+void
+reorganizetags(const Arg *arg) {
+ Client *c;
+ unsigned int occ, unocc, i;
+ unsigned int tagdest[TAGCOUNT];
+ for (i = 0; i < TAGCOUNT; i++)
+ tagdest[i] = 0; /* so no uninitialized memory warning */
+
+ occ = 0;
+ wl_list_for_each(c, &clients, link) {
+ if ((c->mon == selmon) && c->tags) {
+ for(i = 0;; i++) { /* because no ffs() in this C standard */
+ if ((c->tags) & (1 << i)) {
+ occ |= (1 << i);
+ break;
+ }
+ }
+ }
+ }
+ unocc = 0;
+ for (i = 0; i < TAGCOUNT; ++i) {
+ while (unocc < i && (occ & (1 << unocc)))
+ unocc++;
+ if (occ & (1 << i)) {
+ tagdest[i] = unocc;
+ occ &= ~(1 << i);
+ occ |= 1 << unocc;
+ }
+ }
+
+ wl_list_for_each(c, &clients, link) {
+ if ((c->mon == selmon) && c->tags) {
+ for(i = 0;; i++) {
+ if ((c->tags) & (1 << i)) {
+ c->tags = 1 << tagdest[i];
+ break;
+ }
+ }
+ }
+ }
+ if (focustop(selmon))
+ selmon->tagset[selmon->seltags] = focustop(selmon)->tags;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+}
+
void
resize(Client *c, struct wlr_box geo, int interact)
{
--
2.52.0