@@ -30,8 +30,8 @@ function gui_audiosettings() {
30
30
# The list of ALSA cards/devices depends on the 'snd-bcm2385' module parameter 'enable_compat_alsa'
31
31
# * enable_compat_alsa: true - single soundcard, output is routed based on the `numid` control
32
32
# * enable_compat_alsa: false - one soundcard per output type (HDMI/Headphones)
33
- # If PulseAudio is enabled, then try to configure it and leave ALSA alone
34
- if _pa_cmd_audiosettings systemctl -q --user is-enabled pulseaudio.socket; then
33
+ # When PulseAudio/PipeWire is enabled, try to configure it and leave ALSA alone
34
+ if _pa_cmd_audiosettings systemctl -q --user is-enabled { pulseaudio,pipewire-pulse} .socket; then
35
35
_pulseaudio_audiosettings
36
36
elif aplay -l | grep -q " bcm2835 ALSA" ; then
37
37
_bcm2835_alsa_compat_audiosettings
@@ -76,9 +76,13 @@ function _bcm2835_alsa_compat_audiosettings() {
76
76
M " Mixer - adjust output volume"
77
77
R " Reset to default"
78
78
)
79
- # If PulseAudio is installed, add an option to enable it
80
- hasPackage " pulseaudio" && options+=(P " Enable PulseAudio" )
81
-
79
+ # If PulseAudio (PipeWire) is installed, add an option to enable it
80
+ local sound_server=" PulseAudio"
81
+ if hasPackage " wireplumber" ; then
82
+ options+=(P " Enable PipeWire" )
83
+ else
84
+ hasPackage " pulseaudio" && options+=(P " Enable PulseAudio" )
85
+ fi
82
86
choice=$( " ${cmd[@]} " " ${options[@]} " 2>&1 > /dev/tty)
83
87
if [[ -n " $choice " ]]; then
84
88
case " $choice " in
@@ -110,8 +114,8 @@ function _bcm2835_alsa_compat_audiosettings() {
110
114
_reset_alsa_audiosettings
111
115
;;
112
116
P)
113
- _toggle_pulseaudio_audiosettings " on"
114
- printMsgs " dialog" " PulseAudio enabled"
117
+ _toggle_ ${sound_server,,} audiosettings " on"
118
+ printMsgs " dialog" " ${sound_server} enabled"
115
119
;;
116
120
esac
117
121
fi
@@ -134,8 +138,14 @@ function _bcm2835_alsa_internal_audiosettings() {
134
138
R " Reset to default"
135
139
)
136
140
137
- # If PulseAudio is installed, add an option to enable it
138
- hasPackage " pulseaudio" && options+=(P " Enable PulseAudio" )
141
+ # If PulseAudio (PipeWire) is installed, add an option to enable it
142
+ local sound_server=" PulseAudio"
143
+ if hasPackage " wireplumber" ; then
144
+ options+=(P " Enable PipeWire" )
145
+ sound_server=" PipeWire"
146
+ else
147
+ hasPackage " pulseaudio" && options+=(P " Enable PulseAudio" )
148
+ fi
139
149
140
150
choice=$( " ${cmd[@]} " " ${options[@]} " 2>&1 > /dev/tty)
141
151
if [[ -n " $choice " ]]; then
@@ -152,8 +162,8 @@ function _bcm2835_alsa_internal_audiosettings() {
152
162
_reset_alsa_audiosettings
153
163
;;
154
164
P)
155
- _toggle_pulseaudio_audiosettings " on"
156
- printMsgs " dialog" " PulseAudio enabled"
165
+ _toggle_ ${sound_server,,} _audiosettings " on"
166
+ printMsgs " dialog" " $sound_server enabled"
157
167
;;
158
168
esac
159
169
fi
@@ -231,29 +241,31 @@ EOF
231
241
}
232
242
233
243
function _pulseaudio_audiosettings() {
234
- local cmd=(dialog --backtitle " $__backtitle " --menu " Set audio output (PulseAudio)" 22 86 16)
235
244
local options=()
236
245
local sink_index
237
246
local sink_label
247
+ local sound_server=" PulseAudio"
238
248
239
- # Check if PulseAudio is running, otherwise 'pacmd ' will not work
240
- if ! _pa_cmd_audiosettings pacmd stat > /dev/null; then
241
- printMsgs " dialog" " PulseAudio is enabled , but not running\nAudio settings cannot be set right now"
249
+ # Check if PulseAudio is running, otherwise 'pactl ' will not work
250
+ if ! _pa_cmd_audiosettings pactl info > /dev/null; then
251
+ printMsgs " dialog" " PulseAudio is present , but not running. \nAudio settings cannot be set right now. "
242
252
return
243
253
fi
244
254
while read sink_index sink_label; do
245
255
options+=(" $sink_index " " $sink_label " )
246
- done < <( _pa_cmd_audiosettings pacmd list- sinks | \
247
- awk -F [:= ] ' /index/ { idx=$2;
256
+ done < <( _pa_cmd_audiosettings pactl list sinks | \
257
+ awk -F [:= ] ' BEGIN { idx=0}; /Name:/ {
248
258
do {getline} while($0 !~ "alsa.name");
249
259
gsub(/"|bcm2835[^a-zA-Z]+/, "", $2);
250
- print idx,$2 }'
260
+ print idx,$2;
261
+ idx++}'
251
262
)
252
-
263
+ _pa_cmd_audiosettings pactl info | grep -i pipewire > /dev/null && sound_server=" PipeWire"
264
+ local cmd=(dialog --backtitle " $__backtitle " --menu " Set audio output ($sound_server )" 22 86 16)
253
265
options+=(
254
266
M " Mixer - adjust output volume"
255
267
R " Reset to default"
256
- P " Disable PulseAudio "
268
+ P " Disable $sound_server "
257
269
)
258
270
choice=$( " ${cmd[@]} " " ${options[@]} " 2>&1 > /dev/tty)
259
271
if [[ -n " $choice " ]]; then
@@ -275,8 +287,8 @@ function _pulseaudio_audiosettings() {
275
287
printMsgs " dialog" " Audio settings reset to defaults"
276
288
;;
277
289
P)
278
- _toggle_pulseaudio_audiosettings " off"
279
- printMsgs " dialog" " PulseAudio disabled"
290
+ _toggle_ ${sound_server,,} _audiosettings " off"
291
+ printMsgs " dialog" " ${sound_server} disabled"
280
292
;;
281
293
esac
282
294
fi
@@ -296,6 +308,20 @@ function _toggle_pulseaudio_audiosettings() {
296
308
fi
297
309
}
298
310
311
+ function _toggle_pipewire_audiosettings() {
312
+ local state=$1
313
+
314
+ if [[ " $state " == " on" ]]; then
315
+ _pa_cmd_audiosettings systemctl --user unmask pipewire-pulse.socket pipewire.socket
316
+ _pa_cmd_audiosettings systemctl --user start pipewire.service pipewire-pulse.service wireplumber.service
317
+ fi
318
+
319
+ if [[ " $state " == " off" ]]; then
320
+ _pa_cmd_audiosettings systemctl --user mask pipewire-pulse.socket pipewire.socket
321
+ _pa_cmd_audiosettings systemctl --user stop pipewire.service pipewire-pulse.service wireplumber.service
322
+ fi
323
+ }
324
+
299
325
# Run PulseAudio commands as the calling user
300
326
function _pa_cmd_audiosettings() {
301
327
[[ -n " $@ " ]] && sudo -u " $user " XDG_RUNTIME_DIR=/run/user/$SUDO_UID " $@ " 2> /dev/null
0 commit comments