From 414570a9e418ba56224004519bb04497cebf44c2 Mon Sep 17 00:00:00 2001 From: AngeD Date: Wed, 21 Sep 2022 15:47:54 +0200 Subject: [PATCH] feat: set-vol now chooses between pactl and amixer --- .xinitrc | 4 ++-- bin/set-vol | 39 +++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.xinitrc b/.xinitrc index cf93860..3d451f1 100644 --- a/.xinitrc +++ b/.xinitrc @@ -1,8 +1,8 @@ #!/bin/sh xrandr \ - --output HDMI-2 --auto --primary \ - --output eDP-1 --left-of HDMI-2 + --output eDP-1 --primary \ + --output HDMI-2 --right-of-eDP-1 # fix touchscreen xinput --map-to-output 'Raydium Corporation Raydium Touch System' 'eDP-1' diff --git a/bin/set-vol b/bin/set-vol index 0a1d88c..605647f 100755 --- a/bin/set-vol +++ b/bin/set-vol @@ -1,32 +1,47 @@ #!/bin/bash set -e -SINK='@DEFAULT_SINK@' -CUR_FILE=/var/tmp/current_volume +PACTL_SINK='@DEFAULT_SINK@' +SINK="$PACTL_SINK" + +function get_vol() { + VOL="$(pactl get-sink-volume "$SINK" 2> /dev/null)" + + if [ -n "$VOL" ]; then + CMD='pactl set-sink-volume' + else + CMD='amixer sset' + SINK='Master' + + VOL="$(amixer sget "$SINK")" + fi +} set +e -CUR="$(cat "$CUR_FILE" || echo 50)" +get_vol set -e -CUR="$((CUR - CUR % "$1"))" +VOL="$(echo "$VOL" | grep -o -E '[0-9]{,3}%' | head -n 1)" +# Remove everything after first '%' +VOL="${VOL%%%*}" +VOL="$((VOL - VOL % "$1"))" case "${1:0:1}" in '') exit 1 ;; '+'|'-') - NEW="$((CUR + "$1"))" + VOL="$((VOL + "$1"))" ;; *) - NEW="$1" + VOL="$1" ;; esac -[ "$NEW" -lt 0 ] && NEW=0 -[ "$NEW" -gt 100 ] && NEW=100 +[ "$VOL" -lt 0 ] && VOL=0 +[ "$VOL" -gt 100 ] && VOL=100 -pactl set-sink-volume "$SINK" "$NEW%" -pactl set-sink-mute "$SINK" 0 +$CMD "$SINK" "$VOL%" > /dev/null +pactl set-sink-mute "$PACTL_SINK" 0 -echo "$NEW" > "$CUR_FILE" -echo "$NEW" +echo "$VOL"