Advertisement
Guest User

dwm patches

a guest
Mar 18th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. --- config.h 2025-03-18 16:21:26.571159870 +0530
  2. +++ clean/dwm/config.def.h 2025-03-18 16:22:22.759876841 +0530
  3. @@ -55,8 +55,6 @@
  4. /* helper for spawning shell commands in the pre dwm-5.0 fashion */
  5. #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
  6.  
  7. -#define STATUSBAR "dwmblocks"
  8. -
  9. /* commands */
  10. static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
  11. static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
  12. @@ -106,9 +104,7 @@
  13. { ClkLtSymbol, 0, Button1, setlayout, {0} },
  14. { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
  15. { ClkWinTitle, 0, Button2, zoom, {0} },
  16. - { ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} },
  17. - { ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} },
  18. - { ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} },
  19. + { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
  20. { ClkClientWin, MODKEY, Button1, movemouse, {0} },
  21. { ClkClientWin, MODKEY, Button2, togglefloating, {0} },
  22. { ClkClientWin, MODKEY, Button3, resizemouse, {0} },
  23.  
  24.  
  25.  
  26. --- clean/dwm/dwm.c 2025-03-18 16:22:22.759876841 +0530
  27. +++ dwm.c 2025-03-18 16:20:49.831313623 +0530
  28. @@ -171,6 +171,7 @@
  29. static Atom getatomprop(Client *c, Atom prop);
  30. static int getrootptr(int *x, int *y);
  31. static long getstate(Window w);
  32. +static pid_t getstatusbarpid();
  33. static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
  34. static void grabbuttons(Client *c, int focused);
  35. static void grabkeys(void);
  36. @@ -204,6 +205,7 @@
  37. static void setup(void);
  38. static void seturgent(Client *c, int urg);
  39. static void showhide(Client *c);
  40. +static void sigstatusbar(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. @@ -236,6 +238,9 @@
  45. /* variables */
  46. static const char broken[] = "broken";
  47. static char stext[256];
  48. +static int statusw;
  49. +static int statussig;
  50. +static pid_t statuspid = -1;
  51. static int screen;
  52. static int sw, sh; /* X display screen geometry width, height */
  53. static int bh; /* bar height */
  54. @@ -422,6 +427,7 @@
  55. Client *c;
  56. Monitor *m;
  57. XButtonPressedEvent *ev = &e->xbutton;
  58. + char *text, *s, ch;
  59.  
  60. click = ClkRootWin;
  61. /* focus monitor if necessary */
  62. @@ -440,9 +446,27 @@
  63. arg.ui = 1 << i;
  64. } else if (ev->x < x + TEXTW(selmon->ltsymbol))
  65. click = ClkLtSymbol;
  66. - else if (ev->x > selmon->ww - (int)TEXTW(stext))
  67. + else if (ev->x > selmon->ww - statusw) {
  68. + x = selmon->ww - statusw;
  69. click = ClkStatusText;
  70. - else
  71. + statussig = 0;
  72. + for (text = s = stext; *s && x <= ev->x; s++) {
  73. + if ((unsigned char)(*s) < ' ') {
  74. + ch = *s;
  75. + *s = '\0';
  76. + x += TEXTW(text) - lrpad;
  77. + *s = ch;
  78. + text = s + 1;
  79. + if (x >= ev->x)
  80. + break;
  81. + /* reset on matching signal raw byte */
  82. + if (ch == statussig)
  83. + statussig = 0;
  84. + else
  85. + statussig = ch;
  86. + }
  87. + }
  88. + } else
  89. click = ClkWinTitle;
  90. } else if ((c = wintoclient(ev->window))) {
  91. focus(c);
  92. @@ -708,9 +732,24 @@
  93.  
  94. /* draw status first so it can be overdrawn by tags later */
  95. if (m == selmon) { /* status is only drawn on selected monitor */
  96. + char *text, *s, ch;
  97. drw_setscheme(drw, scheme[SchemeNorm]);
  98. - tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
  99. - drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
  100. +
  101. + x = 0;
  102. + for (text = s = stext; *s; s++) {
  103. + if ((unsigned char)(*s) < ' ') {
  104. + ch = *s;
  105. + *s = '\0';
  106. + tw = TEXTW(text) - lrpad;
  107. + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
  108. + x += tw;
  109. + *s = ch;
  110. + text = s + 1;
  111. + }
  112. + }
  113. + tw = TEXTW(text) - lrpad + 2;
  114. + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
  115. + tw = statusw;
  116. }
  117.  
  118. for (c = m->clients; c; c = c->next) {
  119. @@ -876,6 +915,30 @@
  120. return atom;
  121. }
  122.  
  123. +pid_t
  124. +getstatusbarpid()
  125. +{
  126. + char buf[32], *str = buf, *c;
  127. + FILE *fp;
  128. +
  129. + if (statuspid > 0) {
  130. + snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
  131. + if ((fp = fopen(buf, "r"))) {
  132. + fgets(buf, sizeof(buf), fp);
  133. + while ((c = strchr(str, '/')))
  134. + str = c + 1;
  135. + fclose(fp);
  136. + if (!strcmp(str, STATUSBAR))
  137. + return statuspid;
  138. + }
  139. + }
  140. + if (!(fp = popen("pidof -s "STATUSBAR, "r")))
  141. + return -1;
  142. + fgets(buf, sizeof(buf), fp);
  143. + pclose(fp);
  144. + return strtol(buf, NULL, 10);
  145. +}
  146. +
  147. int
  148. getrootptr(int *x, int *y)
  149. {
  150. @@ -1644,6 +1707,20 @@
  151. }
  152.  
  153. void
  154. +sigstatusbar(const Arg *arg)
  155. +{
  156. + union sigval sv;
  157. +
  158. + if (!statussig)
  159. + return;
  160. + sv.sival_int = arg->i;
  161. + if ((statuspid = getstatusbarpid()) <= 0)
  162. + return;
  163. +
  164. + sigqueue(statuspid, SIGRTMIN+statussig, sv);
  165. +}
  166. +
  167. +void
  168. spawn(const Arg *arg)
  169. {
  170. struct sigaction sa;
  171. @@ -2004,8 +2081,25 @@
  172. void
  173. updatestatus(void)
  174. {
  175. - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  176. + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) {
  177. strcpy(stext, "dwm-"VERSION);
  178. + statusw = TEXTW(stext) - lrpad + 2;
  179. + } else {
  180. + char *text, *s, ch;
  181. +
  182. + statusw = 0;
  183. + for (text = s = stext; *s; s++) {
  184. + if ((unsigned char)(*s) < ' ') {
  185. + ch = *s;
  186. + *s = '\0';
  187. + statusw += TEXTW(text) - lrpad;
  188. + *s = ch;
  189. + text = s + 1;
  190. + }
  191. + }
  192. + statusw += TEXTW(text) - lrpad + 2;
  193. +
  194. + }
  195. drawbar(selmon);
  196. }
  197.  
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement