aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applied/dwm-restartsig-20180523-6.2.diff139
-rw-r--r--config.def.h3
-rw-r--r--dwm.c44
3 files changed, 175 insertions, 11 deletions
diff --git a/applied/dwm-restartsig-20180523-6.2.diff b/applied/dwm-restartsig-20180523-6.2.diff
new file mode 100644
index 0000000..f1f8680
--- /dev/null
+++ b/applied/dwm-restartsig-20180523-6.2.diff
@@ -0,0 +1,139 @@
+From 2991f37f0aaf44b9f9b11e7893ff0af8eb88f649 Mon Sep 17 00:00:00 2001
+From: Christopher Drelich <cd@cdrakka.com>
+Date: Wed, 23 May 2018 22:50:38 -0400
+Subject: [PATCH] Modifies quit to handle restarts and adds SIGHUP and SIGTERM
+ handlers.
+
+Modified quit() to restart if it receives arg .i = 1
+MOD+CTRL+SHIFT+Q was added to confid.def.h to do just that.
+
+Signal handlers were handled for SIGHUP and SIGTERM.
+If dwm receives these signals it calls quit() with
+arg .i = to 1 or 0, respectively.
+
+To restart dwm:
+MOD+CTRL+SHIFT+Q
+or
+kill -HUP dwmpid
+
+To quit dwm cleanly:
+MOD+SHIFT+Q
+or
+kill -TERM dwmpid
+---
+ config.def.h | 1 +
+ dwm.1 | 10 ++++++++++
+ dwm.c | 22 ++++++++++++++++++++++
+ 3 files changed, 33 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index a9ac303..e559429 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -94,6 +94,7 @@ static Key keys[] = {
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
++ { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} },
+ };
+
+ /* button definitions */
+diff --git a/dwm.1 b/dwm.1
+index 13b3729..36a331c 100644
+--- a/dwm.1
++++ b/dwm.1
+@@ -142,6 +142,9 @@ Add/remove all windows with nth tag to/from the view.
+ .TP
+ .B Mod1\-Shift\-q
+ Quit dwm.
++.TP
++.B Mod1\-Control\-Shift\-q
++Restart dwm.
+ .SS Mouse commands
+ .TP
+ .B Mod1\-Button1
+@@ -155,6 +158,13 @@ Resize focused window while dragging. Tiled windows will be toggled to the float
+ .SH CUSTOMIZATION
+ dwm is customized by creating a custom config.h and (re)compiling the source
+ code. This keeps it fast, secure and simple.
++.SH SIGNALS
++.TP
++.B SIGHUP - 1
++Restart the dwm process.
++.TP
++.B SIGTERM - 15
++Cleanly terminate the dwm process.
+ .SH SEE ALSO
+ .BR dmenu (1),
+ .BR st (1)
+diff --git a/dwm.c b/dwm.c
+index bb95e26..286eecd 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -205,6 +205,8 @@ static void setup(void);
+ static void seturgent(Client *c, int urg);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
++static void sighup(int unused);
++static void sigterm(int unused);
+ static void spawn(const Arg *arg);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+@@ -260,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
+ [UnmapNotify] = unmapnotify
+ };
+ static Atom wmatom[WMLast], netatom[NetLast];
++static int restart = 0;
+ static int running = 1;
+ static Cur *cursor[CurLast];
+ static Clr **scheme;
+@@ -1248,6 +1251,7 @@ propertynotify(XEvent *e)
+ void
+ quit(const Arg *arg)
+ {
++ if(arg->i) restart = 1;
+ running = 0;
+ }
+
+@@ -1536,6 +1540,9 @@ setup(void)
+ /* clean up any zombies immediately */
+ sigchld(0);
+
++ signal(SIGHUP, sighup);
++ signal(SIGTERM, sigterm);
++
+ /* init screen */
+ screen = DefaultScreen(dpy);
+ sw = DisplayWidth(dpy, screen);
+@@ -1637,6 +1644,20 @@ sigchld(int unused)
+ }
+
+ void
++sighup(int unused)
++{
++ Arg a = {.i = 1};
++ quit(&a);
++}
++
++void
++sigterm(int unused)
++{
++ Arg a = {.i = 0};
++ quit(&a);
++}
++
++void
+ spawn(const Arg *arg)
+ {
+ if (arg->v == dmenucmd)
+@@ -2139,6 +2160,7 @@ main(int argc, char *argv[])
+ setup();
+ scan();
+ run();
++ if(restart) execvp(argv[0], argv);
+ cleanup();
+ XCloseDisplay(dpy);
+ return EXIT_SUCCESS;
+--
+2.7.4
+
diff --git a/config.def.h b/config.def.h
index dae6ecc..95a6dd3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -10,7 +10,7 @@ static const unsigned int systrayonleft = 0; /* 0: systray in the right corne
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 */
-static const int showbar = 0; /* 0 means no bar */
+static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const int user_bh = 25; /* 0 means that dwm will calculate bar height, >= 1 means dwm will user_bh as bar height */
static const int focusonwheel = 0;
@@ -278,6 +278,7 @@ static const Key keys[] = {
{ MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_e, quit, {0} },
+ { MODKEY|ShiftMask, XK_r, quit, {1} },
{ MODKEY, XK_o, winview, {0} },
};
diff --git a/dwm.c b/dwm.c
index eec383a..9a25210 100644
--- a/dwm.c
+++ b/dwm.c
@@ -258,6 +258,8 @@ static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
+static void sighup(int unused);
+static void sigterm(int unused);
static void spawn(const Arg *arg);
static Monitor *systraytomon(Monitor *m);
static void switchtag(const Arg *arg);
@@ -333,6 +335,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify
};
static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
+static int restart = 0;
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
@@ -654,24 +657,24 @@ bstack(Monitor *m) {
if (n == 0)
return;
if (n > m->nmaster) {
- mh = m->nmaster ? m->mfact * m->wh : 0;
- tw = m->ww / (n - m->nmaster);
+ mh = m->nmaster ? m->mfact * m->wh - m->gappx : 0;
+ tw = m->ww / (n - m->nmaster) - m->gappx;
ty = m->wy + mh;
} else {
mh = m->wh;
tw = m->ww;
ty = m->wy;
}
- for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ for (i = mx = m->gappx, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if (i < m->nmaster) {
- w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
- resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
- mx += WIDTH(c);
+ w = (m->ww - mx) / (MIN(n, m->nmaster) - i) - m->gappx;
+ resize(c, m->wx + mx + m->gappx, m->wy, w - (2 * c->bw) - m->gappx, mh - (2 * c->bw), 0);
+ mx += WIDTH(c) + m->gappx;
} else {
- h = m->wh - mh;
- resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0);
- if (tw != m->ww)
- tx += WIDTH(c);
+ h = m->wh - mh - m->gappx;
+ resize(c, tx + m->gappx, ty, tw - (2 * c->bw) - 2 * m->gappx, h - (2 * c->bw), 0);
+ if (tw + m->gappx != m->ww)
+ tx += WIDTH(c) + m->gappx;
}
}
}
@@ -2011,6 +2014,8 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
+ if (arg->i)
+ restart = 1;
running = 0;
}
@@ -2361,6 +2366,9 @@ setup(void)
/* clean up any zombies (inherited from .xinitrc etc) immediately */
while (waitpid(-1, NULL, WNOHANG) > 0);
+ signal(SIGHUP, sighup);
+ signal(SIGTERM, sigterm);
+
/* init screen */
screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen);
@@ -2467,6 +2475,20 @@ showhide(Client *c)
}
void
+sighup(int unused)
+{
+ Arg a = {.i = 1};
+ quit(&a);
+}
+
+void
+sigterm(int unused)
+{
+ Arg a = {.i = 0};
+ quit(&a);
+}
+
+void
spawn(const Arg *arg)
{
struct sigaction sa;
@@ -3578,6 +3600,8 @@ main(int argc, char *argv[])
#endif /* __OpenBSD__ */
scan();
run();
+ if (restart)
+ execvp(argv[0], argv);
cleanup();
XCloseDisplay(dpy);
return EXIT_SUCCESS;