diff --git a/config/eww/scripts/daemons/microphone.sh b/config/eww/scripts/daemons/microphone.sh index abcb9dc..38b1da1 100755 --- a/config/eww/scripts/daemons/microphone.sh +++ b/config/eww/scripts/daemons/microphone.sh @@ -1,8 +1,17 @@ -#!/bin/bash +#!/usr/bin/env bash +old_source=$(pactl get-default-source) old_status=-1 update() { - info="$(pactl list sources | awk '/Name: alsa_input.pci/{nr[NR+6]}; NR in nr')" + default_source=$(pactl get-default-source) + info="$(pactl get-source-mute "$default_source")" status="$([[ "$info" == *"Mute: yes"* ]] && echo off || echo on)" + + if [[ "$default_source" != "$old_source" ]]; then + device=$(pactl list sources | awk '/Name: '$default_source'/{nr[NR+1]}; NR in nr {print substr($0, index($0, $2))}') + notify-send.sh -R /tmp/recording-device-notification --urgency low "Recording device" "$device" + old_source="$default_source" + fi + # Only update if status changed if [ "$old_status" != "$status" ]; then eww update microphone="$status" @@ -15,18 +24,6 @@ if [ "$1" == "oneshot" ]; then exit fi -LANG=C pactl subscribe 2> /dev/null | grep --line-buffered "Event 'change' on source #" | while read -r line ; do +LANG=C pactl subscribe 2> /dev/null | grep --line-buffered "source #" | while read -r line ; do update done - -# ------ Before pipewire -# update() { -# info="$(pacmd list-sources | awk '/\\* index: /{nr[NR+7];nr[NR+11]}; NR in nr' | tail -1)" -# muted="$([[ "$info" == *"muted: yes"* ]] && echo '' || echo active)" -# eww update microphone="$muted" -# } - -# update -# pactl subscribe 2> /dev/null | grep --line-buffered "source #" | while read -r line ; do -# update -# done