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
This commit is contained in:
Daniel Barlow 2022-03-27 18:30:45 +01:00
parent 448a0317fb
commit 4c63c0338d
3 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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)]

View File

@ -8,3 +8,6 @@
box.hey {
font-size: 18px;
}
label {
margin: 0px 12px;
}