summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2015-08-18 02:58:27 +0200
committerjao <jao@gnu.org>2015-08-18 02:58:27 +0200
commitaee4dad69764015aa1578f43d44dd72382f11de6 (patch)
treedfd55d3ca9c0a2cb9645f0487c3a969ae0830963 /src/Plugins
parent1b4660954574fa06ffe89b2be3865f6e9072308f (diff)
downloadxmobar-aee4dad69764015aa1578f43d44dd72382f11de6.tar.gz
xmobar-aee4dad69764015aa1578f43d44dd72382f11de6.tar.bz2
Batt: protecting against charge_now > charge_full
(yes, it's happening on an xps with kernel 4.1.5)
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors/Batt.hs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index f7b31e4..61961cb 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -1,7 +1,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Batt
--- Copyright : (c) 2010, 2011, 2012, 2013 Jose A Ortega
+-- Copyright : (c) 2010, 2011, 2012, 2013, 2015 Jose A Ortega
-- (c) 2010 Andrea Rossato, Petr Rockai
-- License : BSD-style (see LICENSE)
--
@@ -160,11 +160,10 @@ readBatteries opts bfs =
ft = sum (map full bats)
left = if ft > 0 then sum (map now bats) / ft else 0
watts = sign * sum (map power bats)
- idle = watts == 0
- time = if idle then 0 else sum $ map time' bats
- mwatts = if idle then 1 else sign * watts
+ time = if watts == 0 then 0 else max 0 (sum $ map time' bats)
+ mwatts = if watts == 0 then 1 else sign * watts
time' b = (if ac then full b - now b else now b) / mwatts
- acst | idle = Idle
+ acst | time == 0 = Idle
| ac = Charging
| otherwise = Discharging
return $ if isNaN left then NA else Result left watts time acst