Networkwidget: Add support for bt power levels.

This commit is contained in:
Dmitry Voronin 2024-12-17 09:12:00 +03:00
parent 15a2b9b1fc
commit 69eb5390c4
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
3 changed files with 36 additions and 15 deletions

View file

@ -69,6 +69,7 @@ in {
#custom-display.modified,
#custom-network.issue,
#custom-network.vpn,
#custom-network.btlow,
#memory.critical,
#pulseaudio.muted,
#pulseaudio.source-muted,

View file

@ -83,7 +83,7 @@
class="modified"
fi
printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${_dndstate} / Monitor: ''${_monitorstate} / Gaming: ''${_gamingstate} / Recording: ''${_recordingstate}\", \"class\": \"''${class}\"}\n"
printf "%s" "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${_dndstate} / Monitor: ''${_monitorstate} / Gaming: ''${_gamingstate} / Recording: ''${_recordingstate}\", \"class\": \"''${class}\"}\n"
}
function monitorstate() {
@ -91,21 +91,21 @@
for state in "''${outputs[@]}"; do
''${state} || {
printf Y
printf "%s" Y
return 1
}
done
printf n
printf "%s" n
return 0
}
function recordingstate() {
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf "%s" n || printf "%s" Y
}
function dndstate() {
[[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n
[[ "$(makoctl mode)" = "dnd" ]] && printf "%s" Y || printf "%s" n
}
function gamingstate() {
@ -113,12 +113,12 @@
for state in "''${outputs[@]}"; do
[[ "''${state}" = "disabled" ]] || {
printf Y
printf "%s" Y
return 1
}
done
printf n
printf "%s" n
return 0
}
'';

View file

@ -7,12 +7,32 @@
local _ethernets=($(nmcli connection show --active | rg ethernet | sed "s/ .*//"))
local _vpns=($(nmcli connection show --active | rg vpn | sed "s/ .*//"))
local _wifis=($(nmcli connection show --active | rg wifi | sed "s/ .*//"))
local _bts=($(bluetoothctl devices Connected | cut -d\ -f3))
local _bts_raw=($(bluetoothctl devices Connected))
local _bts=()
local _bt_lowest=100
local icon="󰖩"
local class=""
for bt in ''${_bts_raw[@]}; do
local name=$(printf "%s" ''${bt} | cut -d\ -f3)
local mac=$(printf "%s" ''${bt} | cut -d\ -f2 | sed -e "s/:/_/g")
local bat=$(dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_''${mac} org.freedesktop.DBus.Properties.Get string:"org.bluez.Battery1" string:"Percentage" 2> /dev/null | cut -d\ -f12)
local btinfo="''${name}"
if [[ "''${bat}" != "" ]]; then
btinfo+=" ''${bat}%"
[[ ''${bat} -lt ''${_bt_lowest} ]] && _bt_lowest=bat
fi
_bts+=("''${btinfo}")
done
if [[ "''${_bts}" != "" ]]; then
icon="󱛃"
if [[ "''${_bt_lowest}" != "" ]] && [[ ''${_bt_lowest} -lt 20 ]]; then
class="btlow"
fi
fi
if [[ "''${_vpns}" != "" ]]; then
@ -26,23 +46,23 @@
fi
for net in ''${_vpns[@]}; do
networks+=" ''${net}\\\n"
networks+=" ''${net}\\n"
done
for net in ''${_ethernets[@]}; do
networks+=" ''${net}\\\n"
networks+=" ''${net}\\n"
done
for net in ''${_wifis[@]}; do
networks+="󰖩 ''${net}\\\n"
networks+="󰖩 ''${net}\\n"
done
for bt in ''${_bts[@]}; do
networks+="󰂯 ''${bt}\\\n"
networks+="󰂯 ''${bt}\\n"
done
networks=''${networks%\\\n}
printf "{\"text\": \"''${icon}\", \"tooltip\": \"''${networks}\", \"class\": \"''${class}\"}\n"
networks=''${networks%\\n}
printf "%s" "{\"text\": \"''${icon}\", \"tooltip\": \"''${networks}\", \"class\": \"''${class}\"}\n"
}
# Toggle network.