From 51ece34332f7f509403efe03cf3d612d545067a9 Mon Sep 17 00:00:00 2001 From: Joshua Yun Date: Tue, 1 Apr 2025 00:29:51 -0500 Subject: feat: adding volume status bar file --- .gitignore | 3 +++ components/pamixer_vol_perc.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .gitignore create mode 100644 components/pamixer_vol_perc.c 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 +#include +#include +#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); + } +} -- cgit v1.2.3