dwm-restartsig-20180523-6.2.diff 3.2 KB

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