From cc739ef47192f6bfd930ae5b3f9cfb8b96b34f10 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 5 Mar 2017 22:15:34 -0800 Subject: Add battery widget to mowedline --- mowedline/.config/mowedline/init.org | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'mowedline/.config') diff --git a/mowedline/.config/mowedline/init.org b/mowedline/.config/mowedline/init.org index f31be02..c7854b6 100644 --- a/mowedline/.config/mowedline/init.org +++ b/mowedline/.config/mowedline/init.org @@ -121,6 +121,48 @@ Define a convenience function to add a Font Awesome icon to a widget. #:format (compose text-maybe-pad-left (add-fa-icon "")))) #+END_SRC +* Battery + + I'm on a laptop and seeing the state of my battery is pretty important. + + #+BEGIN_SRC scheme + (define (clamp x low high) + (max low (min high x))) + + (define (source:sys) + (list + (/ (clamp (with-input-from-file + "/sys/class/power_supply/BAT0/capacity" + read) + 0 100) + 100.0) + (with-input-from-file + "/sys/class/power_supply/BAT0/status" + read))) + + (define (widget:battery) + (widget:text + font: "FontAwesome-10" + format: + (compose + text-maybe-pad-left + (match-lambda + ((capacity status) + (list + (list-ref + '((color "#a85454" "") + (color "#a88654" "") + (color "#8d995c" "") + (color "#65a854" "") + (color "#5476a8" "")) + (inexact->exact + (round (* 4 capacity)))) + (if (eq? 'Charging status) " " ""))) + (val val))) + init: (lambda (widget) + (widget-update-at-interval widget 5 source:sys)))) + #+END_SRC + * The window Create a mowedline window, put it at the bottom. @@ -154,5 +196,6 @@ Define a convenience function to add a Font Awesome icon to a widget. clipboard-widget (widget:text #:name "irc" #:format (lambda (text) (text-maybe-pad-left (with-input-from-string text read)))) email-widget + (widget:battery) (widget:clock #:format text-maybe-pad-left)) #+END_SRC -- cgit v1.2.3-54-g00ecf