| dwm-onlyquitonempty-20201204-61bb8b2.diff - sites - public wiki contents of suc… | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| dwm-onlyquitonempty-20201204-61bb8b2.diff (2419B) | |
| --- | |
| 1 From f00572701a18f17650f193a708f419814c87f408 Mon Sep 17 00:00:00 2001 | |
| 2 From: thatlittlegit <[email protected]> | |
| 3 Date: Fri, 19 Jun 2020 22:04:25 -0400 | |
| 4 Subject: [PATCH] Don't quit unless all windows are closed | |
| 5 | |
| 6 This patch is the second version. Changes: | |
| 7 | |
| 8 * add an override via Ctrl-Mod-Shift-Q | |
| 9 * remove a useless malloc(3) call | |
| 10 | |
| 11 The w1, w2, and children variables unfortunately don't seem removable, | |
| 12 since XQueryTree would segfault. | |
| 13 --- | |
| 14 config.def.h | 8 +++++++- | |
| 15 dwm.c | 17 +++++++++++++++++ | |
| 16 2 files changed, 24 insertions(+), 1 deletion(-) | |
| 17 | |
| 18 diff --git a/config.def.h b/config.def.h | |
| 19 index 1c0b587..c7b8e16 100644 | |
| 20 --- a/config.def.h | |
| 21 +++ b/config.def.h | |
| 22 @@ -93,7 +93,8 @@ static Key keys[] = { | |
| 23 TAGKEYS( XK_7, 6) | |
| 24 TAGKEYS( XK_8, 7) | |
| 25 TAGKEYS( XK_9, 8) | |
| 26 - { MODKEY|ShiftMask, XK_q, quit, {0} … | |
| 27 + { MODKEY|ShiftMask, XK_q, try_quit, {0} … | |
| 28 + { MODKEY|ShiftMask|ControlMask, XK_q, quit, {0} … | |
| 29 }; | |
| 30 | |
| 31 /* button definitions */ | |
| 32 @@ -113,3 +114,8 @@ static Button buttons[] = { | |
| 33 { ClkTagBar, MODKEY, Button3, togglet… | |
| 34 }; | |
| 35 | |
| 36 +/* how many windows should be open when quitting? */ | |
| 37 +/* on a stock dwm install, this seems to be two; however, you'll have to | |
| 38 + * change it depending on how many invisible X windows exist */ | |
| 39 +/* you can get a list with `xwininfo -tree -root`. */ | |
| 40 +static const int EMPTY_WINDOW_COUNT = 2; | |
| 41 diff --git a/dwm.c b/dwm.c | |
| 42 index 664c527..85ee948 100644 | |
| 43 --- a/dwm.c | |
| 44 +++ b/dwm.c | |
| 45 @@ -214,6 +214,7 @@ static void togglebar(const Arg *arg); | |
| 46 static void togglefloating(const Arg *arg); | |
| 47 static void toggletag(const Arg *arg); | |
| 48 static void toggleview(const Arg *arg); | |
| 49 +static void try_quit(const Arg *arg); | |
| 50 static void unfocus(Client *c, int setfocus); | |
| 51 static void unmanage(Client *c, int destroyed); | |
| 52 static void unmapnotify(XEvent *e); | |
| 53 @@ -1749,6 +1750,22 @@ toggleview(const Arg *arg) | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 +void | |
| 58 +try_quit(const Arg *arg) | |
| 59 +{ | |
| 60 + unsigned int n; | |
| 61 + Window w1, w2, *children = NULL; | |
| 62 + XQueryTree(dpy, root, &w1, &w2, &children, &n); | |
| 63 + | |
| 64 + if (children != NULL) | |
| 65 + XFree(children); | |
| 66 + | |
| 67 + if (n == EMPTY_WINDOW_COUNT) | |
| 68 + running = 0; | |
| 69 + else | |
| 70 + printf("[dwm] try_quit condition failed (n=%d)\n", n); | |
| 71 +} | |
| 72 + | |
| 73 void | |
| 74 unfocus(Client *c, int setfocus) | |
| 75 { | |
| 76 -- | |
| 77 2.20.1 | |
| 78 |