summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--config.def.h6
-rw-r--r--dwm.c21
-rw-r--r--patch/fullscreen.c4
-rw-r--r--patches.h6
5 files changed, 39 insertions, 3 deletions
diff --git a/README.md b/README.md
index 61a01d7..de452ee 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
+2019-10-03 - Added onlyquitonempty patch
+
2019-10-02 - Added restartsig, emptyview, focusurgent and focusadjacenttag patches
2019-10-01 - Added leftlayout, fullscreen, holdbar and unfloatvisible patches
@@ -135,6 +137,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- adds rules per monitor, e.g. have default layouts per monitor
- the use case for this is if the second monitor is vertical (i.e. rotated) then you may want to use a different default layout for this monitor than what is used for the main monitor (for example normal vertical split for main monitor and horizontal split for the second)
+ - [onlyquitonempty](https://dwm.suckless.org/patches/onlyquitonempty/)
+ - makes it so dwm will only exit via quit() if no windows are open (in order to prevent accidental loss of work)
+
- [pertag](https://dwm.suckless.org/patches/pertag/)
- adds nmaster, mfact, layouts and more per tag rather than per monitor
diff --git a/config.def.h b/config.def.h
index 857acc2..33d4436 100644
--- a/config.def.h
+++ b/config.def.h
@@ -29,6 +29,9 @@ static const unsigned int systrayspacing = 2; /* systray spacing */
static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
static const int showsystray = 1; /* 0 means no systray */
#endif // SYSTRAY_PATCH
+#if ONLYQUITONEMPTY_PATCH
+static const int quit_empty_window_count = 2; /* only allow dwm to quit if no windows are open, value here represents number of deamons */
+#endif // ONLYQUITONEMPTY_PATCH
static const char *fonts[] = { "monospace:size=10" };
static const char dmenufont[] = "monospace:size=10";
@@ -210,6 +213,9 @@ static const int resizehints = 1; /* 1 means respect size hints in tiled resi
#define FORCE_VSPLIT 1
#endif
+/* Position of the monocle layout in the layouts variable, used by warp and fullscreen patches */
+#define MONOCLE_LAYOUT_POS 2
+
#if FLEXTILE_DELUXE_LAYOUT
static const Layout layouts[] = {
/* symbol arrange function, { nmaster, nstack, layout, master axis, stack axis, secondary stack axis } */
diff --git a/dwm.c b/dwm.c
index 7fed237..a14788f 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1978,11 +1978,30 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
+ #if ONLYQUITONEMPTY_PATCH
+ unsigned int n;
+ Window *junk = malloc(1);
+
+ XQueryTree(dpy, root, junk, junk, &junk, &n);
+
+ if (n == quit_empty_window_count) {
+ #if RESTARTSIG_PATCH
+ if (arg->i)
+ restart = 1;
+ #endif // RESTARTSIG_PATCH
+ running = 0;
+ }
+ else
+ printf("[dwm] not exiting (n=%d)\n", n);
+
+ free(junk);
+ #else
#if RESTARTSIG_PATCH
if (arg->i)
restart = 1;
#endif // RESTARTSIG_PATCH
running = 0;
+ #endif // ONLYQUITONEMPTY_PATCH
}
Monitor *
@@ -2153,7 +2172,7 @@ restack(Monitor *m)
XSync(dpy, False);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
#if WARP_PATCH
- if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && selmon->lt[selmon->sellt] != &layouts[2]) // <-- NB! hardcoded monocle
+ if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && selmon->lt[selmon->sellt] != &layouts[MONOCLE_LAYOUT_POS])
warp(m->sel);
#endif // WARP_PATCH
}
diff --git a/patch/fullscreen.c b/patch/fullscreen.c
index 3ddb0e1..aace550 100644
--- a/patch/fullscreen.c
+++ b/patch/fullscreen.c
@@ -1,11 +1,11 @@
-Layout *last_layout;
+Layout *last_layout = &layouts[0];
void
fullscreen(const Arg *arg)
{
if (selmon->showbar) {
for (last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++);
- setlayout(&((Arg) { .v = &layouts[2] })); // <-- NB! hardcoded monocle
+ setlayout(&((Arg) { .v = &layouts[MONOCLE_LAYOUT_POS] }));
} else {
setlayout(&((Arg) { .v = last_layout }));
}
diff --git a/patches.h b/patches.h
index 95002a2..eed308b 100644
--- a/patches.h
+++ b/patches.h
@@ -197,6 +197,12 @@
*/
#define MONITOR_RULES_PATCH 0
+/* This patch makes it so dwm will only exit via quit() if no windows are open.
+ * This is to prevent you accidentally losing all your work.
+ * https://dwm.suckless.org/patches/onlyquitonempty/
+ */
+#define ONLYQUITONEMPTY_PATCH 0
+
/* The pertag patch adds nmaster, mfacts and layouts per tag rather than per
* monitor (default).
* https://dwm.suckless.org/patches/pertag/