From 67a52eca861df348384daa7bd158440352ded91b Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 13 Jul 2023 00:40:52 +0000 Subject: [PATCH] sxmo: conky: include battery estimate --- hosts/modules/gui/sxmo/battery_estimate | 31 +++++++++++++++++++++++++ hosts/modules/gui/sxmo/conky-config | 4 ++-- hosts/modules/gui/sxmo/default.nix | 13 ++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100755 hosts/modules/gui/sxmo/battery_estimate diff --git a/hosts/modules/gui/sxmo/battery_estimate b/hosts/modules/gui/sxmo/battery_estimate new file mode 100755 index 00000000..0c4afc23 --- /dev/null +++ b/hosts/modules/gui/sxmo/battery_estimate @@ -0,0 +1,31 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash + +full=$(cat /sys/class/power_supply/axp20x-battery/charge_full_design) +rate=$(cat /sys/class/power_supply/axp20x-battery/current_now) +perc=$(cat /sys/class/power_supply/axp20x-battery/capacity) +perc_left=$((100 - $perc)) +# these icons come from sxmo; they only render in nerdfonts +bat_dis="󱊢" +bat_chg="󱊥" + +fmt_minutes() { + if [[ $2 -gt 1440 ]]; then + echo "∞" # more than 1d + else + hr=$(($2 / 60)) + hr_in_min=$(($hr * 60)) + min=$(($2 - $hr_in_min)) + echo "$1 ${hr}h${min}m" + fi +} + +if [[ $rate -lt 0 ]]; then + # discharging + fmt_minutes "$bat_dis" $(($full * 60 * $perc / (-100 * $rate))) +elif [[ $rate -gt 0 ]]; then + # charging + fmt_minutes "$bat_chg" $(($full * 60 * $perc_left / (100 * $rate))) +else + echo "󱊢 N/A" +fi diff --git a/hosts/modules/gui/sxmo/conky-config b/hosts/modules/gui/sxmo/conky-config index 20741a63..a06ab092 100644 --- a/hosts/modules/gui/sxmo/conky-config +++ b/hosts/modules/gui/sxmo/conky-config @@ -17,7 +17,7 @@ ${alignc}${font Sxmo:size=50:style=Bold}${exec date +"%H"}${font Sxmo:size=50}:$ ${font Sxmo:size=20}${exec date +"%a %d %b %Y"}${font} ${alignc}${font Sxmo:size=15}${color lightgrey}☵ $memperc%${font} -${alignc}${font Sxmo:size=15}${color lightgrey} $cpu%${font} +${alignc}${font Sxmo:size=15}${color lightgrey} $cpu%${font} ${alignc}${font Sxmo:size=15}${color lightgrey}⇅ ${downspeedf wlan0}K/s${font} -${alignc}${font Sxmo:size=15}${color lightgrey} ${exec echo $(( $(cat /sys/class/power_supply/axp20x-battery/charge_full_design) * -60 / $(cat /sys/class/power_supply/axp20x-battery/current_now) )) }m${font} +${alignc}${font Sxmo:size=15}${color lightgrey}${exec @bat@ }${font} ]] diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index 538e1e33..ce570dcd 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -43,7 +43,7 @@ # - gestures: lisgd # - on-screen keyboard: wvkbd (if wayland), svkbd (if X) # -{ lib, config, pkgs, sane-lib, ... }: +{ config, lib, pkgs, sane-lib, ... }: let cfg = config.sane.gui.sxmo; @@ -217,8 +217,15 @@ in # sane.user.fs.".config/waybar/style.css".symlink.text = # builtins.readFile ./waybar-style.css; - sane.user.fs.".config/sxmo/conky.conf".symlink.target = - builtins.readFile ./conky-config; + sane.user.fs.".config/sxmo/conky.conf".symlink.target = let + battery_estimate = pkgs.static-nix-shell.mkBash { + pname = "battery_estimate"; + src = ./.; + }; + in pkgs.substituteAll { + src = ./conky-config; + bat = "${battery_estimate}/bin/battery_estimate"; + }; ## greeter