From 7b779ba9e4fd460655eed62a8538c44227f5c6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Mon, 24 Apr 2023 15:16:29 +0300 Subject: waybar: better battery energy status --- dotfiles/.config/waybar/config | 10 +++++----- dotfiles/.config/waybar/style.css | 2 -- dotfiles/.local/bin/barbatwatt | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100755 dotfiles/.local/bin/barbatwatt diff --git a/dotfiles/.config/waybar/config b/dotfiles/.config/waybar/config index 35f7c4d..94839e5 100644 --- a/dotfiles/.config/waybar/config +++ b/dotfiles/.config/waybar/config @@ -19,13 +19,13 @@ "custom/mail-status", "custom/pac-status", "custom/news-status", - "custom/batwatt", "memory", - "custom/torrent-status", - "network", "backlight", "battery#bat0", "battery#bat1", + "custom/batwatt", + "custom/torrent-status", + "network", "tray" ], "sway/mode": { @@ -219,10 +219,10 @@ "exec": "bards4battery" }, "custom/batwatt": { - "format": " {}", + "return-type": "json", "interval": 10, "exec-if": "test -e /sys/class/power_supply/BAT0", - "exec": "echo print\\(\\'{}W\\'.format\\($(grep 'POWER_SUPPLY_POWER_NOW' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}')/1000000\\)\\) | python", + "exec": "barbatwatt", "exec-on-event": true, "on-click": "" }, diff --git a/dotfiles/.config/waybar/style.css b/dotfiles/.config/waybar/style.css index 17d083d..9c4aa78 100644 --- a/dotfiles/.config/waybar/style.css +++ b/dotfiles/.config/waybar/style.css @@ -8,9 +8,7 @@ window#waybar { min-height: 0; } #tray, -#battery, #network, -#backlight, #custom-torrent-status, #workspaces { background: #151517; diff --git a/dotfiles/.local/bin/barbatwatt b/dotfiles/.local/bin/barbatwatt new file mode 100755 index 0000000..3ac93df --- /dev/null +++ b/dotfiles/.local/bin/barbatwatt @@ -0,0 +1,27 @@ +#!/bin/sh +# Show the charge or discharge rate of the battery + +rate="$(printf "scale=3\n%s\n" "$(grep 'POWER_SUPPLY_POWER_NOW' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}') / 1000000" | bc)" +stat="$(grep 'POWER_SUPPLY_STATUS' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}')" + +if [ "$1" = "-p" ]; then + # Output in plain text + echo "Battery $stat at a rate of ${rate}W" + exit 0 +fi + +if [ "$stat" = "Charging" ]; then + tooltip="Battery is charging at a rate of" + arrow="↑" + color="#5b8277" +elif [ "$stat" = "Discharging" ]; then + tooltip="Battery is discharging at a rate of" + arrow="↓" + color="#b2872f" +else + tooltip="Battery is not charging" + arrow="" + color="#fcf8e2" +fi + +printf '{ "class": "%s", "text": "%s %sW", "tooltip": "%s: %sW" }' "$stat" "$color" "$arrow" "$rate" "$tooltip" "$rate" -- cgit v1.2.3