diff --git a/bin/omarchy-headphone-status b/bin/omarchy-headphone-status new file mode 100755 index 0000000000..e1f085dd75 --- /dev/null +++ b/bin/omarchy-headphone-status @@ -0,0 +1,23 @@ +#!/bin/bash +# Shows headphone icon with battery level if bluetooth audio device is the active sink + +# Get the active audio sink (marked with *) +ACTIVE_SINK=$(wpctl status 2>/dev/null | sed -n '/Audio/,/Video/p' | grep -E "^\s*│\s+\*" | head -1) + +if echo "$ACTIVE_SINK" | grep -qiE "WH-|WF-|airpods|buds|headphone|headset|earbuds|bose|jabra|beats|galaxy|sony|xm[0-9]"; then + # Get battery percentage from upower for headset devices + BATTERY="" + for device in $(upower -e 2>/dev/null | grep headset); do + PERCENTAGE=$(upower -i "$device" 2>/dev/null | grep -oP 'percentage:\s+\K\d+') + if [ -n "$PERCENTAGE" ]; then + BATTERY="$PERCENTAGE%" + break + fi + done + + if [ -n "$BATTERY" ]; then + echo "󰋋 $BATTERY" + else + echo "󰋋" + fi +fi diff --git a/config/waybar/config.jsonc b/config/waybar/config.jsonc index 62863cb06b..ca09571196 100644 --- a/config/waybar/config.jsonc +++ b/config/waybar/config.jsonc @@ -8,6 +8,7 @@ "modules-center": ["clock", "custom/update", "custom/screenrecording-indicator"], "modules-right": [ "group/tray-expander", + "custom/headphone", "bluetooth", "network", "pulseaudio", @@ -106,6 +107,12 @@ "tooltip-format": "Devices connected: {num_connections}", "on-click": "omarchy-launch-bluetooth" }, + "custom/headphone": { + "exec": "omarchy-headphone-status", + "interval": 3, + "format": "{}", + "tooltip-format": "Headphones connected" + }, "pulseaudio": { "format": "{icon}", "on-click": "omarchy-launch-or-focus-tui wiremix", diff --git a/config/waybar/style.css b/config/waybar/style.css index 7b7a980e37..d3b4ec9f81 100644 --- a/config/waybar/style.css +++ b/config/waybar/style.css @@ -44,6 +44,10 @@ margin-right: 16px; } +#custom-headphone { + margin-right: 12px; +} + #bluetooth { margin-right: 17px; }