summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-06-16 18:10:25 +0200
committerTom Barrett <tom@tombarrett.xyz>2020-06-16 18:10:25 +0200
commit3f1090257b39088e50fa84e238d73a9a6530d168 (patch)
tree82d1b0a14c0400f021d756fc6fc85b2a6a68c775
parente60d9facc8437c986fe39fe1bde7ff7967e83285 (diff)
added volume control
-rw-r--r--dwm/config.h5
-rw-r--r--dwmstatus/custom.diff31
2 files changed, 31 insertions, 5 deletions
diff --git a/dwm/config.h b/dwm/config.h
index ae2980e..689c2ee 100644
--- a/dwm/config.h
+++ b/dwm/config.h
@@ -58,6 +58,8 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col, "-sf", col_gray4, NULL };
static const char *passmenucmd[] = { "passmenu", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col, "-sf", col_gray4, NULL };
+static const char *volumeup[] = { "amixer", "-D", "pulse", "sset", "Master", "5%+", NULL};
+static const char *volumedown[] = { "amixer", "-D", "pulse", "sset", "Master", "5%-", NULL};
static const char *termcmd[] = { "st", NULL };
static const char *exitcmd[] = { "killall", "xinit", NULL };
@@ -67,6 +69,9 @@ static Key keys[] = {
{ MODKEY, XK_d, spawn, {.v = dmenucmd } },
{ MODKEY, XK_c, spawn, {.v = passmenucmd } },
+ { MODKEY, XK_equal, spawn, {.v = volumeup } },
+ { MODKEY, XK_minus, spawn, {.v = volumedown } },
+
{ MODKEY, XK_q, killclient, {0} },
{ MODKEY, XK_r, quit, {0} },
{ MODKEY|ShiftMask, XK_e, spawn, {.v = exitcmd} },
diff --git a/dwmstatus/custom.diff b/dwmstatus/custom.diff
index 0650010..11e5d05 100644
--- a/dwmstatus/custom.diff
+++ b/dwmstatus/custom.diff
@@ -1,5 +1,5 @@
diff --git a/dwmstatus.c b/dwmstatus.c
-index d2a4b03..4b5e093 100644
+index d2a4b03..555f0bd 100644
--- a/dwmstatus.c
+++ b/dwmstatus.c
@@ -17,8 +17,6 @@
@@ -29,7 +29,7 @@ index d2a4b03..4b5e093 100644
}
if (remcap < 0 || descap < 0)
-@@ -175,47 +173,49 @@ gettemperature(char *base, char *sensor)
+@@ -175,47 +173,70 @@ gettemperature(char *base, char *sensor)
return smprintf("%02.0f°C", atof(co) / 1000);
}
@@ -50,6 +50,24 @@ index d2a4b03..4b5e093 100644
+ return smprintf("%s", ret);
+}
+
++char *
++getvolume() {
++ char *co = smprintf("amixer -D pulse sget Master | grep % | head -n 1 | cut -d ' ' -f 7 | tr -d '[]\n'");
++ FILE *fd = popen(co, "r");
++
++ if (fd == NULL)
++ return smprintf("invalid");
++
++ char ret[8];
++ if (fgets(ret, 8, fd) == NULL)
++ return smprintf("invalid");
++
++ if (pclose(fd) == -1)
++ return smprintf("invalid");
++
++ return smprintf("%s", ret);
++}
++
int
main(void)
{
@@ -62,6 +80,7 @@ index d2a4b03..4b5e093 100644
char *tmbln;
- char *t0, *t1, *t2;
+ char *partition;
++ char *volume;
if (!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "dwmstatus: cannot open display.\n");
@@ -69,7 +88,7 @@ index d2a4b03..4b5e093 100644
}
- for (;;sleep(60)) {
-+ for (;;sleep(10)) {
++ for (;;sleep(1)) {
avgs = loadavg();
+ partition = getpartition("/$");
bat = getbattery("/sys/class/power_supply/BAT0");
@@ -85,15 +104,17 @@ index d2a4b03..4b5e093 100644
- t0, t1, t2, avgs, bat, bat1, tmar, tmutc,
- tmbln);
+ tmbln = mktimes("%a %d %b %H:%M", tzberlin);
++ volume = getvolume();
+
-+ status = smprintf(" %s | %s | %s | %s",
-+ avgs, partition, bat, tmbln);
++ status = smprintf(" %s | %s | %s | %s | %s",
++ avgs, partition, volume, bat, tmbln);
setstatus(status);
- free(t0);
- free(t1);
- free(t2);
free(avgs);
++ free(volume);
free(bat);
- free(bat1);
- free(tmar);