add statuscmd and status2d
This commit is contained in:
parent
dd59139c5e
commit
c792ffe63b
2 changed files with 83 additions and 6 deletions
|
|
@ -107,6 +107,8 @@ static const Layout layouts[] = {
|
||||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||||
|
|
||||||
|
#define STATUSBAR "dwmblocks"
|
||||||
|
|
||||||
/* commands */
|
/* commands */
|
||||||
#define TERM_CMD "wezterm"
|
#define TERM_CMD "wezterm"
|
||||||
#define TERM(cmd) { .v = (const char*[]){ TERM_CMD, cmd, NULL } }
|
#define TERM(cmd) { .v = (const char*[]){ TERM_CMD, cmd, NULL } }
|
||||||
|
|
@ -233,7 +235,9 @@ static const Button buttons[] = {
|
||||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
{ ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} },
|
||||||
|
{ ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} },
|
||||||
|
{ ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} },
|
||||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||||
|
|
|
||||||
83
dwm.c
83
dwm.c
|
|
@ -217,6 +217,7 @@ static void focusstack(const Arg *arg);
|
||||||
static Atom getatomprop(Client *c, Atom prop);
|
static Atom getatomprop(Client *c, Atom prop);
|
||||||
static int getrootptr(int *x, int *y);
|
static int getrootptr(int *x, int *y);
|
||||||
static long getstate(Window w);
|
static long getstate(Window w);
|
||||||
|
static pid_t getstatusbarpid();
|
||||||
static unsigned int getsystraywidth();
|
static unsigned int getsystraywidth();
|
||||||
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||||
static void grabbuttons(Client *c, int focused);
|
static void grabbuttons(Client *c, int focused);
|
||||||
|
|
@ -259,6 +260,7 @@ static void setmfact(const Arg *arg);
|
||||||
static void setup(void);
|
static void setup(void);
|
||||||
static void seturgent(Client *c, int urg);
|
static void seturgent(Client *c, int urg);
|
||||||
static void showhide(Client *c);
|
static void showhide(Client *c);
|
||||||
|
static void sigstatusbar(const Arg *arg);
|
||||||
static void spawn(const Arg *arg);
|
static void spawn(const Arg *arg);
|
||||||
static Monitor *systraytomon(Monitor *m);
|
static Monitor *systraytomon(Monitor *m);
|
||||||
static void tag(const Arg *arg);
|
static void tag(const Arg *arg);
|
||||||
|
|
@ -308,6 +310,9 @@ static Systray *systray = NULL;
|
||||||
static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
|
static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
|
||||||
static const char broken[] = "broken";
|
static const char broken[] = "broken";
|
||||||
static char stext[1024];
|
static char stext[1024];
|
||||||
|
static int statussig;
|
||||||
|
static int statusw;
|
||||||
|
static pid_t statuspid = -1;
|
||||||
static int screen;
|
static int screen;
|
||||||
static int sw, sh; /* X display screen geometry width, height */
|
static int sw, sh; /* X display screen geometry width, height */
|
||||||
static int bh; /* bar height */
|
static int bh; /* bar height */
|
||||||
|
|
@ -564,9 +569,33 @@ buttonpress(XEvent *e)
|
||||||
arg.ui = 1 << i;
|
arg.ui = 1 << i;
|
||||||
} else if (ev->x < x + TEXTW(selmon->ltsymbol, 0))
|
} else if (ev->x < x + TEXTW(selmon->ltsymbol, 0))
|
||||||
click = ClkLtSymbol;
|
click = ClkLtSymbol;
|
||||||
else if (ev->x > selmon->ww - TEXTW(stext, 0) - getsystraywidth())
|
else if (ev->x > selmon->ww - statusw - getsystraywidth()) {
|
||||||
|
x = selmon->ww - statusw;
|
||||||
click = ClkStatusText;
|
click = ClkStatusText;
|
||||||
else
|
char *text, *s, ch;
|
||||||
|
statussig = 0;
|
||||||
|
for (text = s = stext; *s && x <= ev->x; s++) {
|
||||||
|
if ((unsigned char)(*s) < ' ') {
|
||||||
|
ch = *s;
|
||||||
|
*s = '\0';
|
||||||
|
x += TEXTW(text, statusfontindex) - lrpad;
|
||||||
|
*s = ch;
|
||||||
|
text = s + 1;
|
||||||
|
if (x >= ev->x)
|
||||||
|
break;
|
||||||
|
statussig = ch;
|
||||||
|
} else if (*s == '^') {
|
||||||
|
*s = '\0';
|
||||||
|
x += TEXTW(text, statusfontindex) - lrpad;
|
||||||
|
*s = '^';
|
||||||
|
if (*(++s) == 'f')
|
||||||
|
x += atoi(++s);
|
||||||
|
while (*(s++) != '^');
|
||||||
|
text = s;
|
||||||
|
s--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
click = ClkWinTitle;
|
click = ClkWinTitle;
|
||||||
} else if ((c = wintoclient(ev->window))) {
|
} else if ((c = wintoclient(ev->window))) {
|
||||||
focus(c);
|
focus(c);
|
||||||
|
|
@ -914,7 +943,7 @@ dirtomon(int dir)
|
||||||
|
|
||||||
int
|
int
|
||||||
drawstatusbar(Monitor *m, int bh, char* stext) {
|
drawstatusbar(Monitor *m, int bh, char* stext) {
|
||||||
int ret, i, w, x, len;
|
int ret, i, j, w, x, len;
|
||||||
short isCode = 0;
|
short isCode = 0;
|
||||||
char *text;
|
char *text;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
@ -923,7 +952,12 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
|
||||||
if (!(text = (char*) malloc(sizeof(char)*len)))
|
if (!(text = (char*) malloc(sizeof(char)*len)))
|
||||||
die("malloc");
|
die("malloc");
|
||||||
p = text;
|
p = text;
|
||||||
memcpy(text, stext, len);
|
|
||||||
|
i = -1, j = 0;
|
||||||
|
while (stext[++i])
|
||||||
|
if ((unsigned char)stext[i] >= ' ')
|
||||||
|
text[j++] = stext[i];
|
||||||
|
text[j] = '\0';
|
||||||
|
|
||||||
/* compute width of the status text */
|
/* compute width of the status text */
|
||||||
w = 0;
|
w = 0;
|
||||||
|
|
@ -1040,7 +1074,8 @@ drawbar(Monitor *m)
|
||||||
// drw_setscheme(drw, scheme[SchemeNorm]);
|
// drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
// tw = TEXTW(stext, statusfontindex) - lrpad + 2; /* 2px right padding */
|
// tw = TEXTW(stext, statusfontindex) - lrpad + 2; /* 2px right padding */
|
||||||
// drw_text(drw, m->ww - tw - stw, 0, tw, bh, 0, stext, 0, statusfontindex);
|
// drw_text(drw, m->ww - tw - stw, 0, tw, bh, 0, stext, 0, statusfontindex);
|
||||||
tw = m->ww - drawstatusbar(m, bh, stext);
|
// tw = m->ww - drawstatusbar(m, bh, stext);
|
||||||
|
tw = statusw = m->ww - drawstatusbar(m, bh, stext);
|
||||||
}
|
}
|
||||||
|
|
||||||
resizebarwin(m);
|
resizebarwin(m);
|
||||||
|
|
@ -1287,6 +1322,30 @@ getatomprop(Client *c, Atom prop)
|
||||||
return atom;
|
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 strtoul(buf, NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
getrootptr(int *x, int *y)
|
getrootptr(int *x, int *y)
|
||||||
{
|
{
|
||||||
|
|
@ -2458,6 +2517,20 @@ showhide(Client *c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
spawn(const Arg *arg)
|
spawn(const Arg *arg)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue