Add battery widget to mowedline
This commit is contained in:
parent
a6429be2a3
commit
cc739ef471
1 changed files with 43 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue