From 90c0e2c903eac79e95b07ddc158538b25aa6ac6c Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Thu, 18 Feb 2021 16:24:25 +0100 Subject: [PATCH] sway_volume: improve notifications --- bin/sway_volume | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/sway_volume b/bin/sway_volume index d2455e3..73fae9f 100755 --- a/bin/sway_volume +++ b/bin/sway_volume @@ -2,8 +2,23 @@ source $HOME/.config/sway/bin/sway_helpers SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3) ICON_PATH=$HOME/.local/share/icons/Tela-circle-dark/16/actions -NOTIFY_APP="dunstify -a \"Volume\" -r 97" +NOTIFY_APP="dunstify -a \"Volume\" -h string:x-dunst-stack-tag:volume" +function getProgressString() { + ITEMS="$1" # The total number of items(the width of the bar) + FILLED_ITEM="$2" # The look of a filled item + NOT_FILLED_ITEM="$3" # The look of a not filled item + STATUS="$4" # The current progress status in percent + + # calculate how many items need to be filled and not filled + FILLED_ITEMS=$(echo "((${ITEMS} * ${STATUS})/100 + 0.5) / 1" | bc) + NOT_FILLED_ITEMS=$(echo "$ITEMS - $FILLED_ITEMS" | bc) + + # Assemble the bar string + msg=$(printf "%${FILLED_ITEMS}s" | sed "s| |${FILLED_ITEM}|g") + msg=${msg}$(printf "%${NOT_FILLED_ITEMS}s" | sed "s| |${NOT_FILLED_ITEM}|g") + echo "$msg" +} function notify() { VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//') MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2) @@ -11,16 +26,24 @@ function notify() { echo $MUTE ICON="" + TITLE="" + M="" if [ "$MUTE" = "yes" ]; then ICON=$ICON_PATH/audio-volume-muted.svg + TITLE="Volume ${VOLUME}%" + M="" elif [ $VOLUME -le 33 ]; then ICON=$ICON_PATH/audio-volume-low.svg + TITLE="Volume ${VOLUME}%" elif [ $VOLUME -le 67 ]; then ICON=$ICON_PATH/audio-volume-medium.svg + TITLE="Volume ${VOLUME}%" else ICON=$ICON_PATH/audio-volume-high.svg + TITLE="Volume ${VOLUME}%" fi - $NOTIFY_APP -i $ICON -a "Volume" "$VOLUME Mute: $MUTE" + # $NOTIFY_APP -i $ICON -a "Volume" "$TEXT" + $NOTIFY_APP -i $ICON -a "$TITLE" "[$(getProgressString 15 "$M" " " $VOLUME)]" } APP="pavucontrol"