From acc15e78ab080d32c3756c3e2f4bce0da480784a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 10 Oct 2024 01:42:06 -0300 Subject: [PATCH] waybar: add controller battery status --- scripts/controller-battery | 38 ++++++++++++++++++++++++++++++++++++++ scripts/default.nix | 1 + user/waybar/default.nix | 7 +++++++ user/waybar/style.css | 1 + 4 files changed, 47 insertions(+) create mode 100755 scripts/controller-battery diff --git a/scripts/controller-battery b/scripts/controller-battery new file mode 100755 index 0000000..b8ed4f2 --- /dev/null +++ b/scripts/controller-battery @@ -0,0 +1,38 @@ +#!/bin/sh + +set -e + +CONTROLLER=$(find /sys/class/power_supply -maxdepth 1 -name '*controller*' || true) + +if test -z "$CONTROLLER"; then + echo + exit 0 +fi + +CAPACITY=$(cat "$CONTROLLER/capacity") + +echo -n '󰊴' + +if test "$CAPACITY" -ge 90; then + echo '󰁹' +elif test "$CAPACITY" -ge 90; then + echo '󰂂' +elif test "$CAPACITY" -ge 80; then + echo '󰂁' +elif test "$CAPACITY" -ge 70; then + echo '󰂀' +elif test "$CAPACITY" -ge 60; then + echo '󰁿' +elif test "$CAPACITY" -ge 50; then + echo '󰁾' +elif test "$CAPACITY" -ge 40; then + echo '󰁽' +elif test "$CAPACITY" -ge 30; then + echo '󰁼' +elif test "$CAPACITY" -ge 20; then + echo '󰁻' +elif test "$CAPACITY" -ge 10; then + echo '󰁺' +else + echo '󰂎' +fi diff --git a/scripts/default.nix b/scripts/default.nix index 1e3290e..99b6635 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -130,6 +130,7 @@ libratbag ]; vrr-fullscreen = [ ]; + controller-battery = [ ]; } // lib.mapAttrs importScript { wdmenu = ./wdmenu.nix; diff --git a/user/waybar/default.nix b/user/waybar/default.nix index d33076e..b36dfce 100644 --- a/user/waybar/default.nix +++ b/user/waybar/default.nix @@ -35,6 +35,7 @@ in "mpd" "custom/playerctl" "tray" + "custom/controller-battery" "custom/caffeine" "pulseaudio" (lib.optional (osConfig.services.vpn.enable or false) "custom/vpn") @@ -157,6 +158,12 @@ in "sway/language" = { format = "{short} {variant}"; }; + "custom/controller-battery" = { + format = "{}"; + exec = lib.getExe pkgs.controller-battery; + interval = 1; + tooltip = false; + }; "custom/caffeine" = { format = "{}"; exec = "systemctl --user status swayidle > /dev/null && echo 󰒲 || echo 󰒳"; diff --git a/user/waybar/style.css b/user/waybar/style.css index f9c0fb1..36c6ebd 100644 --- a/user/waybar/style.css +++ b/user/waybar/style.css @@ -37,6 +37,7 @@ window#waybar.solo { #mpd, #custom-mpd, #custom-playerctl, +#custom-controller-battery, #tray, #clock, #network,