Xinqi Bao's Git

minor update, tab to space
[dwm.git] / patches / dwm-restartsig-20180523-6.2.diff
1 From 2991f37f0aaf44b9f9b11e7893ff0af8eb88f649 Mon Sep 17 00:00:00 2001
2 From: Christopher Drelich <cd@cdrakka.com>
3 Date: Wed, 23 May 2018 22:50:38 -0400
4 Subject: [PATCH] Modifies quit to handle restarts and adds SIGHUP and SIGTERM
5 handlers.
6
7 Modified quit() to restart if it receives arg .i = 1
8 MOD+CTRL+SHIFT+Q was added to confid.def.h to do just that.
9
10 Signal handlers were handled for SIGHUP and SIGTERM.
11 If dwm receives these signals it calls quit() with
12 arg .i = to 1 or 0, respectively.
13
14 To restart dwm:
15 MOD+CTRL+SHIFT+Q
16 or
17 kill -HUP dwmpid
18
19 To quit dwm cleanly:
20 MOD+SHIFT+Q
21 or
22 kill -TERM dwmpid
23 ---
24 config.def.h | 1 +
25 dwm.1 | 10 ++++++++++
26 dwm.c | 22 ++++++++++++++++++++++
27 3 files changed, 33 insertions(+)
28
29 diff --git a/config.def.h b/config.def.h
30 index a9ac303..e559429 100644
31 --- a/config.def.h
32 +++ b/config.def.h
33 @@ -94,6 +94,7 @@ static Key keys[] = {
34 TAGKEYS( XK_8, 7)
35 TAGKEYS( XK_9, 8)
36 { MODKEY|ShiftMask, XK_q, quit, {0} },
37 + { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} },
38 };
39
40 /* button definitions */
41 diff --git a/dwm.1 b/dwm.1
42 index 13b3729..36a331c 100644
43 --- a/dwm.1
44 +++ b/dwm.1
45 @@ -142,6 +142,9 @@ Add/remove all windows with nth tag to/from the view.
46 .TP
47 .B Mod1\-Shift\-q
48 Quit dwm.
49 +.TP
50 +.B Mod1\-Control\-Shift\-q
51 +Restart dwm.
52 .SS Mouse commands
53 .TP
54 .B Mod1\-Button1
55 @@ -155,6 +158,13 @@ Resize focused window while dragging. Tiled windows will be toggled to the float
56 .SH CUSTOMIZATION
57 dwm is customized by creating a custom config.h and (re)compiling the source
58 code. This keeps it fast, secure and simple.
59 +.SH SIGNALS
60 +.TP
61 +.B SIGHUP - 1
62 +Restart the dwm process.
63 +.TP
64 +.B SIGTERM - 15
65 +Cleanly terminate the dwm process.
66 .SH SEE ALSO
67 .BR dmenu (1),
68 .BR st (1)
69 diff --git a/dwm.c b/dwm.c
70 index bb95e26..286eecd 100644
71 --- a/dwm.c
72 +++ b/dwm.c
73 @@ -205,6 +205,8 @@ static void setup(void);
74 static void seturgent(Client *c, int urg);
75 static void showhide(Client *c);
76 static void sigchld(int unused);
77 +static void sighup(int unused);
78 +static void sigterm(int unused);
79 static void spawn(const Arg *arg);
80 static void tag(const Arg *arg);
81 static void tagmon(const Arg *arg);
82 @@ -260,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
83 [UnmapNotify] = unmapnotify
84 };
85 static Atom wmatom[WMLast], netatom[NetLast];
86 +static int restart = 0;
87 static int running = 1;
88 static Cur *cursor[CurLast];
89 static Clr **scheme;
90 @@ -1248,6 +1251,7 @@ propertynotify(XEvent *e)
91 void
92 quit(const Arg *arg)
93 {
94 + if(arg->i) restart = 1;
95 running = 0;
96 }
97
98 @@ -1536,6 +1540,9 @@ setup(void)
99 /* clean up any zombies immediately */
100 sigchld(0);
101
102 + signal(SIGHUP, sighup);
103 + signal(SIGTERM, sigterm);
104 +
105 /* init screen */
106 screen = DefaultScreen(dpy);
107 sw = DisplayWidth(dpy, screen);
108 @@ -1637,6 +1644,20 @@ sigchld(int unused)
109 }
110
111 void
112 +sighup(int unused)
113 +{
114 + Arg a = {.i = 1};
115 + quit(&a);
116 +}
117 +
118 +void
119 +sigterm(int unused)
120 +{
121 + Arg a = {.i = 0};
122 + quit(&a);
123 +}
124 +
125 +void
126 spawn(const Arg *arg)
127 {
128 if (arg->v == dmenucmd)
129 @@ -2139,6 +2160,7 @@ main(int argc, char *argv[])
130 setup();
131 scan();
132 run();
133 + if(restart) execvp(argv[0], argv);
134 cleanup();
135 XCloseDisplay(dpy);
136 return EXIT_SUCCESS;
137 --
138 2.7.4
139