From 85ae4cca37aa3832bd5cc6fffcd3b128141d72fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Sep 2020 13:39:52 +0200 Subject: [PATCH] =?UTF-8?q?module/alsa:=20add=20=E2=80=98percent=E2=80=99?= =?UTF-8?q?=20tag=20-=20volume=20level=20as=20a=20percentage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes part of #10 --- CHANGELOG.md | 5 +++++ doc/yambar-modules.5.scd | 3 +++ modules/alsa.c | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd3c67..61037ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ ## Unreleased ### Added + +* alsa: `percentage` tag. This is an integer tag that represents the + current volume as a percentage value. + + ### Deprecated ### Removed ### Fixed diff --git a/doc/yambar-modules.5.scd b/doc/yambar-modules.5.scd index 947b57d..3a099c6 100644 --- a/doc/yambar-modules.5.scd +++ b/doc/yambar-modules.5.scd @@ -145,6 +145,9 @@ Monitors an alsa soundcard for volume and mute/unmute changes. | volume : range : Volume level, with min and max as start and end range values +| percent +: range +: Volume level, as a percentage | muted : bool : True if muted, otherwise false diff --git a/modules/alsa.c b/modules/alsa.c index b274903..6933fe5 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -43,13 +43,18 @@ content(struct module *mod) { struct private *m = mod->private; + int percent = m->vol_max - m->vol_min > 0 + ? 100 * m->vol_cur / (m->vol_max - m->vol_min) + : 0; + mtx_lock(&mod->lock); struct tag_set tags = { .tags = (struct tag *[]){ tag_new_int_range(mod, "volume", m->vol_cur, m->vol_min, m->vol_max), + tag_new_int_range(mod, "percent", percent, 0, 100), tag_new_bool(mod, "muted", m->muted), }, - .count = 2, + .count = 3, }; mtx_unlock(&mod->lock);