From f985d16d36c8002822fd0e3c50306ba0ce086ce7 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 8 Oct 2022 13:38:18 -0700 Subject: [PATCH] Add battery module to polybar --- polybar/index.nix | 55 +++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/polybar/index.nix b/polybar/index.nix index f1d91b3..36ff057 100644 --- a/polybar/index.nix +++ b/polybar/index.nix @@ -1,5 +1,14 @@ { pkgs, lib, ... }: +let + background = "#2e3440"; + background-alt = "#3b4252"; + foreground = "#eceff4"; + primary = "#8fbcbb"; + secondary = "#ff00ff"; # not sure what this does + alert = "#ff00ff"; # not sure what this does + disabled = "#434c5e"; +in { # Dependencies home.packages = with pkgs; [ @@ -15,19 +24,12 @@ }; config = { "colors" = { - background = "#2e3440"; - background-alt = "#3b4252"; - foreground = "#eceff4"; - primary = "#8fbcbb"; - secondary = "#ff00ff"; # not sure what this does - alert = "#ff00ff"; # not sure what this does - disabled = "#434c5e"; - }; + }; "bar/top" = { font-0 = "Noto Sans Mono;2"; font-1 = "Noto Sans CJK JP;2"; - background = "\${colors.background}"; - foreground = "\${colors.foreground}"; + background = "${background}"; + foreground = "${foreground}"; width = "100%"; height = "24pt"; @@ -35,7 +37,7 @@ padding-right = 1; module-margin = 1; separator = "|"; - separator-foreground = "\${colors.disabled}"; + separator-foreground = "${disabled}"; cursor-click = "pointer"; cursor-scroll = "ns-resize"; modules-left = [ @@ -49,22 +51,23 @@ "pulseaudio" "memory" "cpu" + "battery" "date" ]; }; "module/xworkspaces" = { type = "internal/xworkspaces"; - label-active-background = "\${colors.background-alt}"; - label-active-underline = "\${colors.primary}"; + label-active-background = "${background-alt}"; + label-active-underline = "${primary}"; label-active-padding-right = 1; label-occupied-padding-right = 1; - label-urgent-background = "\${colors.alert}"; + label-urgent-background = "${alert}"; label-urgent-padding-right = 1; - label-empty-foreground = "\${colors.disabled}"; + label-empty-foreground = "${disabled}"; label-empty-padding-right = 1; }; "module/xwindow" = { @@ -93,16 +96,16 @@ label-mounted = "%{F#88c0d0}%mountpoint%%{F-} %percentage_used%%"; label-unmounted = "%mountpoint% not mounted"; - label-unmounted-foreground = "\${colors.disabled}"; + label-unmounted-foreground = "${disabled}"; }; "module/pulseaudio" = { type = "internal/pulseaudio"; format-volume-prefix = "VOL "; - format-volume-prefix-foreground = "\${colors.primary}"; + format-volume-prefix-foreground = "${primary}"; label-muted = "muted"; - label-muted-foreground = "\${colors.disabled}"; + label-muted-foreground = "${disabled}"; }; "module/memory" = { type = "internal/memory"; @@ -110,7 +113,7 @@ interval = 2; format-prefix = "RAM "; - format-prefix-foreground = "\${colors.primary}"; + format-prefix-foreground = "${primary}"; }; "module/cpu" = { type = "internal/cpu"; @@ -118,7 +121,17 @@ interval = 2; format-prefix = "CPU "; - format-prefix-foreground = "\${colors.primary}"; + format-prefix-foreground = "${primary}"; + }; + # TODO: Only build battery module on ThinkPad host + "module/battery" = { + type = "internal/battery"; + battery = "BAT0"; + adapter = "AC"; + + label-charging = "%{F${primary}}AC%{F-} %percentage%%"; + label-discharging = "%{F${primary}}BAT%{F-} %percentage%%"; + label-full = "%{F${primary}}AC%{F-}"; }; "module/date" = { type = "internal/date"; @@ -128,7 +141,7 @@ date = "%H:%M"; date-alt = "%Y-%m-%d %H:%M:%S"; - label-foreground = "\${colors.primary}"; + label-foreground = "${primary}"; }; }; };