dwm-statuscmd-signal-6.2.diff (4543B)
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 87 +void 88 +copyvalidchars(char *text, char *rawtext) 89 +{ 90 + int i = -1, j = 0; 91 + 92 + while(rawtext[++i]) { 93 + if ((unsigned char)rawtext[i] >= ' ') { 94 + text[j++] = rawtext[i]; 95 + } 96 + } 97 + text[j] = '\0'; 98 +} 99 + 100 Monitor * 101 createmon(void) 102 { 103 @@ -871,6 +907,18 @@ getatomprop(Client *c, Atom prop) 104 return atom; 105 } 106 107 +int 108 +getdwmblockspid() 109 +{ 110 + char buf[16]; 111 + FILE *fp = popen("pidof -s dwmblocks", "r"); 112 + fgets(buf, sizeof(buf), fp); 113 + pid_t pid = strtoul(buf, NULL, 10); 114 + pclose(fp); 115 + dwmblockspid = pid; 116 + return pid != 0 ? 0 : -1; 117 +} 118 + 119 int 120 getrootptr(int *x, int *y) 121 { 122 @@ -1636,6 +1684,23 @@ sigchld(int unused) 123 while (0 < waitpid(-1, NULL, WNOHANG)); 124 } 125 126 +void 127 +sigdwmblocks(const Arg *arg) 128 +{ 129 + union sigval sv; 130 + sv.sival_int = (dwmblockssig << 8) | arg->i; 131 + if (!dwmblockspid) 132 + if (getdwmblockspid() == -1) 133 + return; 134 + 135 + if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) { 136 + if (errno == ESRCH) { 137 + if (!getdwmblockspid()) 138 + sigqueue(dwmblockspid, SIGUSR1, sv); 139 + } 140 + } 141 +} 142 + 143 void 144 spawn(const Arg *arg) 145 { 146 @@ -1987,8 +2052,10 @@ updatesizehints(Client *c) 147 void 148 updatestatus(void) 149 { 150 - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) 151 + if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) 152 strcpy(stext, "dwm-"VERSION); 153 + else 154 + copyvalidchars(stext, rawstext); 155 drawbar(selmon); 156 } 157