diff options
Diffstat (limited to 'src/Xmobar')
| -rw-r--r-- | src/Xmobar/Plugins/Monitors/Volume.hs | 30 | 
1 files changed, 25 insertions, 5 deletions
| diff --git a/src/Xmobar/Plugins/Monitors/Volume.hs b/src/Xmobar/Plugins/Monitors/Volume.hs index de07aa6..a52261f 100644 --- a/src/Xmobar/Plugins/Monitors/Volume.hs +++ b/src/Xmobar/Plugins/Monitors/Volume.hs @@ -23,16 +23,26 @@ module Xmobar.Plugins.Monitors.Volume  import Control.Applicative ( (<$>), liftA3 )  import Control.Monad ( liftM2, liftM3, mplus ) +import Data.Maybe (fromMaybe)  import Data.Traversable (sequenceA)  import Xmobar.Plugins.Monitors.Common  import Sound.ALSA.Mixer  import qualified Sound.ALSA.Exception as AE  import System.Console.GetOpt -volumeConfig :: IO MConfig -volumeConfig = mkMConfig "Vol: <volume>% <status>" -                         ["volume", "volumebar", "volumevbar", "dB","status", "volumeipat"] +volumeConfig :: IO MConfig +volumeConfig = +    mkMConfig +        "Vol: <volume>% <status>" +        [ "volume" +        , "volumebar" +        , "volumevbar" +        , "dB" +        , "status" +        , "volumeipat" +        , "volumestatus" +        ]  data VolumeOpts = VolumeOpts      { onString :: String @@ -135,7 +145,7 @@ switchHelper opts cHelp strHelp vs = return $      ++ maybe "" (const "</fc>") (cHelp opts)  formatSwitch :: VolumeOpts -> Bool -> VolumeStatus -> Monitor String -formatSwitch opts True vs = switchHelper opts onColor onString vs +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 @@ -183,7 +193,13 @@ runVolumeWith opts mixerName controlName = do                           (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] + +    -- Volume and status in one. +    let vs = if isVolOff sw +            then offString opts -- User defined off string +            else s ++ p         -- Status string, current volume in % + +    parseTemplate [p, b, v, d, s, ipat, vs]    where @@ -239,4 +255,8 @@ runVolumeWith opts mixerName controlName = do      getFormatSwitch _ _ Nothing = unavailable      getFormatSwitch opts' (Just sw) (Just vs) = formatSwitch opts' sw vs +    -- | Determine whether the volume is off based on the value of 'sw' from +    -- 'runVolumeWith'. +    isVolOff = not . fromMaybe False +      unavailable = getConfigValue naString | 
