Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(polybar): multiple devices flicker, added icons #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions files/theme/polybar/scripts/bluetooth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

# Colors
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
CDIR=`cd "$DIR" && cd .. && pwd`
POWER_ON=`cat $CDIR/colors.ini | grep 'GREEN' | head -n1 | cut -d '=' -f2 | tr -d ' '`
POWER_OFF=`cat $CDIR/colors.ini | grep 'ALTFOREGROUND' | head -n1 | cut -d '=' -f2 | tr -d ' '`
CDIR=$(cd "$DIR" && cd .. && pwd)
POWER_ON=$(grep 'GREEN' < "$CDIR"/colors.ini | head -n1 | cut -d '=' -f2 | tr -d ' ')
POWER_OFF=$(grep 'ALTFOREGROUND' < "$CDIR"/colors.ini | head -n1 | cut -d '=' -f2 | tr -d ' ')

# Checks if bluetooth controller is powered on
power_on() {
Expand All @@ -31,7 +31,7 @@ device_connected() {
# Useful for status bars like polybar, etc.
print_status() {
if power_on; then
if [[ -z `bluetoothctl info "$device" | grep "Alias" | cut -d ' ' -f 2-` ]]; then
if [[ -z $(bluetoothctl info "$device" | grep "Alias" | cut -d ' ' -f 2-) ]]; then
echo "%{F$POWER_ON}%{T2}%{T-} %{F-}On"
fi

Expand All @@ -43,20 +43,48 @@ print_status() {

mapfile -t paired_devices < <(bluetoothctl $paired_devices_cmd | grep Device | cut -d ' ' -f 2)
counter=0
icons=""

for device in "${paired_devices[@]}"; do
if device_connected "$device"; then
device_alias=$(bluetoothctl info "$device" | grep "Alias" | cut -d ' ' -f 2-)
device_type=$(bluetoothctl info "$device" | grep "Icon" | cut -d ' ' -f 2-)

if [ $counter -gt 0 ]; then
echo "%{F$POWER_ON}%{T2}%{T-} %{F-}$device_alias"
else
echo "%{F$POWER_ON}%{T2}%{T-} %{F-}$device_alias"
fi

case $device_type in
"input-mouse")
icons="$icons | 󰍽"
;;
"audio-headset")
icons="$icons | 󰋎"
;;
"audio-headphones")
icons="$icons | "
;;
"audio-card" | "audio-speaker")
icons="$icons | 󰓃"
;;
"input-keyboard")
icons="$icons | 󰌌"
;;
"input-gaming")
icons="$icons | 󰖺"
;;
"phone")
icons="$icons | "
;;
*)
icons="$icons | $device_type"
esac
((counter++))
fi
done
icons=$(echo "$icons" | cut -c3-)

if [[ $counter -gt 1 ]]; then
echo "%{F$POWER_ON}%{T2}%{T-} %{F-}$icons"
elif [[ $counter -gt 0 ]]; then
echo "%{F$POWER_ON}%{T2}%{T-} %{F-}$icons | $device_alias"
fi
else
echo "%{F$POWER_OFF}%{T2}%{T-} Off%{F-}"
fi
Expand Down