I had earlier solved this issue in my previous arch DWM build but that was somehow broken; so had to configure this again. Considering it was such a pain I thought of sharing my own approach.
I wrote a small script that changes the volume based on the parameters passed via DWM, once the volume is changed a notification is sent via dunst.
Identifying Keys
You first need to identify which keys toggle the volume, what is their assigned tag.
It can be easily done by using the following command:
xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'
In my case they were:
XF86_AudioRaiseVolume
XF86_AudioLowerVolume
XF86_AudioMute
Script
The following script volstat
to be created and added to path like /usr/local/bin/
#!/bin/bash
pamixer -$1 $2
# Below for showing volume level(numeric), its stacks
# notify-send -t 1000 "Volume is: $(pamixer --get-volume)"
# Progress bar
dunstify -t 1000 "Volume: " -h int:value:"`pamixer --get-volume`"
DWM config changes
Include this package #include <X11/XF86keysym.h>
in config.h
also add the following lines:
/* volume keys */
static const char *upvol[] = {"volstat", "i", "5", NULL}; //increases volume by 5
static const char *downvol[] = {"volstat", "d", "5", NULL}; //decreases volume by 5
static const char *toggle[] = {"pamixer", "-t", NULL}; //for muting
/* add in static const Key keys[] = {..} */
{ 0, XF86XK_AudioRaiseVolume, spawn, {.v = upvol} },
{ 0, XF86XK_AudioLowerVolume, spawn, {.v = downvol} },
{ 0, XF86XK_AudioMute, spawn, {.v = toggle} },
The key name might differ according to your device
Do sudo make clean install
and also add dunst &
to your .xinitrc
file.
I didnt configure for mute keypress as visual feedback for that via led, was already present on my keyboard, but it can be done in a similar fashion.