summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorJoshua Yun <joshua@joshuayun.com>2025-04-01 00:29:51 -0500
committerJoshua Yun <joshua@joshuayun.com>2025-04-01 00:29:51 -0500
commit51ece34332f7f509403efe03cf3d612d545067a9 (patch)
tree25e346401368d53f81b130264527cf695d9e74ce /components
parent4c8d59a13cf615481694e07535ec672dcdab59aa (diff)
downloadslstatus-51ece34332f7f509403efe03cf3d612d545067a9.tar.gz
feat: adding volume status bar filejoshua
Diffstat (limited to 'components')
-rw-r--r--components/pamixer_vol_perc.c37
1 files changed, 37 insertions, 0 deletions
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);
+ }
+}