From 4e11816ff41b971aa072d93bd5ca4764de343557 Mon Sep 17 00:00:00 2001 From: Ryan Kes Date: Tue, 2 Apr 2019 11:37:14 +0200 Subject: [PATCH] added alsa patch --- .gitignore | 2 + PKGBUILD | 4 +- alsa-20190402-eeb3975.diff | 116 +++++++++++++++++++++++++++++++++++++ config_desktop.h | 2 +- 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 alsa-20190402-eeb3975.diff diff --git a/.gitignore b/.gitignore index f6b4a85..b457094 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ pkg/ src/ # End of https://www.gitignore.io/api/archlinuxpackages + +slstatus/ diff --git a/PKGBUILD b/PKGBUILD index 666a18e..ffdc38a 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -16,6 +16,7 @@ _patches=( "ipv4-multiple-20190312-5f08c89.diff" "netspeed-multiple-20190312-2ac86e1.diff" "combined_network-20190312-619ed9f.diff" + "alsa-20190402-eeb3975.diff" ) source=("git+https://git.suckless.org/${pkgname%-git}" @@ -28,7 +29,8 @@ md5sums=('SKIP' '58404d0af1893f560926daf605a79919' 'fc9b31ea31470b6816f1f92c6bc6fa9d' '30f0a42ffc0e4f1e102ad2e3d1afe988' - '865b046340744bc08c52170e0be78355') + '865b046340744bc08c52170e0be78355' + '567fdf2576d647be311827bc8f82c5cd') pkgver() { cd "${pkgname%-git}" diff --git a/alsa-20190402-eeb3975.diff b/alsa-20190402-eeb3975.diff new file mode 100644 index 0000000..d2472c0 --- /dev/null +++ b/alsa-20190402-eeb3975.diff @@ -0,0 +1,116 @@ +From: Đoàn Trần Công Danh + +There's a non-posix assignment inside config.mk, +but it's supported with both gmake and bmake. + + var != shell command +--- + components/volume.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ + config.def.h | 1 + + config.mk | 3 ++- + 3 files changed, 62 insertions(+), 1 deletion(-) + +diff --git a/components/volume.c b/components/volume.c +index 61cec90..eeb3975 100644 +--- a/components/volume.c ++++ b/components/volume.c +@@ -1,5 +1,6 @@ + /* See LICENSE file for copyright and license details. */ + #include ++#include + #include + #include + #include +@@ -72,6 +73,64 @@ + + return bprintf("%d", m ? 0 : v * 100 / 255); + } ++#elif defined(__linux__) ++#include ++#include ++ ++#define SOUND_CARD "default" ++#define MIXER_IDX 0 ++ ++const char* ++vol_perc(const char *mixer) ++{ ++ snd_mixer_t* handle; ++ snd_mixer_elem_t* elem; ++ snd_mixer_selem_id_t* sid; ++ snd_mixer_selem_channel_id_t c; ++ ++ int emute, muted = 0; ++ long minv, maxv, elemv, vol = LONG_MIN; ++ const char *result = NULL; ++ ++ snd_mixer_selem_id_alloca(&sid); ++ ++ //sets simple-mixer index and name ++ snd_mixer_selem_id_set_index(sid, MIXER_IDX); ++ snd_mixer_selem_id_set_name(sid, mixer); ++ ++ if ((snd_mixer_open(&handle, 0)) < 0) ++ goto out; ++ if (snd_mixer_attach(handle, SOUND_CARD) < 0 || ++ snd_mixer_selem_register(handle, NULL, NULL) < 0 || ++ snd_mixer_load(handle) < 0 || ++ !(elem = snd_mixer_find_selem(handle, sid))) ++ goto cleanup; ++ ++ snd_mixer_selem_get_playback_volume_range(elem, &minv, &maxv); ++ ++ if(minv == maxv) ++ goto cleanup; ++ ++ for (c = 0; c <= SND_MIXER_SCHN_LAST; ++c) ++ if (snd_mixer_selem_has_playback_channel(elem, c)) { ++ if (!snd_mixer_selem_get_playback_volume(elem, c, &elemv) ++ && elemv > vol) ++ vol = elemv; ++ if (!muted ++ && !snd_mixer_selem_get_playback_switch(elem, c, &emute)) ++ muted = !emute; ++ } ++ if (minv > vol || maxv < vol) ++ goto cleanup; ++ ++ result = bprintf("%d%% [%s]", ++ (200 * (vol - minv) + maxv - minv) / (maxv - minv) / 2, ++ muted ? "off" : "on"); ++cleanup: ++ snd_mixer_close(handle); ++out: ++ return result; ++} + #else + #include + +diff --git a/config.def.h b/config.def.h +index e06be66..40f0a28 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -58,6 +58,7 @@ static const char unknown_str[] = "n/a"; + * uptime system uptime NULL + * username username of current user NULL + * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) ++ * mixer name on Linux (Master) + * wifi_perc WiFi signal in percent interface name (wlan0) + * wifi_essid WiFi ESSID interface name (wlan0) + */ +diff --git a/config.mk b/config.mk +index 3b32b7c..6903fe1 100644 +--- a/config.mk ++++ b/config.mk +@@ -14,7 +14,8 @@ X11LIB = /usr/X11R6/lib + CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE + CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os + LDFLAGS = -L$(X11LIB) -s +-LDLIBS = -lX11 ++ALSALIBS != [ Linux = `uname -s` ] && printf "%s" "-lasound" ++LDLIBS = -lX11 $(ALSALIBS) + + # compiler and linker + CC = cc +-- +2.21.0 diff --git a/config_desktop.h b/config_desktop.h index 0bf0671..af91d83 100644 --- a/config_desktop.h +++ b/config_desktop.h @@ -70,7 +70,7 @@ static const struct arg args[] = { { netspeed_rx, "\x0A  %s", "eno1" }, { netspeed_tx, "  %s ", "eno1" }, /* { seperator, "\x0F", NULL }, */ - { vol_perc, "\x10 蓼 %s%% ", "/dev/mixer" }, + { vol_perc, "\x10 蓼 %s ", "Master" }, /* { seperator, "\x11", NULL }, */ { disk_perc, "\x12 / %s%%", "/" }, { disk_perc, "  %s%% ", "/home" },