[wiki] [sites] add slstatus-alsa-master-20230420-84a2f11.diff || willrabbermann
commit ddc7f93ec2f3981cb54c8645b28eaf445da446ee
Author: willrabbermann <willrabbermann_AT_gmail.com>
Date: Thu Apr 20 11:16:32 2023 -0500
add slstatus-alsa-master-20230420-84a2f11.diff
diff --git a/tools.suckless.org/slstatus/patches/alsa-master/index.md b/tools.suckless.org/slstatus/patches/alsa-master/index.md
new file mode 100644
index 00000000..3a1af99e
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/alsa-master/index.md
_AT_@ -0,0 +1,18 @@
+alsa-master
+===========
+
+Description
+-----------
+This patch adds a function to find the audio state (in percentage or as MUTE)
+of the Master ALSA device using a pipe stream to the command-line mixer for
+ALSA, amixer. It is simple and does not add additional compilation flags or
+require use of a /dev/mixer file. The output string will include the % char
+if the Master interface is on.
+
+Download
+--------
+* [slstatus-alsa-master-20230420-84a2f11.diff](slstatus-alsa-master-20230420-84a2f11.diff)
+
+Authors
+-------
+* William Rabbermann <willrabbermann_AT_gmail.com>
diff --git a/tools.suckless.org/slstatus/patches/alsa-master/slstatus-alsa-master-20230420-84a2f11.diff b/tools.suckless.org/slstatus/patches/alsa-master/slstatus-alsa-master-20230420-84a2f11.diff
new file mode 100644
index 00000000..34a960b7
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/alsa-master/slstatus-alsa-master-20230420-84a2f11.diff
_AT_@ -0,0 +1,106 @@
+diff --git a/Makefile b/Makefile
+index 2f93b87..41d5e9a 100644
+--- a/Makefile
++++ b/Makefile
+_AT_@ -6,6 +6,7 @@ include config.mk
+
+ REQ = util
+ COM =\
++ components/alsa_master_vol\
+ components/battery\
+ components/cpu\
+ components/datetime\
+diff --git a/components/alsa_master_vol.c b/components/alsa_master_vol.c
+new file mode 100644
+index 0000000..acc283b
+--- /dev/null
++++ b/components/alsa_master_vol.c
+_AT_@ -0,0 +1,64 @@
++/* Created by William Rabbermann */
++#include <stdio.h>
++#include <stdbool.h>
++#include <string.h>
++#include "../util.h"
++
++#define TMP_BUF_SIZE 14
++#define VOL_BUF_SIZE 5
++
++const char *
++alsa_master_vol(void)
++{
++ bool MASTER_IS_MUTED = true;
++ char tmp_buf[TMP_BUF_SIZE];
++ short b;
++ unsigned short i = 0;
++
++ FILE *fp = popen("amixer get Master | tail -c13", "r");
++ char ch;
++ while ((ch = fgetc(fp)) != EOF && i < TMP_BUF_SIZE)
++ tmp_buf[i++] = ch;
++ tmp_buf[i] = '++ pclose(fp);
++
++ b = i - 1;
++ while (b >= 0)
++ {
++ if ('[' == tmp_buf[b])
++ {
++ if (tmp_buf[b+1] == 'o' && tmp_buf[b+2] == 'n')
++ MASTER_IS_MUTED = false;
++ b -= 3;
++ break;
++ }
++ b--;
++ }
++
++ if (MASTER_IS_MUTED) return bprintf("MUTE");
++ else
++ {
++ char vol_buf[VOL_BUF_SIZE];
++ while (b >= 0)
++ {
++ if ('[' == tmp_buf[b])
++ break;
++ b--;
++ }
++
++ i = 0;
++ while (i < VOL_BUF_SIZE)
++ {
++ b++;
++ if (']' == tmp_buf[b])
++ {
++ vol_buf[i] = '++ break;
++ }
++ else
++ vol_buf[i++] = tmp_buf[b];
++ }
++
++ return bprintf("%s", vol_buf);
++ }
++}
+diff --git a/config.def.h b/config.def.h
+index 93a875a..6074441 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -58,6 +58,7 @@ static const char unknown_str[] = "n/a";
+ * uid UID of current user NULL
+ * uptime system uptime NULL
+ * username username of current user NULL
++ * alsa_master_vol ALSA Master device volume NULL
+ * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
+ * NULL on OpenBSD
+ * wifi_perc WiFi signal in percent interface name (wlan0)
+diff --git a/slstatus.h b/slstatus.h
+index b0f2564..415afc1 100644
+--- a/slstatus.h
++++ b/slstatus.h
+_AT_@ -78,6 +78,7 @@ const char *uid(void);
+
+ /* volume */
+ const char *vol_perc(const char *card);
++const char *alsa_master_vol(void);
+
+ /* wifi */
+ const char *wifi_perc(const char *interface);
Received on Thu Apr 20 2023 - 18:17:46 CEST
This archive was generated by hypermail 2.3.0
: Thu Apr 20 2023 - 18:24:57 CEST