aboutsummaryrefslogtreecommitdiffstats
path: root/mowedline
diff options
context:
space:
mode:
authorGravatar Tom Willemse2017-03-05 22:15:34 -0800
committerGravatar Tom Willemse2017-03-05 22:15:34 -0800
commitcc739ef47192f6bfd930ae5b3f9cfb8b96b34f10 (patch)
tree975d12399a3eaab8c233f85b3c9da1642494e30f /mowedline
parenta6429be2a36e17ba6aa6e8119bc5a1e34c7bfdcd (diff)
downloadnew-dotfiles-cc739ef47192f6bfd930ae5b3f9cfb8b96b34f10.tar.gz
new-dotfiles-cc739ef47192f6bfd930ae5b3f9cfb8b96b34f10.zip
Add battery widget to mowedline
Diffstat (limited to 'mowedline')
-rw-r--r--mowedline/.config/mowedline/init.org43
1 files changed, 43 insertions, 0 deletions
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