From 5784018c18d5af4e8fa1bca7975547fb02dda873 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Wed, 22 Dec 2021 16:29:51 -0500 Subject: Applied the statuscmd patch https://dwm.suckless.org/patches/statuscmd/ This was done in preparation for using Luke's build of dwmblocks, and is needed to support clickable statusbar elements. --- dwm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 4 deletions(-) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 8ff8be3..9ab5b32 100644 --- a/dwm.c +++ b/dwm.c @@ -203,6 +203,7 @@ static void focusstack(const Arg *arg); static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); +static pid_t getstatusbarpid(); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); @@ -237,6 +238,7 @@ static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void sigchld(int unused); +static void sigstatusbar(const Arg *arg); static void sighup(int unused); static void sigterm(int unused); static void spawn(const Arg *arg); @@ -279,6 +281,9 @@ static pid_t winpid(Window w); /* variables */ static const char broken[] = "broken"; static char stext[256]; +static int statusw; +static int statussig; +static pid_t statuspid = -1; static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh, blw = 0; /* bar geometry */ @@ -520,6 +525,7 @@ buttonpress(XEvent *e) Client *c; Monitor *m; XButtonPressedEvent *ev = &e->xbutton; + char *text, *s, ch; click = ClkRootWin; /* focus monitor if necessary */ @@ -538,9 +544,23 @@ buttonpress(XEvent *e) arg.ui = 1 << i; } else if (ev->x < x + blw) click = ClkLtSymbol; - else if (ev->x > selmon->ww - (int)TEXTW(stext, statusfontindex)) + else if (ev->x > selmon->ww - statusw) { + x = selmon->ww - statusw; click = ClkStatusText; - else + statussig = 0; + for (text = s = stext; *s && x <= ev->x; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + x += TEXTW(text, 0) - lrpad; + *s = ch; + text = s + 1; + if (x >= ev->x) + break; + statussig = ch; + } + } + } else click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { focus(c); @@ -812,9 +832,23 @@ drawbar(Monitor *m) /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ + char *text, *s, ch; drw_setscheme(drw, scheme[SchemeNorm]); + x = 0; + for (text = s = stext; *s; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + tw = TEXTW(text, statusfontindex) - lrpad; + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0, statusfontindex); + x += tw; + *s = ch; + text = s + 1; + } + } tw = TEXTW(stext, statusfontindex) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0, statusfontindex); + drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0, statusfontindex); + tw = statusw; } for (c = m->clients; c; c = c->next) { @@ -980,6 +1014,30 @@ getatomprop(Client *c, Atom prop) return atom; } +pid_t +getstatusbarpid() +{ + char buf[32], *str = buf, *c; + FILE *fp; + + if (statuspid > 0) { + snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid); + if ((fp = fopen(buf, "r"))) { + fgets(buf, sizeof(buf), fp); + while ((c = strchr(str, '/'))) + str = c + 1; + fclose(fp); + if (!strcmp(str, STATUSBAR)) + return statuspid; + } + } + if (!(fp = popen("pidof -s "STATUSBAR, "r"))) + return -1; + fgets(buf, sizeof(buf), fp); + pclose(fp); + return strtol(buf, NULL, 10); +} + int getrootptr(int *x, int *y) { @@ -1771,6 +1829,20 @@ sigterm(int unused) quit(&a); } +void +sigstatusbar(const Arg *arg) +{ + union sigval sv; + + if (!statussig) + return; + sv.sival_int = arg->i; + if ((statuspid = getstatusbarpid()) <= 0) + return; + + sigqueue(statuspid, SIGRTMIN+statussig, sv); +} + void spawn(const Arg *arg) { @@ -2139,8 +2211,25 @@ updatesizehints(Client *c) void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) { strcpy(stext, "dwm-"VERSION); + statusw = TEXTW(stext, statusfontindex) - lrpad + 2; + } else { + char *text, *s, ch; + + statusw = 0; + for (text = s = stext; *s; s++) { + if ((unsigned char)(*s) < ' ') { + ch = *s; + *s = '\0'; + statusw += TEXTW(text, statusfontindex) - lrpad; + *s = ch; + text = s + 1; + } + } + statusw += TEXTW(text, statusfontindex) - lrpad + 2; + + } drawbar(selmon); } -- cgit v1.2.3