diff --git a/bar/eww/bar/widget.yuck b/bar/eww/bar/widget.yuck index 31f9e4c..b9fc7d0 100644 --- a/bar/eww/bar/widget.yuck +++ b/bar/eww/bar/widget.yuck @@ -20,8 +20,7 @@ (defpoll refresh_rate :interval "10s" :initial "165" "~/.config/eww/scripts/refresh_rate") (defpoll vpn_status :interval "60s" :initial '{"connected": false}' "~/.config/eww/scripts/vpn_status") -(deflisten connectivity :initial '{"state": "disconnected"}' "~/.config/eww/scripts/get-connectivity wlan0") -(deflisten bluetoothinfo :initial '{"count": 0}' "~/.config/eww/scripts/get-bluetooth-info") +(deflisten connectivity :initial '{"bluetooth": {}, "network": {}}' "~/.config/eww/scripts/get-connectivity-info") (deflisten hypr :initial '{"spaces": [], "current": 0, "title": ""}' "~/.config/eww/scripts/hypr/hyprstatus") (deflisten volume :initial "{}" "~/.config/eww/scripts/get-volume") @@ -58,14 +57,14 @@ (label :class "connectivity" :text "${ - connectivity.state == "wireless" - ? network-icon["wifi-${connectivity.wifi.signal}"] - : network-icon[connectivity.state] + connectivity.network.state == "wireless" + ? network-icon["wifi-${connectivity.network.wifi.signal}"] + : network-icon[connectivity.network.state] } ${ - connectivity.state == "disconnected" ? "No network" : - connectivity.state == "ethernet" ? "Ethernet" : - connectivity.state == "wireless" ? connectivity.wifi.ssid : - connectivity.state == "tethering" ? "USB tethering" : '' + connectivity.network.state == "disconnected" ? "No network" : + connectivity.network.state == "ethernet" ? "Ethernet" : + connectivity.network.state == "wireless" ? connectivity.network.wifi.ssid : + connectivity.network.state == "tethering" ? "USB tethering" : '' }" :limit-width 14) ) @@ -76,7 +75,7 @@ :onclick "bash -c 'blueman-manager &> /dev/null &'" (label :class "bluetooth" - :text " ${bluetoothinfo.count > 0 ? bluetoothinfo.count : bluetoothinfo.power}") + :text " ${connectivity.bluetooth.count > 0 ? connectivity.bluetooth.count : connectivity.bluetooth.power}") ) ) diff --git a/bar/eww/default.nix b/bar/eww/default.nix index 4b0dcfc..00412f2 100644 --- a/bar/eww/default.nix +++ b/bar/eww/default.nix @@ -11,6 +11,7 @@ home.packages = [ pkgs.eww # Script dependencies + pkgs.iw pkgs.jq pkgs.dash pkgs.socat diff --git a/bar/eww/scripts/get-bluetooth-info b/bar/eww/scripts/get-bluetooth-info deleted file mode 100755 index 77a5c4a..0000000 --- a/bar/eww/scripts/get-bluetooth-info +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env dash - -info (){ - power=$(bluetoothctl show | grep Powered | awk '{print $2}' | sed 's/yes/on/g; s/no/off/g') - count=$(bluetoothctl devices Connected | wc -l) - echo "{\"power\": \"${power}\", \"count\": \"${count}\"}" -} - -info -dbus-monitor --system "sender=:1.3" | while read -r line; do - info -done diff --git a/bar/eww/scripts/get-connectivity b/bar/eww/scripts/get-connectivity-info similarity index 62% rename from bar/eww/scripts/get-connectivity rename to bar/eww/scripts/get-connectivity-info index 8009206..cc6cee3 100755 --- a/bar/eww/scripts/get-connectivity +++ b/bar/eww/scripts/get-connectivity-info @@ -1,6 +1,7 @@ #!/usr/bin/env dash -print_state() { + +print_network_state() { case "$1" in eth*) echo ethernet @@ -26,7 +27,7 @@ wifi_strength() { fi } -print_infos() { +print_network_infos() { if [ -n "$1" ]; then route_line=$(ip route show dev "$1" | awk '($1 == "default") { print }') @@ -45,15 +46,27 @@ print_infos() { print_network_status() { device=$(ip route | awk '($1 == "default") { print $5 }') - state=$(print_state "$device") + state=$(print_network_state "$device") printf '{"state":"%s"%s}\n' \ "$state" \ - "$(print_infos "$device")" + "$(print_network_infos "$device")" } -print_network_status -tail -f -n 0 /run/dhcpcd/log /var/log/iwd/current | \ -while read -r _unused; do - print_network_status +print_bluetooth_status (){ + power=$(bluetoothctl show | grep Powered | awk '{print $2}' | sed 's/yes/on/g; s/no/off/g') + count=$(bluetoothctl devices Connected | wc -l) + echo "{\"power\": \"${power}\", \"count\": \"${count}\"}" +} + +print_connectivity_info () { + network="$(print_network_status)" + bluetooth="$(print_bluetooth_status)" + + echo "{\"bluetooth\": ${bluetooth}, \"network\": ${network}}" +} + +print_connectivity_info +dbus-monitor --system "interface=org.freedesktop.DBus.ObjectManager" 2> /dev/null | while read -r line; do + print_connectivity_info done