Add battery widget to mowedline

This commit is contained in:
Tom Willemse 2017-03-05 22:15:34 -08:00
parent a6429be2a3
commit cc739ef471

View file

@ -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 "")))) #:format (compose text-maybe-pad-left (add-fa-icon ""))))
#+END_SRC #+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 * The window
Create a mowedline window, put it at the bottom. 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 clipboard-widget
(widget:text #:name "irc" #:format (lambda (text) (text-maybe-pad-left (with-input-from-string text read)))) (widget:text #:name "irc" #:format (lambda (text) (text-maybe-pad-left (with-input-from-string text read))))
email-widget email-widget
(widget:battery)
(widget:clock #:format text-maybe-pad-left)) (widget:clock #:format text-maybe-pad-left))
#+END_SRC #+END_SRC