Skip to content

Commit

Permalink
switch to pipewire/wpctl
Browse files Browse the repository at this point in the history
At this point, most modern distributions should be using pipewire.
  • Loading branch information
Arctize committed Aug 21, 2024
1 parent b07c968 commit 8cb6213
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions barify
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ if ! flock -x -w $TIMEOUT $FD; then
fi

function get_volume {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print int($2 * 100)}'
}

function is_mute {
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep -q 'MUTED'
}

function get_brightness {
Expand Down Expand Up @@ -165,22 +165,25 @@ function send_notification {
}

if [ $mode == $MODE_VOLUME ]; then
if ! type wpctl &>/dev/null; then
echo 'Error: wpctl is required for volume control' 1>&2
exit 1
fi
case $action in
"$ACTION_INCREASE")
# Set the volume on (if it was muted)
amixer -D pulse set Master on >/dev/null
# Up the volume (+ 5%)
amixer -D pulse sset Master 4%+ >/dev/null
# Unmute when changing volume
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.05+
send_notification "$(get_volume)"
;;
"$ACTION_DECREASE")
amixer -D pulse set Master on >/dev/null
amixer -D pulse sset Master 4%- >/dev/null
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.05-
send_notification "$(get_volume)"
;;
"$ACTION_MUTE")
# Toggle mute
amixer -D pulse set Master 1+ toggle >/dev/null
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
send_notification "$(get_volume)"
;;
esac
Expand Down

0 comments on commit 8cb6213

Please sign in to comment.