added patches

This commit is contained in:
λmolinae 2025-03-12 08:38:50 -06:00
parent f68f49273e
commit 8c6890f943
13 changed files with 395 additions and 205 deletions

View file

@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
@ -8,6 +9,22 @@
#include "../slstatus.h"
#include "../util.h"
const char *
vol_icon(const char *arg)
{
char *p;
const char *perc;
static const char *icons[] = { "󰕿", "󰖀", "󰕾" };
unsigned long ul_perc;
if (!(perc = vol_perc(arg)))
return NULL;
p = strrchr(perc, ' ');
ul_perc = strtoul(p ? p + 1 : perc, NULL, 10);
return bprintf("%s %d", p ? "󰝟" : icons[ul_perc / 34], ul_perc);
}
#if defined(__OpenBSD__) | defined(__FreeBSD__)
#include <poll.h>
#include <sndio.h>
@ -182,6 +199,68 @@
return bprintf("%d", value);
}
#elif defined(ALSA)
#include <alsa/asoundlib.h>
static const char *devname = "default";
const char *
vol_perc(const char *mixname)
{
snd_mixer_t *mixer = NULL;
snd_mixer_selem_id_t *mixid = NULL;
snd_mixer_elem_t *elem = NULL;
long min = 0, max = 0, volume = -1;
int err, sw1, sw2;
if ((err = snd_mixer_open(&mixer, 0))) {
warn("snd_mixer_open: %d", err);
return NULL;
}
if ((err = snd_mixer_attach(mixer, devname))) {
warn("snd_mixer_attach(mixer, \"%s\"): %d", devname, err);
goto cleanup;
}
if ((err = snd_mixer_selem_register(mixer, NULL, NULL))) {
warn("snd_mixer_selem_register(mixer, NULL, NULL): %d", err);
goto cleanup;
}
if ((err = snd_mixer_load(mixer))) {
warn("snd_mixer_load(mixer): %d", err);
goto cleanup;
}
snd_mixer_selem_id_alloca(&mixid);
snd_mixer_selem_id_set_name(mixid, mixname);
snd_mixer_selem_id_set_index(mixid, 0);
elem = snd_mixer_find_selem(mixer, mixid);
if (!elem) {
warn("snd_mixer_find_selem(mixer, \"%s\") == NULL", mixname);
goto cleanup;
}
if ((err = snd_mixer_selem_get_playback_volume_range(elem, &min, &max))) {
warn("snd_mixer_selem_get_playback_volume_range(): %d", err);
goto cleanup;
}
if ((err = snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume))) {
warn("snd_mixer_selem_get_playback_volume(): %d", err);
}
if ((err = snd_mixer_selem_get_playback_switch(elem, 0, &sw1))) {
warn("snd_mixer_selem_get_playback_switch(): %d", err);
}
if ((err = snd_mixer_selem_get_playback_switch(elem, 1, &sw2))) {
warn("snd_mixer_selem_get_playback_switch(): %d", err);
}
cleanup:
snd_mixer_free(mixer);
snd_mixer_detach(mixer, devname);
snd_mixer_close(mixer);
return volume == -1 ? NULL : bprintf("%s%.0f",
!(sw1 || sw2) ? "muted " : "", (volume-min)*100./(max-min));
}
#else
#include <sys/soundcard.h>