From d180eaa72e3a1b2ca72e7b76b5a6533a5c02cb01 Mon Sep 17 00:00:00 2001 From: "agausmann@fastmail.com" Date: Sat, 8 Feb 2025 09:09:26 -0600 Subject: [PATCH] waybar: Add battery widget --- hosts/liberation.toml | 1 + install.py | 5 ++--- templates/.config/waybar/config.jsonc | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hosts/liberation.toml b/hosts/liberation.toml index 8b6267a..4901fac 100644 --- a/hosts/liberation.toml +++ b/hosts/liberation.toml @@ -1,6 +1,7 @@ wireless = ["wlp170s0"] #ethernet = ["enp2s0"] temperature_path = "/sys/class/hwmon/hwmon4/temp1_input" +has_battery = true [[outputs]] match = "eDP-1" diff --git a/install.py b/install.py index 88344a0..48b7af1 100755 --- a/install.py +++ b/install.py @@ -153,6 +153,7 @@ class HostConfig: wireless: list[str] = field(factory=list) ethernet: list[str] = field(factory=list) disks: list[str] = field(factory=lambda: ["/"]) + has_battery: bool = False system_font: str = "Fira Sans" system_mono_font: str = "Fira Mono" temperature_path: str | None = None @@ -263,9 +264,7 @@ def main(): print( "Could not find SWAYSOCK or NIRI_SOCKET, cannot retrieve output names." ) - print( - "Please re-run in sway or niri to finish configuring swaylock." - ) + print("Please re-run in sway or niri to finish configuring swaylock.") except subprocess.CalledProcessError: print("Could not contact sway or niri to retrieve output names.") diff --git a/templates/.config/waybar/config.jsonc b/templates/.config/waybar/config.jsonc index 786d8cd..9ef707c 100644 --- a/templates/.config/waybar/config.jsonc +++ b/templates/.config/waybar/config.jsonc @@ -17,6 +17,7 @@ % endfor "wireplumber", + "battery", "group/disks", "cpu", "memory", @@ -55,6 +56,23 @@ "format-icons": ["\uf026", "\uf027", "\uf028"] }, +% if host.has_battery: + "battery": { + "design-capacity": true, + "format": "{icon} {capacity}% {time}", + "format-time": "{H}:{m}", + "format-icons": [ + "\uf244", + "\uf243", + "\uf242", + "\uf241", + "\uf240", + ], + "format-charging": "\ue55b {capacity}% {time}", + "format-full": "\ue55c {capacity}%", + }, +% endif + "group/disks": { // TODO: make drawer that expands orthogonally, outside of the bar "orientation": "inherit",