summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorslotThe <soliditsallgood@tuta.io>2019-10-14 12:41:39 +0200
committerslotThe <soliditsallgood@tuta.io>2019-10-14 12:55:31 +0200
commit85f9d7c227cbfb761b8f578a522095ea675ad612 (patch)
tree9cf884f3e6729f7bc17e7ef4d8dcc12bd8698094
parent4b53fb8a9319f286fcf944926caa5a6e142ad853 (diff)
downloadxmobar-85f9d7c227cbfb761b8f578a522095ea675ad612.tar.gz
xmobar-85f9d7c227cbfb761b8f578a522095ea675ad612.tar.bz2
Add ability to display string based on volume percentage
-rw-r--r--src/Xmobar/Plugins/Monitors/Volume.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Volume.hs b/src/Xmobar/Plugins/Monitors/Volume.hs
index d857402..b9bdbc0 100644
--- a/src/Xmobar/Plugins/Monitors/Volume.hs
+++ b/src/Xmobar/Plugins/Monitors/Volume.hs
@@ -21,7 +21,7 @@ module Xmobar.Plugins.Monitors.Volume
, VolumeOpts
) where
-import Control.Applicative ((<$>))
+import Control.Applicative ( (<$>), liftA3 )
import Control.Monad ( liftM2, liftM3, mplus )
import Data.Traversable (sequenceA)
import Xmobar.Plugins.Monitors.Common
@@ -132,15 +132,18 @@ formatVolDStr ipat lo hi v =
switchHelper :: VolumeOpts
-> (VolumeOpts -> Maybe String)
-> (VolumeOpts -> String)
+ -> VolumeStatus
-> Monitor String
-switchHelper opts cHelp strHelp = return $
+switchHelper opts cHelp strHelp vs = return $
colorHelper (cHelp opts)
+ ++ volHelper vs opts
++ strHelp opts
++ maybe "" (const "</fc>") (cHelp opts)
-formatSwitch :: VolumeOpts -> Bool -> Monitor String
-formatSwitch opts True = switchHelper opts onColor onString
-formatSwitch opts False = switchHelper opts offColor offString
+formatSwitch :: VolumeOpts -> Bool -> VolumeStatus -> Monitor String
+formatSwitch opts True vs = switchHelper opts onColor onString vs
+formatSwitch opts False _ = switchHelper opts offColor offString VolOff
+
-- | Convert the current volume status into user defined strings
volHelper :: VolumeStatus -> VolumeOpts -> String
volHelper volStatus opts =
@@ -180,7 +183,11 @@ runVolumeWith opts mixerName controlName = do
b <- liftMonitor $ liftM3 formatVolBar lo hi val
v <- liftMonitor $ liftM3 formatVolVBar lo hi val
d <- getFormatDB opts db
- s <- getFormatSwitch opts sw
+ let volStat = liftA3 getVolStatus
+ (lowVolThresh opts)
+ (highVolThresh opts)
+ (liftA3 percent val lo hi) -- current volume in %
+ s <- getFormatSwitch opts sw volStat
ipat <- liftMonitor $ liftM3 (formatVolDStr $ volumeIconPattern opts) lo hi val
parseTemplate [p, b, v, d, s, ipat]
@@ -233,8 +240,9 @@ runVolumeWith opts mixerName controlName = do
getFormatDB _ Nothing = unavailable
getFormatDB opts' (Just d) = formatDb opts' d
- getFormatSwitch :: VolumeOpts -> Maybe Bool -> Monitor String
- getFormatSwitch _ Nothing = unavailable
- getFormatSwitch opts' (Just sw) = formatSwitch opts' sw
+ getFormatSwitch :: VolumeOpts -> Maybe Bool -> Maybe VolumeStatus -> Monitor String
+ getFormatSwitch _ Nothing _ = unavailable
+ getFormatSwitch _ _ Nothing = unavailable
+ getFormatSwitch opts' (Just sw) (Just vs) = formatSwitch opts' sw vs
unavailable = getConfigValue naString