forked from external/yambar
module/alsa: add ‘percent’ tag - volume level as a percentage
Fixes part of #10
This commit is contained in:
parent
eceee99fb0
commit
85ae4cca37
3 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue