Compatibility with dwmblocks, and some extra improvements

This commit is contained in:
appeasementPolitik 2022-09-13 09:17:39 +00:00 committed by GitHub
parent 4c672dec95
commit 930dd4e574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,11 +29,13 @@ power_on() {
toggle_power() { toggle_power() {
if power_on; then if power_on; then
bluetoothctl power off bluetoothctl power off
pkill -RTMIN+2 "${STATUSBAR:-dwmblocks}"
show_menu show_menu
else else
rfkill list bluetooth | grep -q 'blocked: yes' && rfkill unblock bluetooth && sleep 3 rfkill list bluetooth | grep -q 'blocked: yes' && rfkill unblock bluetooth && sleep 3
bluetoothctl power on bluetoothctl power on
pkill -RTMIN+2 "${STATUSBAR:-dwmblocks}"
show_menu show_menu
fi fi
} }
@ -48,8 +50,8 @@ scan_on() {
# Toggles scanning state # Toggles scanning state
toggle_scan() { toggle_scan() {
scan_on && scan_on &&
kill "$(pgrep -f 'bluetoothctl scan on')" && bluetoothctl scan off && show_menu || pkill -f 'bluetoothctl scan on' && bluetoothctl scan off && show_menu ||
{ bluetoothctl scan on & echo 'Scanning...' && sleep 5 && show_menu; } { bluetoothctl scan on & notify-send 'Scanning...' && sleep 5 && show_menu; }
} }
# Checks if controller is able to pair to devices # Checks if controller is able to pair to devices
@ -108,6 +110,8 @@ toggle_paired() {
device_paired "$1" && device_paired "$1" &&
bluetoothctl remove "$1" && device_menu "$device" || bluetoothctl remove "$1" && device_menu "$device" ||
{ bluetoothctl pair "$1" && device_menu "$device"; } { bluetoothctl pair "$1" && device_menu "$device"; }
pkill -RTMIN+2 "${STATUSBAR:-dwmblocks}"
} }
# Checks if a device is trusted # Checks if a device is trusted
@ -141,15 +145,13 @@ device_menu() {
paired=$(device_paired "$mac") paired=$(device_paired "$mac")
trusted=$(device_trusted "$mac") trusted=$(device_trusted "$mac")
options="${connected}\n${paired}\n${trusted}\n${divider}\n${goback}\nExit" options="${connected}\n${paired}\n${trusted}\n${goback}\nExit"
# Open dmenu, read chosen option # Open dmenu, read chosen option
chosen="$(printf '%b' "$options" | $dmenu_command "$device_name")" chosen="$(printf '%b' "$options" | $dmenu_command "$device_name")"
# Match chosen option to command # Match chosen option to command
case $chosen in case $chosen in
"" | "$divider")
echo 'No option chosen.' ;;
"$connected") "$connected")
toggle_connection "$mac" ;; toggle_connection "$mac" ;;
"$paired") "$paired")
@ -158,6 +160,8 @@ device_menu() {
toggle_trust "$mac" ;; toggle_trust "$mac" ;;
"$goback") "$goback")
show_menu ;; show_menu ;;
*)
exit ;;
esac esac
} }
@ -177,7 +181,7 @@ show_menu() {
discoverable=$(discoverable_on) discoverable=$(discoverable_on)
# Options passed to dmenu # Options passed to dmenu
options="${devices}\n${divider}\n${power}\n${scan}\n${pairable}\n${discoverable}\nExit" options="${devices:+$devices\n$divider\n}${power}\n${scan}\n${pairable}\n${discoverable}\nExit"
else else
power='Power: off' power='Power: off'
options="$power\nExit" options="$power\nExit"
@ -188,8 +192,8 @@ show_menu() {
# Match chosen option to command # Match chosen option to command
case $chosen in case $chosen in
"" | "$divider") "" | "$divider" | 'Exit')
echo 'No option chosen.' ;; exit ;;
"$power") "$power")
toggle_power ;; toggle_power ;;
"$scan") "$scan")