summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2013-05-26 14:20:51 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2013-05-26 14:20:51 +0200
commit12424d6eda711947eff7fad4f1429627b780fe01 (patch)
treefeed0b91141d2beb737476c490d72be30f0b04ff /src
parent430b8d21493092690a3c27c8c285202312f776bd (diff)
downloadxmobar-12424d6eda711947eff7fad4f1429627b780fe01.tar.gz
xmobar-12424d6eda711947eff7fad4f1429627b780fe01.tar.bz2
New idle status for battery monitor
Diffstat (limited to 'src')
-rw-r--r--src/Plugins/Monitors/Batt.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index dc18c54..eddec06 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -25,6 +25,7 @@ import System.Console.GetOpt
data BattOpts = BattOpts
{ onString :: String
, offString :: String
+ , idleString :: String
, posColor :: Maybe String
, lowWColor :: Maybe String
, mediumWColor :: Maybe String
@@ -39,6 +40,7 @@ defaultOpts :: BattOpts
defaultOpts = BattOpts
{ onString = "On"
, offString = "Off"
+ , idleString = "On"
, posColor = Nothing
, lowWColor = Nothing
, mediumWColor = Nothing
@@ -53,6 +55,7 @@ options :: [OptDescr (BattOpts -> BattOpts)]
options =
[ Option "O" ["on"] (ReqArg (\x o -> o { onString = x }) "") ""
, Option "o" ["off"] (ReqArg (\x o -> o { offString = x }) "") ""
+ , Option "i" ["idle"] (ReqArg (\x o -> o { idleString = x }) "") ""
, Option "p" ["positive"] (ReqArg (\x o -> o { posColor = Just x }) "") ""
, Option "l" ["low"] (ReqArg (\x o -> o { lowWColor = Just x }) "") ""
, Option "m" ["medium"] (ReqArg (\x o -> o { mediumWColor = Just x }) "") ""
@@ -140,10 +143,12 @@ 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)
- time = if watts == 0 then 0 else sum $ map time' bats
- mwatts = if watts == 0 then 1 else sign * watts
+ idle = watts == 0
+ time = if idle then 0 else sum $ map time' bats
+ mwatts = if idle then 1 else sign * watts
time' b = (if ac then full b - now b else now b) / mwatts
- acstr = if ac then onString opts else offString opts
+ acstr = if idle then idleString opts else
+ if ac then onString opts else offString opts
return $ if isNaN left then NA else Result left watts time acstr
runBatt :: [String] -> Monitor String