My patched version of suckless' dwm.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.4 KiB

  1. diff --git a/config.def.h b/config.def.h
  2. index 1c0b587..b67825e 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -103,7 +103,9 @@ static Button buttons[] = {
  6. { ClkLtSymbol, 0, Button1, setlayout, {0} },
  7. { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
  8. { ClkWinTitle, 0, Button2, zoom, {0} },
  9. - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
  10. + { ClkStatusText, 0, Button1, sigdwmblocks, {.i = 1} },
  11. + { ClkStatusText, 0, Button2, sigdwmblocks, {.i = 2} },
  12. + { ClkStatusText, 0, Button3, sigdwmblocks, {.i = 3} },
  13. { ClkClientWin, MODKEY, Button1, movemouse, {0} },
  14. { ClkClientWin, MODKEY, Button2, togglefloating, {0} },
  15. { ClkClientWin, MODKEY, Button3, resizemouse, {0} },
  16. diff --git a/dwm.c b/dwm.c
  17. index 4465af1..c600131 100644
  18. --- a/dwm.c
  19. +++ b/dwm.c
  20. @@ -156,6 +156,7 @@ static void clientmessage(XEvent *e);
  21. static void configure(Client *c);
  22. static void configurenotify(XEvent *e);
  23. static void configurerequest(XEvent *e);
  24. +static void copyvalidchars(char *text, char *rawtext);
  25. static Monitor *createmon(void);
  26. static void destroynotify(XEvent *e);
  27. static void detach(Client *c);
  28. @@ -169,6 +170,7 @@ static void focus(Client *c);
  29. static void focusin(XEvent *e);
  30. static void focusmon(const Arg *arg);
  31. static void focusstack(const Arg *arg);
  32. +static int getdwmblockspid();
  33. static int getrootptr(int *x, int *y);
  34. static long getstate(Window w);
  35. static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
  36. @@ -205,6 +207,7 @@ static void setup(void);
  37. static void seturgent(Client *c, int urg);
  38. static void showhide(Client *c);
  39. static void sigchld(int unused);
  40. +static void sigdwmblocks(const Arg *arg);
  41. static void spawn(const Arg *arg);
  42. static void tag(const Arg *arg);
  43. static void tagmon(const Arg *arg);
  44. @@ -237,6 +240,9 @@ static void zoom(const Arg *arg);
  45. /* variables */
  46. static const char broken[] = "broken";
  47. static char stext[256];
  48. +static char rawstext[256];
  49. +static int dwmblockssig;
  50. +pid_t dwmblockspid = 0;
  51. static int screen;
  52. static int sw, sh; /* X display screen geometry width, height */
  53. static int bh, blw = 0; /* bar geometry */
  54. @@ -439,9 +445,26 @@ buttonpress(XEvent *e)
  55. arg.ui = 1 << i;
  56. } else if (ev->x < x + blw)
  57. click = ClkLtSymbol;
  58. - else if (ev->x > selmon->ww - TEXTW(stext))
  59. + else if (ev->x > (x = selmon->ww - TEXTW(stext) + lrpad)) {
  60. click = ClkStatusText;
  61. - else
  62. +
  63. + char *text = rawstext;
  64. + int i = -1;
  65. + char ch;
  66. + dwmblockssig = 0;
  67. + while (text[++i]) {
  68. + if ((unsigned char)text[i] < ' ') {
  69. + ch = text[i];
  70. + text[i] = '\0';
  71. + x += TEXTW(text) - lrpad;
  72. + text[i] = ch;
  73. + text += i+1;
  74. + i = -1;
  75. + if (x >= ev->x) break;
  76. + dwmblockssig = ch;
  77. + }
  78. + }
  79. + } else
  80. click = ClkWinTitle;
  81. } else if ((c = wintoclient(ev->window))) {
  82. focus(c);
  83. @@ -627,6 +650,19 @@ configurerequest(XEvent *e)
  84. XSync(dpy, False);
  85. }
  86. +void
  87. +copyvalidchars(char *text, char *rawtext)
  88. +{
  89. + int i = -1, j = 0;
  90. +
  91. + while(rawtext[++i]) {
  92. + if ((unsigned char)rawtext[i] >= ' ') {
  93. + text[j++] = rawtext[i];
  94. + }
  95. + }
  96. + text[j] = '\0';
  97. +}
  98. +
  99. Monitor *
  100. createmon(void)
  101. {
  102. @@ -871,6 +907,18 @@ getatomprop(Client *c, Atom prop)
  103. return atom;
  104. }
  105. +int
  106. +getdwmblockspid()
  107. +{
  108. + char buf[16];
  109. + FILE *fp = popen("pidof -s dwmblocks", "r");
  110. + fgets(buf, sizeof(buf), fp);
  111. + pid_t pid = strtoul(buf, NULL, 10);
  112. + pclose(fp);
  113. + dwmblockspid = pid;
  114. + return pid != 0 ? 0 : -1;
  115. +}
  116. +
  117. int
  118. getrootptr(int *x, int *y)
  119. {
  120. @@ -1636,6 +1684,23 @@ sigchld(int unused)
  121. while (0 < waitpid(-1, NULL, WNOHANG));
  122. }
  123. +void
  124. +sigdwmblocks(const Arg *arg)
  125. +{
  126. + union sigval sv;
  127. + sv.sival_int = (dwmblockssig << 8) | arg->i;
  128. + if (!dwmblockspid)
  129. + if (getdwmblockspid() == -1)
  130. + return;
  131. +
  132. + if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) {
  133. + if (errno == ESRCH) {
  134. + if (!getdwmblockspid())
  135. + sigqueue(dwmblockspid, SIGUSR1, sv);
  136. + }
  137. + }
  138. +}
  139. +
  140. void
  141. spawn(const Arg *arg)
  142. {
  143. @@ -1987,8 +2052,10 @@ updatesizehints(Client *c)
  144. void
  145. updatestatus(void)
  146. {
  147. - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  148. + if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)))
  149. strcpy(stext, "dwm-"VERSION);
  150. + else
  151. + copyvalidchars(stext, rawstext);
  152. drawbar(selmon);
  153. }