From d5d5e3b8ce00f1f559905f9c689866f778388e84 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Thu, 23 Nov 2023 00:08:25 +0100 Subject: Specify custom battery/adapter names for polybar --- tw/home/frm.scm | 2 ++ tw/home/lap.scm | 2 ++ tw/services/desktop.scm | 25 ++++++++++++++++++++----- tw/services/files/polybar.ini | 3 +++ 4 files changed, 27 insertions(+), 5 deletions(-) (limited to 'tw') diff --git a/tw/home/frm.scm b/tw/home/frm.scm index 7af42170..a60c0d73 100644 --- a/tw/home/frm.scm +++ b/tw/home/frm.scm @@ -87,6 +87,8 @@ (service home-desktop-layout-service-type (home-desktop-layout-configuration (desktop-background "~/blobs-d.png") + (battery-name "BAT1") + (ac-adapter-name "ACAD") (monitors (list (home-monitor-configuration (name "eDP") diff --git a/tw/home/lap.scm b/tw/home/lap.scm index 4f68ecd6..a1b11e42 100644 --- a/tw/home/lap.scm +++ b/tw/home/lap.scm @@ -185,6 +185,8 @@ (service home-desktop-layout-service-type (home-desktop-layout-configuration (desktop-background "~/pictures/Backgrounds/greece/IMG_20181201_104748_DRO.jpg") + (battery-name "BAT0") + (ac-adapter-name "AC") (monitors (list (home-monitor-configuration (name "eDP-1-1") diff --git a/tw/services/desktop.scm b/tw/services/desktop.scm index c04b2feb..8de8231d 100644 --- a/tw/services/desktop.scm +++ b/tw/services/desktop.scm @@ -11,6 +11,7 @@ #:use-module (guix packages) #:use-module ((guix records) #:select (match-record)) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module ((tw theme) #:select (catppuccin-polybar)) #:export (home-desktop-layout-configuration home-monitor-configuration @@ -20,6 +21,8 @@ ;; Monitor layout and polybars +(define-maybe/no-serialization string) + (define (list-of-strings? thing) (and (list? thing) (every string? thing))) @@ -34,6 +37,10 @@ configure this monitor.")) (define-configuration/no-serialization home-desktop-layout-configuration (desktop-background string "Path to an image that will be set as the desktop background. An initial @code{~/} is replaced with $HOME/.") + (battery-name maybe-string "The device name of the system's battery, if any. +See @code{/sys/class/power_supply}.") + (ac-adapter-name maybe-string "The device name of the system's mains power +supply, if any. See @code{/sys/class/power_supply}.") (monitors list-of-monitors "List of monitor declarations to apply.")) (define (polybar-config monitors) @@ -59,7 +66,10 @@ background. An initial @code{~/} is replaced with $HOME/.") (when monitor-connected? (execl #$(file-append polybar "/bin/polybar"))))))) -(define (polybar-service monitor) +(define (maybe-value maybe fallback) + (if (maybe-value-set? maybe) maybe fallback)) + +(define (polybar-service monitor battery-name ac-adapter-name) (shepherd-service (documentation (string-append "Polybar desktop bar for monitor " monitor ".")) (provision (list (symbol-append 'polybar- (string->symbol monitor)))) @@ -67,12 +77,15 @@ background. An initial @code{~/} is replaced with $HOME/.") (start #~(make-forkexec-constructor (list #$polybar-wrapper) #:environment-variables - (cons #$(string-append "POLYBAR_MONITOR=" monitor) - (default-environment-variables)))) + (cons* #$(string-append "POLYBAR_MONITOR=" monitor) + #$(string-append "POLYBAR_BATTERY=" (maybe-value battery-name "")) + #$(string-append "POLYBAR_AC_ADAPTER=" (maybe-value ac-adapter-name "")) + (default-environment-variables)))) (stop #~(make-kill-destructor)))) (define (desktop-layout-services config) - (match-record config (desktop-background monitors) + (match-record config + (desktop-background battery-name ac-adapter-name monitors) (cons* (shepherd-service (documentation "Set up X displays on login.") (provision '(xorg-setup)) @@ -97,7 +110,9 @@ background. An initial @code{~/} is replaced with $HOME/.") ;; xrandr works and sets it for both screens. (system* #$(file-append hsetroot "/bin/hsetroot") "-cover" (replace-home #$desktop-background))))) - (map (compose polybar-service home-monitor-configuration-name) monitors)))) + (map (compose (cut polybar-service <> battery-name ac-adapter-name) + home-monitor-configuration-name) + monitors)))) (define home-desktop-layout-service-type (service-type diff --git a/tw/services/files/polybar.ini b/tw/services/files/polybar.ini index 201c5131..54f6ff19 100644 --- a/tw/services/files/polybar.ini +++ b/tw/services/files/polybar.ini @@ -204,6 +204,9 @@ format-connected-prefix-foreground = ${colors.green} [module/battery] type = internal/battery +battery = ${env:POLYBAR_BATTERY} +adapter = ${env:POLYBAR_AC_ADAPTER} + low-at = 25 time-format = %-Hh%Mm format-discharging = -- cgit v1.2.3