From 578bb7af2bd5c496e29f2d3ff712137a9dc79cef Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Sun, 5 Jul 2026 11:36:47 +0200 Subject: [PATCH] fix(i3blocks): mic_mute now detects mic presence --- home/oli/.config/i3blocks/config | 3 +-- home/oli/.config/sway/config | 1 - home/oli/bin/i3blocks/mic_mute | 23 +++++++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/home/oli/.config/i3blocks/config b/home/oli/.config/i3blocks/config index 571aa2f..4327d4b 100644 --- a/home/oli/.config/i3blocks/config +++ b/home/oli/.config/i3blocks/config @@ -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] diff --git a/home/oli/.config/sway/config b/home/oli/.config/sway/config index f85bcbf..2cc540c 100644 --- a/home/oli/.config/sway/config +++ b/home/oli/.config/sway/config @@ -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 diff --git a/home/oli/bin/i3blocks/mic_mute b/home/oli/bin/i3blocks/mic_mute index 56f86b2..a2be519 100755 --- a/home/oli/bin/i3blocks/mic_mute +++ b/home/oli/bin/i3blocks/mic_mute @@ -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 $stat \n"