auroraace9df5
waybar: add bluetooth battery status custom module
+32 −0
3 files changed
- M .config/waybar/config.jsonc +8 −0
- A .config/waybar/scripts/bluetooth-battery.sh +17 −0
- M .config/waybar/style.css +7 −0
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | "modules-right": [ | |
| 15 | 15 | "tray", | |
| 16 | 16 | "custom/gpumode", | |
| 17 | + | "custom/headset-battery", | |
| 17 | 18 | "pulseaudio", | |
| 18 | 19 | "battery", | |
| 19 | 20 | "backlight", | |
| @@ -87,6 +88,13 @@ | |||
| 87 | 88 | "interval": "once", | |
| 88 | 89 | "on-click": "~/.local/bin/envyswitch", | |
| 89 | 90 | }, | |
| 91 | + | "custom/headset-battery": { | |
| 92 | + | "exec": "~/.config/waybar/scripts/bluetooth-battery.sh", | |
| 93 | + | "format": " {}", | |
| 94 | + | "return-type": "json", | |
| 95 | + | "interval": 15, | |
| 96 | + | "hide-empty-text": true | |
| 97 | + | }, | |
| 90 | 98 | "custom/cpucat": { | |
| 91 | 99 | "exec":"~/.config/waybar/scripts/catloop.sh", | |
| 92 | 100 | }, | |
| @@ -0,0 +1,17 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | # Find the UPower device path for any connected headset/headphones | |
| 4 | + | DEVICE_PATH=$(upower -e | grep -E 'headset|headphone' | head -n 1) | |
| 5 | + | ||
| 6 | + | # If no headset device is found in UPower, exit silently so Waybar hides the module | |
| 7 | + | if [ -z "$DEVICE_PATH" ]; then | |
| 8 | + | exit 0 | |
| 9 | + | fi | |
| 10 | + | ||
| 11 | + | # Extract the percentage value (e.g., "90%") | |
| 12 | + | PERCENTAGE=$(upower -i "$DEVICE_PATH" | awk '/percentage:/ {print $2}') | |
| 13 | + | ||
| 14 | + | # Output JSON format for Waybar | |
| 15 | + | if [ -n "$PERCENTAGE" ]; then | |
| 16 | + | printf '{"text": "%s", "tooltip": "Headset Battery: %s", "class": "connected"}\n' "$PERCENTAGE" "$PERCENTAGE" | |
| 17 | + | fi | |
| @@ -105,6 +105,7 @@ window#waybar.hidden { | |||
| 105 | 105 | #custom-media, | |
| 106 | 106 | #tray, | |
| 107 | 107 | #window, | |
| 108 | + | #custom-headset-battery, | |
| 108 | 109 | #custom-notification, | |
| 109 | 110 | #mpd { | |
| 110 | 111 | background-color: @background; | |
| @@ -161,6 +162,12 @@ window#waybar.hidden { | |||
| 161 | 162 | box-shadow: inset 0 -1px @color14; | |
| 162 | 163 | } | |
| 163 | 164 | ||
| 165 | + | #custom-headset-battery { | |
| 166 | + | color: @foreground; | |
| 167 | + | box-shadow: inset 0 -1px @color14; | |
| 168 | + | } | |
| 169 | + | ||
| 170 | + | ||
| 164 | 171 | @keyframes blink { | |
| 165 | 172 | to { | |
| 166 | 173 | background-color: #ffffff; | |