This commit is contained in:
soraefir
2026-06-13 22:42:46 +02:00
parent 0a3fef0b1c
commit 0796677cd7

View File

@@ -80,14 +80,21 @@ emit_status() {
'{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations, "media": $media}'
}
get_mpv_node() {
wpctl status 2>/dev/null | awk '
get_stream_node() {
local name="$1"
wpctl status 2>/dev/null | awk -v pat="$name" '
/Streams:/ { in_s = 1 }
/Sinks:|Sources:|Clients:/ { in_s = 0 }
in_s && /[0-9]+\..*mpv/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }
in_s && /[0-9]+\./ && tolower($0) ~ tolower(pat) {
match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit
}
'
}
get_mpv_node() {
get_stream_node "mpv"
}
get_volume() {
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
local node_id; node_id=$(get_mpv_node)
@@ -112,23 +119,19 @@ do_vol() {
}
do_mute() {
local node_id
if [ "$PID" -gt 0 ] && kill -0 "$PID" 2>/dev/null; then
local node_id; node_id=$(get_mpv_node)
if [ -n "$node_id" ]; then
wpctl set-mute "$node_id" toggle
if wpctl get-volume "$node_id" 2>/dev/null | grep -q MUTED; then
eww update radio-muted=true
else
eww update radio-muted=false
fi
fi
node_id=$(get_mpv_node)
else
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
if wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null | grep -q MUTED; then
eww update radio-muted=true
else
eww update radio-muted=false
fi
local player; player=$(playerctl -l 2>/dev/null | grep -Ev '^mpv' | head -1)
[ -n "$player" ] && node_id=$(get_stream_node "${player%%.*}")
fi
[ -z "$node_id" ] && return
wpctl set-mute "$node_id" toggle
if wpctl get-volume "$node_id" 2>/dev/null | grep -q MUTED; then
eww update radio-muted=true
else
eww update radio-muted=false
fi
}