src/audio: update

Update icon path, remove minor error and change steps to 5%.
This commit is contained in:
Luc Bijl 2025-08-14 20:33:09 +00:00
parent 944201b3bb
commit 479ed6be92

View file

@ -5,7 +5,7 @@ function notify_state {
case "$type" in
"sink") # Handle notifications for audio sink (output)
# Read the last audio sink notification ID from state, or set default if it does not exist
sink_last_notify_id="$(cat $HOME/.local/state/audio/sink || echo "1024")"
sink_last_notify_id="$(cat "$HOME/.local/state/audio/sink" || echo "1024")"
# Get the volume level and mute status of the default audio sink
local volume="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print $2 * 100}')"
@ -16,22 +16,22 @@ function notify_state {
# Send a different notification based on the volume level
if [ $volume -gt 67 ]; then
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_high -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_high -t 2000 -r $sink_last_notify_id -p)"
elif [ $volume -gt 33 ]; then
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_medium -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_medium -t 2000 -r $sink_last_notify_id -p)"
else
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_low -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_low -t 2000 -r $sink_last_notify_id -p)"
fi
else
sink_last_notify_id="$(notify-send "Volume sink: muted" -h int:value:${volume} -h string:synchronous: -i $sink_muted -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: muted" -h int:value:$volume -h string:synchronous: -i $sink_muted -t 2000 -r $sink_last_notify_id -p)"
fi
# Write the last audio sink notification ID to state
echo $sink_last_notify_id > $HOME/.local/state/audio/sink
echo "$sink_last_notify_id" > "$HOME/.local/state/audio/sink"
;;
"source") # Handle notifications for audio source (input)
# Read the last audio source notification from state, or set default if it does not exist
source_last_notify_id="$(cat $HOME/.local/state/audio/source || echo "1024")"
# Read the last audio source notification ID from state, or set default if it does not exist
source_last_notify_id="$(cat "$HOME/.local/state/audio/source" || echo "1024")"
# Get the volume level and mute status of the default audio source
local volume="$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | awk '{print $2 * 100}')"
@ -42,18 +42,18 @@ function notify_state {
# Send a different notification based on the volume level
if [ $volume -gt 67 ]; then
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_high -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_high -t 2000 -r $source_last_notify_id -p)"
elif [ $volume -gt 33 ]; then
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_medium -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_medium -t 2000 -r $source_last_notify_id -p)"
else
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_low -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_low -t 2000 -r $source_last_notify_id -p)"
fi
else
source_last_notify_id="$(notify-send "Volume source: muted" -h int:value:${volume} -h string:synchronous: -i $source_muted -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: muted" -h int:value:$volume -h string:synchronous: -i $source_muted -t 2000 -r $source_last_notify_id -p)"
fi
# Write the last audio source notification ID to state
echo $source_last_notify_id > $HOME/.local/state/audio/source
echo "$source_last_notify_id" > "$HOME/.local/state/audio/source"
;;
esac
}
@ -62,30 +62,31 @@ function notify_state {
type="$1"
action="$2"
# Define icon theme
icon_theme="tela-circle-black"
# Define icon theme and path
icon_theme="Tela-circle-black-dark"
icon_path="/usr/share/icons/${icon_theme}/24/panel"
# Define paths to icon files for different audio sink states
sink_high="/usr/share/icons/${icon_theme}/24/panel/audio-volume-high.svg"
sink_medium="/usr/share/icons/${icon_theme}/24/panel/audio-volume-medium.svg"
sink_low="/usr/share/icons/${icon_theme}/24/panel/audio-volume-low.svg"
sink_muted="/usr/share/icons/${icon_theme}/24/panel/audio-volume-muted.svg"
# Define icon files for different audio sink states
sink_high="${icon_path}/audio-volume-high.svg"
sink_medium="${icon_path}/audio-volume-medium.svg"
sink_low="${icon_path}/audio-volume-low.svg"
sink_muted="${icon_path}/audio-volume-muted.svg"
# Define paths to icon files for different audio source states
source_high="/usr/share/icons/${icon_theme}/24/panel/mic-volume-high.svg"
source_medium="/usr/share/icons/${icon_theme}/24/panel/mic-volume-medium.svg"
source_low="/usr/share/icons/${icon_theme}/24/panel/mic-volume-low.svg"
source_muted="/usr/share/icons/${icon_theme}/24/panel/mic-volume-muted.svg"
# Define icon files for different audio source states
source_high="${icon_path}/mic-volume-high.svg"
source_medium="${icon_path}/mic-volume-medium.svg"
source_low="${icon_path}/mic-volume-low.svg"
source_muted="${icon_path}/mic-volume-muted.svg"
# Determine action to take based on type
case "$type" in
"sink") # Actions for audio sink
case "$action" in
"volup") # Increase audio sink volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%+
"volup") # Increase audio sink volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
;;
"voldown") # Decrease audio sink volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%-
"voldown") # Decrease audio sink volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
;;
"toggle") # Toggle audio sink mute
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
@ -98,11 +99,11 @@ case "$type" in
;;
"source") # Actions for audio source
case "$action" in
"volup") # Increase audio source volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 10%+
"volup") # Increase audio source volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%+
;;
"voldown") # Decrease audio source volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 10%-
"voldown") # Decrease audio source volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%-
;;
"toggle") # Toggle audio source mute
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle