diff options
| author | Craig Jennings <c@cjennings.net> | 2026-01-25 22:18:03 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-01-25 22:18:03 -0600 |
| commit | c1195946fe6c72365310919a6250d1fdb6dd215f (patch) | |
| tree | 000134894ed97ef700ed81ffdaaa74cece3049fc /dotfiles/hyprland/.local | |
| parent | f29cf8d115f5c8a765d3f51af1e285502391cb9d (diff) | |
feat(waybar): redesign network module with connection type icons
Show WiFi icon (with signal strength) + SSID, or ethernet icon +
interface name. Move upload/download speeds to tooltip for cleaner
display.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'dotfiles/hyprland/.local')
| -rwxr-xr-x | dotfiles/hyprland/.local/bin/waybar-netspeed | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/dotfiles/hyprland/.local/bin/waybar-netspeed b/dotfiles/hyprland/.local/bin/waybar-netspeed index 504ad8c..97e8e5e 100755 --- a/dotfiles/hyprland/.local/bin/waybar-netspeed +++ b/dotfiles/hyprland/.local/bin/waybar-netspeed @@ -1,14 +1,16 @@ #!/bin/sh -# Network speed monitor with fixed-width output for waybar -# Outputs JSON with upload/download speeds padded to consistent width +# Network status indicator for waybar +# Shows: WiFi icon (signal strength) + SSID, or Ethernet icon + interface +# Tooltip: upload/download speeds INTERFACE=$(ip route | awk '/default/ {print $5; exit}') if [ -z "$INTERFACE" ]; then - echo '{"text": "No network", "class": "disconnected"}' + echo '{"text": " Disconnected", "tooltip": "No network connection", "class": "disconnected"}' exit 0 fi +# Measure network speed (requires 1 second delay) RX1=$(cat /sys/class/net/$INTERFACE/statistics/rx_bytes) TX1=$(cat /sys/class/net/$INTERFACE/statistics/tx_bytes) sleep 1 @@ -21,32 +23,45 @@ TX_RATE=$((TX2 - TX1)) format_speed() { local bytes=$1 if [ $bytes -ge 1073741824 ]; then - printf "%6.2f G" $(echo "scale=2; $bytes / 1073741824" | bc) + printf "%.2f GB/s" $(echo "scale=2; $bytes / 1073741824" | bc) elif [ $bytes -ge 1048576 ]; then - printf "%6.2f M" $(echo "scale=2; $bytes / 1048576" | bc) + printf "%.2f MB/s" $(echo "scale=2; $bytes / 1048576" | bc) elif [ $bytes -ge 1024 ]; then - printf "%6.2f K" $(echo "scale=2; $bytes / 1024" | bc) + printf "%.2f KB/s" $(echo "scale=2; $bytes / 1024" | bc) else - printf "%6d B" $bytes + printf "%d B/s" $bytes fi } UP=$(format_speed $TX_RATE) DOWN=$(format_speed $RX_RATE) -# Get IP for tooltip -IP=$(ip -4 addr show $INTERFACE | awk '/inet / {print $2}') +# Determine connection type and get appropriate icon/label +if [ -d "/sys/class/net/$INTERFACE/wireless" ]; then + # WiFi connection + LABEL=$(iwgetid -r 2>/dev/null || echo "WiFi") -# Check if WiFi and get SSID -SSID="" -if command -v iwgetid >/dev/null 2>&1; then - SSID=$(iwgetid -r 2>/dev/null) -fi + # Get signal strength in percentage + SIGNAL=$(awk 'NR==3 {print int($3 * 100 / 70)}' /proc/net/wireless 2>/dev/null) -if [ -n "$SSID" ]; then - TOOLTIP="$SSID ($INTERFACE: $IP)" + # Select icon based on signal strength + if [ -z "$SIGNAL" ] || [ "$SIGNAL" -le 0 ]; then + ICON="" # No signal + elif [ "$SIGNAL" -le 25 ]; then + ICON="" # Weak + elif [ "$SIGNAL" -le 50 ]; then + ICON="" # Fair + elif [ "$SIGNAL" -le 75 ]; then + ICON="" # Good + else + ICON="" # Excellent + fi else - TOOLTIP="$INTERFACE: $IP" + # Ethernet connection + ICON="" + LABEL="$INTERFACE" fi -echo "{\"text\": \"${UP} ${DOWN} \", \"tooltip\": \"$TOOLTIP\", \"class\": \"connected\"}" +TOOLTIP="Up: $UP\nDown: $DOWN" + +echo "{\"text\": \"<span size='large'>$ICON</span> $LABEL\", \"tooltip\": \"$TOOLTIP\", \"class\": \"connected\"}" |
