commit 4c63c0338db2a5310922916c6c7a4cf204380f99
parent 448a0317fb7cdbd8ed4929e2da5fb4b88d507e07
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 27 Mar 2022 18:30:45 +0100
smarter poll timeout interval
use highest common factor of requested intervals. this will still
suck if we have e.g. intervals of 333 and 1000, we could probably
refine it a bit. no interval over 3s cares about millisecond precision
Diffstat:
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/blinkenlicht/README.md b/blinkenlicht/README.md
@@ -44,8 +44,8 @@ Gtk will find it anyway. Magic.
* [X] set indicator background colour (use css for this?)
* [ ] update image/label widget instead of destroying
* [ ] allow height customisation
-* [ ] set poll interval based on indicators' requested intervals
-* [ ] allow indicator to change styles based on status
+* [X] set poll interval based on indicators' requested intervals
+* [X] allow indicator to change styles based on status
* [ ] add metrics for
- wireless connected/strength
- wwan connected/type (hspa, lte, etc)/signal
diff --git a/blinkenlicht/blinkenlicht.fnl b/blinkenlicht/blinkenlicht.fnl
@@ -139,18 +139,40 @@
(if indicator.interval
(> now (or (. update-times indicator) 0))))
+(fn hcf [a b]
+ (let [remainder (% a b)]
+ (if (= remainder 0)
+ b
+ (hcf b remainder))))
+
+(assert (= (hcf 198 360) 18))
+(assert (= (hcf 10 15) 5))
+
+(fn minimum-interval [intervals]
+ (accumulate [min (. intervals 1)
+ _ interval (ipairs intervals)]
+ (hcf min interval)))
+
+(assert (= (minimum-interval [ 350 1000 5000 ]) 50))
+
(fn run []
+ (var intervals [])
(each [_ bar (ipairs bars)]
(each [_ indicator (ipairs bar.indicators)]
+ (if indicator.interval
+ (table.insert intervals indicator.interval))
(each [_ file (ipairs indicator.inputs)]
(GLib.Source.attach
(gsource-for-file-input
file
#(or (indicator:update) true))))))
- (let [update-times {}]
+ (let [update-times {}
+ interval (minimum-interval intervals)]
+ (when (< interval 100)
+ (print (.. "required refresh interval is " interval "ms")))
(GLib.timeout_add
0
- 100
+ (minimum-interval intervals)
(fn []
(let [now (/ (GLib.get_monotonic_time) 1000)]
(each [_ bar (ipairs bars)]
diff --git a/blinkenlicht/licht.css b/blinkenlicht/licht.css
@@ -8,3 +8,6 @@
box.hey {
font-size: 18px;
}
+label {
+ margin: 0px 12px;
+}