From a20c17de66b417c133883e9b983db6315e532c0a Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 31 Oct 2020 16:51:20 +0100 Subject: Added config and patches Patches: - Pulseaudio volume - Battery warning --- components/battery.c | 5 ++++ components/custom.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 components/custom.c (limited to 'components') diff --git a/components/battery.c b/components/battery.c index 07b6ac1..f54db93 100644 --- a/components/battery.c +++ b/components/battery.c @@ -4,6 +4,9 @@ #include "../util.h" +// Used for battery warning +extern void batt_hook(int perc); + #if defined(__linux__) #include #include @@ -40,6 +43,8 @@ return NULL; } + batt_hook(perc); + return bprintf("%d", perc); } diff --git a/components/custom.c b/components/custom.c new file mode 100644 index 0000000..d68f506 --- /dev/null +++ b/components/custom.c @@ -0,0 +1,74 @@ + +#include +#include +#include + +#include "../util.h" + +// https://stackoverflow.com/questions/7657624/get-master-sound-volume-in-c-in-linux +const char *vol_pulse(void) +{ + snd_mixer_t *handle; + snd_mixer_elem_t *elem; + snd_mixer_selem_id_t *sid; + + static const char *mix_name = "Master"; + static const char *card = "default"; + static int mix_index = 0; + + static const char *notfound = "n/a"; + + snd_mixer_selem_id_alloca(&sid); + + snd_mixer_selem_id_set_index(sid, mix_index); + snd_mixer_selem_id_set_name(sid, mix_name); + + if ((snd_mixer_open(&handle, 0)) < 0) { + fprintf(stderr, "could not open mixer\n"); + return notfound; + } + if ((snd_mixer_attach(handle, card)) < 0) { + snd_mixer_close(handle); + fprintf(stderr, "could not open card %s\n", card); + return notfound; + } + if ((snd_mixer_selem_register(handle, NULL, NULL)) < 0) { + snd_mixer_close(handle); + fprintf(stderr, "could not register selem\n"); + return notfound; + } + int ret = snd_mixer_load(handle); + if (ret < 0) { + snd_mixer_close(handle); + fprintf(stderr, "could not load mixer\n"); + return notfound; + } + elem = snd_mixer_find_selem(handle, sid); + if (!elem) { + snd_mixer_close(handle); + fprintf(stderr, "could not find selem with index=%d, name=%s\n", mix_index, mix_name); + return notfound; + } + + long minv, maxv; + long outvol; + int muted; + + snd_mixer_selem_get_playback_volume_range(elem, &minv, &maxv); + + if(snd_mixer_selem_get_playback_volume(elem, 0, &outvol) < 0) { + fprintf(stderr, "could not read output volume\n"); + snd_mixer_close(handle); + return notfound; + } + + if(snd_mixer_selem_get_playback_switch(elem, 0, &muted) < 0) { + fprintf(stderr, "could not read mute output\n"); + snd_mixer_close(handle); + return notfound; + } + + snd_mixer_close(handle); + + return bprintf("%0.0f%s", ((float)outvol / (float)maxv) * 100, muted ? "" : "M"); +} -- cgit v1.2.3