1. Software switching support
Check, if your sound card supports software switching for the front audio panel. Some older motherboards don't support software switching at all. Some sound cards have connectors for both variants on the motherboard: software and hardware switching. In this case, make sure from your motherboard manual, that you use the connector with software switching.
2. Alsamixer Auto-Mute
Auto-Mute is a feature of Alsa. It ensures that when you connect your headphones, the other audio outputs are automatically muted. You can find and disable this in
alsamixer. Open AlsaMixer, choose your sound card with F6 then move with < and > and find Auto-Mute. If it's enabled, disable it with the down arrow key.
3. PulseAudio configuration
This was the most problematic part for me because PulseAudio is poorly documented. When I disabled AutoMute in the previous step, speakers played in both cases. No matter, if I switched to Headphones or Line-out.
So what I had to do was look into AlsaMixer again and understand, how the volume bars react to audio switching in settings or pavucontrol.
As you can see, after switching to headphones, almost all volume bars got muted. But as I found out after a while, the volume of my speakers is for some reason controlled by Front bar. So now the last thing I had to do, was to configure PulseAudio to mute this Front volume-bar after switching to headphones.
PulseAudio configuration files we need to edit are stored in
/usr/share/pulseaudio/alsa-mixer/paths/. In my case, I only edited the file
analog-output-headphones.conf but this may vary depending on the configuration. You have to edit the file as root to contain these lines:
switch = off
volume = off
Once you are done, save the file and restart PulseAudio with
Output switching should now work as expected.