dwm
dynamic window manager
git clone https://9o.is/git/dwm.git
commit e6e2cca529a2e51abb21ccbc410363a7c3df183a parent 0b4cafb297403ec0cef951441969bfdd270a8990 Author: Jul <jul@9o.is> Date: Sun, 1 Feb 2026 02:19:44 -0500 handle term and hup signals Diffstat:
| M | config.def.h | | | 1 | + |
| M | config.h | | | 2 | +- |
| M | dwm.1 | | | 10 | ++++++++++ |
| M | dwm.c | | | 34 | +++++++++++++++++++++++++++++++++- |
4 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h @@ -96,6 +96,7 @@ static const 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/config.h b/config.h @@ -89,7 +89,7 @@ static const Key keys[] = { TAGKEYS( XK_7, 6) TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) - { MODKEY|Mod1Mask, XK_q, quit, {0} }, + { MODKEY|Mod1Mask, XK_q, quit, {1} }, }; /* button definitions */ diff --git 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 @@ -204,6 +204,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 void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -259,6 +261,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; @@ -1258,6 +1261,7 @@ propertynotify(XEvent *e) void quit(const Arg *arg) { + if(arg->i) restart = 1; running = 0; } @@ -1542,7 +1546,7 @@ setup(void) int i; XSetWindowAttributes wa; Atom utf8string; - struct sigaction sa; + struct sigaction sa, sa_term, sa_hup; /* do not transform children into zombies when they terminate */ sigemptyset(&sa.sa_mask); @@ -1550,6 +1554,18 @@ setup(void) sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, NULL); + /* handle termination */ + sigemptyset(&sa_term.sa_mask); + sa_term.sa_flags = SA_RESTART; + sa_term.sa_handler = sigterm; + sigaction(SIGTERM, &sa_term, NULL); + + /* handle hangup */ + sigemptyset(&sa_hup.sa_mask); + sa_hup.sa_flags = SA_RESTART; + sa_hup.sa_handler = sighup; + sigaction(SIGHUP, &sa_hup, NULL); + /* clean up any zombies (inherited from .xinitrc etc) immediately */ while (waitpid(-1, NULL, WNOHANG) > 0); @@ -1645,6 +1661,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; @@ -2159,6 +2189,8 @@ main(int argc, char *argv[]) #endif /* __OpenBSD__ */ scan(); run(); + if(restart) + execvp(argv[0], argv); cleanup(); XCloseDisplay(dpy); return EXIT_SUCCESS;