[wiki] [sites] [dwm][patches][pertag] cleanup last selection pointer when client is closed || Leonardo-Boss

From: <git_AT_suckless.org>
Date: Wed, 04 Oct 2023 05:48:16 +0200

commit 2b1ff4f11e8e6e31cf2d59e207db9febe162e47c
Author: Leonardo-Boss <70913810+Leonardo-Boss_AT_users.noreply.github.com>
Date: Wed Oct 4 00:41:48 2023 -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

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
index e2620748..72a2a2f7 100644
--- 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
_AT_@ -1,20 +1,20 @@
-From fa197138818a4838df142e995c0be14b9a5c73bb Mon Sep 17 00:00:00 2001
-From: Leonardo-Boss <leonardoboss2001_AT_gmail.com>
+From b47a32da69a1bb6f60b9c81619f3e504278cc780 Mon Sep 17 00:00:00 2001
+From: Leonardo-Boss <70913810+Leonardo-Boss_AT_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
 _AT_@ -111,6 +111,7 @@ typedef struct {
          void (*arrange)(Monitor *);
  } Layout;
-
+
 +typedef struct Pertag Pertag;
  struct Monitor {
          char ltsymbol[16];
_AT_@ -25,12 +25,12 @@ index f1d86b2..cef6e18 100644
          const Layout *lt[2];
 + Pertag *pertag;
  };
-
+
  typedef struct {
 _AT_@ -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 */
_AT_@ -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]; };
-
+
 _AT_@ -634,6 +646,7 @@ Monitor *
  createmon(void)
  {
          Monitor *m;
 + unsigned int i;
-
+
          m = ecalloc(1, sizeof(Monitor));
          m->tagset[0] = m->tagset[1] = 1;
 _AT_@ -644,6 +657,20 @@ createmon(void)
_AT_@ -72,15 +72,15 @@ index f1d86b2..cef6e18 100644
 +
          return m;
  }
-
+
 _AT_@ -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();
  }
-
+
 _AT_@ -980,7 +1008,7 @@ grabkeys(void)
  void
  incnmaster(const Arg *arg)
_AT_@ -89,7 +89,7 @@ index f1d86b2..cef6e18 100644
 + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
          arrange(selmon);
  }
-
+
 _AT_@ -1511,9 +1539,9 @@ void
  setlayout(const Arg *arg)
  {
_AT_@ -110,7 +110,7 @@ index f1d86b2..cef6e18 100644
 + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
          arrange(selmon);
  }
-
+
 _AT_@ -1715,7 +1743,7 @@ tile(Monitor *m)
  void
  togglebar(const Arg *arg)
_AT_@ -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;
 +
_AT_@ -154,7 +154,22 @@ index f1d86b2..cef6e18 100644
                  focus(NULL);
                  arrange(selmon);
          }
-_AT_@ -2053,12 +2105,38 @@ updatewmhints(Client *c)
+_AT_@ -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) {
+_AT_@ -2053,12 +2110,38 @@ updatewmhints(Client *c)
  void
  view(const Arg *arg)
  {
_AT_@ -194,7 +209,7 @@ index f1d86b2..cef6e18 100644
 + focus(selmon->pertag->sel[selmon->pertag->curtag]);
          arrange(selmon);
  }
-
---
+ 
+-- 
 2.41.0
 
Received on Wed Oct 04 2023 - 05:48:16 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 04 2023 - 05:48:50 CEST