From a0803fae0be4e68d62792ec3493e68a2701ca9f4 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 6 Jul 2023 19:25:17 +0200 Subject: [PATCH] Add restartsig --- config.h | 5 +++-- dwm.1 | 10 ++++++++++ dwm.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 67ab154..d15653a 100644 --- a/config.h +++ b/config.h @@ -127,8 +127,8 @@ static const Key keys[] = { { MODKEY, XK_n, incnmaster, {.i = -1 } }, { MODKEY|ControlMask, XK_i, incnstack, {.i = +1 } }, { MODKEY|ControlMask, XK_u, incnstack, {.i = -1 } }, - { MODKEY|ShiftMask, XK_a, setmfact, {.f = -0.05} }, - { MODKEY|ShiftMask, XK_d, setmfact, {.f = +0.05} }, + { MODKEY|ShiftMask, XK_h, setmfact, {.f = -0.05} }, + { MODKEY|ShiftMask, XK_l, setmfact, {.f = +0.05} }, { MODKEY|ShiftMask, XK_k, setcfact, {.f = +0.25} }, { MODKEY|ShiftMask, XK_j, setcfact, {.f = -0.25} }, { MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} }, @@ -147,6 +147,7 @@ static const Key keys[] = { { MODKEY|Mod1Mask, XK_9, incrovgaps, {.i = +1 } }, { MODKEY|Mod1Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } }, { MODKEY|Mod1Mask|ShiftMask, XK_0, defaultgaps, {0} }, + { MODKEY|ControlMask|ShiftMask, XK_r, quit, {.i = 1 } }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY|ControlMask, XK_z, showhideclient, {0} }, diff --git a/dwm.1 b/dwm.1 index ddc8321..7b6cadb 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 16de0b0..dd8b980 100644 --- a/dwm.c +++ b/dwm.c @@ -317,6 +317,8 @@ static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void spawn(const Arg *arg); +static void sighup(int unused); +static void sigterm(int unused); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void togglebar(const Arg *arg); @@ -391,6 +393,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { }; static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast]; static int running = 1; +static int restart = 0; static Cur *cursor[CurLast]; static Display *dpy; static Drw *drw; @@ -1855,6 +1858,8 @@ quit(const Arg *arg) { size_t i; + if(arg->i) restart = 1; + /* kill child processes */ for (i = 0; i < autostart_len; i++) { if (0 < autostart_pids[i]) { @@ -2253,6 +2258,9 @@ setup(void) } + signal(SIGHUP, sighup); + signal(SIGTERM, sigterm); + /* init screen */ screen = DefaultScreen(dpy); sw = DisplayWidth(dpy, screen); @@ -2363,6 +2371,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) { @@ -3246,6 +3268,7 @@ main(int argc, char *argv[]) #endif /* __OpenBSD__ */ scan(); run(); + if(restart) execvp(argv[0], argv); cleanup(); XCloseDisplay(dpy); return EXIT_SUCCESS;