Feature request: alsa support
This feature would be great!
In the meantime, here's a script that outputs Alsa volume level on demand, as well as a class muted when audio is either muted or at 0%.
It's very simple so you'll need to set it up to be polled every second with the interval option, but it's better than nothing. Also note that I wrote it for my own setup, wherein I don't need to specify which audio device I'm targeting - it should be easily amendable if you need to pass extra arguments to amixer.
Using intervals is an option but if you want to be updated on demand, every time you update it you could use signal traps. The script I'm using is:
#!/bin/bash
amixer get Master | grep '%' | awk -F '[][]' '{print $2}';
function print {
amixer get Master | grep '%' | awk -F '[][]' '{print $2}';
}
trap print RTMIN+1
while true; do
sleep infinity & wait $!
done
Basically you print it once, then enter an infinite loop of sleeping and waiting for a new signal to print the updated value.
Of course you have to send the signal from somewhere, in my case I've set my sway configuration to increase/decrease volume with a custom keybinding that also sends the signal to the script like this:
bindsym Control+Up exec amixer set Master 10%+; exec pkill -SIGRTMIN+1 custom-alsa.sh
bindsym Control+Down exec amixer set Master 10%-; exec pkill -SIGRTMIN+1 custom-alsa.sh
This is probably an alternate solution for #170
I plan on creating an ALSA module but for now here's my one-liner which is most efficient and featured (as of now)
"custom/alsa": {
"exec": "amixer get Master | sed -nre 's/.*\\[off\\].*/ \n\nmuted/p; s/.*\\[(.*%)\\].*/ \\1/p'",
"on-click": "amixer set Master toggle; pkill -x -RTMIN+11 waybar",
"on-scroll-up": "amixer set Master 1+; pkill -x -RTMIN+11 waybar",
"on-scroll-down": "amixer set Master 1-; pkill -x -RTMIN+11 waybar",
"signal": 11,
"interval": 10,
"tooltip": false
},
Those are FontAwesome4 icons so replace them and the signal as needed. I also bind my laptop's volume keys with
bindsym --locked XF86AudioLowerVolume exec amixer set Master 5%- && pkill -x -RTMIN+11 waybar
bindsym --locked XF86AudioRaiseVolume exec amixer set Master 5%+ && pkill -x -RTMIN+11 waybar
bindsym --locked XF86AudioLowerVolume+shift exec amixer set Master 1%- && pkill -x -RTMIN+11 waybar
bindsym --locked XF86AudioRaiseVolume+shift exec amixer set Master 1%+ && pkill -x -RTMIN+11 waybar
Hope I've helped a few more people move away from pulseaudio's bloat...
Hi @unresolvedsymbol, I am trying to get your alsa module working, but for some reason it's not showing up in my waybar. This is my waybar config:
{
"layer": "top",
"position": "top",
"height": 30,
"modules-left": ["sway/workspaces", "sway/mode"],
"modules-center": ["sway/window"],
"modules-right": ["custom/alsa", "network", "cpu","temperature", "memory", "backlight", "battery", "clock"],
"sway/mode": {
"format": "<span style=\"italic\">{}</span>"
},
"tray": {
"icon-size": 30,
"spacing": 10
},
"clock": {
"format": "{:%d/%m/%Y %H:%M}"
},
"cpu": {
"format": "{usage}% ",
"tooltip": false
},
"memory": {
"format": "{}% "
},
"battery": {
"states": {
"good": 95,
"warning": 30,
"critical": 15
},
"format": "{capacity}% {icon}",
"format-icons": ["", "", "", "", ""]
},
"battery#bat2": {
"bat": "BAT2"
},
"network": {
// "interface": "wlp2s0", // (Optional) To force the use of this interface
"format-wifi": "{essid} ({signalStrength}%) ",
"format-ethernet": "{ifname}: {ipaddr}/{cidr} ",
"format-disconnected": "Disconnected ⚠"
},
"temperature": {
// "thermal-zone": 2,
// "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input",
"critical-threshold": 80,
// "format-critical": "{temperatureC}°C {icon}",
"format": "{temperatureC}°C {icon}",
"format-icons": ["", "", ""]
},
"backlight": {
// "device": "acpi_video1",
"format": "{percent}% {icon}",
"format-icons": ["", ""]
},
"custom/alsa": {
"exec": "amixer get Master | sed -nre 's/.*\\[off\\].*/ \n\nmuted/p; s/.*\\[(.*%)\\].*/ \\1/p'",
"on-click": "amixer set Master toggle; pkill -x -RTMIN+11 waybar",
"on-scroll-up": "amixer set Master 1+; pkill -x -RTMIN+11 waybar",
"on-scroll-down": "amixer set Master 1-; pkill -x -RTMIN+11 waybar",
"signal": 11,
"interval": 10,
"tooltip": false
}
}
All the other modules show up as expected, except for the custom/alsa...
@kflak: it seems that there's an issue somewhere between waybar config parsing and sed, since sed appears to receive a malformed command string - even though it does its job when ran directly, in waybar logs you will stumble upon sth like this:
sed: -e expression #1, char 26: unterminated `s' command
However, after getting read of the two newline characters (purpose of which I'm not sure, frankly), everything works just fine.
- "exec": "amixer get Master | sed -nre 's/.*\\[off\\].*/ \n\nmuted/p; s/.*\\[(.*%)\\].*/ \\1/p'",
+ "exec": "amixer get Master | sed -nre 's/.*\\[off\\].*/ muted/p; s/.*\\[(.*%)\\].*/ \\1/p'",
@Asgavar Thanks! Getting rid of the newlines does the trick. However, in the meantime I don't really use waybar anymore, I found i3status-rust to be a better alternative for my statusbar needs.
The newlines are for setting the "muted" class in which I have CSS making the background red (#custom-alsa.muted) not sure why it doesn't work in your case but thank you @Asgavar
Any one still working on this?
I would also like to see this feature implemented. I'm not familiar with the implementation, but alsactl monitor can be used to detect when the volume changes, so there is no need for polling.
Any progress on this?
Also looking for this feature. I'll try implementing it but I can't make any promises due to lack of free time.