1
0
Fork 0

fix(i3blocks): mic_mute now detects mic presence

This commit is contained in:
Oliver Ladner 2026-07-05 11:36:47 +02:00
commit 578bb7af2b
3 changed files with 18 additions and 9 deletions

View file

@ -44,8 +44,7 @@ signal=1
[mic_mute]
markup=pango
command=~/bin/i3blocks/mic_mute
interval=once
signal=2
interval=5
# Indoor temperature and humidity
[homeassistant-slow]

View file

@ -217,7 +217,6 @@ bar {
position bottom
# font "BerkeleyMono Nerd Font Mono Normal Bold 10"
font "BerkeleyMono Nerd Font Mono Normal Regular 11"
# status_command ~/.config/sway/status.sh
status_command i3blocks
strip_workspace_name no
strip_workspace_numbers no

View file

@ -5,26 +5,37 @@
. ~/bin/i3blocks/_utils
# If wpctl get-volume @DEFAULT_AUDIO_SOURCE@ output doesn't start with
# "Volume" we consider no microphone is connected. This is hacky, but needed
# as wpctl doesn't RC != 0 when no mic is connected
mic_mute() {
if [[ "$BLOCK_BUTTON" == "1" ]]; then
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
fi
local wpctl_output
wpctl_output=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)
wpctl_output=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ 2>/dev/null)
local muted
muted=$(echo "$wpctl_output" | grep -c '\[MUTED\]')
local bg fg icon stat
if [[ "$muted" -ge 1 ]]; then
# If the output does NOT start with 'Volume:', no microphone is connected
if [[ ! "$(echo $wpctl_output)" =~ ^Volume ]]; then
bg=$mute_bg
fg=$mute_fg
stat="MUT"
stat="N/A"
else
bg=$crit_bg
fg=$crit_fg
stat="REC"
if [[ "$muted" -ge 1 ]]; then
bg=$mute_bg
fg=$mute_fg
stat="MUT"
else
bg=$crit_bg
fg=$crit_fg
stat="REC"
fi
fi
echo -e "MIC <span background=\"$bg\" color=\"$fg\"> $stat </span>\n"