Adjusting the Linux (Xfce) Volume Control
Posted on Sunday, February 20, 2022 by TheBlackzone
Like many others I like to listen to music while sitting at my computer. When I am coding or doing other work I need to concentrate on, I do so at a very low volume level, just enough that the music is audible without distracting me. For this reason I use the volume controls of my keyboard quite often to adjust the level according to the current situation.
Normally the volume keys increase or decrease the volume level by 5%, which in most cases is a reasonable setting. But combined with my DELL AC511 sound bar, a step of 5% sometimes goes from “mute” directly to “too loud”, forcing me to use the mouse to make adjustments with the volume slider control.
I was looking for some way to have a more fine-grained control over the amount of volume change when using the keyboard and came up with two solutions to this “problem”.
The first one is specific to the Xfce desktop environment with the “xfce4-pulseaudio-plugin”, which is what I am using, the second one is more generic and works in Xfce as well as in other Linux desktop environments.
Let’s get started…
Solution for the “Xfce4-pulseaudio-plugin”
Unfortunately the “xfce4-pulseaudio-plugin” has no user accessible way to adjust the amount of volume change using to the volume control keys and the official documentation contains no hint on how to change it.
So I grabbed the “xfce4-pulseaudio-plugin” source code and quickly flicked through it to see if there is any way to change it without changing the source code itself and compiling the plugin myself. And in fact, the plugin is querying for a global configuration value named “volume-step”.
With this knowledge it becomes easy:
Open the Xfce Settings Manager and go to the “xfce4-panel” settings. There look through the “plugins” and find the “pulseaudio” plugin (here it is “plugin-9”):
There create a new
integer value named “volume-step” and set it to the desired value, which is in my case “2” (percent).
The same can be done from the shell with the following commands.
First find the plugin number of the “xfce-pluseaudio-plugin”:
xfconf-query -c xfce4-panel -lv | grep pulseaudio
Which in my case yields the result
Then create a new property for the plugin named “volume-step” of type “integer” with the required value, which again is “2” (percent) in my case:
xfconf-query -c xfce4-panel -p /plugins/plugin-9/volume-step --create -t int -s 2
Now restart the Xfce4 session (or reboot your computer) to activate the new setting.
Another, more generic solution which is also applicable for other Linux desktop environments, is to use
amixer command and bind it to your keyboard’s volume control keys.
In the case of Xfce this is done from the keyboard settings in the “Application Shortcuts” tab.
There create new bindings for the following commands, each assigned to the appropriate volume control key:
For “Volume up”:
amixer -q -D pulse sset Master 2%+
For “Volume down”:
amixer -q -D pulse sset Master 2%-
And, if necessary, for “Toggle mute”:
amixer -q -D pulse sset Master toggle
I went for the
amixer solution first before I thought “I can’t believe that there is no setting for that in Xfce.” and made the effort to check the source code of the “xfce-pulseaudio-plugin” and finally found the “hidden” option there.
But because of this curiosity I have yet again spent too much time on figuring out how something obviously easy can be solved. So I put it here in the hope that it will save you some time if you are looking to achieve something similar…
Tags: computer, linux