summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors
diff options
context:
space:
mode:
authorslotThe <soliditsallgood@tuta.io>2019-10-14 12:23:08 +0200
committerslotThe <soliditsallgood@tuta.io>2019-10-14 12:55:31 +0200
commit4b53fb8a9319f286fcf944926caa5a6e142ad853 (patch)
tree69ea0794ba46903e304fe714d7829a9f41324577 /src/Xmobar/Plugins/Monitors
parent01cc232d3e1fee19a93d054b69dbb8590059e813 (diff)
downloadxmobar-4b53fb8a9319f286fcf944926caa5a6e142ad853.tar.gz
xmobar-4b53fb8a9319f286fcf944926caa5a6e142ad853.tar.bz2
Add VolumeStatus and ways to convert Float -> VolumeStatus, VolumeStatus -> [low,medium,high]String
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r--src/Xmobar/Plugins/Monitors/Volume.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Volume.hs b/src/Xmobar/Plugins/Monitors/Volume.hs
index fb158eb..d857402 100644
--- a/src/Xmobar/Plugins/Monitors/Volume.hs
+++ b/src/Xmobar/Plugins/Monitors/Volume.hs
@@ -65,6 +65,25 @@ defaultOpts = VolumeOpts
, highString = ""
}
+data VolumeStatus
+ = VolLow
+ | VolMedium
+ | VolHigh
+ | VolOff
+
+-- | Set the volume status according to user set thresholds and the current
+-- volume
+getVolStatus :: Float -- ^ Low volume threshold, in [0,100]
+ -> Float -- ^ High volume threshold, in [0,100]
+ -> Float -- ^ Current volume, in [0,1]
+ -> VolumeStatus
+getVolStatus lo hi val'
+ | val >= hi = VolHigh
+ | val >= lo = VolMedium
+ | otherwise = VolLow
+ where
+ val = val' * 100
+
options :: [OptDescr (VolumeOpts -> VolumeOpts)]
options =
[ Option "O" ["on"] (ReqArg (\x o -> o { onString = x }) "") ""
@@ -122,6 +141,14 @@ switchHelper opts cHelp strHelp = return $
formatSwitch :: VolumeOpts -> Bool -> Monitor String
formatSwitch opts True = switchHelper opts onColor onString
formatSwitch opts False = switchHelper opts offColor offString
+-- | Convert the current volume status into user defined strings
+volHelper :: VolumeStatus -> VolumeOpts -> String
+volHelper volStatus opts =
+ case volStatus of
+ VolHigh -> highString opts
+ VolMedium -> mediumString opts
+ VolLow -> lowString opts
+ VolOff -> ""
colorHelper :: Maybe String -> String
colorHelper = maybe "" (\c -> "<fc=" ++ c ++ ">")