DWM Dunst and Thinkpad audio keys
2025-04-24
How I got them working, microphone mute led included
DWM isn't a desktop environment, so there are a few things to add, like notifications and audio keys.
I installed dunst and acpid. Dunst is managed by systemd, if you edit ~/.config/dunst/dunstrc restart dunst with systemctl --user restart dunst.service
dwm/config.h
The audio keys are registered in dwm/config.h
...
{ 0, XF86XK_AudioMicMute, spawn, SHCMD("~/.local/bin/dwm-audio mictoggle") },
{ 0, XF86XK_AudioMute, spawn, SHCMD("~/.local/bin/dwm-audio voltoggle") },
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("~/.local/bin/dwm-audio volquieter") },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("~/.local/bin/dwm-audio vollouder") },
...
~/.local/bin/dwm-audio
The audio keys run a bash script which sets volume, speaker mute, and microphone mute.
#!/bin/bash
# Manage Thinkpad Audio keys
msgTag="Audio"
# Microphone
if [[ "$@" == "mictoggle" ]]; then
pamixer --default-source -t
micmute="$(pamixer --default-source --get-mute)"
if [[ "$micmute" == "true" ]]; then
# Mic muted notification
dunstify -t 1000 -a "Microphone" -u low -i audio-input-microphone \
-h string:x-dunst-stack-tag:$msgTag "Microphone muted"
else
# Mic unmuted notification
dunstify -t 1000 -a "Microphone" -u low -i audio-input-microphone \
-h string:x-dunst-stack-tag:$msgTag "Microphone unmuted"
fi
exit 0
fi
# Speakers
if [[ "$@" == "voltoggle" ]]; then
pamixer --toggle-mute
elif [[ "$@" == "vollouder" ]]; then
pamixer -i 10
elif [[ "$@" == "volquieter" ]]; then
pamixer -d 10
fi
volume="$(pamixer --get-volume-human)"
mute="$(pamixer --get-mute)"
if [[ $volume == 0 || "$mute" == "true" ]]; then
# Sound muted notification
dunstify -t 1000 -a "changeVolume" -u low -i audio-speakers \
-h string:x-dunst-stack-tag:$msgTag "Volume muted"
else
# Volume notification
dunstify -t 1000 -a "changeVolume" -u low -i audio-speakers \
-h string:x-dunst-stack-tag:$msgTag -h int:value:"$volume" "Volume: ${volume}"
fi
Microphone mute led
I'm running Arch Linux on a Thinkpad X220, so I need to make the mic/mute button's led lights up when muted. This can't be done with normal user permissions, so I installed acpid. On Arch linux all acpi events are passed to /etc/acpi/handler.sh, so I added another function to this file.
...
button/micmute)
if [[ "$(cat /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness)" == "1" ]]; then
echo "0" > /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness
else
echo "1" > /sys/devices/platform/thinkpad_acpi/leds/platform\:\:micmute/brightness
fi
;;
...