在 i3 wm 上,当我切换音频输出时,音量键停止工作

在 i3 wm 上,当我切换音频输出时,音量键停止工作

我习惯pavucontrol在声卡和 USB DAC 之间切换。每当我更换输出设备时,音量键就不再控制音量。

这是我的.i3/config文件

bindsym XF86AudioRaiseVolume exec pactl set-sink-volume 0 +5% || pactl set-sink-volume 0 -- +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume 0 -5% || pactl set-sink-volume 0 -- -5%
bindsym XF86AudioMute exec pactl set-sink-mute 0 toggle

我已尝试用 刷新我的 i3Status MOD+Shift+r

答案1

尝试.i3/config一下这个:

bindsym XF86AudioRaiseVolume exec pactl set-sink-volume $(pactl info | grep 'Default Sink: ' | sed 's/^Default Sink: //') +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume $(pactl info | grep 'Default Sink: ' | sed 's/^Default Sink: //') -5%

答案2

我认为我在从内置音频切换到 USB 条形音箱时也遇到了同样的问题。我对手动操作感到厌烦,而且经常忘记单击“输出设备”选项卡中的绿色勾选按钮,因此我决定编写脚本并从启动器中调用它。

我的脚本(我称之为切换音频输出) 使用的输出pacmd list-sinks查询所有输出接收器并切换到下一个。我的系统有 HDMI 音频,但由于我没有使用它,脚本会跳过它。脚本中有足够的注释,可以自定义您自己的系统。

#!/bin/bash
###############################################################################
# -- ToggleAudioOutput -- Script to change audio output sink.
#
################
# Program logic
#
# The function GetSinks performs a query and transformation.
# The output of GetSinks is stored in a variable.
# The number of sinks and the active sink (*) is determined.
# An array of all sinks is created, the active sink's position is saved.
# The next (or rolling to the first) sink in the array is marked.
# The marked sink is made active. 
# Is an application using the previous sink, force it to use the active.
# A notification about the active sink is shown on the screen.
################

function GetSinks()
{
# Function logic
#
# From the (lengthy) output of 'pacmd list-sinks':
#   grep for 'index' and 'device.description'; giving 2 lines,
#   awk merges 2 lines to 1,
#   remove the 'HDMI' line,  (optional)
#   remove 'index:' and 'device.description ='
#
# For example, the result on my system
#    index: 0
#       device.description = "Built-in Audio Digital Stereo (HDMI)"
#    index: 1
#       device.description = " Logitech Z305   Analog Stereo"
#  * index: 2
#       device.description = "Built-in Audio Analog Stereo"
#
# is transformed to:
#   1  Logitech Z305   Analog Stereo
#  *2 Built-in Audio Analog Stereo
#

################
# Function body.

Property="device.description"

# if HDMI must be in the toggle, comment it out or delete it.
# Be sure to not change the sequence of the following lines.
pacmd list-sinks                    |\
  grep -e"index:" -e"${Property}"   |\
  awk 'NR%2{printf "%s",$0;next;}1' |\
  grep -v HDMI                      |\
  sed "s/^\ \ //"                   |\
  sed "s/ index: //"                |\
  sed "s/[ \x9]*$Property = / /"    |\
  tr -d '\"'
}
# End Of Function

################
# Script body.

Sinks=$(GetSinks)       # call the function, store the output in a variable.
NrSinks=$(echo "$Sinks" | wc -l)
ActSink=$(echo "$Sinks" | grep '*' | cut -c2)

# fill the array, save the active sink's position.
i=1
while read Line
do
  set -- $Line
  SinkNr[$i]=$1;shift
  SinkName[$i]="$@"
  ((SinkNr[$i]==ActSink)) && ((Index=i))
  ((i++))
done < <(echo "$Sinks" | tr -d '*')

# The next or first sink becomes the active.
((Index++))
if ((Index > NrSinks))
then
  Index=1
fi

# Make it happen:
pacmd set-default-sink ${SinkNr[$Index]}

for InputIndex in $(pacmd list-sink-inputs | grep 'index:' | awk '{print $2}')
do
  pacmd move-sink-input $InputIndex ${SinkNr[$Index]}
done

notify-send "Audio output device set to:   >${SinkName[$Index]}<" -t 5000
# End Of File

相关内容