commit 16dd82faee301033bd0bbe6eb8019bbc4622cd79
Author: thatlittlegit <[email protected]>
Date:   Sun Apr 25 22:33:32 2021 -0400

    [dwm][patch][onlyquitonempty] add updated version to fix bugs
    
    (Dates are a bit weird: patch committed to my dwm repo June 2020, patch
    apparently made December 2020, committed here April 2021)
    
    This is the new version of onlyquitonempty, which fixes a few bugs
    compared to the old one. It also has new documentation, to make it
    easier to use.
    
    The primary bugfix is that a temporary allocation 'junk' has been
    removed. This would have been overflowed in any case, and has been
    replaced with stack variables. Unfortunately, X demands to give us
    'children', so we need to XFree that, but oh well. (Potentially that's
    a memory leak fixed?)
    
    In addition, an override has been added so you can still get out if you
    mess up your configuration.

diff --git 
a/dwm.suckless.org/patches/onlyquitonempty/dwm-onlyquitonempty-20201204-61bb8b2.diff
 
b/dwm.suckless.org/patches/onlyquitonempty/dwm-onlyquitonempty-20201204-61bb8b2.diff
new file mode 100644
index 00000000..7eff4297
--- /dev/null
+++ 
b/dwm.suckless.org/patches/onlyquitonempty/dwm-onlyquitonempty-20201204-61bb8b2.diff
@@ -0,0 +1,78 @@
+From f00572701a18f17650f193a708f419814c87f408 Mon Sep 17 00:00:00 2001
+From: thatlittlegit <[email protected]>
+Date: Fri, 19 Jun 2020 22:04:25 -0400
+Subject: [PATCH] Don't quit unless all windows are closed
+
+This patch is the second version. Changes:
+
+  * add an override via Ctrl-Mod-Shift-Q
+  * remove a useless malloc(3) call
+
+The w1, w2, and children variables unfortunately don't seem removable,
+since XQueryTree would segfault.
+---
+ config.def.h |  8 +++++++-
+ dwm.c        | 17 +++++++++++++++++
+ 2 files changed, 24 insertions(+), 1 deletion(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..c7b8e16 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -93,7 +93,8 @@ static Key keys[] = {
+       TAGKEYS(                        XK_7,                      6)
+       TAGKEYS(                        XK_8,                      7)
+       TAGKEYS(                        XK_9,                      8)
+-      { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
++      { MODKEY|ShiftMask,             XK_q,      try_quit,       {0} },
++      { MODKEY|ShiftMask|ControlMask, XK_q,      quit,           {0} },
+ };
+ 
+ /* button definitions */
+@@ -113,3 +114,8 @@ static Button buttons[] = {
+       { ClkTagBar,            MODKEY,         Button3,        toggletag,      
{0} },
+ };
+ 
++/* how many windows should be open when quitting? */
++/* on a stock dwm install, this seems to be two; however, you'll have to
++ * change it depending on how many invisible X windows exist */
++/* you can get a list with `xwininfo -tree -root`. */
++static const int EMPTY_WINDOW_COUNT = 2;
+diff --git a/dwm.c b/dwm.c
+index 664c527..85ee948 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -214,6 +214,7 @@ static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
++static void try_quit(const Arg *arg);
+ static void unfocus(Client *c, int setfocus);
+ static void unmanage(Client *c, int destroyed);
+ static void unmapnotify(XEvent *e);
+@@ -1749,6 +1750,22 @@ toggleview(const Arg *arg)
+       }
+ }
+ 
++void
++try_quit(const Arg *arg)
++{
++      unsigned int n;
++      Window w1, w2, *children = NULL;
++      XQueryTree(dpy, root, &w1, &w2, &children, &n);
++
++      if (children != NULL)
++              XFree(children);
++
++      if (n == EMPTY_WINDOW_COUNT)
++              running = 0;
++      else
++              printf("[dwm] try_quit condition failed (n=%d)
", n);
++}
++
+ void
+ unfocus(Client *c, int setfocus)
+ {
+-- 
+2.20.1
+
diff --git a/dwm.suckless.org/patches/onlyquitonempty/index.md 
b/dwm.suckless.org/patches/onlyquitonempty/index.md
index 84ab63a5..4b2fdb59 100644
--- a/dwm.suckless.org/patches/onlyquitonempty/index.md
+++ b/dwm.suckless.org/patches/onlyquitonempty/index.md
@@ -3,16 +3,27 @@ onlyquitonempty
 
 Description
 -----------
-On the default keybinding of Alt-Shift-Q, it is possible to press it by
-accident, closing all your work. This patch makes it so dwm will only exit via
-quit() if no windows are open.
+On the default keybinding of Mod-Shift-Q, it is possible to press it by
+accident, closing all your work. This patch makes it so dwm will only exit if
+no windows are open.
 
-Because people may have different daemons, etc. open, you can configure the
-count considered to be 'empty' via `EMPTY_WINDOW_COUNT`.
+You probably have various other "windows" open according to the X server; this
+includes not only a panel, but often also settings daemons, notification
+daemons, odd scripts, or other X utilities. As a result, you will probably need
+to consider changing `EMPTY_WINDOW_COUNT` to a number that works best for you.
+You can get a list of open X windows with `xwininfo -tree -root`. The command
+`xwininfo -tree -root | grep child | head -1` with an empty desktop should get
+you most of the way there (although of course your terminal is open). Be
+prepared to recompile a few times to test!
+
+Version two adds an override shortcut as Ctrl-Mod-Shift-Q; this is obviously
+configurable in config.h. It also removes a useless allocation, which could
+even potentially be overflowed (`sizeof(Window) > 1`).
 
 Download
 --------
-* 
[dwm-onlyquitonempty-20180428-6.2.diff](dwm-onlyquitonempty-20180428-6.2.diff)
+* [dwm-onlyquitonempty-20201204-61bb8b2.diff (version 
2)](dwm-onlyquitonempty-20201204-61bb8b2.diff)
+* [dwm-onlyquitonempty-20180428-6.2.diff (version 
1)](dwm-onlyquitonempty-20180428-6.2.diff)
 
 Author
 ------


Reply via email to