commit 2b1ff4f11e8e6e31cf2d59e207db9febe162e47c
parent 825ffa03c10543a93879cbba4f57c450bdcc05a8
Author: Leonardo-Boss <70913810+Leonardo-Boss@users.noreply.github.com>
Date: Wed, 4 Oct 2023 00:41:48 -0300
[dwm][patches][pertag] cleanup last selection pointer when client is closed
It's necessary to nullify the pointer to the client when it closes to
prevent invalid memory access which crashes the dwm
Diffstat:
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/dwm.suckless.org/patches/pertag/dwm-pertag_with_sel-20231003-9f88553.diff b/dwm.suckless.org/patches/pertag/dwm-pertag_with_sel-20231003-9f88553.diff
@@ -1,20 +1,20 @@
-From fa197138818a4838df142e995c0be14b9a5c73bb Mon Sep 17 00:00:00 2001
-From: Leonardo-Boss <leonardoboss2001@gmail.com>
+From b47a32da69a1bb6f60b9c81619f3e504278cc780 Mon Sep 17 00:00:00 2001
+From: Leonardo-Boss <70913810+Leonardo-Boss@users.noreply.github.com>
Date: Tue, 3 Oct 2023 12:33:58 -0300
Subject: [PATCH] pertag with last selection
---
- dwm.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
- 1 file changed, 85 insertions(+), 7 deletions(-)
+ dwm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 90 insertions(+), 7 deletions(-)
diff --git a/dwm.c b/dwm.c
-index f1d86b2..cef6e18 100644
+index f1d86b2..0e4d444 100644
--- a/dwm.c
+++ b/dwm.c
@@ -111,6 +111,7 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
-
+
+typedef struct Pertag Pertag;
struct Monitor {
char ltsymbol[16];
@@ -25,12 +25,12 @@ index f1d86b2..cef6e18 100644
const Layout *lt[2];
+ Pertag *pertag;
};
-
+
typedef struct {
@@ -271,6 +273,16 @@ static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
-
+
+struct Pertag {
+ unsigned int curtag, prevtag; /* current and previous tag */
+ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
@@ -43,13 +43,13 @@ index f1d86b2..cef6e18 100644
+
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
-
+
@@ -634,6 +646,7 @@ Monitor *
createmon(void)
{
Monitor *m;
+ unsigned int i;
-
+
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
@@ -644,6 +657,20 @@ createmon(void)
@@ -72,15 +72,15 @@ index f1d86b2..cef6e18 100644
+
return m;
}
-
+
@@ -808,6 +835,7 @@ focus(Client *c)
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
}
selmon->sel = c;
-+ selmon->pertag->sel[selmon->pertag->curtag] = c;
++ selmon->pertag->sel[selmon->pertag->curtag] = c;
drawbars();
}
-
+
@@ -980,7 +1008,7 @@ grabkeys(void)
void
incnmaster(const Arg *arg)
@@ -89,7 +89,7 @@ index f1d86b2..cef6e18 100644
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
arrange(selmon);
}
-
+
@@ -1511,9 +1539,9 @@ void
setlayout(const Arg *arg)
{
@@ -110,7 +110,7 @@ index f1d86b2..cef6e18 100644
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
arrange(selmon);
}
-
+
@@ -1715,7 +1743,7 @@ tile(Monitor *m)
void
togglebar(const Arg *arg)
@@ -125,7 +125,7 @@ index f1d86b2..cef6e18 100644
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+ int i;
-
+
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
+
@@ -154,7 +154,22 @@ index f1d86b2..cef6e18 100644
focus(NULL);
arrange(selmon);
}
-@@ -2053,12 +2105,38 @@ updatewmhints(Client *c)
+@@ -1778,9 +1830,14 @@ unfocus(Client *c, int setfocus)
+ void
+ unmanage(Client *c, int destroyed)
+ {
++ int i;
+ Monitor *m = c->mon;
+ XWindowChanges wc;
+
++ for (i = 0; i < LENGTH(tags) + 1; i++)
++ if (c->mon->pertag->sel[i] == c)
++ c->mon->pertag->sel[i] = NULL;
++
+ detach(c);
+ detachstack(c);
+ if (!destroyed) {
+@@ -2053,12 +2110,38 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
@@ -194,7 +209,7 @@ index f1d86b2..cef6e18 100644
+ focus(selmon->pertag->sel[selmon->pertag->curtag]);
arrange(selmon);
}
-
---
+
+--
2.41.0