diff options
author | Joshua Yun <joshua@joshuayun.com> | 2025-04-01 00:29:51 -0500 |
---|---|---|
committer | Joshua Yun <joshua@joshuayun.com> | 2025-04-01 00:29:51 -0500 |
commit | 51ece34332f7f509403efe03cf3d612d545067a9 (patch) | |
tree | 25e346401368d53f81b130264527cf695d9e74ce | |
parent | 4c8d59a13cf615481694e07535ec672dcdab59aa (diff) | |
download | slstatus-51ece34332f7f509403efe03cf3d612d545067a9.tar.gz |
feat: adding volume status bar filejoshua
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | components/pamixer_vol_perc.c | 37 |
2 files changed, 40 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a89fac9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +config.h +slstatus diff --git a/components/pamixer_vol_perc.c b/components/pamixer_vol_perc.c new file mode 100644 index 0000000..4376d2f --- /dev/null +++ b/components/pamixer_vol_perc.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdbool.h> +#include <string.h> +#include "../util.h" + +#define VOL_BUF_SIZE 4 + +const char * +pamixer_vol_perc(void) +{ + bool MUTED = false; + char vol_buf[VOL_BUF_SIZE]; + char mute, ch; + unsigned short i = 0; + + FILE *mute_fp = popen("pamixer --get-mute | head -c1", "r"); + FILE *vol_fp = popen("pamixer --get-volume | head -c3", "r"); + + mute = fgetc(mute_fp); + pclose (mute_fp); + + ch = fgetc(vol_fp); + while (ch != '\n' && ch != EOF && i < VOL_BUF_SIZE) { + vol_buf[i++] = ch; + ch = fgetc(vol_fp); + } + vol_buf[i] = '\0'; + + pclose (vol_fp); + + if (mute == 't') { + return bprintf(""); + } + else { + return bprintf("%s%%", vol_buf); + } +} |