From 0796677cd75f938f4cbca899618d4260c4d78a69 Mon Sep 17 00:00:00 2001 From: soraefir Date: Sat, 13 Jun 2026 22:42:46 +0200 Subject: [PATCH] fix mute --- .../home/wayland/apps/eww/bar/scripts/radio | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/home/wayland/apps/eww/bar/scripts/radio b/modules/home/wayland/apps/eww/bar/scripts/radio index 99ab68a..14597af 100755 --- a/modules/home/wayland/apps/eww/bar/scripts/radio +++ b/modules/home/wayland/apps/eww/bar/scripts/radio @@ -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 }