summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Volume.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/Monitors/Volume.hs')
-rw-r--r--src/Plugins/Monitors/Volume.hs54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs
index f3d0f4c..8c39b9f 100644
--- a/src/Plugins/Monitors/Volume.hs
+++ b/src/Plugins/Monitors/Volume.hs
@@ -1,7 +1,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Volume
--- Copyright : (c) 2011 Thomas Tuegel
+-- Copyright : (c) 2011, 2013 Thomas Tuegel
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
@@ -24,7 +24,7 @@ import System.Console.GetOpt
volumeConfig :: IO MConfig
volumeConfig = mkMConfig "Vol: <volume>% <status>"
- ["volume", "volumebar", "dB","status"]
+ ["volume", "volumebar", "volumevbar", "dB","status", "volumeipat"]
data VolumeOpts = VolumeOpts
@@ -34,6 +34,7 @@ data VolumeOpts = VolumeOpts
, offColor :: Maybe String
, highDbThresh :: Float
, lowDbThresh :: Float
+ , volumeIconPattern :: Maybe IconPattern
}
defaultOpts :: VolumeOpts
@@ -44,6 +45,7 @@ defaultOpts = VolumeOpts
, offColor = Just "red"
, highDbThresh = -5.0
, lowDbThresh = -30.0
+ , volumeIconPattern = Nothing
}
options :: [OptDescr (VolumeOpts -> VolumeOpts)]
@@ -54,6 +56,8 @@ options =
, Option "" ["highd"] (ReqArg (\x o -> o { highDbThresh = read x }) "") ""
, Option "C" ["onc"] (ReqArg (\x o -> o { onColor = Just x }) "") ""
, Option "c" ["offc"] (ReqArg (\x o -> o { offColor = Just x }) "") ""
+ , Option "" ["volume-icon-pattern"] (ReqArg (\x o ->
+ o { volumeIconPattern = Just $ parseIconPattern x }) "") ""
]
parseOpts :: [String] -> IO VolumeOpts
@@ -76,6 +80,14 @@ formatVolBar :: Integer -> Integer -> Integer -> Monitor String
formatVolBar lo hi v =
showPercentBar (100 * x) x where x = percent v lo hi
+formatVolVBar :: Integer -> Integer -> Integer -> Monitor String
+formatVolVBar lo hi v =
+ showVerticalBar (100 * x) x where x = percent v lo hi
+
+formatVolDStr :: Maybe IconPattern -> Integer -> Integer -> Integer -> Monitor String
+formatVolDStr ipat lo hi v =
+ showIconPattern ipat $ percent v lo hi
+
switchHelper :: VolumeOpts
-> (VolumeOpts -> Maybe String)
-> (VolumeOpts -> String)
@@ -110,16 +122,20 @@ formatDb opts dbi = do
runVolume :: String -> String -> [String] -> Monitor String
runVolume mixerName controlName argv = do
opts <- io $ parseOpts argv
- control <- io $ getControlByName mixerName controlName
- (lo, hi) <- io . liftMaybe $ getRange <$> volumeControl control
- val <- getVal $ volumeControl control
- db <- getDB $ volumeControl control
- sw <- getSw $ switchControl control
+ (lo, hi, val, db, sw) <- io $ withMixer mixerName $ \mixer -> do
+ control <- getControlByName mixer controlName
+ (lo, hi) <- liftMaybe $ getRange <$> volumeControl control
+ val <- getVal $ volumeControl control
+ db <- getDB $ volumeControl control
+ sw <- getSw $ switchControl control
+ return (lo, hi, val, db, sw)
p <- liftMonitor $ liftM3 formatVol lo hi val
b <- liftMonitor $ liftM3 formatVolBar lo hi val
+ v <- liftMonitor $ liftM3 formatVolVBar lo hi val
d <- getFormatDB opts db
s <- getFormatSwitch opts sw
- parseTemplate [p, b, d, s]
+ ipat <- liftMonitor $ liftM3 (formatVolDStr $ volumeIconPattern opts) lo hi val
+ parseTemplate [p, b, v, d, s, ipat]
where
@@ -135,28 +151,28 @@ runVolume mixerName controlName argv = do
liftMaybe = fmap (liftM2 (,) (fmap fst) (fmap snd)) . sequenceA
liftMonitor :: Maybe (Monitor String) -> Monitor String
- liftMonitor Nothing = return unavailable
+ liftMonitor Nothing = unavailable
liftMonitor (Just m) = m
- getDB :: Maybe Volume -> Monitor (Maybe Integer)
+ getDB :: Maybe Volume -> IO (Maybe Integer)
getDB Nothing = return Nothing
- getDB (Just v) = io $ AE.catch (getChannel FrontLeft $ dB v)
- (const $ return $ Just 0)
+ getDB (Just v) = AE.catch (getChannel FrontLeft $ dB v)
+ (const $ return $ Just 0)
- getVal :: Maybe Volume -> Monitor (Maybe Integer)
+ getVal :: Maybe Volume -> IO (Maybe Integer)
getVal Nothing = return Nothing
- getVal (Just v) = io $ getChannel FrontLeft $ value v
+ getVal (Just v) = getChannel FrontLeft $ value v
- getSw :: Maybe Switch -> Monitor (Maybe Bool)
+ getSw :: Maybe Switch -> IO (Maybe Bool)
getSw Nothing = return Nothing
- getSw (Just s) = io $ getChannel FrontLeft s
+ getSw (Just s) = getChannel FrontLeft s
getFormatDB :: VolumeOpts -> Maybe Integer -> Monitor String
- getFormatDB _ Nothing = return unavailable
+ getFormatDB _ Nothing = unavailable
getFormatDB opts (Just d) = formatDb opts d
getFormatSwitch :: VolumeOpts -> Maybe Bool -> Monitor String
- getFormatSwitch _ Nothing = return unavailable
+ getFormatSwitch _ Nothing = unavailable
getFormatSwitch opts (Just sw) = formatSwitch opts sw
- unavailable = "N/A"
+ unavailable = getConfigValue naString