sway: use pamixer for volume control bindings

Fixes: SIG#22
This commit is contained in:
Aleksei Bavshin 2022-06-29 00:10:50 -07:00 committed by Aleksei Bavshin
commit 3e47597ac1
No known key found for this signature in database
GPG key ID: 4F071603387A382A
3 changed files with 13 additions and 38 deletions

View file

@ -1,30 +0,0 @@
#!/bin/sh
if ! command -v notify-send >/dev/null || ! command -v pactl > /dev/null; then
exit 0;
fi
# pactl output depends on the current locale
export LANG=C.UTF-8 LC_ALL=C.UTF-8
SINK=${1:-@DEFAULT_SINK@}
VOLUME=$(pactl get-sink-volume "$SINK")
# get first percent value
VOLUME=${VOLUME%%%*}
VOLUME=${VOLUME##* }
TEXT="Volume: ${VOLUME}%"
case $(pactl get-sink-mute "$SINK") in
*yes)
TEXT="Volume: muted"
VOLUME=0
;;
esac
notify-send \
--app-name sway \
--expire-time 800 \
--hint string:x-canonical-private-synchronous:volume \
--hint "int:value:$VOLUME" \
--transient \
"${TEXT}"

View file

@ -42,8 +42,8 @@ Requires: desktop-backgrounds-compat
Requires: grimshot
Requires: light
Requires: lxqt-policykit
Requires: pamixer
Requires: playerctl
Requires: pulseaudio-utils
Requires: swaybg
Requires: swayidle
Requires: swaylock

View file

@ -1,20 +1,25 @@
# Key bindings to control pipewire or pulseaudio volume with pactl.
# Key bindings to control pipewire or pulseaudio volume with pamixer.
# Displays a notification with the current state if /usr/bin/notify-send is available
#
# Volume increase/decrease step can be customized by setting the `$volume_step`
# variable to a numeric value before including the file.
#
# Requires: pulseaudio-utils
# Requires: pamixer
# Recommends: libnotify
set $volume_notification_cmd /usr/libexec/sway/notify-volume
set $volume_notification_cmd command -v notify-send >/dev/null && \
VOLUME=$(pamixer --get-volume-human) VALUE=${VOLUME%%%} && \
if [ -z "$VALUE" ] || [ "$VALUE" = muted ]; then VALUE=0; fi && \
notify-send -e -a sway -h string:x-canonical-private-synchronous:volume \
-h "int:value:$VALUE" -t 800 "Volume: $VOLUME"
# Allow volume controls even if the screen is locked
# Note the 'single quotes' around the commands; it is required to exec a command with a semicolon.
bindsym --locked {
XF86AudioRaiseVolume exec \
'STEP="$volume_step" && pactl set-sink-volume @DEFAULT_SINK@ +${STEP:-5}% && $volume_notification_cmd'
'STEP="$volume_step" && pamixer --increase ${STEP:-5} && $volume_notification_cmd'
XF86AudioLowerVolume exec \
'STEP="$volume_step" && pactl set-sink-volume @DEFAULT_SINK@ -${STEP:-5}% && $volume_notification_cmd'
XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle && $volume_notification_cmd
XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
'STEP="$volume_step" && pamixer --decrease ${STEP:-5} && $volume_notification_cmd'
XF86AudioMute exec 'pamixer --toggle-mute && $volume_notification_cmd'
XF86AudioMicMute exec pamixer --toggle-mute --default-source
}